diff --git a/examples/jsm/lines/LineMaterial.js b/examples/jsm/lines/LineMaterial.js index 7e29ff847d0df1..5890e91607c34a 100644 --- a/examples/jsm/lines/LineMaterial.js +++ b/examples/jsm/lines/LineMaterial.js @@ -405,17 +405,11 @@ ShaderLib[ 'line' ] = { class LineMaterial extends ShaderMaterial { - - static get type() { - - return 'LineMaterial'; - - } - constructor( parameters ) { super( { + type: 'LineMaterial', uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ), vertexShader: ShaderLib[ 'line' ].vertexShader, diff --git a/examples/jsm/loaders/MMDLoader.js b/examples/jsm/loaders/MMDLoader.js index 503b647be9d3e5..eb87a91aa0bdc0 100644 --- a/examples/jsm/loaders/MMDLoader.js +++ b/examples/jsm/loaders/MMDLoader.js @@ -2131,18 +2131,14 @@ class CubicBezierInterpolation extends Interpolant { class MMDToonMaterial extends ShaderMaterial { - static get type() { - - return 'MMDToonMaterial'; - - } - constructor( parameters ) { super(); this.isMMDToonMaterial = true; + this.type = 'MMDToonMaterial'; + this._matcapCombine = AddOperation; this.emissiveIntensity = 1.0; this.normalMapType = TangentSpaceNormalMap; diff --git a/examples/jsm/materials/MeshGouraudMaterial.js b/examples/jsm/materials/MeshGouraudMaterial.js index 178825831aaa7f..56d45c4f867b23 100644 --- a/examples/jsm/materials/MeshGouraudMaterial.js +++ b/examples/jsm/materials/MeshGouraudMaterial.js @@ -315,18 +315,14 @@ const GouraudShader = { class MeshGouraudMaterial extends ShaderMaterial { - static get type() { - - return 'MeshGouraudMaterial'; - - } - constructor( parameters ) { super(); this.isMeshGouraudMaterial = true; + this.type = 'MeshGouraudMaterial'; + //this.color = new THREE.Color( 0xffffff ); // diffuse //this.map = null; diff --git a/src/materials/LineBasicMaterial.js b/src/materials/LineBasicMaterial.js index 851da837a2a660..b6cc7be93afff5 100644 --- a/src/materials/LineBasicMaterial.js +++ b/src/materials/LineBasicMaterial.js @@ -3,18 +3,14 @@ import { Color } from '../math/Color.js'; class LineBasicMaterial extends Material { - static get type() { - - return 'LineBasicMaterial'; - - } - constructor( parameters ) { super(); this.isLineBasicMaterial = true; + this.type = 'LineBasicMaterial'; + this.color = new Color( 0xffffff ); this.map = null; diff --git a/src/materials/LineDashedMaterial.js b/src/materials/LineDashedMaterial.js index ab7947daec4c16..9a7b108d4a28e7 100644 --- a/src/materials/LineDashedMaterial.js +++ b/src/materials/LineDashedMaterial.js @@ -2,17 +2,12 @@ import { LineBasicMaterial } from './LineBasicMaterial.js'; class LineDashedMaterial extends LineBasicMaterial { - static get type() { - - return 'LineDashedMaterial'; - - } - constructor( parameters ) { super(); this.isLineDashedMaterial = true; + this.type = 'LineDashedMaterial'; this.scale = 1; this.dashSize = 3; diff --git a/src/materials/Material.js b/src/materials/Material.js index 0ffbf1a7c738d0..5e5863267e1e34 100644 --- a/src/materials/Material.js +++ b/src/materials/Material.js @@ -7,20 +7,6 @@ let _materialId = 0; class Material extends EventDispatcher { - static get type() { - - return 'Material'; - - } - - get type() { - - return this.constructor.type; - - } - - set type( _value ) { /* */ } - constructor() { super(); @@ -32,6 +18,7 @@ class Material extends EventDispatcher { this.uuid = MathUtils.generateUUID(); this.name = ''; + this.type = 'Material'; this.blending = NormalBlending; this.side = FrontSide; diff --git a/src/materials/MeshBasicMaterial.js b/src/materials/MeshBasicMaterial.js index fecbdcc53d27f8..1e7211a5569b01 100644 --- a/src/materials/MeshBasicMaterial.js +++ b/src/materials/MeshBasicMaterial.js @@ -5,18 +5,14 @@ import { Euler } from '../math/Euler.js'; class MeshBasicMaterial extends Material { - static get type() { - - return 'MeshBasicMaterial'; - - } - constructor( parameters ) { super(); this.isMeshBasicMaterial = true; + this.type = 'MeshBasicMaterial'; + this.color = new Color( 0xffffff ); // emissive this.map = null; diff --git a/src/materials/MeshDepthMaterial.js b/src/materials/MeshDepthMaterial.js index 766c3c021616f2..b56155d00ce58b 100644 --- a/src/materials/MeshDepthMaterial.js +++ b/src/materials/MeshDepthMaterial.js @@ -3,18 +3,14 @@ import { BasicDepthPacking } from '../constants.js'; class MeshDepthMaterial extends Material { - static get type() { - - return 'MeshDepthMaterial'; - - } - constructor( parameters ) { super(); this.isMeshDepthMaterial = true; + this.type = 'MeshDepthMaterial'; + this.depthPacking = BasicDepthPacking; this.map = null; diff --git a/src/materials/MeshDistanceMaterial.js b/src/materials/MeshDistanceMaterial.js index a04082a8daf370..a12add1551f8cf 100644 --- a/src/materials/MeshDistanceMaterial.js +++ b/src/materials/MeshDistanceMaterial.js @@ -2,18 +2,14 @@ import { Material } from './Material.js'; class MeshDistanceMaterial extends Material { - static get type() { - - return 'MeshDistanceMaterial'; - - } - constructor( parameters ) { super(); this.isMeshDistanceMaterial = true; + this.type = 'MeshDistanceMaterial'; + this.map = null; this.alphaMap = null; diff --git a/src/materials/MeshLambertMaterial.js b/src/materials/MeshLambertMaterial.js index 60180dba9e8100..f92202880901c5 100644 --- a/src/materials/MeshLambertMaterial.js +++ b/src/materials/MeshLambertMaterial.js @@ -6,18 +6,14 @@ import { Euler } from '../math/Euler.js'; class MeshLambertMaterial extends Material { - static get type() { - - return 'MeshLambertMaterial'; - - } - constructor( parameters ) { super(); this.isMeshLambertMaterial = true; + this.type = 'MeshLambertMaterial'; + this.color = new Color( 0xffffff ); // diffuse this.map = null; diff --git a/src/materials/MeshMatcapMaterial.js b/src/materials/MeshMatcapMaterial.js index 42e367a8bcce34..84030dcae04ab2 100644 --- a/src/materials/MeshMatcapMaterial.js +++ b/src/materials/MeshMatcapMaterial.js @@ -5,12 +5,6 @@ import { Color } from '../math/Color.js'; class MeshMatcapMaterial extends Material { - static get type() { - - return 'MeshMatcapMaterial'; - - } - constructor( parameters ) { super(); @@ -19,6 +13,8 @@ class MeshMatcapMaterial extends Material { this.defines = { 'MATCAP': '' }; + this.type = 'MeshMatcapMaterial'; + this.color = new Color( 0xffffff ); // diffuse this.matcap = null; diff --git a/src/materials/MeshNormalMaterial.js b/src/materials/MeshNormalMaterial.js index fbd60efed08fe6..b891031b013022 100644 --- a/src/materials/MeshNormalMaterial.js +++ b/src/materials/MeshNormalMaterial.js @@ -4,18 +4,14 @@ import { Vector2 } from '../math/Vector2.js'; class MeshNormalMaterial extends Material { - static get type() { - - return 'MeshNormalMaterial'; - - } - constructor( parameters ) { super(); this.isMeshNormalMaterial = true; + this.type = 'MeshNormalMaterial'; + this.bumpMap = null; this.bumpScale = 1; diff --git a/src/materials/MeshPhongMaterial.js b/src/materials/MeshPhongMaterial.js index d67c25f56c17a6..6373cc98038198 100644 --- a/src/materials/MeshPhongMaterial.js +++ b/src/materials/MeshPhongMaterial.js @@ -3,21 +3,16 @@ import { Material } from './Material.js'; import { Vector2 } from '../math/Vector2.js'; import { Color } from '../math/Color.js'; import { Euler } from '../math/Euler.js'; - class MeshPhongMaterial extends Material { - static get type() { - - return 'MeshPhongMaterial'; - - } - constructor( parameters ) { super(); this.isMeshPhongMaterial = true; + this.type = 'MeshPhongMaterial'; + this.color = new Color( 0xffffff ); // diffuse this.specular = new Color( 0x111111 ); this.shininess = 30; @@ -51,6 +46,7 @@ class MeshPhongMaterial extends Material { this.envMap = null; this.envMapRotation = new Euler(); + this.combine = MultiplyOperation; this.reflectivity = 1; this.refractionRatio = 0.98; diff --git a/src/materials/MeshPhysicalMaterial.js b/src/materials/MeshPhysicalMaterial.js index 2d4585e7ce21a2..840d70183a5693 100644 --- a/src/materials/MeshPhysicalMaterial.js +++ b/src/materials/MeshPhysicalMaterial.js @@ -5,12 +5,6 @@ import * as MathUtils from '../math/MathUtils.js'; class MeshPhysicalMaterial extends MeshStandardMaterial { - static get type() { - - return 'MeshPhysicalMaterial'; - - } - constructor( parameters ) { super(); @@ -24,6 +18,8 @@ class MeshPhysicalMaterial extends MeshStandardMaterial { }; + this.type = 'MeshPhysicalMaterial'; + this.anisotropyRotation = 0; this.anisotropyMap = null; diff --git a/src/materials/MeshStandardMaterial.js b/src/materials/MeshStandardMaterial.js index 32cec6d3901d8b..05b0f2795d9aa9 100644 --- a/src/materials/MeshStandardMaterial.js +++ b/src/materials/MeshStandardMaterial.js @@ -6,18 +6,14 @@ import { Euler } from '../math/Euler.js'; class MeshStandardMaterial extends Material { - static get type() { - - return 'MeshStandardMaterial'; - - } - constructor( parameters ) { super(); this.isMeshStandardMaterial = true; + this.type = 'MeshStandardMaterial'; + this.defines = { 'STANDARD': '' }; this.color = new Color( 0xffffff ); // diffuse diff --git a/src/materials/MeshToonMaterial.js b/src/materials/MeshToonMaterial.js index eacd72e42e9c0e..2f9b2f9e273b5e 100644 --- a/src/materials/MeshToonMaterial.js +++ b/src/materials/MeshToonMaterial.js @@ -5,12 +5,6 @@ import { Color } from '../math/Color.js'; class MeshToonMaterial extends Material { - static get type() { - - return 'MeshToonMaterial'; - - } - constructor( parameters ) { super(); @@ -19,6 +13,8 @@ class MeshToonMaterial extends Material { this.defines = { 'TOON': '' }; + this.type = 'MeshToonMaterial'; + this.color = new Color( 0xffffff ); this.map = null; diff --git a/src/materials/PointsMaterial.js b/src/materials/PointsMaterial.js index 883ef2ca8b2c52..8ca5500d6ee124 100644 --- a/src/materials/PointsMaterial.js +++ b/src/materials/PointsMaterial.js @@ -3,18 +3,14 @@ import { Color } from '../math/Color.js'; class PointsMaterial extends Material { - static get type() { - - return 'PointsMaterial'; - - } - constructor( parameters ) { super(); this.isPointsMaterial = true; + this.type = 'PointsMaterial'; + this.color = new Color( 0xffffff ); this.map = null; diff --git a/src/materials/RawShaderMaterial.js b/src/materials/RawShaderMaterial.js index 7a435af08958b5..e2ab4377aeb98b 100644 --- a/src/materials/RawShaderMaterial.js +++ b/src/materials/RawShaderMaterial.js @@ -2,18 +2,14 @@ import { ShaderMaterial } from './ShaderMaterial.js'; class RawShaderMaterial extends ShaderMaterial { - static get type() { - - return 'RawShaderMaterial'; - - } - constructor( parameters ) { super( parameters ); this.isRawShaderMaterial = true; + this.type = 'RawShaderMaterial'; + } } diff --git a/src/materials/ShaderMaterial.js b/src/materials/ShaderMaterial.js index 33972495288e80..ca3dbbe9f4a6c2 100644 --- a/src/materials/ShaderMaterial.js +++ b/src/materials/ShaderMaterial.js @@ -6,18 +6,14 @@ import default_fragment from '../renderers/shaders/ShaderChunk/default_fragment. class ShaderMaterial extends Material { - static get type() { - - return 'ShaderMaterial'; - - } - constructor( parameters ) { super(); this.isShaderMaterial = true; + this.type = 'ShaderMaterial'; + this.defines = {}; this.uniforms = {}; this.uniformsGroups = []; diff --git a/src/materials/ShadowMaterial.js b/src/materials/ShadowMaterial.js index 2dc4cd6cae7d22..deea305d9e633c 100644 --- a/src/materials/ShadowMaterial.js +++ b/src/materials/ShadowMaterial.js @@ -3,18 +3,14 @@ import { Color } from '../math/Color.js'; class ShadowMaterial extends Material { - static get type() { - - return 'ShadowMaterial'; - - } - constructor( parameters ) { super(); this.isShadowMaterial = true; + this.type = 'ShadowMaterial'; + this.color = new Color( 0x000000 ); this.transparent = true; diff --git a/src/materials/SpriteMaterial.js b/src/materials/SpriteMaterial.js index 72fe93013b1992..911e9abe75f376 100644 --- a/src/materials/SpriteMaterial.js +++ b/src/materials/SpriteMaterial.js @@ -3,18 +3,14 @@ import { Color } from '../math/Color.js'; class SpriteMaterial extends Material { - static get type() { - - return 'SpriteMaterial'; - - } - constructor( parameters ) { super(); this.isSpriteMaterial = true; + this.type = 'SpriteMaterial'; + this.color = new Color( 0xffffff ); this.map = null; diff --git a/src/materials/nodes/NodeMaterial.js b/src/materials/nodes/NodeMaterial.js index d5319a8c2b9d7a..96efbf7345896d 100644 --- a/src/materials/nodes/NodeMaterial.js +++ b/src/materials/nodes/NodeMaterial.js @@ -32,14 +32,20 @@ class NodeMaterial extends Material { } + get type() { + + return this.constructor.type; + + } + + set type( _value ) { /* */ } + constructor() { super(); this.isNodeMaterial = true; - this.type = this.constructor.type; - this.forceSinglePass = false; this.fog = true; diff --git a/src/renderers/common/nodes/NodeLibrary.js b/src/renderers/common/nodes/NodeLibrary.js index 8d1e56ee9a8bd8..eb1e7281b1fc7f 100644 --- a/src/renderers/common/nodes/NodeLibrary.js +++ b/src/renderers/common/nodes/NodeLibrary.js @@ -50,9 +50,9 @@ class NodeLibrary { } - addMaterial( materialNodeClass, materialClass ) { + addMaterial( materialNodeClass, materialClassType ) { - this.addType( materialNodeClass, materialClass.type, this.materialNodes ); + this.addType( materialNodeClass, materialClassType, this.materialNodes ); } diff --git a/src/renderers/webgpu/nodes/StandardNodeLibrary.js b/src/renderers/webgpu/nodes/StandardNodeLibrary.js index 626900e4b46f96..2ad69f4ff70a29 100644 --- a/src/renderers/webgpu/nodes/StandardNodeLibrary.js +++ b/src/renderers/webgpu/nodes/StandardNodeLibrary.js @@ -1,31 +1,18 @@ import NodeLibrary from '../../common/nodes/NodeLibrary.js'; // Materials -import { MeshPhongMaterial } from '../../../materials/MeshPhongMaterial.js'; import MeshPhongNodeMaterial from '../../../materials/nodes/MeshPhongNodeMaterial.js'; -import { MeshStandardMaterial } from '../../../materials/MeshStandardMaterial.js'; import MeshStandardNodeMaterial from '../../../materials/nodes/MeshStandardNodeMaterial.js'; -import { MeshPhysicalMaterial } from '../../../materials/MeshPhysicalMaterial.js'; import MeshPhysicalNodeMaterial from '../../../materials/nodes/MeshPhysicalNodeMaterial.js'; -import { MeshToonMaterial } from '../../../materials/MeshToonMaterial.js'; import MeshToonNodeMaterial from '../../../materials/nodes/MeshToonNodeMaterial.js'; -import { MeshBasicMaterial } from '../../../materials/MeshBasicMaterial.js'; import MeshBasicNodeMaterial from '../../../materials/nodes/MeshBasicNodeMaterial.js'; -import { MeshLambertMaterial } from '../../../materials/MeshLambertMaterial.js'; import MeshLambertNodeMaterial from '../../../materials/nodes/MeshLambertNodeMaterial.js'; -import { MeshNormalMaterial } from '../../../materials/MeshNormalMaterial.js'; import MeshNormalNodeMaterial from '../../../materials/nodes/MeshNormalNodeMaterial.js'; -import { MeshMatcapMaterial } from '../../../materials/MeshMatcapMaterial.js'; import MeshMatcapNodeMaterial from '../../../materials/nodes/MeshMatcapNodeMaterial.js'; -import { LineBasicMaterial } from '../../../materials/LineBasicMaterial.js'; import LineBasicNodeMaterial from '../../../materials/nodes/LineBasicNodeMaterial.js'; -import { LineDashedMaterial } from '../../../materials/LineDashedMaterial.js'; import LineDashedNodeMaterial from '../../../materials/nodes/LineDashedNodeMaterial.js'; -import { PointsMaterial } from '../../../materials/PointsMaterial.js'; import PointsNodeMaterial from '../../../materials/nodes/PointsNodeMaterial.js'; -import { SpriteMaterial } from '../../../materials/SpriteMaterial.js'; import SpriteNodeMaterial from '../../../materials/nodes/SpriteNodeMaterial.js'; -import { ShadowMaterial } from '../../../materials/ShadowMaterial.js'; import ShadowNodeMaterial from '../../../materials/nodes/ShadowNodeMaterial.js'; //import { MeshDepthMaterial } from '../../../materials/MeshDepthMaterial.js'; //import MeshDepthNodeMaterial from '../../../materials/nodes/MeshDepthNodeMaterial.js'; @@ -60,19 +47,19 @@ class StandardNodeLibrary extends NodeLibrary { super(); - this.addMaterial( MeshPhongNodeMaterial, MeshPhongMaterial ); - this.addMaterial( MeshStandardNodeMaterial, MeshStandardMaterial ); - this.addMaterial( MeshPhysicalNodeMaterial, MeshPhysicalMaterial ); - this.addMaterial( MeshToonNodeMaterial, MeshToonMaterial ); - this.addMaterial( MeshBasicNodeMaterial, MeshBasicMaterial ); - this.addMaterial( MeshLambertNodeMaterial, MeshLambertMaterial ); - this.addMaterial( MeshNormalNodeMaterial, MeshNormalMaterial ); - this.addMaterial( MeshMatcapNodeMaterial, MeshMatcapMaterial ); - this.addMaterial( LineBasicNodeMaterial, LineBasicMaterial ); - this.addMaterial( LineDashedNodeMaterial, LineDashedMaterial ); - this.addMaterial( PointsNodeMaterial, PointsMaterial ); - this.addMaterial( SpriteNodeMaterial, SpriteMaterial ); - this.addMaterial( ShadowNodeMaterial, ShadowMaterial ); + this.addMaterial( MeshPhongNodeMaterial, 'MeshPhongMaterial' ); + this.addMaterial( MeshStandardNodeMaterial, 'MeshStandardMaterial' ); + this.addMaterial( MeshPhysicalNodeMaterial, 'MeshPhysicalMaterial' ); + this.addMaterial( MeshToonNodeMaterial, 'MeshToonMaterial' ); + this.addMaterial( MeshBasicNodeMaterial, 'MeshBasicMaterial' ); + this.addMaterial( MeshLambertNodeMaterial, 'MeshLambertMaterial' ); + this.addMaterial( MeshNormalNodeMaterial, 'MeshNormalMaterial' ); + this.addMaterial( MeshMatcapNodeMaterial, 'MeshMatcapMaterial' ); + this.addMaterial( LineBasicNodeMaterial, 'LineBasicMaterial' ); + this.addMaterial( LineDashedNodeMaterial, 'LineDashedMaterial' ); + this.addMaterial( PointsNodeMaterial, 'PointsMaterial' ); + this.addMaterial( SpriteNodeMaterial, 'SpriteMaterial' ); + this.addMaterial( ShadowNodeMaterial, 'ShadowMaterial' ); this.addLight( PointLightNode, PointLight ); this.addLight( DirectionalLightNode, DirectionalLight );