浏览代码

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

Takahiro 7 年之前
父节点
当前提交
ecbaf2f256
共有 1 个文件被更改,包括 15 次插入5 次删除
  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;
 
 	};