Browse Source

Simplified PointLightHelper.

Mr.doob 12 years ago
parent
commit
93f7d95952
2 changed files with 73 additions and 126 deletions
  1. 61 85
      editor/js/ui/Viewport.js
  2. 12 41
      src/extras/helpers/PointLightHelper.js

+ 61 - 85
editor/js/ui/Viewport.js

@@ -4,14 +4,12 @@ var Viewport = function ( signals ) {
 	container.setPosition( 'absolute' );
 	container.setPosition( 'absolute' );
 	container.setBackgroundColor( '#aaa' );
 	container.setBackgroundColor( '#aaa' );
 
 
-	// settings
+	var objects = [];
 
 
-	var enableHelpersFog = true;
 
 
 	// helpers
 	// helpers
 
 
-	var objects = [];
-
+	var helpers = {};
 	var sceneHelpers = new THREE.Scene();
 	var sceneHelpers = new THREE.Scene();
 
 
 	var size = 500, step = 25;
 	var size = 500, step = 25;
@@ -274,13 +272,18 @@ var Viewport = function ( signals ) {
 
 
 	var handleAddition = function ( object ) {
 	var handleAddition = function ( object ) {
 
 
-		// add to picking list
+		// create helpers for invisible object types (lights, cameras, targets)
 
 
-		objects.push( object );
+		if ( object instanceof THREE.PointLight ) {
 
 
-		// create helpers for invisible object types (lights, cameras, targets)
+			var helper = new THREE.PointLightHelper( object, 5 );
+
+			sceneHelpers.add( helper );
+			objects.push( helper );
+
+			helpers[ object.id ] = helper;
 
 
-		if ( object instanceof THREE.DirectionalLight ) {
+		} else if ( object instanceof THREE.DirectionalLight ) {
 
 
 			var sphereSize = 5;
 			var sphereSize = 5;
 			var arrowLength = 30;
 			var arrowLength = 30;
@@ -298,18 +301,6 @@ var Viewport = function ( signals ) {
 			objects.push( lightGizmo.targetSphere );
 			objects.push( lightGizmo.targetSphere );
 			objects.push( lightGizmo.targetLine );
 			objects.push( lightGizmo.targetLine );
 
 
-		} else if ( object instanceof THREE.PointLight ) {
-
-			var sphereSize = 5;
-
-			var lightGizmo = new THREE.PointLightHelper( object, sphereSize );
-			sceneHelpers.add( lightGizmo );
-
-			object.userData.helper = lightGizmo;
-			object.userData.pickingProxy = lightGizmo.lightSphere;
-
-			objects.push( lightGizmo.lightSphere );
-
 		} else if ( object instanceof THREE.SpotLight ) {
 		} else if ( object instanceof THREE.SpotLight ) {
 
 
 			var sphereSize = 5;
 			var sphereSize = 5;
@@ -340,6 +331,12 @@ var Viewport = function ( signals ) {
 
 
 			objects.push( lightGizmo.lightSphere );
 			objects.push( lightGizmo.lightSphere );
 
 
+		} else {
+
+			// add to picking list
+
+			objects.push( object );
+
 		}
 		}
 
 
 	};
 	};
@@ -368,7 +365,7 @@ var Viewport = function ( signals ) {
 
 
 		scene.add( object );
 		scene.add( object );
 
 
-		if ( object instanceof THREE.Light && ! ( object instanceof THREE.AmbientLight ) )  {
+		if ( object instanceof THREE.Light )  {
 
 
 			updateMaterials( scene );
 			updateMaterials( scene );
 
 
@@ -386,9 +383,12 @@ var Viewport = function ( signals ) {
 
 
 			object.updateProjectionMatrix();
 			object.updateProjectionMatrix();
 
 
+		} else if ( object instanceof THREE.PointLight ) {
+
+			helpers[ object.id ].update();
+
 		} else if ( object instanceof THREE.DirectionalLight ||
 		} else if ( object instanceof THREE.DirectionalLight ||
 					object instanceof THREE.HemisphereLight ||
 					object instanceof THREE.HemisphereLight ||
-					object instanceof THREE.PointLight ||
 					object instanceof THREE.SpotLight ) {
 					object instanceof THREE.SpotLight ) {
 
 
 			object.userData.helper.update();
 			object.userData.helper.update();
@@ -500,7 +500,7 @@ var Viewport = function ( signals ) {
 
 
 		}
 		}
 
 
-		if ( selected instanceof THREE.Light && ! ( selected instanceof THREE.AmbientLight ) )  {
+		if ( selected instanceof THREE.Light )  {
 
 
 			updateMaterials( scene );
 			updateMaterials( scene );
 
 
@@ -518,74 +518,64 @@ var Viewport = function ( signals ) {
 		selectionBox.visible = false;
 		selectionBox.visible = false;
 		selectionAxis.visible = false;
 		selectionAxis.visible = false;
 
 
-		var geometry;
-
 		if ( object !== null ) {
 		if ( object !== null ) {
 
 
-			selected = object;
-
-			if ( object.geometry ) {
-
-				geometry = object.geometry;
-
-			} else if ( object.userData.pickingProxy ) {
-
-				geometry = object.userData.pickingProxy.geometry;
+			if ( object.geometry !== undefined ) {
 
 
-			}
+				var geometry = object.geometry;
 
 
-			selectionAxis.matrixWorld = object.matrixWorld;
-			selectionAxis.visible = true;
+				if ( geometry.boundingBox === null ) {
 
 
-		}
+					geometry.computeBoundingBox();
 
 
-		if ( geometry ) {
+				}
 
 
-			if ( geometry.boundingBox === null ) {
+				var vertices = selectionBox.geometry.vertices;
 
 
-				geometry.computeBoundingBox();
+				vertices[ 0 ].x = geometry.boundingBox.max.x;
+				vertices[ 0 ].y = geometry.boundingBox.max.y;
+				vertices[ 0 ].z = geometry.boundingBox.max.z;
 
 
-			}
+				vertices[ 1 ].x = geometry.boundingBox.max.x;
+				vertices[ 1 ].y = geometry.boundingBox.max.y;
+				vertices[ 1 ].z = geometry.boundingBox.min.z;
 
 
-			var vertices = selectionBox.geometry.vertices;
+				vertices[ 2 ].x = geometry.boundingBox.max.x;
+				vertices[ 2 ].y = geometry.boundingBox.min.y;
+				vertices[ 2 ].z = geometry.boundingBox.max.z;
 
 
-			vertices[ 0 ].x = geometry.boundingBox.max.x;
-			vertices[ 0 ].y = geometry.boundingBox.max.y;
-			vertices[ 0 ].z = geometry.boundingBox.max.z;
+				vertices[ 3 ].x = geometry.boundingBox.max.x;
+				vertices[ 3 ].y = geometry.boundingBox.min.y;
+				vertices[ 3 ].z = geometry.boundingBox.min.z;
 
 
-			vertices[ 1 ].x = geometry.boundingBox.max.x;
-			vertices[ 1 ].y = geometry.boundingBox.max.y;
-			vertices[ 1 ].z = geometry.boundingBox.min.z;
+				vertices[ 4 ].x = geometry.boundingBox.min.x;
+				vertices[ 4 ].y = geometry.boundingBox.max.y;
+				vertices[ 4 ].z = geometry.boundingBox.min.z;
 
 
-			vertices[ 2 ].x = geometry.boundingBox.max.x;
-			vertices[ 2 ].y = geometry.boundingBox.min.y;
-			vertices[ 2 ].z = geometry.boundingBox.max.z;
+				vertices[ 5 ].x = geometry.boundingBox.min.x;
+				vertices[ 5 ].y = geometry.boundingBox.max.y;
+				vertices[ 5 ].z = geometry.boundingBox.max.z;
 
 
-			vertices[ 3 ].x = geometry.boundingBox.max.x;
-			vertices[ 3 ].y = geometry.boundingBox.min.y;
-			vertices[ 3 ].z = geometry.boundingBox.min.z;
+				vertices[ 6 ].x = geometry.boundingBox.min.x;
+				vertices[ 6 ].y = geometry.boundingBox.min.y;
+				vertices[ 6 ].z = geometry.boundingBox.min.z;
 
 
-			vertices[ 4 ].x = geometry.boundingBox.min.x;
-			vertices[ 4 ].y = geometry.boundingBox.max.y;
-			vertices[ 4 ].z = geometry.boundingBox.min.z;
+				vertices[ 7 ].x = geometry.boundingBox.min.x;
+				vertices[ 7 ].y = geometry.boundingBox.min.y;
+				vertices[ 7 ].z = geometry.boundingBox.max.z;
 
 
-			vertices[ 5 ].x = geometry.boundingBox.min.x;
-			vertices[ 5 ].y = geometry.boundingBox.max.y;
-			vertices[ 5 ].z = geometry.boundingBox.max.z;
+				selectionBox.geometry.computeBoundingSphere();
+				selectionBox.geometry.verticesNeedUpdate = true;
 
 
-			vertices[ 6 ].x = geometry.boundingBox.min.x;
-			vertices[ 6 ].y = geometry.boundingBox.min.y;
-			vertices[ 6 ].z = geometry.boundingBox.min.z;
+				selectionBox.matrixWorld = object.matrixWorld;
+				selectionBox.visible = true;
 
 
-			vertices[ 7 ].x = geometry.boundingBox.min.x;
-			vertices[ 7 ].y = geometry.boundingBox.min.y;
-			vertices[ 7 ].z = geometry.boundingBox.max.z;
+			}
 
 
-			selectionBox.geometry.computeBoundingSphere();
-			selectionBox.geometry.verticesNeedUpdate = true;
+			selectionAxis.matrixWorld = object.matrixWorld;
+			selectionAxis.visible = true;
 
 
-			selectionBox.matrixWorld = object.matrixWorld;
-			selectionBox.visible = true;
+			selected = object;
 
 
 		}
 		}
 
 
@@ -627,13 +617,6 @@ var Viewport = function ( signals ) {
 
 
 			updateMaterials( scene );
 			updateMaterials( scene );
 
 
-			if ( enableHelpersFog )	{
-
-				sceneHelpers.fog = scene.fog;
-				updateMaterials( sceneHelpers );
-
-			}
-
 			oldFogType = fogType;
 			oldFogType = fogType;
 
 
 		}
 		}
@@ -806,13 +789,6 @@ var Viewport = function ( signals ) {
 
 
 		}
 		}
 
 
-		if ( enableHelpersFog )	{
-
-			sceneHelpers.fog = scene.fog;
-			updateMaterials( sceneHelpers );
-
-		}
-
 		signals.sceneChanged.dispatch( scene );
 		signals.sceneChanged.dispatch( scene );
 		signals.objectSelected.dispatch( camera );
 		signals.objectSelected.dispatch( camera );
 
 

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

@@ -6,35 +6,13 @@
 
 
 THREE.PointLightHelper = function ( light, sphereSize ) {
 THREE.PointLightHelper = function ( light, sphereSize ) {
 
 
-	THREE.Object3D.call( this );
-
-	this.light = light;
-
-	// position
-
-	this.position = light.position;
-
-	// color
-
-	var intensity = THREE.Math.clamp( light.intensity, 0, 1 );
-
-	this.color = light.color.clone();
-	this.color.multiplyScalar( intensity );
-
-	var hexColor = this.color.getHex();
-
+	/*
 	// light helper
 	// light helper
 
 
-	var bulbGeometry = new THREE.SphereGeometry( sphereSize, 16, 8 );
-	var raysGeometry = new THREE.AsteriskGeometry( sphereSize * 1.25, sphereSize * 2.25 );
 	var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
 	var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
-
-	var bulbMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false } );
-	var raysMaterial = new THREE.LineBasicMaterial( { color: hexColor, fog: false } );
 	var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
 	var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
 
 
 	this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
 	this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
-	this.lightRays = new THREE.Line( raysGeometry, raysMaterial, THREE.LinePieces );
 	this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
 	this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
 
 
 	var d = light.distance;
 	var d = light.distance;
@@ -52,36 +30,28 @@ THREE.PointLightHelper = function ( light, sphereSize ) {
 	this.add( this.lightSphere );
 	this.add( this.lightSphere );
 	this.add( this.lightRays );
 	this.add( this.lightRays );
 	this.add( this.lightDistance );
 	this.add( this.lightDistance );
+	*/
 
 
-	//
+	var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
+	var material = new THREE.MeshBasicMaterial( { color: light.color.getHex(), fog: false, wireframe: true } );
 
 
-	this.lightSphere.userData.isGizmo = true;
-	this.lightSphere.userData.gizmoSubject = light;
-	this.lightSphere.userData.gizmoRoot = this;
+	THREE.Mesh.call( this, geometry, material );
 
 
-	//
-
-	this.userData.isGizmo = true;
+	this.light = light;
+	this.position = light.position;
 
 
 }
 }
 
 
-THREE.PointLightHelper.prototype = Object.create( THREE.Object3D.prototype );
+THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
 
 
 THREE.PointLightHelper.prototype.update = function () {
 THREE.PointLightHelper.prototype.update = function () {
 
 
-	// update sphere and rays colors to light color * light intensity
-
-	var intensity = THREE.Math.clamp( this.light.intensity, 0, 1 );
+	this.material.color.copy( this.light.color );
+	this.material.color.multiplyScalar( THREE.Math.clamp( this.light.intensity, 0, 1 ) );
 
 
-	this.color.copy( this.light.color );
-	this.color.multiplyScalar( intensity );
-
-	this.lightSphere.material.color.copy( this.color );
-	this.lightRays.material.color.copy( this.color );
+	/*
 	this.lightDistance.material.color.copy( this.color );
 	this.lightDistance.material.color.copy( this.color );
 
 
-	//
-
 	var d = this.light.distance;
 	var d = this.light.distance;
 
 
 	if ( d === 0.0 ) {
 	if ( d === 0.0 ) {
@@ -94,6 +64,7 @@ THREE.PointLightHelper.prototype.update = function () {
 		this.lightDistance.scale.set( d, d, d );
 		this.lightDistance.scale.set( d, d, d );
 
 
 	}
 	}
+	*/
 
 
 }
 }