Explorar el Código

GLTFExporter: Restore multi material support for non-indexed geometries. (#27268)

Michael Herzog hace 1 año
padre
commit
1b4dff01c0
Se han modificado 1 ficheros con 24 adiciones y 0 borrados
  1. 24 0
      examples/jsm/exporters/GLTFExporter.js

+ 24 - 0
examples/jsm/exporters/GLTFExporter.js

@@ -1835,6 +1835,24 @@ class GLTFWriter {
 
 		if ( isMultiMaterial && geometry.groups.length === 0 ) return null;
 
+		let didForceIndices = false;
+
+		if ( isMultiMaterial && geometry.index === null ) {
+
+			const indices = [];
+
+			for ( let i = 0, il = geometry.attributes.position.count; i < il; i ++ ) {
+
+				indices[ i ] = i;
+
+			}
+
+			geometry.setIndex( indices );
+
+			didForceIndices = true;
+
+		}
+
 		const materials = isMultiMaterial ? mesh.material : [ mesh.material ];
 		const groups = isMultiMaterial ? geometry.groups : [ { materialIndex: 0, start: undefined, count: undefined } ];
 
@@ -1882,6 +1900,12 @@ class GLTFWriter {
 
 		}
 
+		if ( didForceIndices === true ) {
+
+			geometry.setIndex( null );
+
+		}
+
 		meshDef.primitives = primitives;
 
 		if ( ! json.meshes ) json.meshes = [];