1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /**
- * @author alteredq / http://alteredqualia.com/
- * @author mrdoob / http://mrdoob.com/
- * @author WestLangley / http://github.com/WestLangley
- */
- THREE.SpotLightHelper = function ( light ) {
- THREE.Object3D.call( this );
- this.light = light;
- this.light.updateMatrixWorld();
- this.matrix = light.matrixWorld;
- this.matrixAutoUpdate = false;
- var geometry = new THREE.BufferGeometry();
- var positions = [];
- positions.push(
- 0, 0, 0, 0, 0, 1,
- 0, 0, 0, 1, 0, 1,
- 0, 0, 0, - 1, 0, 1,
- 0, 0, 0, 0, 1, 1,
- 0, 0, 0, 0, - 1, 1
- );
- var length = 32;
- for ( var i = 0; i < length; i ++ ) {
- var p1 = ( i / length ) * Math.PI * 2;
- var p2 = ( ( i + 1 ) / length ) * Math.PI * 2;
- positions.push( Math.cos( p1 ), Math.sin( p1 ), 1 );
- positions.push( Math.cos( p2 ), Math.sin( p2 ), 1 );
- }
- geometry.addAttribute( 'position', new THREE.Float32Attribute( positions, 3 ) );
- var material = new THREE.LineBasicMaterial( { fog: false } );
- this.cone = new THREE.LineSegments( geometry, material );
- this.add( this.cone );
- this.update();
- };
- THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
- THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
- THREE.SpotLightHelper.prototype.dispose = function () {
- this.cone.geometry.dispose();
- this.cone.material.dispose();
- };
- THREE.SpotLightHelper.prototype.update = function () {
- var vector = new THREE.Vector3();
- var vector2 = new THREE.Vector3();
- return function () {
- var coneLength = this.light.distance ? this.light.distance : 1000;
- var coneWidth = coneLength * Math.tan( this.light.angle );
- this.cone.scale.set( coneWidth, coneWidth, coneLength );
- vector.setFromMatrixPosition( this.light.matrixWorld );
- vector2.setFromMatrixPosition( this.light.target.matrixWorld );
- this.cone.lookAt( vector2.sub( vector ) );
- this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
- };
- }();
|