浏览代码

Editor: Fixed Viewport add/remove object handler.
I'm surprised I didn't notice how broken this was until now...

Mr.doob 12 年之前
父节点
当前提交
fa44aacdd7
共有 1 个文件被更改,包括 19 次插入13 次删除
  1. 19 13
      editor/js/Viewport.js

+ 19 - 13
editor/js/Viewport.js

@@ -245,20 +245,18 @@ var Viewport = function ( editor ) {
 
 	signals.objectAdded.add( function ( object ) {
 
-		if ( object instanceof THREE.Light ) {
-
-			updateMaterials();
-
-		}
-
-		objects.push( object );
+		var materialsNeedUpdate = false;
 
 		object.traverse( function ( child ) {
 
+			if ( child instanceof THREE.Light ) materialsNeedUpdate = true;
+
 			objects.push( child );
 
 		} );
 
+		if ( materialsNeedUpdate === true ) updateMaterials();
+
 	} );
 
 	signals.objectChanged.add( function ( object ) {
@@ -289,13 +287,17 @@ var Viewport = function ( editor ) {
 
 	signals.objectRemoved.add( function ( object ) {
 
-		if ( object instanceof THREE.Light ) {
+		var materialsNeedUpdate = false;
 
-			updateMaterials();
+		object.traverse( function ( child ) {
 
-		}
+			if ( child instanceof THREE.Light ) materialsNeedUpdate = true;
+
+			objects.splice( objects.indexOf( child ), 1 );
 
-		objects.splice( objects.indexOf( object ), 1 );
+		} );
+
+		if ( materialsNeedUpdate === true ) updateMaterials();
 
 	} );
 
@@ -390,12 +392,14 @@ var Viewport = function ( editor ) {
 	signals.playAnimations.add( function (animations) {
 		
 		function animate() {
+
 			requestAnimationFrame( animate );
 			
-			for (var i = 0; i < animations.length ; i++ ){
+			for ( var i = 0; i < animations.length ; i ++ ) {
+
 				animations[i].update(0.016);
-			} 
 
+			} 
 
 			render();
 		}
@@ -523,6 +527,8 @@ var Viewport = function ( editor ) {
 		renderer.render( scene, camera );
 		renderer.render( sceneHelpers, camera );
 
+		console.trace();
+
 	}
 
 	return container;