PointLightHelper.js 1.8 KB

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