123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- import clone from "../Core/clone.js";
- import combine from "../Core/combine.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import BlendingState from "./BlendingState.js";
- import CullFace from "./CullFace.js";
- function Appearance(options) {
- options = defaultValue(options, defaultValue.EMPTY_OBJECT);
-
- this.material = options.material;
-
- this.translucent = defaultValue(options.translucent, true);
- this._vertexShaderSource = options.vertexShaderSource;
- this._fragmentShaderSource = options.fragmentShaderSource;
- this._renderState = options.renderState;
- this._closed = defaultValue(options.closed, false);
- }
- Object.defineProperties(Appearance.prototype, {
-
- vertexShaderSource: {
- get: function () {
- return this._vertexShaderSource;
- },
- },
-
- fragmentShaderSource: {
- get: function () {
- return this._fragmentShaderSource;
- },
- },
-
- renderState: {
- get: function () {
- return this._renderState;
- },
- },
-
- closed: {
- get: function () {
- return this._closed;
- },
- },
- });
- Appearance.prototype.getFragmentShaderSource = function () {
- var parts = [];
- if (this.flat) {
- parts.push("#define FLAT");
- }
- if (this.faceForward) {
- parts.push("#define FACE_FORWARD");
- }
- if (defined(this.material)) {
- parts.push(this.material.shaderSource);
- }
- parts.push(this.fragmentShaderSource);
- return parts.join("\n");
- };
- Appearance.prototype.isTranslucent = function () {
- return (
- (defined(this.material) && this.material.isTranslucent()) ||
- (!defined(this.material) && this.translucent)
- );
- };
- Appearance.prototype.getRenderState = function () {
- var translucent = this.isTranslucent();
- var rs = clone(this.renderState, false);
- if (translucent) {
- rs.depthMask = false;
- rs.blending = BlendingState.ALPHA_BLEND;
- } else {
- rs.depthMask = true;
- }
- return rs;
- };
- Appearance.getDefaultRenderState = function (translucent, closed, existing) {
- var rs = {
- depthTest: {
- enabled: true,
- },
- };
- if (translucent) {
- rs.depthMask = false;
- rs.blending = BlendingState.ALPHA_BLEND;
- }
- if (closed) {
- rs.cull = {
- enabled: true,
- face: CullFace.BACK,
- };
- }
- if (defined(existing)) {
- rs = combine(existing, rs, true);
- }
- return rs;
- };
- export default Appearance;
|