PointLightHelper.js 1.8 KB
Newer Older
A
alteredq 已提交
1 2
/**
 * @author alteredq / http://alteredqualia.com/
M
Mr.doob 已提交
3
 * @author mrdoob / http://mrdoob.com/
A
alteredq 已提交
4 5
 */

M
Mr.doob 已提交
6 7 8 9
import { Mesh } from '../objects/Mesh';
import { MeshBasicMaterial } from '../materials/MeshBasicMaterial';
import { SphereBufferGeometry } from '../geometries/SphereGeometry';

L
Lewy Blue 已提交
10
function PointLightHelper( light, sphereSize, color ) {
A
alteredq 已提交
11

12
	this.light = light;
M
Mr.doob 已提交
13
	this.light.updateMatrixWorld();
14

L
Lewy Blue 已提交
15
	this.color = color;
16

R
Rich Harris 已提交
17
	var geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
L
Lewy Blue 已提交
18
	var material = new MeshBasicMaterial( { wireframe: true, fog: false, color: this.color } );
19

R
Rich Harris 已提交
20
	Mesh.call( this, geometry, material );
21

22
	this.matrix = this.light.matrixWorld;
23
	this.matrixAutoUpdate = false;
24

25 26 27
	this.update();


28
	/*
29 30
	var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
	var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
A
alteredq 已提交
31

32
	this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
33 34 35 36 37 38 39 40 41 42 43 44 45
	this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );

	var d = light.distance;

	if ( d === 0.0 ) {

		this.lightDistance.visible = false;

	} else {

		this.lightDistance.scale.set( d, d, d );

	}
A
alteredq 已提交
46

47
	this.add( this.lightDistance );
M
Mr.doob 已提交
48
	*/
49

M
Mr.doob 已提交
50
}
A
alteredq 已提交
51

R
Rich Harris 已提交
52 53
PointLightHelper.prototype = Object.create( Mesh.prototype );
PointLightHelper.prototype.constructor = PointLightHelper;
A
alteredq 已提交
54

R
Rich Harris 已提交
55
PointLightHelper.prototype.dispose = function () {
56

57 58
	this.geometry.dispose();
	this.material.dispose();
G
gero3 已提交
59

60 61
};

R
Rich Harris 已提交
62
PointLightHelper.prototype.update = function () {
A
alteredq 已提交
63

L
Lewy Blue 已提交
64 65 66 67 68 69 70 71 72
	if ( this.color !== undefined ) {

		this.material.color.set( this.color );

	} else {

		this.material.color.copy( this.light.color );

	}
73

M
Mr.doob 已提交
74
	/*
75 76 77 78 79 80 81 82 83 84 85 86
	var d = this.light.distance;

	if ( d === 0.0 ) {

		this.lightDistance.visible = false;

	} else {

		this.lightDistance.visible = true;
		this.lightDistance.scale.set( d, d, d );

	}
M
Mr.doob 已提交
87
	*/
A
alteredq 已提交
88

M
Mr.doob 已提交
89
};
R
Rich Harris 已提交
90 91


92
export { PointLightHelper };