Browse Source

Merge remote-tracking branch 'ZuBsPaCe/dev-fix-sceneloader-hierarchy' into dev

Mr.doob 12 years ago
parent
commit
2b7e5da354
1 changed files with 36 additions and 16 deletions
  1. 36 16
      src/loaders/SceneLoader.js

+ 36 - 16
src/loaders/SceneLoader.js

@@ -173,11 +173,10 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 			// check by id if child has already been handled,
 			// check by id if child has already been handled,
 			// if not, create new object
 			// if not, create new object
 
 
-			if ( result.objects[ objID ] === undefined ) {
+            var object = result.objects[ objID ];
+            var objJSON = children[ objID ];
 
 
-				var objJSON = children[ objID ];
-
-				var object = null;
+			if ( object === undefined ) {
 
 
 				// meshes
 				// meshes
 
 
@@ -505,15 +504,16 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 					}
 					}
 
 
-					if ( objJSON.children !== undefined ) {
+				}
 
 
-						handle_children( object, objJSON.children );
+			}
 
 
-					}
+            if ( object !== undefined && objJSON.children !== undefined )
+            {
 
 
-				}
+                handle_children( object, objJSON.children );
 
 
-			}
+            }
 
 
 		}
 		}
 
 
@@ -729,6 +729,24 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	};
 	};
 
 
+    function traverse_json_hierarchy( objJSON, callback ) {
+
+        callback( objJSON );
+
+        if ( objJSON.children !== undefined ) {
+
+            var objChildID;
+
+            for ( objChildID in objJSON.children ) {
+
+                traverse_json_hierarchy( objJSON.children[ objChildID ], callback );
+
+            }
+
+        }
+
+    };
+
 	// first go synchronous elements
 	// first go synchronous elements
 
 
 	// fogs
 	// fogs
@@ -780,21 +798,23 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 
 	// count how many hierarchies will be loaded asynchronously
 	// count how many hierarchies will be loaded asynchronously
 
 
-	var objID, objJSON;
+	var objID;
 
 
 	for ( objID in data.objects ) {
 	for ( objID in data.objects ) {
 
 
-		objJSON = data.objects[ objID ];
+        traverse_json_hierarchy( data.objects[ objID ], function ( objJSON ) {
 
 
-		if ( objJSON.type && ( objJSON.type in this.hierarchyHandlerMap ) ) {
+            if ( objJSON.type && ( objJSON.type in scope.hierarchyHandlerMap ) ) {
 
 
-			counter_models += 1;
+                counter_models += 1;
 
 
-			scope.onLoadStart();
+                scope.onLoadStart();
 
 
-		}
+            }
 
 
-	}
+        });
+
+    }
 
 
 	total_models = counter_models;
 	total_models = counter_models;