|
@@ -1,7 +1,6 @@
|
|
|
/**
|
|
|
* @author alteredq / http://alteredqualia.com/
|
|
|
- *
|
|
|
- * - shows directional light color, intensity, position, orientation and target
|
|
|
+ * @author mrdoob / http://mrdoob.com/
|
|
|
*/
|
|
|
|
|
|
THREE.DirectionalLightHelper = function ( light, sphereSize ) {
|
|
@@ -10,67 +9,39 @@ THREE.DirectionalLightHelper = function ( light, sphereSize ) {
|
|
|
|
|
|
this.light = light;
|
|
|
|
|
|
- // position
|
|
|
-
|
|
|
- this.position = light.position;
|
|
|
-
|
|
|
- // direction
|
|
|
-
|
|
|
- this.direction = new THREE.Vector3();
|
|
|
- this.direction.subVectors( light.target.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
|
|
|
+ var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
|
|
|
+ var material = new THREE.MeshBasicMaterial( { fog: false, wireframe: true } );
|
|
|
+ material.color.copy( light.color ).multiplyScalar( light.intensity );
|
|
|
|
|
|
- var bulbGeometry = new THREE.SphereGeometry( sphereSize, 16, 8 );
|
|
|
- var bulbMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false } );
|
|
|
+ this.lightSphere = new THREE.Mesh( geometry, material );
|
|
|
+ this.lightSphere.position.copy( this.light.position );
|
|
|
+ this.add( this.lightSphere );
|
|
|
|
|
|
- this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
|
|
|
+ var lineGeometry = new THREE.Geometry();
|
|
|
+ lineGeometry.vertices.push( this.light.position.clone() );
|
|
|
+ lineGeometry.vertices.push( new THREE.Vector3() );
|
|
|
+ lineGeometry.computeLineDistances();
|
|
|
|
|
|
- this.add( this.lightSphere );
|
|
|
+ var lineMaterial = new THREE.LineDashedMaterial( { dashSize: 4, gapSize: 4, opacity: 0.75, transparent: true, fog: false } );
|
|
|
+ lineMaterial.color.copy( material.color );
|
|
|
|
|
|
- this.lightSphere.userData.isGizmo = true;
|
|
|
- this.lightSphere.userData.gizmoSubject = light;
|
|
|
- this.lightSphere.userData.gizmoRoot = this;
|
|
|
+ this.targetLine = new THREE.Line( lineGeometry, lineMaterial );
|
|
|
+ this.add( this.targetLine );
|
|
|
|
|
|
+ /*
|
|
|
// light target helper
|
|
|
|
|
|
this.targetSphere = null;
|
|
|
|
|
|
if ( light.target.userData.targetInverse !== undefined ) {
|
|
|
|
|
|
- var targetGeo = new THREE.SphereGeometry( sphereSize, 8, 4 );
|
|
|
- var targetMaterial = new THREE.MeshBasicMaterial( { color: hexColor, wireframe: true, fog: false } );
|
|
|
-
|
|
|
- this.targetSphere = new THREE.Mesh( targetGeo, targetMaterial );
|
|
|
+ this.targetSphere = new THREE.Mesh( geometry, material );
|
|
|
this.targetSphere.position = light.target.position;
|
|
|
|
|
|
- this.targetSphere.userData.isGizmo = true;
|
|
|
- this.targetSphere.userData.gizmoSubject = light.target;
|
|
|
- this.targetSphere.userData.gizmoRoot = this.targetSphere;
|
|
|
-
|
|
|
- var lineMaterial = new THREE.LineDashedMaterial( { color: hexColor, dashSize: 4, gapSize: 4, opacity: 0.75, transparent: true, fog: false } );
|
|
|
- var lineGeometry = new THREE.Geometry();
|
|
|
- lineGeometry.vertices.push( this.position.clone() );
|
|
|
- lineGeometry.vertices.push( this.targetSphere.position.clone() );
|
|
|
- lineGeometry.computeLineDistances();
|
|
|
-
|
|
|
- this.targetLine = new THREE.Line( lineGeometry, lineMaterial );
|
|
|
- this.targetLine.userData.isGizmo = true;
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- this.userData.isGizmo = true;
|
|
|
+ */
|
|
|
|
|
|
}
|
|
|
|
|
@@ -78,35 +49,23 @@ THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype
|
|
|
|
|
|
THREE.DirectionalLightHelper.prototype.update = function () {
|
|
|
|
|
|
- // update arrow orientation
|
|
|
- // pointing from light to target
|
|
|
-
|
|
|
- this.direction.subVectors( this.light.target.position, this.light.position );
|
|
|
-
|
|
|
- // update arrow, spheres and line colors to light color * light intensity
|
|
|
+ this.lightSphere.position.copy( this.light.position );
|
|
|
+ this.lightSphere.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
|
|
|
|
|
|
- var intensity = 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.targetLine.geometry.vertices[ 0 ].copy( this.light.position );
|
|
|
+ this.targetLine.geometry.computeLineDistances();
|
|
|
+ this.targetLine.geometry.verticesNeedUpdate = true;
|
|
|
+ this.targetLine.material.color.copy( this.lightSphere.material.color );
|
|
|
|
|
|
+ /*
|
|
|
// Only update targetSphere and targetLine if available
|
|
|
+
|
|
|
if ( this.targetSphere !== null ) {
|
|
|
|
|
|
this.targetSphere.material.color.copy( this.color );
|
|
|
- this.targetLine.material.color.copy( this.color );
|
|
|
-
|
|
|
- // update target line vertices
|
|
|
-
|
|
|
- this.targetLine.geometry.vertices[ 0 ].copy( this.light.position );
|
|
|
- this.targetLine.geometry.vertices[ 1 ].copy( this.light.target.position );
|
|
|
-
|
|
|
- this.targetLine.geometry.computeLineDistances();
|
|
|
- this.targetLine.geometry.verticesNeedUpdate = true;
|
|
|
|
|
|
}
|
|
|
+ */
|
|
|
|
|
|
}
|
|
|
|