Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix target updating
  • Loading branch information
AdaRoseCannon committed Mar 22, 2022
commit 23d1ffcb801a7ab5abc86e28d7ced51fa14ed54a
2 changes: 1 addition & 1 deletion docs/components/light.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ additional properties:
|---------------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------|---------------|
| castShadow | | Whether this light casts shadows on the scene. | false |
| shadowBias | | Offset depth when deciding whether a surface is in shadow. Tiny adjustments here (in the order of +/-0.0001) may reduce artifacts in shadows. | 0 |
| shadowCameraAuto | `directional` | Automatically configure the Bottom, Top, Left, Right, Near and Far of a directional light's shadow map, from an element | |
| shadowCameraAuto | `directional` | Automatically configure the Bottom, Top, Left, Right and Near of a directional light's shadow map, from an element | |
| shadowCameraBottom | `directional` | Bottom plane of shadow camera frustum. | -5 |
| shadowCameraFar | | Far plane of shadow camera frustum. | 500 |
| shadowCameraFov | `point`, `spot` | Shadow camera's FOV. | 50 |
Expand Down
3 changes: 2 additions & 1 deletion examples/boilerplate/ar-hello-world/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
reflection="directionalLight:a-light[type=directional]"
ar-hit-test="target:#objects;"
renderer="physicallyCorrectLights:true;colorManagement:true;exposure:1;toneMapping:ACESFilmic;"
shadow="type:pcfsoft"
>
<a-light type="directional" light="castShadow:true;" position="1 1 1" intensity="0.5" auto-shadow-cam="#objects"></a-light>
<a-light type="directional" light="castShadow:true;" position="1 1 1" intensity="0.5" shadow-camera-auto="#objects"></a-light>
<a-camera position="0 0.4 0" wasd-controls="acceleration:10;"></a-camera>
<a-entity id="objects" scale="0.2 0.2 0.2" position="0 0 -1" shadow>
<a-box position="-1 0.5 1" rotation="0 45 0" color="#4CC3D9"></a-box>
Expand Down
24 changes: 17 additions & 7 deletions src/components/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports.Component = registerComponent('light', {
}

case 'envMap':
this.updateProbeMap(data, light);
self.updateProbeMap(data, light);
break;

case 'castShadow':
Expand All @@ -151,6 +151,14 @@ module.exports.Component = registerComponent('light', {
}
break;

case 'shadowCameraAuto':
if (data.shadowCameraAuto) {
self.shadowCameraAutoEls = Array.from(document.querySelectorAll(data.shadowCameraAuto));
} else {
self.shadowCameraAutoEls = [];
}
break;

default: {
light[key] = value;
}
Expand All @@ -159,10 +167,6 @@ module.exports.Component = registerComponent('light', {
return;
}

if (data.shadowCameraAutoTarget) {
this.shadowCameraAutoTargetEls = Array.from(document.querySelectorAll(data.shadowCameraAutoTarget));
}

// No light yet or light type has changed. Create and add light.
this.setLight(this.data);
this.updateShadow();
Expand All @@ -181,7 +185,7 @@ module.exports.Component = registerComponent('light', {
this.data.type === 'directional' &&
this.light.shadow &&
this.light.shadow.camera instanceof THREE.OrthographicCamera &&
this.shadowCameraAutoTargetEls.length
this.shadowCameraAutoEls.length
) {
var camera = this.light.shadow.camera;
camera.getWorldDirection(normal);
Expand All @@ -194,7 +198,7 @@ module.exports.Component = registerComponent('light', {
camera.right = -100000;
camera.top = -100000;
camera.bottom = 100000;
this.shadowCameraAutoTargetEls.forEach(function (el) {
this.shadowCameraAutoEls.forEach(function (el) {
bbox.setFromObject(el.object3D);
bbox.getBoundingSphere(sphere);
var distanceToPlane = distanceOfPointFromPlane(cameraWorldPosition, normal, sphere.center);
Expand Down Expand Up @@ -234,6 +238,12 @@ module.exports.Component = registerComponent('light', {
el.setObject3D('light-target', this.defaultTarget);
el.getObject3D('light-target').position.set(0, 0, -1);
}

if (data.shadowCameraAuto) {
this.shadowCameraAutoEls = Array.from(document.querySelectorAll(data.shadowCameraAuto));
} else {
this.shadowCameraAutoEls = [];
}
}
},

Expand Down