未验证 提交 65fc6489 编写于 作者: M Michael Herzog 提交者: GitHub

Material: Convert to class syntax. (#21804)

上级 b13eccc8
......@@ -4,91 +4,89 @@ import * as MathUtils from '../math/MathUtils.js';
let materialId = 0;
function Material() {
class Material extends EventDispatcher {
Object.defineProperty( this, 'id', { value: materialId ++ } );
constructor() {
this.uuid = MathUtils.generateUUID();
super();
this.name = '';
this.type = 'Material';
Object.defineProperty( this, 'id', { value: materialId ++ } );
this.fog = true;
this.uuid = MathUtils.generateUUID();
this.blending = NormalBlending;
this.side = FrontSide;
this.vertexColors = false;
this.name = '';
this.type = 'Material';
this.opacity = 1;
this.transparent = false;
this.fog = true;
this.blendSrc = SrcAlphaFactor;
this.blendDst = OneMinusSrcAlphaFactor;
this.blendEquation = AddEquation;
this.blendSrcAlpha = null;
this.blendDstAlpha = null;
this.blendEquationAlpha = null;
this.blending = NormalBlending;
this.side = FrontSide;
this.vertexColors = false;
this.depthFunc = LessEqualDepth;
this.depthTest = true;
this.depthWrite = true;
this.opacity = 1;
this.transparent = false;
this.stencilWriteMask = 0xff;
this.stencilFunc = AlwaysStencilFunc;
this.stencilRef = 0;
this.stencilFuncMask = 0xff;
this.stencilFail = KeepStencilOp;
this.stencilZFail = KeepStencilOp;
this.stencilZPass = KeepStencilOp;
this.stencilWrite = false;
this.blendSrc = SrcAlphaFactor;
this.blendDst = OneMinusSrcAlphaFactor;
this.blendEquation = AddEquation;
this.blendSrcAlpha = null;
this.blendDstAlpha = null;
this.blendEquationAlpha = null;
this.clippingPlanes = null;
this.clipIntersection = false;
this.clipShadows = false;
this.depthFunc = LessEqualDepth;
this.depthTest = true;
this.depthWrite = true;
this.shadowSide = null;
this.stencilWriteMask = 0xff;
this.stencilFunc = AlwaysStencilFunc;
this.stencilRef = 0;
this.stencilFuncMask = 0xff;
this.stencilFail = KeepStencilOp;
this.stencilZFail = KeepStencilOp;
this.stencilZPass = KeepStencilOp;
this.stencilWrite = false;
this.colorWrite = true;
this.clippingPlanes = null;
this.clipIntersection = false;
this.clipShadows = false;
this.precision = null; // override the renderer's default precision for this material
this.shadowSide = null;
this.polygonOffset = false;
this.polygonOffsetFactor = 0;
this.polygonOffsetUnits = 0;
this.colorWrite = true;
this.dithering = false;
this.precision = null; // override the renderer's default precision for this material
this.alphaTest = 0;
this.alphaToCoverage = false;
this.premultipliedAlpha = false;
this.polygonOffset = false;
this.polygonOffsetFactor = 0;
this.polygonOffsetUnits = 0;
this.visible = true;
this.dithering = false;
this.toneMapped = true;
this.alphaTest = 0;
this.alphaToCoverage = false;
this.premultipliedAlpha = false;
this.userData = {};
this.visible = true;
this.version = 0;
this.toneMapped = true;
}
Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
this.userData = {};
constructor: Material,
this.version = 0;
isMaterial: true,
}
onBuild: function ( /* shaderobject, renderer */ ) {},
onBuild( /* shaderobject, renderer */ ) {}
onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
onBeforeCompile( /* shaderobject, renderer */ ) {}
customProgramCacheKey: function () {
customProgramCacheKey() {
return this.onBeforeCompile.toString();
},
}
setValues: function ( values ) {
setValues( values ) {
if ( values === undefined ) return;
......@@ -137,9 +135,9 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
}
},
}
toJSON: function ( meta ) {
toJSON( meta ) {
const isRoot = ( meta === undefined || typeof meta === 'string' );
......@@ -353,15 +351,15 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
return data;
},
}
clone: function () {
clone() {
return new this.constructor().copy( this );
},
}
copy: function ( source ) {
copy( source ) {
this.name = source.name;
......@@ -438,24 +436,22 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
return this;
},
}
dispose: function () {
dispose() {
this.dispatchEvent( { type: 'dispose' } );
}
} );
Object.defineProperty( Material.prototype, 'needsUpdate', {
set: function ( value ) {
set needsUpdate( value ) {
if ( value === true ) this.version ++;
}
} );
}
Material.prototype.isMaterial = true;
export { Material };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册