DirectionalLightHelper.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @author mrdoob / http://mrdoob.com/
  4. * @author WestLangley / http://github.com/WestLangley
  5. */
  6. THREE.DirectionalLightHelper = function ( light, size ) {
  7. THREE.Object3D.call( this );
  8. this.light = light;
  9. this.light.updateMatrixWorld();
  10. this.matrixWorld = light.matrixWorld;
  11. this.matrixAutoUpdate = false;
  12. size = size || 1;
  13. var geometry = new THREE.PlaneGeometry( size, size );
  14. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  15. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  16. this.lightPlane = new THREE.Mesh( geometry, material );
  17. this.add( this.lightPlane );
  18. geometry = new THREE.Geometry();
  19. geometry.vertices.push( new THREE.Vector3() );
  20. geometry.vertices.push( new THREE.Vector3() );
  21. material = new THREE.LineBasicMaterial( { fog: false } );
  22. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23. this.targetLine = new THREE.Line( geometry, material );
  24. this.add( this.targetLine );
  25. this.update();
  26. };
  27. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  28. THREE.DirectionalLightHelper.prototype.dispose = function () {
  29. this.lightPlane.geometry.dispose();
  30. this.lightPlane.material.dispose();
  31. this.targetLine.geometry.dispose();
  32. this.targetLine.material.dispose();
  33. };
  34. THREE.DirectionalLightHelper.prototype.update = function () {
  35. var v1 = new THREE.Vector3();
  36. var v2 = new THREE.Vector3();
  37. var v3 = new THREE.Vector3();
  38. return function () {
  39. v1.getPositionFromMatrix( this.light.matrixWorld );
  40. v2.getPositionFromMatrix( this.light.target.matrixWorld );
  41. v3.subVectors( v2, v1 );
  42. this.lightPlane.lookAt( v3 );
  43. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  44. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  45. this.targetLine.geometry.verticesNeedUpdate = true;
  46. this.targetLine.material.color.copy( this.lightPlane.material.color );
  47. }
  48. }();