Skip to content

Commit 4a8f94e

Browse files
authored
Only update shadow properties of lights that support shadows (#5748)
1 parent ec29410 commit 4a8f94e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/components/light.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ export var Component = registerComponent('light', {
199199
if (newLight) {
200200
if (this.light) {
201201
el.removeObject3D('light');
202+
if (el.getObject3D('cameraHelper')) {
203+
el.removeObject3D('cameraHelper');
204+
}
202205
}
203206

204207
this.light = newLight;
@@ -232,18 +235,20 @@ export var Component = registerComponent('light', {
232235
var data = this.data;
233236
var light = this.light;
234237

235-
light.castShadow = data.castShadow;
238+
// Cast shadows if enabled and light type supports shadows.
239+
light.castShadow = data.castShadow && light.shadow;
236240

237241
// Shadow camera helper.
238242
var cameraHelper = el.getObject3D('cameraHelper');
239-
if (data.shadowCameraVisible && !cameraHelper) {
243+
var shadowCameraVisible = data.shadowCameraVisible && light.shadow;
244+
if (shadowCameraVisible && !cameraHelper) {
240245
cameraHelper = new THREE.CameraHelper(light.shadow.camera);
241246
el.setObject3D('cameraHelper', cameraHelper);
242-
} else if (!data.shadowCameraVisible && cameraHelper) {
247+
} else if (!shadowCameraVisible && cameraHelper) {
243248
el.removeObject3D('cameraHelper');
244249
}
245250

246-
if (!data.castShadow) { return light; }
251+
if (!light.castShadow) { return light; }
247252

248253
// Shadow appearance.
249254
light.shadow.bias = data.shadowBias;

0 commit comments

Comments
 (0)