PointLightHelper.js 1.9 KB

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