PageSourceSearch

https://static.studyladder.co.uk/cdn/games/0.170/three/examples/jsm/helpers/RectAreaLightHelper.js

js studyladder.co.uk collected 2026-10-01 14:53:35 UTC 2,114 bytes, 85 lines download raw bytes

1import {
2	BackSide,
3	BufferGeometry,
4	Float32BufferAttribute,
5	Line,
6	LineBasicMaterial,
7	Mesh,
8	MeshBasicMaterial
9} from 'https://static.studyladder.com/cdn/games/0.143/three/three.module.js';
10
11/**
12 *  This helper must be added as a child of the light
13 */
14
15class RectAreaLightHelper extends Line {
16
17	constructor( light, color ) {
18
19		const positions = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, - 1, 0, 1, 1, 0 ];
20
21		const geometry = new BufferGeometry();
22		geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
23		geometry.computeBoundingSphere();
24
25		const material = new LineBasicMaterial( { fog: false } );
26
27		super( geometry, material );
28
29		this.light = light;
30		this.color = color; // optional hardwired color for the helper
31		this.type = 'RectAreaLightHelper';
32
33		//
34
35		const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
36
37		const geometry2 = new BufferGeometry();
38		geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
39		geometry2.computeBoundingSphere();
40
41		this.add( new Mesh( geometry2, new MeshBasicMaterial( { side: BackSide, fog: false } ) ) );
42
43	}
44
45	updateMatrixWorld() {
46
47		this.scale.set( 0.5 * this.light.width, 0.5 * this.light.height, 1 );
48
49		if ( this.color !== undefined ) {
50
51			this.material.color.set( this.color );
52			this.children[ 0 ].material.color.set( this.color );
53
54		} else {
55
56			this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
57
58			// prevent hue shift
59			const c = this.material.color;
60			const max = Math.max( c.r, c.g, c.b );
61			if ( max > 1 ) c.multiplyScalar( 1 / max );
62
63			this.children[ 0 ].material.color.copy( this.material.color );
64
65		}
66
67		// ignore world scale on light
68		this.matrixWorld.extractRotation( this.light.matrixWorld ).scale( this.scale ).copyPosition( this.light.matrixWorld );
69
70		this.children[ 0 ].matrixWorld.copy( this.matrixWorld );
71
72	}
73
74	dispose() {
75
76		this.geometry.dispose();
77		this.material.dispose();
78		this.children[ 0 ].geometry.dispose();
79		this.children[ 0 ].material.dispose();
80
81	}
82
83}
84
85export { RectAreaLightHelper };

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.