Преглед на файлове

MaterialXLoader: Unlit Material (#27575)

* Support for MeshBasicNodeMaterial
sunag преди 1 година
родител
ревизия
21b0b81977
променени са 1 файла, в които са добавени 44 реда и са изтрити 3 реда
  1. 44 3
      examples/jsm/loaders/MaterialXLoader.js

+ 44 - 3
examples/jsm/loaders/MaterialXLoader.js

@@ -6,7 +6,7 @@ import {
 } from 'three';
 } from 'three';
 
 
 import {
 import {
-	MeshPhysicalNodeMaterial,
+	MeshBasicNodeMaterial, MeshPhysicalNodeMaterial,
 	float, bool, int, vec2, vec3, vec4, color, texture,
 	float, bool, int, vec2, vec3, vec4, color, texture,
 	positionLocal, positionWorld, uv, vertexColor,
 	positionLocal, positionWorld, uv, vertexColor,
 	normalLocal, normalWorld, tangentLocal, tangentWorld,
 	normalLocal, normalWorld, tangentLocal, tangentWorld,
@@ -697,7 +697,28 @@ class MaterialXNode {
 
 
 	}
 	}
 
 
-	toMaterial() {
+	toBasicMaterial() {
+
+		const material = new MeshBasicNodeMaterial();
+		material.name = this.name;
+
+		for ( const nodeX of this.children.toReversed() ) {
+
+			if ( nodeX.name === 'out' ) {
+
+				material.colorNode = nodeX.getNode();
+
+				break;
+
+			}
+
+		}
+
+		return material;
+
+	}
+
+	toPhysicalMaterial() {
 
 
 		const material = new MeshPhysicalNodeMaterial();
 		const material = new MeshPhysicalNodeMaterial();
 		material.name = this.name;
 		material.name = this.name;
@@ -717,14 +738,34 @@ class MaterialXNode {
 
 
 		const materials = {};
 		const materials = {};
 
 
+		let isUnlit = true;
+
 		for ( const nodeX of this.children ) {
 		for ( const nodeX of this.children ) {
 
 
 			if ( nodeX.element === 'surfacematerial' ) {
 			if ( nodeX.element === 'surfacematerial' ) {
 
 
-				const material = nodeX.toMaterial();
+				const material = nodeX.toPhysicalMaterial();
 
 
 				materials[ material.name ] = material;
 				materials[ material.name ] = material;
 
 
+				isUnlit = false;
+
+			}
+
+		}
+
+		if ( isUnlit ) {
+
+			for ( const nodeX of this.children ) {
+
+				if ( nodeX.element === 'nodegraph' ) {
+
+					const material = nodeX.toBasicMaterial();
+
+					materials[ material.name ] = material;
+
+				}
+
 			}
 			}
 
 
 		}
 		}