Browse Source

Editor: Handling helpers within the added object.

Mr.doob 12 năm trước cách đây
mục cha
commit
f31d06a1e4

+ 23 - 7
editor/js/Editor.js

@@ -65,8 +65,15 @@ Editor.prototype = {
 
 	addObject: function ( object ) {
 
+		var scope = this;
+
+		object.traverse( function ( child ) {
+
+			scope.addHelper( child );
+
+		} );
+
 		this.scene.add( object );
-		this.addHelper( object );
 
 		this.signals.objectAdded.dispatch( object );
 		this.signals.sceneGraphChanged.dispatch();
@@ -79,8 +86,15 @@ Editor.prototype = {
 
 		if ( confirm( 'Delete ' + object.name + '?' ) === false ) return;
 
+		var scope = this;
+
+		object.traverse( function ( child ) {
+
+			scope.removeHelper( child );
+
+		} );
+
 		object.parent.remove( object );
-		this.removeHelper( object );
 
 		this.signals.objectRemoved.dispatch( object );
 		this.signals.sceneGraphChanged.dispatch();
@@ -118,7 +132,7 @@ Editor.prototype = {
 		if ( object instanceof THREE.PointLight ) {
 
 			var helper = new THREE.PointLightHelper( object, 10 );
-			helper.lightSphere.id = object.id;
+			helper.userData.object = object;
 			this.sceneHelpers.add( helper );
 			this.helpers[ object.id ] = helper;
 
@@ -127,7 +141,7 @@ Editor.prototype = {
 		} else if ( object instanceof THREE.DirectionalLight ) {
 
 			var helper = new THREE.DirectionalLightHelper( object, 10 );
-			helper.lightSphere.id = object.id;
+			helper.userData.object = object;
 			this.sceneHelpers.add( helper );
 			this.helpers[ object.id ] = helper;
 
@@ -136,7 +150,7 @@ Editor.prototype = {
 		} else if ( object instanceof THREE.SpotLight ) {
 
 			var helper = new THREE.SpotLightHelper( object, 10 );
-			helper.lightSphere.id = object.id;
+			helper.userData.object = object;
 			this.sceneHelpers.add( helper );
 			this.helpers[ object.id ] = helper;
 
@@ -145,7 +159,7 @@ Editor.prototype = {
 		} else if ( object instanceof THREE.HemisphereLight ) {
 
 			var helper = new THREE.HemisphereLightHelper( object, 10 );
-			helper.lightSphere.id = object.id;
+			helper.userData.object = object;
 			this.sceneHelpers.add( helper );
 			this.helpers[ object.id ] = helper;
 
@@ -159,7 +173,9 @@ Editor.prototype = {
 
 		if ( this.helpers[ object.id ] !== undefined ) {
 
-			this.helpers[ object.id ].parent.remove( this.helpers[ object.id ] );
+			var helper = this.helpers[ object.id ];
+			helper.parent.remove( helper );
+
 			delete this.helpers[ object.id ];
 
 			this.signals.helperRemoved.dispatch( helper );

+ 24 - 8
editor/js/Viewport.js

@@ -117,15 +117,16 @@ var Viewport = function ( editor ) {
 
 				var object = intersects[ 0 ].object;
 
-				editor.select( object );
+				if ( object.userData.object !== undefined ) {
 
-				/*
-				if ( helpersToObjects[ object.id ] !== undefined ) {
+				
+					editor.select( object.userData.object );
 
-					editor.select( helpersToObjects[ object.id ] );
+				} else {
+
+					editor.select( object );
 
 				}
-				*/
 
 			} else {
 
@@ -242,14 +243,14 @@ var Viewport = function ( editor ) {
 
 	signals.objectAdded.add( function ( object ) {
 
-		objects.push( object );
-
 		if ( object instanceof THREE.Light ) {
 
 			updateMaterials();
 
 		}
 
+		objects.push( object );
+
 	} );
 
 	signals.objectChanged.add( function ( object ) {
@@ -257,7 +258,6 @@ var Viewport = function ( editor ) {
 		if ( object.geometry !== undefined ) {
 
 			selectionBox.update( object );
-			transformControls.update();
 
 		}
 
@@ -267,6 +267,8 @@ var Viewport = function ( editor ) {
 
 		}
 
+		transformControls.update();
+
 		render();
 		updateInfo();
 
@@ -280,6 +282,20 @@ var Viewport = function ( editor ) {
 
 		}
 
+		objects.splice( objects.indexOf( object ), 1 );
+
+	} );
+
+	signals.helperAdded.add( function ( object ) {
+
+		objects.push( object );
+
+	} );
+
+	signals.helperRemoved.add( function ( object ) {
+
+		objects.splice( objects.indexOf( object ), 1 );
+
 	} );
 
 	signals.materialChanged.add( function ( material ) {

+ 1 - 1
src/extras/helpers/FaceNormalsHelper.js

@@ -40,7 +40,7 @@ THREE.FaceNormalsHelper.prototype.update = ( function ( object ) {
 
 	var v1 = new THREE.Vector3();
 
-	return function( object ) {
+	return function ( object ) {
 
 		this.object.updateMatrixWorld( true );
 

+ 6 - 12
src/extras/helpers/PointLightHelper.js

@@ -5,20 +5,16 @@
 
 THREE.PointLightHelper = function ( light, sphereSize ) {
 
-	THREE.Object3D.call( this );
-
-	this.matrixAutoUpdate = false;
-
 	this.light = light;
 
 	var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
 	var material = new THREE.MeshBasicMaterial( { fog: false, wireframe: true } );
 	material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
 
-	this.lightSphere = new THREE.Mesh( geometry, material );
-	this.lightSphere.matrixWorld = this.light.matrixWorld;
-	this.lightSphere.matrixAutoUpdate = false;
-	this.add( this.lightSphere );
+	THREE.Mesh.call( this, geometry, material );
+
+	this.matrixWorld = this.light.matrixWorld;
+	this.matrixAutoUpdate = false;
 
 	/*
 	var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
@@ -44,15 +40,13 @@ THREE.PointLightHelper = function ( light, sphereSize ) {
 
 };
 
-THREE.PointLightHelper.prototype = Object.create( THREE.Object3D.prototype );
+THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
 
 THREE.PointLightHelper.prototype.update = function () {
 
-	this.lightSphere.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
+	this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
 
 	/*
-	this.lightDistance.material.color.copy( this.color );
-
 	var d = this.light.distance;
 
 	if ( d === 0.0 ) {