Browse Source

Fix performance issue by adding cache to GLTFParser.getDependencies()

Takahiro 7 years ago
parent
commit
ecbaf2f256
1 changed files with 15 additions and 5 deletions
  1. 15 5
      examples/js/loaders/GLTFLoader.js

+ 15 - 5
examples/js/loaders/GLTFLoader.js

@@ -1342,14 +1342,24 @@ THREE.GLTFLoader = ( function () {
 	 */
 	GLTFParser.prototype.getDependencies = function ( type ) {
 
-		var parser = this;
-		var defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
+		var dependencies = this.cache.get( type );
+
+		if ( ! dependencies ) {
+
+			var parser = this;
+			var defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
+
+			dependencies = Promise.all( defs.map( function ( def, index ) {
 
-		return Promise.all( defs.map( function ( def, index ) {
+				return parser.getDependency( type, index );
 
-			return parser.getDependency( type, index );
+			} ) );
+
+			this.cache.add( type, dependencies );
+
+		}
 
-		} ) );
+		return dependencies;
 
 	};