DirectionalLightHelper.js 1.8 KB

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