Просмотр исходного кода

Fixed handling of hierarchies and custom properties for asynchronously loaded objects in SceneLoader.

Bah, this one was tricky, all sorts of shenanigans were going on. Hope this is it, I still don't fully understand how "object" variable was keeping value from other invocations of "handle_children" (instead of just being "undefined" after "var object;"), seems like closures keeping value in recursive function calls.
alteredq 13 лет назад
Родитель
Сommit
3e906bf6fa
4 измененных файлов с 205 добавлено и 195 удалено
  1. 177 177
      build/three.min.js
  2. 8 3
      examples/scenes/test_scene.js
  3. 2 2
      examples/webgl_loader_scene.html
  4. 18 13
      src/loaders/SceneLoader.js

Разница между файлами не показана из-за своего большого размера
+ 177 - 177
build/three.min.js


+ 8 - 3
examples/scenes/test_scene.js

@@ -17,7 +17,9 @@
 			"scale"	   : [ 1, 1, 1 ],
 			"visible"  : true,
 			"properties" : {
-				"rotating" : true
+				"rotating" : true,
+				"rotateX"  : true,
+				"rotateY"  : true
 			}
 		},
 
@@ -66,7 +68,6 @@
 			"visible"  : true
 		},
 
-
 		"torus" : {
 			"geometry" : "torus",
 			"materials": [ "phong_orange" ],
@@ -166,7 +167,11 @@
 			"position" : [ -28, -1, 29 ],
 			"rotation" : [ 0, 0.5, 0 ],
 			"scale"	   : [ 12, 12, 12 ],
-			"visible"  : true
+			"visible"  : true,
+			"properties" : {
+				"rotating" : true,
+				"rotateY"  : true
+			}
 		},
 
 		"ninja" : {

+ 2 - 2
examples/webgl_loader_scene.html

@@ -461,8 +461,8 @@
 
 					var object = rotatingObjects[ i ];
 
-					object.rotation.x += 0.01;
-					object.rotation.y += 0.02;
+					if ( object.properties.rotateX ) object.rotation.x += 1 * delta;
+					if ( object.properties.rotateY ) object.rotation.y += 0.5 * delta;
 
 				}
 

+ 18 - 13
src/loaders/SceneLoader.js

@@ -62,8 +62,8 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	var urlBase = THREE.Loader.prototype.extractUrlBase( url );
 
-	var dg, dm, dd, dl, dc, df, dt,
-		g, o, m, l, d, p, r, q, s, c, t, f, tt, pp, u,
+	var dg, dm, dl, dc, df, dt,
+		g, m, l, d, p, r, q, s, c, t, f, tt, pp, u,
 		geometry, material, camera, fog,
 		texture, images,
 		light,
@@ -149,16 +149,16 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 	function handle_children( parent, children ) {
 
-		var object;
-
-		for ( dd in children ) {
+		for ( var dd in children ) {
 
 			// check by id if child has already been handled,
 			// if not, create new object
 
 			if ( result.objects[ dd ] === undefined ) {
 
-				o = children[ dd ];
+				var o = children[ dd ];
+
+				var object = null;
 
 				if ( o.geometry !== undefined ) {
 
@@ -320,19 +320,24 @@ THREE.SceneLoader.prototype.parse = function ( json, callbackFinished, url ) {
 
 				}
 
-				if ( o.properties !== undefined )  {
+				if ( object ) {
+
+					if ( o.properties !== undefined )  {
+
+						for ( var key in o.properties ) {
 
-					for ( var key in o.properties ) {
+							var value = o.properties[ key ];
+							object.properties[ key ] = value;
 
-						var value = o.properties[ key ];
-						object.properties[ key ] = value;
+						}
 
 					}
-				}
 
-				if ( o.children !== undefined ) {
+					if ( o.children !== undefined ) {
 
-					handle_children( object, o.children );
+						handle_children( object, o.children );
+
+					}
 
 				}
 

Некоторые файлы не были показаны из-за большого количества измененных файлов

粤ICP备19079148号