Bläddra i källkod

Merge pull request #18647 from kinolaev/patch-1

GLTFExporter: Fix mesh cache key
Mr.doob 5 år sedan
förälder
incheckning
34f9b0ebe4
2 ändrade filer med 38 tillägg och 8 borttagningar
  1. 19 4
      examples/js/exporters/GLTFExporter.js
  2. 19 4
      examples/jsm/exporters/GLTFExporter.js

+ 19 - 4
examples/js/exporters/GLTFExporter.js

@@ -1131,10 +1131,25 @@ THREE.GLTFExporter.prototype = {
 		 */
 		function processMesh( mesh ) {
 
-			var cacheKey = mesh.geometry.uuid + ':' + mesh.material.uuid;
-			if ( cachedData.meshes.has( cacheKey ) ) {
+			var meshCacheKeyParts = [ mesh.geometry.uuid ];
+			if ( Array.isArray( mesh.material ) ) {
 
-				return cachedData.meshes.get( cacheKey );
+				for ( var i = 0, l = mesh.material.length; i < l; i++ ) {
+
+					meshCacheKeyParts.push( mesh.material[ i ].uuid	);
+
+				}
+
+			} else {
+
+				meshCacheKeyParts.push( mesh.material.uuid );
+
+			}
+
+			var meshCacheKey = meshCacheKeyParts.join( ':' );
+			if ( cachedData.meshes.has( meshCacheKey ) ) {
+
+				return cachedData.meshes.get( meshCacheKey );
 
 			}
 
@@ -1459,7 +1474,7 @@ THREE.GLTFExporter.prototype = {
 			outputJSON.meshes.push( gltfMesh );
 
 			var index = outputJSON.meshes.length - 1;
-			cachedData.meshes.set( cacheKey, index );
+			cachedData.meshes.set( meshCacheKey, index );
 
 			return index;
 

+ 19 - 4
examples/jsm/exporters/GLTFExporter.js

@@ -1153,10 +1153,25 @@ GLTFExporter.prototype = {
 		 */
 		function processMesh( mesh ) {
 
-			var cacheKey = mesh.geometry.uuid + ':' + mesh.material.uuid;
-			if ( cachedData.meshes.has( cacheKey ) ) {
+			var meshCacheKeyParts = [ mesh.geometry.uuid ];
+			if ( Array.isArray( mesh.material ) ) {
 
-				return cachedData.meshes.get( cacheKey );
+				for ( var i = 0, l = mesh.material.length; i < l; i++ ) {
+
+					meshCacheKeyParts.push( mesh.material[ i ].uuid	);
+
+				}
+
+			} else {
+
+				meshCacheKeyParts.push( mesh.material.uuid );
+
+			}
+
+			var meshCacheKey = meshCacheKeyParts.join( ':' );
+			if ( cachedData.meshes.has( meshCacheKey ) ) {
+
+				return cachedData.meshes.get( meshCacheKey );
 
 			}
 
@@ -1481,7 +1496,7 @@ GLTFExporter.prototype = {
 			outputJSON.meshes.push( gltfMesh );
 
 			var index = outputJSON.meshes.length - 1;
-			cachedData.meshes.set( cacheKey, index );
+			cachedData.meshes.set( meshCacheKey, index );
 
 			return index;