diff --git a/examples/jsm/lines/LineMaterial.js b/examples/jsm/lines/LineMaterial.js index ec40f9400f32b2..e9672a89630d2a 100644 --- a/examples/jsm/lines/LineMaterial.js +++ b/examples/jsm/lines/LineMaterial.js @@ -247,178 +247,179 @@ ShaderLib[ 'line' ] = { ` }; -var LineMaterial = function ( parameters ) { +class LineMaterial extends ShaderMaterial { - ShaderMaterial.call( this, { + constructor( parameters ) { - type: 'LineMaterial', + super( { - uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ), + type: 'LineMaterial', - vertexShader: ShaderLib[ 'line' ].vertexShader, - fragmentShader: ShaderLib[ 'line' ].fragmentShader, + uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ), - clipping: true // required for clipping support + vertexShader: ShaderLib[ 'line' ].vertexShader, + fragmentShader: ShaderLib[ 'line' ].fragmentShader, - } ); + clipping: true // required for clipping support - this.dashed = false; + } ); - Object.defineProperties( this, { + this.dashed = false; - color: { + Object.defineProperty( this, 'isLineMaterial', { value: true } ); - enumerable: true, + Object.defineProperties( this, { - get: function () { + color: { - return this.uniforms.diffuse.value; + enumerable: true, - }, - - set: function ( value ) { + get: function () { - this.uniforms.diffuse.value = value; - - } + return this.uniforms.diffuse.value; - }, + }, - linewidth: { + set: function ( value ) { - enumerable: true, + this.uniforms.diffuse.value = value; - get: function () { - - return this.uniforms.linewidth.value; + } }, - set: function ( value ) { + linewidth: { - this.uniforms.linewidth.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.linewidth.value; - dashScale: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.linewidth.value = value; - return this.uniforms.dashScale.value; + } }, - set: function ( value ) { + dashScale: { - this.uniforms.dashScale.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.dashScale.value; - dashSize: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.dashScale.value = value; - return this.uniforms.dashSize.value; + } }, - set: function ( value ) { + dashSize: { - this.uniforms.dashSize.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.dashSize.value; - dashOffset: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.dashSize.value = value; - return this.uniforms.dashOffset.value; + } }, - set: function ( value ) { + dashOffset: { - this.uniforms.dashOffset.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.dashOffset.value; - gapSize: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.dashOffset.value = value; - return this.uniforms.gapSize.value; + } }, - set: function ( value ) { + gapSize: { - this.uniforms.gapSize.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.gapSize.value; - opacity: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.gapSize.value = value; - return this.uniforms.opacity.value; + } }, - set: function ( value ) { + opacity: { - this.uniforms.opacity.value = value; + enumerable: true, - } + get: function () { - }, + return this.uniforms.opacity.value; - resolution: { + }, - enumerable: true, + set: function ( value ) { - get: function () { + this.uniforms.opacity.value = value; - return this.uniforms.resolution.value; + } }, - set: function ( value ) { + resolution: { - this.uniforms.resolution.value.copy( value ); + enumerable: true, - } + get: function () { - } + return this.uniforms.resolution.value; - } ); + }, - this.setValues( parameters ); + set: function ( value ) { -}; + this.uniforms.resolution.value.copy( value ); + + } + + } + + } ); + + this.setValues( parameters ); -LineMaterial.prototype = Object.create( ShaderMaterial.prototype ); -LineMaterial.prototype.constructor = LineMaterial; + } -LineMaterial.prototype.isLineMaterial = true; +} export { LineMaterial }; diff --git a/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js b/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js index 90f537ecbcc6f6..9e3839b0b1233a 100644 --- a/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +++ b/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js @@ -2,18 +2,19 @@ import { MeshStandardNode } from './nodes/MeshStandardNode.js'; import { NodeMaterial } from './NodeMaterial.js'; import { NodeUtils } from '../core/NodeUtils.js'; -function MeshStandardNodeMaterial() { +class MeshStandardNodeMaterial extends NodeMaterial { - var node = new MeshStandardNode(); + constructor() { - NodeMaterial.call( this, node, node ); + var node = new MeshStandardNode(); - this.type = 'MeshStandardNodeMaterial'; + super( node, node ); -} + this.type = 'MeshStandardNodeMaterial'; + + } -MeshStandardNodeMaterial.prototype = Object.create( NodeMaterial.prototype ); -MeshStandardNodeMaterial.prototype.constructor = MeshStandardNodeMaterial; +} NodeUtils.addShortcuts( MeshStandardNodeMaterial.prototype, 'properties', [ 'color', diff --git a/examples/jsm/nodes/materials/NodeMaterial.js b/examples/jsm/nodes/materials/NodeMaterial.js index bf5e1289e5899d..aeff98db082c10 100644 --- a/examples/jsm/nodes/materials/NodeMaterial.js +++ b/examples/jsm/nodes/materials/NodeMaterial.js @@ -11,219 +11,209 @@ import { ColorNode } from '../inputs/ColorNode.js'; import { PositionNode } from '../accessors/PositionNode.js'; import { RawNode } from './nodes/RawNode.js'; -function NodeMaterial( vertex, fragment ) { +class NodeMaterial extends ShaderMaterial { - ShaderMaterial.call( this ); + constructor( vertex, fragment ) { - this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) ); - this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) ); + super(); - this.updaters = []; + Object.defineProperty( this, 'isNodeMaterial', { value: true } ); -} - -NodeMaterial.prototype = Object.create( ShaderMaterial.prototype ); -NodeMaterial.prototype.constructor = NodeMaterial; -NodeMaterial.prototype.type = 'NodeMaterial'; - -NodeMaterial.prototype.isNodeMaterial = true; - -Object.defineProperties( NodeMaterial.prototype, { + this.vertex = vertex || new RawNode( new PositionNode( PositionNode.PROJECTION ) ); + this.fragment = fragment || new RawNode( new ColorNode( 0xFF0000 ) ); - properties: { + this.updaters = []; - get: function () { + this.type = 'NodeMaterial'; - return this.fragment.properties; - - } + } - }, + get properties() { - needsUpdate: { + return this.fragment.properties; - set: function ( value ) { + } - if ( value === true ) this.version ++; - this.needsCompile = value; + set needsUpdate( value ) { - }, + if ( value === true ) this.version ++; + this.needsCompile = value; - get: function () { + } - return this.needsCompile; + get needsUpdate() { - } + return this.needsCompile; } -} ); + onBeforeCompile( shader, renderer ) { -NodeMaterial.prototype.onBeforeCompile = function ( shader, renderer ) { + this.build( { renderer: renderer } ); - this.build( { renderer: renderer } ); + shader.defines = this.defines; + shader.uniforms = this.uniforms; + shader.vertexShader = this.vertexShader; + shader.fragmentShader = this.fragmentShader; - shader.defines = this.defines; - shader.uniforms = this.uniforms; - shader.vertexShader = this.vertexShader; - shader.fragmentShader = this.fragmentShader; + shader.extensionDerivatives = ( this.extensions.derivatives === true ); + shader.extensionFragDepth = ( this.extensions.fragDepth === true ); + shader.extensionDrawBuffers = ( this.extensions.drawBuffers === true ); + shader.extensionShaderTextureLOD = ( this.extensions.shaderTextureLOD === true ); - shader.extensionDerivatives = ( this.extensions.derivatives === true ); - shader.extensionFragDepth = ( this.extensions.fragDepth === true ); - shader.extensionDrawBuffers = ( this.extensions.drawBuffers === true ); - shader.extensionShaderTextureLOD = ( this.extensions.shaderTextureLOD === true ); + } -}; + customProgramCacheKey() { -NodeMaterial.prototype.customProgramCacheKey = function () { + var hash = this.getHash(); - var hash = this.getHash(); + return hash; - return hash; + } -}; + getHash() { -NodeMaterial.prototype.getHash = function () { + var hash = '{'; - var hash = '{'; + hash += '"vertex":' + this.vertex.getHash() + ','; + hash += '"fragment":' + this.fragment.getHash(); - hash += '"vertex":' + this.vertex.getHash() + ','; - hash += '"fragment":' + this.fragment.getHash(); + hash += '}'; - hash += '}'; + return hash; - return hash; + } -}; + updateFrame( frame ) { -NodeMaterial.prototype.updateFrame = function ( frame ) { + for ( var i = 0; i < this.updaters.length; ++ i ) { - for ( var i = 0; i < this.updaters.length; ++ i ) { + frame.updateNode( this.updaters[ i ] ); - frame.updateNode( this.updaters[ i ] ); + } } -}; + build( params ) { -NodeMaterial.prototype.build = function ( params ) { + params = params || {}; - params = params || {}; + var builder = params.builder || new NodeBuilder(); - var builder = params.builder || new NodeBuilder(); + builder.setMaterial( this, params.renderer ); + builder.build( this.vertex, this.fragment ); - builder.setMaterial( this, params.renderer ); - builder.build( this.vertex, this.fragment ); + this.vertexShader = builder.getCode( 'vertex' ); + this.fragmentShader = builder.getCode( 'fragment' ); - this.vertexShader = builder.getCode( 'vertex' ); - this.fragmentShader = builder.getCode( 'fragment' ); + this.defines = builder.defines; + this.uniforms = builder.uniforms; + this.extensions = builder.extensions; + this.updaters = builder.updaters; - this.defines = builder.defines; - this.uniforms = builder.uniforms; - this.extensions = builder.extensions; - this.updaters = builder.updaters; + this.fog = builder.requires.fog; + this.lights = builder.requires.lights; - this.fog = builder.requires.fog; - this.lights = builder.requires.lights; + this.transparent = builder.requires.transparent || this.blending > NormalBlending; - this.transparent = builder.requires.transparent || this.blending > NormalBlending; + return this; - return this; + } -}; + copy( source ) { -NodeMaterial.prototype.copy = function ( source ) { + var uuid = this.uuid; - var uuid = this.uuid; + for ( var name in source ) { - for ( var name in source ) { + this[ name ] = source[ name ]; - this[ name ] = source[ name ]; + } - } + this.uuid = uuid; - this.uuid = uuid; + if ( source.userData !== undefined ) { - if ( source.userData !== undefined ) { + this.userData = JSON.parse( JSON.stringify( source.userData ) ); - this.userData = JSON.parse( JSON.stringify( source.userData ) ); + } - } + return this; - return this; + } -}; + toJSON( meta ) { -NodeMaterial.prototype.toJSON = function ( meta ) { + var isRootObject = ( meta === undefined || typeof meta === 'string' ); - var isRootObject = ( meta === undefined || typeof meta === 'string' ); + if ( isRootObject ) { - if ( isRootObject ) { + meta = { + nodes: {} + }; - meta = { - nodes: {} - }; + } - } + if ( meta && ! meta.materials ) meta.materials = {}; - if ( meta && ! meta.materials ) meta.materials = {}; + if ( ! meta.materials[ this.uuid ] ) { - if ( ! meta.materials[ this.uuid ] ) { + var data = {}; - var data = {}; + data.uuid = this.uuid; + data.type = this.type; - data.uuid = this.uuid; - data.type = this.type; + meta.materials[ data.uuid ] = data; - meta.materials[ data.uuid ] = data; + if ( this.name !== '' ) data.name = this.name; - if ( this.name !== '' ) data.name = this.name; + if ( this.size !== undefined ) data.size = this.size; + if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation; - if ( this.size !== undefined ) data.size = this.size; - if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation; + if ( this.blending !== NormalBlending ) data.blending = this.blending; + if ( this.flatShading === true ) data.flatShading = this.flatShading; + if ( this.side !== FrontSide ) data.side = this.side; + if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors; - if ( this.blending !== NormalBlending ) data.blending = this.blending; - if ( this.flatShading === true ) data.flatShading = this.flatShading; - if ( this.side !== FrontSide ) data.side = this.side; - if ( this.vertexColors !== NoColors ) data.vertexColors = this.vertexColors; + if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc; + if ( this.depthTest === false ) data.depthTest = this.depthTest; + if ( this.depthWrite === false ) data.depthWrite = this.depthWrite; - if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc; - if ( this.depthTest === false ) data.depthTest = this.depthTest; - if ( this.depthWrite === false ) data.depthWrite = this.depthWrite; + if ( this.linewidth !== 1 ) data.linewidth = this.linewidth; + if ( this.dashSize !== undefined ) data.dashSize = this.dashSize; + if ( this.gapSize !== undefined ) data.gapSize = this.gapSize; + if ( this.scale !== undefined ) data.scale = this.scale; - if ( this.linewidth !== 1 ) data.linewidth = this.linewidth; - if ( this.dashSize !== undefined ) data.dashSize = this.dashSize; - if ( this.gapSize !== undefined ) data.gapSize = this.gapSize; - if ( this.scale !== undefined ) data.scale = this.scale; + if ( this.dithering === true ) data.dithering = true; - if ( this.dithering === true ) data.dithering = true; + if ( this.wireframe === true ) data.wireframe = this.wireframe; + if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth; + if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap; + if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin; - if ( this.wireframe === true ) data.wireframe = this.wireframe; - if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth; - if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap; - if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin; + if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest; + if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha; - if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest; - if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha; + if ( this.morphTargets === true ) data.morphTargets = true; + if ( this.skinning === true ) data.skinning = true; - if ( this.morphTargets === true ) data.morphTargets = true; - if ( this.skinning === true ) data.skinning = true; + if ( this.visible === false ) data.visible = false; + if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData; - if ( this.visible === false ) data.visible = false; - if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData; + data.fog = this.fog; + data.lights = this.lights; - data.fog = this.fog; - data.lights = this.lights; + data.vertex = this.vertex.toJSON( meta ).uuid; + data.fragment = this.fragment.toJSON( meta ).uuid; - data.vertex = this.vertex.toJSON( meta ).uuid; - data.fragment = this.fragment.toJSON( meta ).uuid; + } - } + meta.material = this.uuid; - meta.material = this.uuid; + return meta; - return meta; + } -}; +} export { NodeMaterial }; diff --git a/examples/jsm/nodes/materials/PhongNodeMaterial.js b/examples/jsm/nodes/materials/PhongNodeMaterial.js index 081ecd68518332..5da038893b8121 100644 --- a/examples/jsm/nodes/materials/PhongNodeMaterial.js +++ b/examples/jsm/nodes/materials/PhongNodeMaterial.js @@ -2,18 +2,19 @@ import { PhongNode } from './nodes/PhongNode.js'; import { NodeMaterial } from './NodeMaterial.js'; import { NodeUtils } from '../core/NodeUtils.js'; -function PhongNodeMaterial() { +class PhongNodeMaterial extends NodeMaterial { - var node = new PhongNode(); + constructor() { - NodeMaterial.call( this, node, node ); + var node = new PhongNode(); - this.type = 'PhongNodeMaterial'; + super( node, node ); -} + this.type = 'PhongNodeMaterial'; + + } -PhongNodeMaterial.prototype = Object.create( NodeMaterial.prototype ); -PhongNodeMaterial.prototype.constructor = PhongNodeMaterial; +} NodeUtils.addShortcuts( PhongNodeMaterial.prototype, 'fragment', [ 'color', diff --git a/examples/jsm/nodes/materials/SpriteNodeMaterial.js b/examples/jsm/nodes/materials/SpriteNodeMaterial.js index 21a4f7f4f2b0e6..d46870cc0b31b9 100644 --- a/examples/jsm/nodes/materials/SpriteNodeMaterial.js +++ b/examples/jsm/nodes/materials/SpriteNodeMaterial.js @@ -2,18 +2,19 @@ import { SpriteNode } from './nodes/SpriteNode.js'; import { NodeMaterial } from './NodeMaterial.js'; import { NodeUtils } from '../core/NodeUtils.js'; -function SpriteNodeMaterial() { +class SpriteNodeMaterial extends NodeMaterial { - var node = new SpriteNode(); + constructor() { - NodeMaterial.call( this, node, node ); + var node = new SpriteNode(); - this.type = 'SpriteNodeMaterial'; + super( node, node ); -} + this.type = 'SpriteNodeMaterial'; + + } -SpriteNodeMaterial.prototype = Object.create( NodeMaterial.prototype ); -SpriteNodeMaterial.prototype.constructor = SpriteNodeMaterial; +} NodeUtils.addShortcuts( SpriteNodeMaterial.prototype, 'fragment', [ 'color', diff --git a/examples/jsm/nodes/materials/StandardNodeMaterial.js b/examples/jsm/nodes/materials/StandardNodeMaterial.js index efddf9c4f022ab..39d7c371d34982 100644 --- a/examples/jsm/nodes/materials/StandardNodeMaterial.js +++ b/examples/jsm/nodes/materials/StandardNodeMaterial.js @@ -2,18 +2,19 @@ import { StandardNode } from './nodes/StandardNode.js'; import { NodeMaterial } from './NodeMaterial.js'; import { NodeUtils } from '../core/NodeUtils.js'; -function StandardNodeMaterial() { +class StandardNodeMaterial extends NodeMaterial { - var node = new StandardNode(); + constructor() { - NodeMaterial.call( this, node, node ); + var node = new StandardNode(); - this.type = 'StandardNodeMaterial'; + super( node, node ); -} + this.type = 'StandardNodeMaterial'; + + } -StandardNodeMaterial.prototype = Object.create( NodeMaterial.prototype ); -StandardNodeMaterial.prototype.constructor = StandardNodeMaterial; +} NodeUtils.addShortcuts( StandardNodeMaterial.prototype, 'fragment', [ 'color', diff --git a/src/materials/LineBasicMaterial.js b/src/materials/LineBasicMaterial.js index e77e19b8a0f6b6..6727cb1bbe2215 100644 --- a/src/materials/LineBasicMaterial.js +++ b/src/materials/LineBasicMaterial.js @@ -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 }; diff --git a/src/materials/LineDashedMaterial.js b/src/materials/LineDashedMaterial.js index a86736ae5ded74..56a59dea16fd67 100644 --- a/src/materials/LineDashedMaterial.js +++ b/src/materials/LineDashedMaterial.js @@ -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 }; diff --git a/src/materials/Material.js b/src/materials/Material.js index 8c48bd5b3c032b..881b1989adbcbd 100644 --- a/src/materials/Material.js +++ b/src/materials/Material.js @@ -4,88 +4,95 @@ 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, 'isMaterial', { value: true } ); - this.fog = true; + Object.defineProperty( this, 'id', { value: materialId ++ } ); - this.blending = NormalBlending; - this.side = FrontSide; - this.vertexColors = false; + this.uuid = MathUtils.generateUUID(); - this.opacity = 1; - this.transparent = false; + this.name = ''; + this.type = 'Material'; - this.blendSrc = SrcAlphaFactor; - this.blendDst = OneMinusSrcAlphaFactor; - this.blendEquation = AddEquation; - this.blendSrcAlpha = null; - this.blendDstAlpha = null; - this.blendEquationAlpha = null; + this.fog = true; - this.depthFunc = LessEqualDepth; - this.depthTest = true; - this.depthWrite = true; + this.blending = NormalBlending; + this.side = FrontSide; + this.flatShading = false; + this.vertexColors = 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.opacity = 1; + this.transparent = false; - this.clippingPlanes = null; - this.clipIntersection = false; - this.clipShadows = false; + this.blendSrc = SrcAlphaFactor; + this.blendDst = OneMinusSrcAlphaFactor; + this.blendEquation = AddEquation; + this.blendSrcAlpha = null; + this.blendDstAlpha = null; + this.blendEquationAlpha = null; - this.shadowSide = null; + this.depthFunc = LessEqualDepth; + this.depthTest = true; + this.depthWrite = true; - this.colorWrite = true; + 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.precision = null; // override the renderer's default precision for this material + this.clippingPlanes = null; + this.clipIntersection = false; + this.clipShadows = false; - this.polygonOffset = false; - this.polygonOffsetFactor = 0; - this.polygonOffsetUnits = 0; + this.shadowSide = null; - this.dithering = false; + this.colorWrite = true; - this.alphaTest = 0; - this.premultipliedAlpha = false; + this.precision = null; // override the renderer's default precision for this material - this.visible = true; + this.polygonOffset = false; + this.polygonOffsetFactor = 0; + this.polygonOffsetUnits = 0; - this.toneMapped = true; + this.dithering = false; - this.userData = {}; + this.alphaTest = 0; + this.premultipliedAlpha = false; - this.version = 0; + this.visible = true; -} + this.toneMapped = true; + + this.userData = {}; + + this.version = 0; + + } -Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), { + set needsUpdate( value ) { - constructor: Material, + 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; @@ -134,9 +141,9 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), } - }, + } - toJSON: function ( meta ) { + toJSON( meta ) { const isRoot = ( meta === undefined || typeof meta === 'string' ); @@ -347,15 +354,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; @@ -431,24 +438,14 @@ Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), return this; - }, - - dispose: function () { - - this.dispatchEvent( { type: 'dispose' } ); - } -} ); + dispose() { -Object.defineProperty( Material.prototype, 'needsUpdate', { - - set: function ( value ) { - - if ( value === true ) this.version ++; + this.dispatchEvent( { type: 'dispose' } ); } -} ); +} export { Material }; diff --git a/src/materials/MeshBasicMaterial.js b/src/materials/MeshBasicMaterial.js index 778b92704a93af..93a7ea88521293 100644 --- a/src/materials/MeshBasicMaterial.js +++ b/src/materials/MeshBasicMaterial.js @@ -34,82 +34,82 @@ import { Color } from '../math/Color.js'; * } */ -function MeshBasicMaterial( parameters ) { +class MeshBasicMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshBasicMaterial'; + super(); - this.color = new Color( 0xffffff ); // emissive + Object.defineProperty( this, 'isMeshBasicMaterial', { value: true } ); - this.map = null; + this.type = 'MeshBasicMaterial'; - this.lightMap = null; - this.lightMapIntensity = 1.0; + this.color = new Color( 0xffffff ); // emissive - this.aoMap = null; - this.aoMapIntensity = 1.0; + this.map = null; - this.specularMap = null; + this.lightMap = null; + this.lightMapIntensity = 1.0; - this.alphaMap = null; + this.aoMap = null; + this.aoMapIntensity = 1.0; - this.envMap = null; - this.combine = MultiplyOperation; - this.reflectivity = 1; - this.refractionRatio = 0.98; + this.specularMap = null; - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; + this.alphaMap = null; - this.skinning = false; - this.morphTargets = false; + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; - this.setValues( parameters ); + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; -} + this.skinning = false; + this.morphTargets = false; -MeshBasicMaterial.prototype = Object.create( Material.prototype ); -MeshBasicMaterial.prototype.constructor = MeshBasicMaterial; + this.setValues( parameters ); -MeshBasicMaterial.prototype.isMeshBasicMaterial = true; + } -MeshBasicMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.copy( source ); - this.color.copy( source.color ); + this.color.copy( source.color ); - this.map = source.map; + this.map = source.map; - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; - this.specularMap = source.specularMap; + this.specularMap = source.specularMap; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.envMap = source.envMap; - this.combine = source.combine; - this.reflectivity = source.reflectivity; - this.refractionRatio = source.refractionRatio; + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; - return this; + return this; -}; + } +} export { MeshBasicMaterial }; diff --git a/src/materials/MeshDepthMaterial.js b/src/materials/MeshDepthMaterial.js index 108dce9b627fba..12d200165fdd58 100644 --- a/src/materials/MeshDepthMaterial.js +++ b/src/materials/MeshDepthMaterial.js @@ -19,62 +19,62 @@ import { BasicDepthPacking } from '../constants.js'; * } */ -function MeshDepthMaterial( parameters ) { +class MeshDepthMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshDepthMaterial'; + super(); - this.depthPacking = BasicDepthPacking; + Object.defineProperty( this, 'isMeshDepthMaterial', { value: true } ); - this.skinning = false; - this.morphTargets = false; + this.type = 'MeshDepthMaterial'; - this.map = null; + this.depthPacking = BasicDepthPacking; - this.alphaMap = null; + this.skinning = false; + this.morphTargets = false; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.map = null; - this.wireframe = false; - this.wireframeLinewidth = 1; + this.alphaMap = null; - this.fog = false; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.setValues( parameters ); + this.wireframe = false; + this.wireframeLinewidth = 1; -} + this.fog = false; -MeshDepthMaterial.prototype = Object.create( Material.prototype ); -MeshDepthMaterial.prototype.constructor = MeshDepthMaterial; + this.setValues( parameters ); -MeshDepthMaterial.prototype.isMeshDepthMaterial = true; + } -MeshDepthMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + Material.prototype.copy.call( this, source ); - this.depthPacking = source.depthPacking; + this.depthPacking = source.depthPacking; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; - this.map = source.map; + this.map = source.map; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; - return this; + return this; -}; + } +} export { MeshDepthMaterial }; diff --git a/src/materials/MeshDistanceMaterial.js b/src/materials/MeshDistanceMaterial.js index 9c47141a693321..e013709dfe0d0d 100644 --- a/src/materials/MeshDistanceMaterial.js +++ b/src/materials/MeshDistanceMaterial.js @@ -22,60 +22,60 @@ import { Vector3 } from '../math/Vector3.js'; * } */ -function MeshDistanceMaterial( parameters ) { +class MeshDistanceMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshDistanceMaterial'; + super(); - this.referencePosition = new Vector3(); - this.nearDistance = 1; - this.farDistance = 1000; + Object.defineProperty( this, 'isMeshDistanceMaterial', { value: true } ); - this.skinning = false; - this.morphTargets = false; + this.type = 'MeshDistanceMaterial'; - this.map = null; + this.referencePosition = new Vector3(); + this.nearDistance = 1; + this.farDistance = 1000; - this.alphaMap = null; + this.skinning = false; + this.morphTargets = false; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.map = null; - this.fog = false; + this.alphaMap = null; - this.setValues( parameters ); + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; -} + this.fog = false; -MeshDistanceMaterial.prototype = Object.create( Material.prototype ); -MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial; + this.setValues( parameters ); -MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true; + } -MeshDistanceMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.clone( source ); - this.referencePosition.copy( source.referencePosition ); - this.nearDistance = source.nearDistance; - this.farDistance = source.farDistance; + this.referencePosition.copy( source.referencePosition ); + this.nearDistance = source.nearDistance; + this.farDistance = source.farDistance; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; - this.map = source.map; + this.map = source.map; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - return this; + return this; -}; + } +} export { MeshDistanceMaterial }; diff --git a/src/materials/MeshLambertMaterial.js b/src/materials/MeshLambertMaterial.js index b3f4ab8bbab843..0db1419c20381c 100644 --- a/src/materials/MeshLambertMaterial.js +++ b/src/materials/MeshLambertMaterial.js @@ -37,92 +37,92 @@ import { Color } from '../math/Color.js'; * } */ -function MeshLambertMaterial( parameters ) { +class MeshLambertMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshLambertMaterial'; + super(); - this.color = new Color( 0xffffff ); // diffuse + Object.defineProperty( this, 'isMeshLambertMaterial', { value: true } ); - this.map = null; + this.type = 'MeshLambertMaterial'; - this.lightMap = null; - this.lightMapIntensity = 1.0; + this.color = new Color( 0xffffff ); // diffuse - this.aoMap = null; - this.aoMapIntensity = 1.0; + this.map = null; - this.emissive = new Color( 0x000000 ); - this.emissiveIntensity = 1.0; - this.emissiveMap = null; + this.lightMap = null; + this.lightMapIntensity = 1.0; - this.specularMap = null; + this.aoMap = null; + this.aoMapIntensity = 1.0; - this.alphaMap = null; + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; - this.envMap = null; - this.combine = MultiplyOperation; - this.reflectivity = 1; - this.refractionRatio = 0.98; + this.specularMap = null; - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; + this.alphaMap = null; - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; - this.setValues( parameters ); + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; -} + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; -MeshLambertMaterial.prototype = Object.create( Material.prototype ); -MeshLambertMaterial.prototype.constructor = MeshLambertMaterial; + this.setValues( parameters ); -MeshLambertMaterial.prototype.isMeshLambertMaterial = true; + } -MeshLambertMaterial.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.map = source.map; + this.map = source.map; - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; - this.emissive.copy( source.emissive ); - this.emissiveMap = source.emissiveMap; - this.emissiveIntensity = source.emissiveIntensity; + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; - this.specularMap = source.specularMap; + this.specularMap = source.specularMap; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.envMap = source.envMap; - this.combine = source.combine; - this.reflectivity = source.reflectivity; - this.refractionRatio = source.refractionRatio; + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - return this; + return this; -}; + } +} export { MeshLambertMaterial }; diff --git a/src/materials/MeshMatcapMaterial.js b/src/materials/MeshMatcapMaterial.js index 48bd2f633a0308..fc6e0cffe68712 100644 --- a/src/materials/MeshMatcapMaterial.js +++ b/src/materials/MeshMatcapMaterial.js @@ -33,82 +33,83 @@ import { Color } from '../math/Color.js'; * } */ -function MeshMatcapMaterial( parameters ) { +class MeshMatcapMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.defines = { 'MATCAP': '' }; + super(); - this.type = 'MeshMatcapMaterial'; + Object.defineProperty( this, 'isMeshMatcapMaterial', { value: true } ); - this.color = new Color( 0xffffff ); // diffuse + this.defines = { 'MATCAP': '' }; - this.matcap = null; + this.type = 'MeshMatcapMaterial'; - this.map = null; + this.color = new Color( 0xffffff ); // diffuse - this.bumpMap = null; - this.bumpScale = 1; + this.matcap = null; - this.normalMap = null; - this.normalMapType = TangentSpaceNormalMap; - this.normalScale = new Vector2( 1, 1 ); + this.map = null; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.bumpMap = null; + this.bumpScale = 1; - this.alphaMap = null; + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.flatShading = false; + this.alphaMap = null; - this.setValues( parameters ); + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; -} + this.flatShading = false; + + this.setValues( parameters ); -MeshMatcapMaterial.prototype = Object.create( Material.prototype ); -MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial; + } -MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true; -MeshMatcapMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.clone( source ); - this.defines = { 'MATCAP': '' }; + this.defines = { 'MATCAP': '' }; - this.color.copy( source.color ); + this.color.copy( source.color ); - this.matcap = source.matcap; + this.matcap = source.matcap; - this.map = source.map; + this.map = source.map; - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; - this.normalMap = source.normalMap; - this.normalMapType = source.normalMapType; - this.normalScale.copy( source.normalScale ); + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - this.flatShading = source.flatShading; + this.flatShading = source.flatShading; - return this; + return this; -}; + } +} export { MeshMatcapMaterial }; diff --git a/src/materials/MeshNormalMaterial.js b/src/materials/MeshNormalMaterial.js index 86f738513b6a8c..9ad09786eed427 100644 --- a/src/materials/MeshNormalMaterial.js +++ b/src/materials/MeshNormalMaterial.js @@ -28,70 +28,70 @@ import { Vector2 } from '../math/Vector2.js'; * } */ -function MeshNormalMaterial( parameters ) { +class MeshNormalMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshNormalMaterial'; + super(); - this.bumpMap = null; - this.bumpScale = 1; + Object.defineProperty( this, 'isMeshNormalMaterial', { value: true } ); - this.normalMap = null; - this.normalMapType = TangentSpaceNormalMap; - this.normalScale = new Vector2( 1, 1 ); + this.type = 'MeshNormalMaterial'; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.bumpMap = null; + this.bumpScale = 1; - this.wireframe = false; - this.wireframeLinewidth = 1; + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); - this.fog = false; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.wireframe = false; + this.wireframeLinewidth = 1; - this.flatShading = false; + this.fog = false; - this.setValues( parameters ); + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; -} + this.flatShading = false; -MeshNormalMaterial.prototype = Object.create( Material.prototype ); -MeshNormalMaterial.prototype.constructor = MeshNormalMaterial; + this.setValues( parameters ); -MeshNormalMaterial.prototype.isMeshNormalMaterial = true; + } -MeshNormalMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.clone( source ); - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; - this.normalMap = source.normalMap; - this.normalMapType = source.normalMapType; - this.normalScale.copy( source.normalScale ); + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - this.flatShading = source.flatShading; + this.flatShading = source.flatShading; - return this; + return this; -}; + } +} export { MeshNormalMaterial }; diff --git a/src/materials/MeshPhongMaterial.js b/src/materials/MeshPhongMaterial.js index 2ff363a5d2018c..dd71a4c87915ab 100644 --- a/src/materials/MeshPhongMaterial.js +++ b/src/materials/MeshPhongMaterial.js @@ -53,122 +53,122 @@ import { Color } from '../math/Color.js'; * } */ -function MeshPhongMaterial( parameters ) { +class MeshPhongMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'MeshPhongMaterial'; + super(); - this.color = new Color( 0xffffff ); // diffuse - this.specular = new Color( 0x111111 ); - this.shininess = 30; + Object.defineProperty( this, 'isMeshPhongMaterial', { value: true } ); - this.map = null; + this.type = 'MeshPhongMaterial'; - this.lightMap = null; - this.lightMapIntensity = 1.0; + this.color = new Color( 0xffffff ); // diffuse + this.specular = new Color( 0x111111 ); + this.shininess = 30; - this.aoMap = null; - this.aoMapIntensity = 1.0; + this.map = null; - this.emissive = new Color( 0x000000 ); - this.emissiveIntensity = 1.0; - this.emissiveMap = null; + this.lightMap = null; + this.lightMapIntensity = 1.0; - this.bumpMap = null; - this.bumpScale = 1; + this.aoMap = null; + this.aoMapIntensity = 1.0; - this.normalMap = null; - this.normalMapType = TangentSpaceNormalMap; - this.normalScale = new Vector2( 1, 1 ); + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.bumpMap = null; + this.bumpScale = 1; - this.specularMap = null; + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); - this.alphaMap = null; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.envMap = null; - this.combine = MultiplyOperation; - this.reflectivity = 1; - this.refractionRatio = 0.98; + this.specularMap = null; - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; + this.alphaMap = null; - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.envMap = null; + this.combine = MultiplyOperation; + this.reflectivity = 1; + this.refractionRatio = 0.98; - this.flatShading = false; + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; - this.setValues( parameters ); + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; -} + this.flatShading = false; -MeshPhongMaterial.prototype = Object.create( Material.prototype ); -MeshPhongMaterial.prototype.constructor = MeshPhongMaterial; + this.setValues( parameters ); -MeshPhongMaterial.prototype.isMeshPhongMaterial = true; + } -MeshPhongMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + Material.prototype.copy.call( this, source ); - this.color.copy( source.color ); - this.specular.copy( source.specular ); - this.shininess = source.shininess; + this.color.copy( source.color ); + this.specular.copy( source.specular ); + this.shininess = source.shininess; - this.map = source.map; + this.map = source.map; - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; - this.emissive.copy( source.emissive ); - this.emissiveMap = source.emissiveMap; - this.emissiveIntensity = source.emissiveIntensity; + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; - this.normalMap = source.normalMap; - this.normalMapType = source.normalMapType; - this.normalScale.copy( source.normalScale ); + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.specularMap = source.specularMap; + this.specularMap = source.specularMap; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.envMap = source.envMap; - this.combine = source.combine; - this.reflectivity = source.reflectivity; - this.refractionRatio = source.refractionRatio; + this.envMap = source.envMap; + this.combine = source.combine; + this.reflectivity = source.reflectivity; + this.refractionRatio = source.refractionRatio; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - this.flatShading = source.flatShading; + this.flatShading = source.flatShading; - return this; + return this; -}; + } +} export { MeshPhongMaterial }; diff --git a/src/materials/MeshPhysicalMaterial.js b/src/materials/MeshPhysicalMaterial.js index d9773153a80499..d2a1816ee128f0 100644 --- a/src/materials/MeshPhysicalMaterial.js +++ b/src/materials/MeshPhysicalMaterial.js @@ -22,90 +22,93 @@ import { MathUtils } from '../math/MathUtils.js'; * } */ -function MeshPhysicalMaterial( parameters ) { +class MeshPhysicalMaterial extends MeshStandardMaterial { - MeshStandardMaterial.call( this ); + constructor( parameters ) { - this.defines = { + super(); - 'STANDARD': '', - 'PHYSICAL': '' + Object.defineProperty( this, 'isMeshPhysicalMaterial', { value: true } ); - }; + this.defines = { - this.type = 'MeshPhysicalMaterial'; + 'STANDARD': '', + 'PHYSICAL': '' - this.clearcoat = 0.0; - this.clearcoatMap = null; - this.clearcoatRoughness = 0.0; - this.clearcoatRoughnessMap = null; - this.clearcoatNormalScale = new Vector2( 1, 1 ); - this.clearcoatNormalMap = null; + }; - this.reflectivity = 0.5; // maps to F0 = 0.04 + this.type = 'MeshPhysicalMaterial'; - Object.defineProperty( this, 'ior', { - get: function () { + this.clearcoat = 0.0; + this.clearcoatMap = null; + this.clearcoatRoughness = 0.0; + this.clearcoatRoughnessMap = null; + this.clearcoatNormalScale = new Vector2( 1, 1 ); + this.clearcoatNormalMap = null; - return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity ); + this.reflectivity = 0.5; // maps to F0 = 0.04 - }, - set: function ( ior ) { + Object.defineProperty( this, 'ior', { + get: function () { - this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 ); + return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity ); - } - } ); + }, + set: function ( ior ) { - this.sheen = null; // null will disable sheen bsdf + this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 ); - this.transmission = 0.0; - this.transmissionMap = null; + } + } ); - this.setValues( parameters ); + this.sheen = null; // null will disable sheen bsdf -} + this.sheen = null; // null will disable sheen bsdf -MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype ); -MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial; + this.transmission = 0.0; + this.transmissionMap = null; -MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true; + this.setValues( parameters ); -MeshPhysicalMaterial.prototype.copy = function ( source ) { + } - MeshStandardMaterial.prototype.copy.call( this, source ); + copy( source ) { - this.defines = { + MeshStandardMaterial.prototype.copy.call( this, source ); - 'STANDARD': '', - 'PHYSICAL': '' + this.defines = { - }; + 'STANDARD': '', + 'PHYSICAL': '' - this.clearcoat = source.clearcoat; - this.clearcoatMap = source.clearcoatMap; - this.clearcoatRoughness = source.clearcoatRoughness; - this.clearcoatRoughnessMap = source.clearcoatRoughnessMap; - this.clearcoatNormalMap = source.clearcoatNormalMap; - this.clearcoatNormalScale.copy( source.clearcoatNormalScale ); + }; - this.reflectivity = source.reflectivity; + this.clearcoat = source.clearcoat; + this.clearcoatMap = source.clearcoatMap; + this.clearcoatRoughness = source.clearcoatRoughness; + this.clearcoatRoughnessMap = source.clearcoatRoughnessMap; + this.clearcoatNormalMap = source.clearcoatNormalMap; + this.clearcoatNormalScale.copy( source.clearcoatNormalScale ); - if ( source.sheen ) { + this.reflectivity = source.reflectivity; - this.sheen = ( this.sheen || new Color() ).copy( source.sheen ); + if ( source.sheen ) { - } else { + this.sheen = ( this.sheen || new Color() ).copy( source.sheen ); - this.sheen = null; + } else { - } + this.sheen = null; - this.transmission = source.transmission; - this.transmissionMap = source.transmissionMap; + } - return this; + this.transmission = source.transmission; + this.transmissionMap = source.transmissionMap; -}; + return this; + + } + +} export { MeshPhysicalMaterial }; diff --git a/src/materials/MeshStandardMaterial.js b/src/materials/MeshStandardMaterial.js index 51f37a2a23b827..c2c6981b6eefe0 100644 --- a/src/materials/MeshStandardMaterial.js +++ b/src/materials/MeshStandardMaterial.js @@ -55,134 +55,134 @@ import { Color } from '../math/Color.js'; * } */ -function MeshStandardMaterial( parameters ) { +class MeshStandardMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.defines = { 'STANDARD': '' }; + super(); - this.type = 'MeshStandardMaterial'; + Object.defineProperty( this, 'isMeshStandardMaterial', { value: true } ); - this.color = new Color( 0xffffff ); // diffuse - this.roughness = 1.0; - this.metalness = 0.0; + this.defines = { 'STANDARD': '' }; - this.map = null; + this.type = 'MeshStandardMaterial'; - this.lightMap = null; - this.lightMapIntensity = 1.0; + this.color = new Color( 0xffffff ); // diffuse + this.roughness = 1.0; + this.metalness = 0.0; - this.aoMap = null; - this.aoMapIntensity = 1.0; + this.map = null; - this.emissive = new Color( 0x000000 ); - this.emissiveIntensity = 1.0; - this.emissiveMap = null; + this.lightMap = null; + this.lightMapIntensity = 1.0; - this.bumpMap = null; - this.bumpScale = 1; + this.aoMap = null; + this.aoMapIntensity = 1.0; - this.normalMap = null; - this.normalMapType = TangentSpaceNormalMap; - this.normalScale = new Vector2( 1, 1 ); + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.bumpMap = null; + this.bumpScale = 1; - this.roughnessMap = null; + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); - this.metalnessMap = null; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.alphaMap = null; + this.roughnessMap = null; - this.envMap = null; - this.envMapIntensity = 1.0; + this.metalnessMap = null; - this.refractionRatio = 0.98; + this.alphaMap = null; - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; + this.envMap = null; + this.envMapIntensity = 1.0; - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.refractionRatio = 0.98; - this.flatShading = false; + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; - this.vertexTangents = false; + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; - this.setValues( parameters ); + this.flatShading = false; -} + this.vertexTangents = false; -MeshStandardMaterial.prototype = Object.create( Material.prototype ); -MeshStandardMaterial.prototype.constructor = MeshStandardMaterial; + this.setValues( parameters ); -MeshStandardMaterial.prototype.isMeshStandardMaterial = true; + } -MeshStandardMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + Material.prototype.copy.call( this, source ); - this.defines = { 'STANDARD': '' }; + this.defines = { 'STANDARD': '' }; - this.color.copy( source.color ); - this.roughness = source.roughness; - this.metalness = source.metalness; + this.color.copy( source.color ); + this.roughness = source.roughness; + this.metalness = source.metalness; - this.map = source.map; + this.map = source.map; - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; - this.emissive.copy( source.emissive ); - this.emissiveMap = source.emissiveMap; - this.emissiveIntensity = source.emissiveIntensity; + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; - this.normalMap = source.normalMap; - this.normalMapType = source.normalMapType; - this.normalScale.copy( source.normalScale ); + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.roughnessMap = source.roughnessMap; + this.roughnessMap = source.roughnessMap; - this.metalnessMap = source.metalnessMap; + this.metalnessMap = source.metalnessMap; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.envMap = source.envMap; - this.envMapIntensity = source.envMapIntensity; + this.envMap = source.envMap; + this.envMapIntensity = source.envMapIntensity; - this.refractionRatio = source.refractionRatio; + this.refractionRatio = source.refractionRatio; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - this.flatShading = source.flatShading; + this.flatShading = source.flatShading; - this.vertexTangents = source.vertexTangents; + this.vertexTangents = source.vertexTangents; - return this; + return this; -}; + } +} export { MeshStandardMaterial }; diff --git a/src/materials/MeshToonMaterial.js b/src/materials/MeshToonMaterial.js index 0327dd490591ce..9b1290a1584b2b 100644 --- a/src/materials/MeshToonMaterial.js +++ b/src/materials/MeshToonMaterial.js @@ -42,104 +42,104 @@ import { Color } from '../math/Color.js'; * } */ -function MeshToonMaterial( parameters ) { +class MeshToonMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.defines = { 'TOON': '' }; + super(); - this.type = 'MeshToonMaterial'; + Object.defineProperty( this, 'isMeshToonMaterial', { value: true } ); - this.color = new Color( 0xffffff ); + this.defines = { 'TOON': '' }; - this.map = null; - this.gradientMap = null; + this.type = 'MeshToonMaterial'; - this.lightMap = null; - this.lightMapIntensity = 1.0; + this.color = new Color( 0xffffff ); - this.aoMap = null; - this.aoMapIntensity = 1.0; + this.map = null; + this.gradientMap = null; - this.emissive = new Color( 0x000000 ); - this.emissiveIntensity = 1.0; - this.emissiveMap = null; + this.lightMap = null; + this.lightMapIntensity = 1.0; - this.bumpMap = null; - this.bumpScale = 1; + this.aoMap = null; + this.aoMapIntensity = 1.0; - this.normalMap = null; - this.normalMapType = TangentSpaceNormalMap; - this.normalScale = new Vector2( 1, 1 ); + this.emissive = new Color( 0x000000 ); + this.emissiveIntensity = 1.0; + this.emissiveMap = null; - this.displacementMap = null; - this.displacementScale = 1; - this.displacementBias = 0; + this.bumpMap = null; + this.bumpScale = 1; - this.alphaMap = null; + this.normalMap = null; + this.normalMapType = TangentSpaceNormalMap; + this.normalScale = new Vector2( 1, 1 ); - this.wireframe = false; - this.wireframeLinewidth = 1; - this.wireframeLinecap = 'round'; - this.wireframeLinejoin = 'round'; + this.displacementMap = null; + this.displacementScale = 1; + this.displacementBias = 0; - this.skinning = false; - this.morphTargets = false; - this.morphNormals = false; + this.alphaMap = null; - this.setValues( parameters ); + this.wireframe = false; + this.wireframeLinewidth = 1; + this.wireframeLinecap = 'round'; + this.wireframeLinejoin = 'round'; -} + this.skinning = false; + this.morphTargets = false; + this.morphNormals = false; -MeshToonMaterial.prototype = Object.create( Material.prototype ); -MeshToonMaterial.prototype.constructor = MeshToonMaterial; + this.setValues( parameters ); -MeshToonMaterial.prototype.isMeshToonMaterial = true; + } -MeshToonMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.clone( source ); - this.color.copy( source.color ); + this.color.copy( source.color ); - this.map = source.map; - this.gradientMap = source.gradientMap; + this.map = source.map; + this.gradientMap = source.gradientMap; - this.lightMap = source.lightMap; - this.lightMapIntensity = source.lightMapIntensity; + this.lightMap = source.lightMap; + this.lightMapIntensity = source.lightMapIntensity; - this.aoMap = source.aoMap; - this.aoMapIntensity = source.aoMapIntensity; + this.aoMap = source.aoMap; + this.aoMapIntensity = source.aoMapIntensity; - this.emissive.copy( source.emissive ); - this.emissiveMap = source.emissiveMap; - this.emissiveIntensity = source.emissiveIntensity; + this.emissive.copy( source.emissive ); + this.emissiveMap = source.emissiveMap; + this.emissiveIntensity = source.emissiveIntensity; - this.bumpMap = source.bumpMap; - this.bumpScale = source.bumpScale; + this.bumpMap = source.bumpMap; + this.bumpScale = source.bumpScale; - this.normalMap = source.normalMap; - this.normalMapType = source.normalMapType; - this.normalScale.copy( source.normalScale ); + this.normalMap = source.normalMap; + this.normalMapType = source.normalMapType; + this.normalScale.copy( source.normalScale ); - this.displacementMap = source.displacementMap; - this.displacementScale = source.displacementScale; - this.displacementBias = source.displacementBias; + this.displacementMap = source.displacementMap; + this.displacementScale = source.displacementScale; + this.displacementBias = source.displacementBias; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; - this.wireframeLinecap = source.wireframeLinecap; - this.wireframeLinejoin = source.wireframeLinejoin; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; + this.wireframeLinecap = source.wireframeLinecap; + this.wireframeLinejoin = source.wireframeLinejoin; - this.skinning = source.skinning; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.skinning = source.skinning; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - return this; + return this; -}; + } +} export { MeshToonMaterial }; diff --git a/src/materials/PointsMaterial.js b/src/materials/PointsMaterial.js index 64fc2aa39bc708..7b4cedaf19951d 100644 --- a/src/materials/PointsMaterial.js +++ b/src/materials/PointsMaterial.js @@ -15,50 +15,50 @@ import { Color } from '../math/Color.js'; * } */ -function PointsMaterial( parameters ) { +class PointsMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'PointsMaterial'; + super(); - this.color = new Color( 0xffffff ); + Object.defineProperty( this, 'isPointsMaterial', { value: true } ); - this.map = null; + this.type = 'PointsMaterial'; - this.alphaMap = null; + this.color = new Color( 0xffffff ); - this.size = 1; - this.sizeAttenuation = true; + this.map = null; - this.morphTargets = false; + this.alphaMap = null; - this.setValues( parameters ); + this.size = 1; + this.sizeAttenuation = true; -} + this.morphTargets = false; -PointsMaterial.prototype = Object.create( Material.prototype ); -PointsMaterial.prototype.constructor = PointsMaterial; + this.setValues( parameters ); -PointsMaterial.prototype.isPointsMaterial = true; + } -PointsMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.clone( source ); - this.color.copy( source.color ); + this.color.copy( source.color ); - this.map = source.map; + this.map = source.map; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.size = source.size; - this.sizeAttenuation = source.sizeAttenuation; + this.size = source.size; + this.sizeAttenuation = source.sizeAttenuation; - this.morphTargets = source.morphTargets; + this.morphTargets = source.morphTargets; - return this; + return this; -}; + } +} export { PointsMaterial }; diff --git a/src/materials/RawShaderMaterial.js b/src/materials/RawShaderMaterial.js index 1af8bd182865ff..35e524beb8750e 100644 --- a/src/materials/RawShaderMaterial.js +++ b/src/materials/RawShaderMaterial.js @@ -1,17 +1,17 @@ import { ShaderMaterial } from './ShaderMaterial.js'; -function RawShaderMaterial( parameters ) { +class RawShaderMaterial extends ShaderMaterial { - ShaderMaterial.call( this, parameters ); + constructor( parameters ) { - this.type = 'RawShaderMaterial'; + super( parameters ); -} + Object.defineProperty( this, 'isRawShaderMaterial', { value: true } ); -RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype ); -RawShaderMaterial.prototype.constructor = RawShaderMaterial; + this.type = 'RawShaderMaterial'; -RawShaderMaterial.prototype.isRawShaderMaterial = true; + } +} export { RawShaderMaterial }; diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index 76b11359a120cf..14ec670164dddc 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -23,191 +23,195 @@ import default_fragment from '../renderers/shaders/ShaderChunk/default_fragment. * } */ -function ShaderMaterial( parameters ) { +class ShaderMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'ShaderMaterial'; + super(); - this.defines = {}; - this.uniforms = {}; + Object.defineProperty( this, 'isShaderMaterial', { value: true } ); - this.vertexShader = default_vertex; - this.fragmentShader = default_fragment; + this.type = 'ShaderMaterial'; - this.linewidth = 1; + this.defines = {}; + this.uniforms = {}; - this.wireframe = false; - this.wireframeLinewidth = 1; + this.vertexShader = default_vertex; + this.fragmentShader = default_fragment; - this.fog = false; // set to use scene fog - this.lights = false; // set to use scene lights - this.clipping = false; // set to use user-defined clipping planes + this.linewidth = 1; - this.skinning = false; // set to use skinning attribute streams - this.morphTargets = false; // set to use morph targets - this.morphNormals = false; // set to use morph normals + this.wireframe = false; + this.wireframeLinewidth = 1; - this.extensions = { - derivatives: false, // set to use derivatives - fragDepth: false, // set to use fragment depth values - drawBuffers: false, // set to use draw buffers - shaderTextureLOD: false // set to use shader texture LOD - }; + this.fog = false; // set to use scene fog + this.lights = false; // set to use scene lights + this.clipping = false; // set to use user-defined clipping planes - // When rendered geometry doesn't include these attributes but the material does, - // use these default values in WebGL. This avoids errors when buffer data is missing. - this.defaultAttributeValues = { - 'color': [ 1, 1, 1 ], - 'uv': [ 0, 0 ], - 'uv2': [ 0, 0 ] - }; + this.skinning = false; // set to use skinning attribute streams + this.morphTargets = false; // set to use morph targets + this.morphNormals = false; // set to use morph normals - this.index0AttributeName = undefined; - this.uniformsNeedUpdate = false; + this.extensions = { + derivatives: false, // set to use derivatives + fragDepth: false, // set to use fragment depth values + drawBuffers: false, // set to use draw buffers + shaderTextureLOD: false // set to use shader texture LOD + }; - this.glslVersion = null; + // When rendered geometry doesn't include these attributes but the material does, + // use these default values in WebGL. This avoids errors when buffer data is missing. + this.defaultAttributeValues = { + 'color': [ 1, 1, 1 ], + 'uv': [ 0, 0 ], + 'uv2': [ 0, 0 ] + }; - if ( parameters !== undefined ) { + this.index0AttributeName = undefined; + this.uniformsNeedUpdate = false; - if ( parameters.attributes !== undefined ) { + this.glslVersion = null; - console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' ); + if ( parameters !== undefined ) { - } + if ( parameters !== undefined ) { - this.setValues( parameters ); + if ( parameters.attributes !== undefined ) { - } + console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' ); -} + } -ShaderMaterial.prototype = Object.create( Material.prototype ); -ShaderMaterial.prototype.constructor = ShaderMaterial; + this.setValues( parameters ); -ShaderMaterial.prototype.isShaderMaterial = true; + } -ShaderMaterial.prototype.copy = function ( source ) { + } - Material.prototype.copy.call( this, source ); + } - this.fragmentShader = source.fragmentShader; - this.vertexShader = source.vertexShader; + copy( source ) { - this.uniforms = cloneUniforms( source.uniforms ); + Material.prototype.copy.call( this, source ); - this.defines = Object.assign( {}, source.defines ); + this.fragmentShader = source.fragmentShader; + this.vertexShader = source.vertexShader; - this.wireframe = source.wireframe; - this.wireframeLinewidth = source.wireframeLinewidth; + this.uniforms = cloneUniforms( source.uniforms ); - this.lights = source.lights; - this.clipping = source.clipping; + this.defines = Object.assign( {}, source.defines ); - this.skinning = source.skinning; + this.wireframe = source.wireframe; + this.wireframeLinewidth = source.wireframeLinewidth; - this.morphTargets = source.morphTargets; - this.morphNormals = source.morphNormals; + this.lights = source.lights; + this.clipping = source.clipping; - this.extensions = Object.assign( {}, source.extensions ); + this.skinning = source.skinning; - this.glslVersion = source.glslVersion; + this.morphTargets = source.morphTargets; + this.morphNormals = source.morphNormals; - return this; + this.extensions = Object.assign( {}, source.extensions ); -}; + this.glslVersion = source.glslVersion; -ShaderMaterial.prototype.toJSON = function ( meta ) { + return this; - const data = Material.prototype.toJSON.call( this, meta ); + } - data.glslVersion = this.glslVersion; - data.uniforms = {}; + toJSON( meta ) { - for ( const name in this.uniforms ) { + const data = super.toJSON( meta ); - const uniform = this.uniforms[ name ]; - const value = uniform.value; + data.glslVersion = this.glslVersion; + data.uniforms = {}; - if ( value && value.isTexture ) { + for ( const name in this.uniforms ) { - data.uniforms[ name ] = { - type: 't', - value: value.toJSON( meta ).uuid - }; + const uniform = this.uniforms[ name ]; + const value = uniform.value; - } else if ( value && value.isColor ) { + if ( value && value.isTexture ) { - data.uniforms[ name ] = { - type: 'c', - value: value.getHex() - }; + data.uniforms[ name ] = { + type: 't', + value: value.toJSON( meta ).uuid + }; - } else if ( value && value.isVector2 ) { + } else if ( value && value.isColor ) { - data.uniforms[ name ] = { - type: 'v2', - value: value.toArray() - }; + data.uniforms[ name ] = { + type: 'c', + value: value.getHex() + }; - } else if ( value && value.isVector3 ) { + } else if ( value && value.isVector2 ) { - data.uniforms[ name ] = { - type: 'v3', - value: value.toArray() - }; + data.uniforms[ name ] = { + type: 'v2', + value: value.toArray() + }; - } else if ( value && value.isVector4 ) { + } else if ( value && value.isVector3 ) { - data.uniforms[ name ] = { - type: 'v4', - value: value.toArray() - }; + data.uniforms[ name ] = { + type: 'v3', + value: value.toArray() + }; - } else if ( value && value.isMatrix3 ) { + } else if ( value && value.isVector4 ) { - data.uniforms[ name ] = { - type: 'm3', - value: value.toArray() - }; + data.uniforms[ name ] = { + type: 'v4', + value: value.toArray() + }; - } else if ( value && value.isMatrix4 ) { + } else if ( value && value.isMatrix3 ) { - data.uniforms[ name ] = { - type: 'm4', - value: value.toArray() - }; + data.uniforms[ name ] = { + type: 'm3', + value: value.toArray() + }; - } else { + } else if ( value && value.isMatrix4 ) { - data.uniforms[ name ] = { - value: value - }; + data.uniforms[ name ] = { + type: 'm4', + value: value.toArray() + }; - // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far + } else { - } + data.uniforms[ name ] = { + value: value + }; - } + // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far - if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines; + } - data.vertexShader = this.vertexShader; - data.fragmentShader = this.fragmentShader; + } - const extensions = {}; + if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines; - for ( const key in this.extensions ) { + data.vertexShader = this.vertexShader; + data.fragmentShader = this.fragmentShader; - if ( this.extensions[ key ] === true ) extensions[ key ] = true; + const extensions = {}; - } + for ( const key in this.extensions ) { - if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions; + if ( this.extensions[ key ] === true ) extensions[ key ] = true; + + } - return data; + if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions; -}; + return data; + } + +} export { ShaderMaterial }; diff --git a/src/materials/ShadowMaterial.js b/src/materials/ShadowMaterial.js index 7889f2e4ae62fb..9d4c9f25fb5da6 100644 --- a/src/materials/ShadowMaterial.js +++ b/src/materials/ShadowMaterial.js @@ -7,33 +7,33 @@ import { Color } from '../math/Color.js'; * } */ -function ShadowMaterial( parameters ) { +class ShadowMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'ShadowMaterial'; + super(); - this.color = new Color( 0x000000 ); - this.transparent = true; + Object.defineProperty( this, 'isShadowMaterial', { value: true } ); - this.setValues( parameters ); + this.type = 'ShadowMaterial'; -} + this.color = new Color( 0x000000 ); + this.transparent = true; -ShadowMaterial.prototype = Object.create( Material.prototype ); -ShadowMaterial.prototype.constructor = ShadowMaterial; + this.setValues( parameters ); -ShadowMaterial.prototype.isShadowMaterial = true; + } -ShadowMaterial.prototype.copy = function ( source ) { + copy( source ) { - Material.prototype.copy.call( this, source ); + super.copy( source ); - this.color.copy( source.color ); + this.color.copy( source.color ); - return this; + return this; -}; + } +} export { ShadowMaterial }; diff --git a/src/materials/SpriteMaterial.js b/src/materials/SpriteMaterial.js index 135daf57330c6a..29c2a7e2172bdf 100644 --- a/src/materials/SpriteMaterial.js +++ b/src/materials/SpriteMaterial.js @@ -11,49 +11,50 @@ import { Color } from '../math/Color.js'; * } */ -function SpriteMaterial( parameters ) { +class SpriteMaterial extends Material { - Material.call( this ); + constructor( parameters ) { - this.type = 'SpriteMaterial'; + super(); - this.color = new Color( 0xffffff ); + Object.defineProperty( this, 'isSpriteMaterial', { value: true } ); - this.map = null; + this.type = 'SpriteMaterial'; - this.alphaMap = null; + this.color = new Color( 0xffffff ); - this.rotation = 0; + this.map = null; - this.sizeAttenuation = true; + this.alphaMap = null; - this.transparent = true; + this.rotation = 0; - this.setValues( parameters ); + this.sizeAttenuation = true; -} + this.transparent = true; + + this.setValues( parameters ); -SpriteMaterial.prototype = Object.create( Material.prototype ); -SpriteMaterial.prototype.constructor = SpriteMaterial; -SpriteMaterial.prototype.isSpriteMaterial = true; + } -SpriteMaterial.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.map = source.map; + this.map = source.map; - this.alphaMap = source.alphaMap; + this.alphaMap = source.alphaMap; - this.rotation = source.rotation; + this.rotation = source.rotation; - this.sizeAttenuation = source.sizeAttenuation; + this.sizeAttenuation = source.sizeAttenuation; - return this; + return this; -}; + } +} export { SpriteMaterial };