| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { Mesh } from '../objects/Mesh.js';
- import { MeshBasicMaterial } from '../materials/MeshBasicMaterial.js';
- import { SphereGeometry } from '../geometries/SphereGeometry.js';
- /**
- * This displays a helper object consisting of a spherical mesh for
- * visualizing an instance of {@link PointLight}.
- *
- * ```js
- * const pointLight = new THREE.PointLight( 0xff0000, 1, 100 );
- * pointLight.position.set( 10, 10, 10 );
- * scene.add( pointLight );
- *
- * const sphereSize = 1;
- * const pointLightHelper = new THREE.PointLightHelper( pointLight, sphereSize );
- * scene.add( pointLightHelper );
- * ```
- *
- * @augments Mesh
- */
- class PointLightHelper extends Mesh {
- /**
- * Constructs a new point light helper.
- *
- * @param {PointLight} light - The light to be visualized.
- * @param {number} [sphereSize=1] - The size of the sphere helper.
- * @param {number|Color|string} [color] - The helper's color. If not set, the helper will take
- * the color of the light.
- */
- constructor( light, sphereSize, color ) {
- const geometry = new SphereGeometry( sphereSize, 4, 2 );
- const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
- super( geometry, material );
- /**
- * The light being visualized.
- *
- * @type {PointLight}
- */
- this.light = light;
- /**
- * The color parameter passed in the constructor.
- * If not set, the helper will take the color of the light.
- *
- * @type {number|Color|string}
- */
- this.color = color;
- this.type = 'PointLightHelper';
- this.matrix = this.light.matrixWorld;
- this.matrixAutoUpdate = false;
- this.update();
- }
- /**
- * Frees the GPU-related resources allocated by this instance. Call this
- * method whenever this instance is no longer used in your app.
- */
- dispose() {
- this.geometry.dispose();
- this.material.dispose();
- }
- /**
- * Updates the helper to match the position of the
- * light being visualized.
- */
- update() {
- this.light.updateWorldMatrix( true, false );
- if ( this.color !== undefined ) {
- this.material.color.set( this.color );
- } else {
- this.material.color.copy( this.light.color );
- }
- /*
- const d = this.light.distance;
- if ( d === 0.0 ) {
- this.lightDistance.visible = false;
- } else {
- this.lightDistance.visible = true;
- this.lightDistance.scale.set( d, d, d );
- }
- */
- }
- }
- export { PointLightHelper };
|