Quellcode durchsuchen

Materials: Revert static types of builtins materials (#29789)

* Materials: Revert static types of builtins materials

* git checkout materials too destructive

* git checkout materials too destructive

* adapt StandardNodeLibrary

* git checkout materials too destructive
Renaud Rohlinger vor 1 Jahr
Ursprung
Commit
c3a6e70fd8

+ 1 - 7
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,

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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;

+ 1 - 6
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;

+ 1 - 14
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;

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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;
 

+ 3 - 7
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;

+ 2 - 6
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;
 

+ 2 - 6
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

+ 2 - 6
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;

+ 2 - 6
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;

+ 2 - 6
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';
+
 	}
 
 }

+ 2 - 6
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 = [];

+ 2 - 6
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;
 

+ 2 - 6
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;

+ 8 - 2
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;

+ 2 - 2
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 );
 
 	}
 

+ 13 - 26
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 );

粤ICP备19079148号