Skip to content

Commit 6387346

Browse files
authored
Merge pull request #20277 from WestLangley/dev_examples_rect_area
Examples: Use RectAreaLightHelper in RectAreaLight example
2 parents d31d001 + dd20ae6 commit 6387346

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

examples/webgl_lights_rectarealight.html

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import { GUI } from './jsm/libs/dat.gui.module.js';
2222

2323
import { OrbitControls } from './jsm/controls/OrbitControls.js';
24+
import { RectAreaLightHelper } from './jsm/helpers/RectAreaLightHelper.js';
2425
import { RectAreaLightUniformsLib } from './jsm/lights/RectAreaLightUniformsLib.js';
2526

2627
var renderer, scene, camera;
2728

2829
var origin = new THREE.Vector3();
2930

30-
var rectLight;
31+
var rectLight, rectLightHelper;
3132

3233
var param = {};
3334
var stats;
@@ -76,13 +77,8 @@
7677
rectLight.position.set( 5, 5, 0 );
7778
scene.add( rectLight );
7879

79-
var rectLightMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial( { side: THREE.BackSide } ) );
80-
rectLightMesh.scale.x = rectLight.width;
81-
rectLightMesh.scale.y = rectLight.height;
82-
rectLight.add( rectLightMesh );
83-
84-
var rectLightMeshBack = new THREE.Mesh( new THREE.PlaneBufferGeometry(), new THREE.MeshBasicMaterial( { color: 0x080808 } ) );
85-
rectLightMesh.add( rectLightMeshBack );
80+
rectLightHelper = new RectAreaLightHelper( rectLight );
81+
rectLight.add( rectLightHelper );
8682

8783
var geoFloor = new THREE.BoxBufferGeometry( 2000, 0.1, 2000 );
8884
var matStdFloor = new THREE.MeshStandardMaterial( { color: 0x808080, roughness: 0, metalness: 0 } );
@@ -142,28 +138,24 @@
142138
lightFolder.add( param, 'width', 1, 20 ).step( 0.1 ).onChange( function ( val ) {
143139

144140
rectLight.width = val;
145-
rectLightMesh.scale.x = val;
146141

147142
} );
148143

149144
lightFolder.add( param, 'height', 1, 20 ).step( 0.1 ).onChange( function ( val ) {
150145

151146
rectLight.height = val;
152-
rectLightMesh.scale.y = val;
153147

154148
} );
155149

156150
lightFolder.addColor( param, 'color' ).onChange( function ( val ) {
157151

158152
rectLight.color.setHex( val );
159-
rectLightMesh.material.color.copy( rectLight.color ).multiplyScalar( rectLight.intensity );
160153

161154
} );
162155

163156
lightFolder.add( param, 'intensity', 0.0, 4.0 ).step( 0.01 ).onChange( function ( val ) {
164157

165158
rectLight.intensity = val;
166-
rectLightMesh.material.color.copy( rectLight.color ).multiplyScalar( rectLight.intensity );
167159

168160
} );
169161

@@ -249,6 +241,8 @@
249241

250242
}
251243

244+
rectLightHelper.update();
245+
252246
renderer.render( scene, camera );
253247

254248
stats.update();

0 commit comments

Comments
 (0)