Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved SpotLightHelper #3470

Merged
merged 1 commit into from
May 13, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions src/extras/helpers/SpotLightHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,52 @@
* @author WestLangley / http://github.com/WestLangley
*/

THREE.SpotLightHelper = function ( light, sphereSize ) {
THREE.SpotLightHelper = function ( light ) {

THREE.Object3D.call( this );

this.matrixAutoUpdate = false;
// spotlight helper must be a child of the scene

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 );
var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );

geometry = new THREE.CylinderGeometry( 0.0001, 1, 1, 8, 1, true );
geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, -0.5, 0 ) );

geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );

material = new THREE.MeshBasicMaterial( { fog: false, wireframe: true, opacity: 0.3, transparent: true } );
material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
var material = new THREE.MeshBasicMaterial( { wireframe: true, opacity: 0.3, transparent: true } );

this.lightCone = new THREE.Mesh( geometry, material );
this.lightCone.position = this.light.position;
THREE.Mesh.call( this, geometry, material );

var coneLength = light.distance ? light.distance : 10000;
var coneWidth = coneLength * Math.tan( light.angle );
this.update();

this.lightCone.scale.set( coneWidth, coneWidth, coneLength );
this.lightCone.lookAt( this.light.target.position );
};

this.add( this.lightCone );
THREE.SpotLightHelper.prototype = Object.create( THREE.Mesh.prototype );

};
THREE.SpotLightHelper.prototype.update = ( function () {

THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
var targetPosition = new THREE.Vector3();

THREE.SpotLightHelper.prototype.update = function () {
return function() {

var coneLength = this.light.distance ? this.light.distance : 10000;
var coneWidth = coneLength * Math.tan( this.light.angle );
var coneLength = this.light.distance ? this.light.distance : 10000;

this.lightCone.scale.set( coneWidth, coneWidth, coneLength );
this.lightCone.lookAt( this.light.target.position );
var coneWidth = coneLength * Math.tan( this.light.angle );

this.lightSphere.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
this.lightCone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
this.scale.set( coneWidth, coneWidth, coneLength );

};
this.light.updateMatrixWorld( true );

this.position.getPositionFromMatrix( this.light.matrixWorld );

this.light.target.updateMatrixWorld( true );

targetPosition.getPositionFromMatrix( this.light.target.matrixWorld );

this.lookAt( targetPosition );

this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );

}

}());