Ver código fonte

NodeMaterial: Fix support for extended classes (2) (#24723)

* fix support for extended classes (2)

* Added MeshPhysicalNodeMaterial

* Added MeshCustomNodeMaterial to test

* some description
sunag 2 anos atrás
pai
commit
ba36d89e33

+ 3 - 1
examples/jsm/nodes/loaders/NodeMaterialLoader.js

@@ -4,6 +4,7 @@ import {
 	LineBasicNodeMaterial,
 	MeshBasicNodeMaterial,
 	MeshStandardNodeMaterial,
+	MeshPhysicalNodeMaterial,
 	PointsNodeMaterial,
 	SpriteNodeMaterial
 } from '../materials/Materials.js';
@@ -17,8 +18,9 @@ MaterialLoader.createMaterialFromType = function ( type ) {
 		LineBasicNodeMaterial,
 		MeshBasicNodeMaterial,
 		MeshStandardNodeMaterial,
+		MeshPhysicalNodeMaterial,
 		PointsNodeMaterial,
-		SpriteNodeMaterial,
+		SpriteNodeMaterial
 	};
 
 	if ( materialLib[ type ] !== undefined ) {

+ 11 - 1
examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js

@@ -73,7 +73,17 @@ class WebGLNodeBuilder extends NodeBuilder {
 
 	_parseShaderLib() {
 
-		const type = this.material.type;
+		const material = this.material;
+
+		let type = material.type;
+
+		// see https://github.com/mrdoob/three.js/issues/23707
+
+		if ( material.isMeshPhysicalNodeMaterial ) type = 'MeshPhysicalNodeMaterial';
+		else if ( material.isMeshStandardNodeMaterial ) type = 'MeshStandardNodeMaterial';
+		else if ( material.isMeshBasicNodeMaterial ) type = 'MeshBasicNodeMaterial';
+		else if ( material.isPointsNodeMaterial ) type = 'PointsNodeMaterial';
+		else if ( material.isLineBasicNodeMaterial ) type = 'LineBasicNodeMaterial';
 
 		// shader lib
 

+ 33 - 1
examples/webgl_nodes_materials_standard.html

@@ -75,9 +75,41 @@
 
 				scene.add( new THREE.HemisphereLight( 0x443333, 0x222233, 4 ) );
 
+				// Test Extended Material
+
+				class MeshCustomNodeMaterial extends Nodes.MeshStandardNodeMaterial {
+
+					constructor() {
+
+						super();
+
+					}
+
+				}
+
+				// Extends Serialization Material
+
+				const superCreateMaterialFromType = THREE.MaterialLoader.createMaterialFromType;
+
+				THREE.MaterialLoader.createMaterialFromType = function ( type ) {
+
+					const materialLib = {
+						MeshCustomNodeMaterial
+					};
+
+					if ( materialLib[ type ] !== undefined ) {
+
+						return new materialLib[ type ]();
+
+					}
+
+					return superCreateMaterialFromType.call( this, type );
+
+				};
+
 				//
 
-				const material = new Nodes.MeshStandardNodeMaterial();
+				const material = new MeshCustomNodeMaterial();
 
 				new OBJLoader()
 					.setPath( 'models/obj/cerberus/' )