Bläddra i källkod

GLTFExporter: Cache meshes sharing material/geometry.

Don McCurdy 6 år sedan
förälder
incheckning
cd62f6cd96
1 ändrade filer med 12 tillägg och 1 borttagningar
  1. 12 1
      examples/js/exporters/GLTFExporter.js

+ 12 - 1
examples/js/exporters/GLTFExporter.js

@@ -104,6 +104,7 @@ THREE.GLTFExporter.prototype = {
 		var extensionsUsed = {};
 		var cachedData = {
 
+			meshes: new Map(),
 			attributes: new Map(),
 			attributesNormalized: new Map(),
 			materials: new Map(),
@@ -1002,6 +1003,13 @@ THREE.GLTFExporter.prototype = {
 		 */
 		function processMesh( mesh ) {
 
+			var cacheKey = mesh.geometry.uuid + ':' + mesh.material.uuid;
+			if ( cachedData.meshes.has( cacheKey ) ) {
+
+				return cachedData.meshes.get( cacheKey );
+
+			}
+
 			var geometry = mesh.geometry;
 
 			var mode;
@@ -1311,7 +1319,10 @@ THREE.GLTFExporter.prototype = {
 
 			outputJSON.meshes.push( gltfMesh );
 
-			return outputJSON.meshes.length - 1;
+			var index = outputJSON.meshes.length - 1;
+			cachedData.meshes.set( cacheKey, index );
+
+			return index;
 
 		}