Skip to content

Commit

Permalink
fix(src/materials): Convert to ES6.
Browse files Browse the repository at this point in the history
  • Loading branch information
linbingquan committed Feb 17, 2021
1 parent 8000053 commit 5c852a2
Show file tree
Hide file tree
Showing 18 changed files with 837 additions and 832 deletions.
45 changes: 23 additions & 22 deletions src/materials/LineBasicMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,45 @@ import { Color } from '../math/Color.js';
* }
*/

function LineBasicMaterial( parameters ) {
class LineBasicMaterial extends Material {

Material.call( this );
constructor( parameters ) {

this.type = 'LineBasicMaterial';
super();

this.color = new Color( 0xffffff );
Object.defineProperty( this, 'isLineBasicMaterial', { value: true } );

this.linewidth = 1;
this.linecap = 'round';
this.linejoin = 'round';
this.type = 'LineBasicMaterial';

this.morphTargets = false;
this.color = new Color( 0xffffff );

this.setValues( parameters );
this.linewidth = 1;
this.linecap = 'round';
this.linejoin = 'round';

}
this.morphTargets = false;

this.setValues( parameters );

LineBasicMaterial.prototype = Object.create( Material.prototype );
LineBasicMaterial.prototype.constructor = LineBasicMaterial;
}

LineBasicMaterial.prototype.isLineBasicMaterial = true;

LineBasicMaterial.prototype.copy = function ( source ) {
copy( source ) {

Material.prototype.copy.call( this, source );
Material.prototype.copy.call( this, source );

this.color.copy( source.color );
this.color.copy( source.color );

this.linewidth = source.linewidth;
this.linecap = source.linecap;
this.linejoin = source.linejoin;
this.linewidth = source.linewidth;
this.linecap = source.linecap;
this.linejoin = source.linejoin;

this.morphTargets = source.morphTargets;
this.morphTargets = source.morphTargets;

return this;
return this;

};
}

}

export { LineBasicMaterial };
36 changes: 18 additions & 18 deletions src/materials/LineDashedMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,36 @@ import { LineBasicMaterial } from './LineBasicMaterial.js';
* }
*/

function LineDashedMaterial( parameters ) {
class LineDashedMaterial extends LineBasicMaterial {

LineBasicMaterial.call( this );
constructor( parameters ) {

this.type = 'LineDashedMaterial';
super();

this.scale = 1;
this.dashSize = 3;
this.gapSize = 1;
Object.defineProperty( this, 'isLineDashedMaterial', { value: true } );

this.setValues( parameters );
this.type = 'LineDashedMaterial';

}
this.scale = 1;
this.dashSize = 3;
this.gapSize = 1;

LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
LineDashedMaterial.prototype.constructor = LineDashedMaterial;
this.setValues( parameters );

LineDashedMaterial.prototype.isLineDashedMaterial = true;
}

LineDashedMaterial.prototype.copy = function ( source ) {
copy( source ) {

LineBasicMaterial.prototype.copy.call( this, source );
super.copy( source );

this.scale = source.scale;
this.dashSize = source.dashSize;
this.gapSize = source.gapSize;
this.scale = source.scale;
this.dashSize = source.dashSize;
this.gapSize = source.gapSize;

return this;
return this;

};
}

}

export { LineDashedMaterial };
138 changes: 67 additions & 71 deletions src/materials/Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,88 +4,94 @@ import { 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 ++ } );
Object.defineProperty( this, 'isMaterial', { value: true } );

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.flatShading = false;
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.premultipliedAlpha = false;
this.polygonOffset = false;
this.polygonOffsetFactor = 0;
this.polygonOffsetUnits = 0;

this.visible = true;
this.dithering = false;

this.toneMapped = true;
this.alphaTest = 0;
this.premultipliedAlpha = false;

this.userData = {};
this.visible = true;

this.version = 0;
this.toneMapped = true;

}
this.userData = {};

this.version = 0;

Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
}

constructor: Material,
set needsUpdate( value ) {

if ( value === true ) this.version ++;

isMaterial: true,
}

onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
onBeforeCompile( /* shaderobject, renderer */ ) {}

customProgramCacheKey: function () {
customProgramCacheKey() {

return this.onBeforeCompile.toString();

},
}

setValues: function ( values ) {
setValues( values ) {

if ( values === undefined ) return;

Expand Down Expand Up @@ -134,9 +140,9 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

}

},
}

toJSON: function ( meta ) {
toJSON( meta ) {

const isRoot = ( meta === undefined || typeof meta === 'string' );

Expand Down Expand Up @@ -347,15 +353,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;

Expand Down Expand Up @@ -431,24 +437,14 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ),

return this;

},

dispose: function () {

this.dispatchEvent( { type: 'dispose' } );

}

} );

Object.defineProperty( Material.prototype, 'needsUpdate', {
dispose() {

set: function ( value ) {

if ( value === true ) this.version ++;
this.dispatchEvent( { type: 'dispose' } );

}

} );
}

export { Material };
Loading

0 comments on commit 5c852a2

Please sign in to comment.