PointLightHelper.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import { Mesh } from '../objects/Mesh.js';
  2. import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
  3. import { SphereGeometry } from '../geometries/SphereGeometry.js';
  4. class PointLightHelper extends Mesh {
  5. constructor( light, sphereSize, color ) {
  6. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  7. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  8. super( geometry, material );
  9. this.light = light;
  10. this.light.updateMatrixWorld();
  11. this.color = color;
  12. this.type = 'PointLightHelper';
  13. this.matrix = this.light.matrixWorld;
  14. this.matrixAutoUpdate = false;
  15. this.update();
  16. /*
  17. // TODO: delete this comment?
  18. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  19. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  22. const d = light.distance;
  23. if ( d === 0.0 ) {
  24. this.lightDistance.visible = false;
  25. } else {
  26. this.lightDistance.scale.set( d, d, d );
  27. }
  28. this.add( this.lightDistance );
  29. */
  30. }
  31. dispose() {
  32. this.geometry.dispose();
  33. this.material.dispose();
  34. }
  35. update() {
  36. if ( this.color !== undefined ) {
  37. this.material.color.set( this.color );
  38. } else {
  39. this.material.color.copy( this.light.color );
  40. }
  41. /*
  42. const d = this.light.distance;
  43. if ( d === 0.0 ) {
  44. this.lightDistance.visible = false;
  45. } else {
  46. this.lightDistance.visible = true;
  47. this.lightDistance.scale.set( d, d, d );
  48. }
  49. */
  50. }
  51. }
  52. export { PointLightHelper };