Skip to content

Commit

Permalink
Disable pc-sky rendering when entering AR
Browse files Browse the repository at this point in the history
  • Loading branch information
willeastcott committed Dec 11, 2024
1 parent 172c511 commit 4142baf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion examples/scripts/ui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,36 @@ document.addEventListener('DOMContentLoaded', async () => {
}

// On entering/exiting AR, we need to set the camera clear color to transparent black
let cameraEntity;
let cameraEntity, skyType = null;
const clearColor = new Color();

app.xr.on('start', () => {
if (app.xr.type === 'immersive-ar') {
cameraEntity = app.xr.camera;
clearColor.copy(cameraEntity.camera.clearColor);
cameraEntity.camera.clearColor = new Color(0, 0, 0, 0);

const sky = document.querySelector('pc-sky');
if (sky && sky.type !== 'none') {
skyType = sky.type;
sky.type = 'none';
}
}
});

app.xr.on('end', () => {
if (app.xr.type === 'immersive-ar') {
cameraEntity.camera.clearColor = clearColor;

const sky = document.querySelector('pc-sky');
if (sky) {
if (skyType) {
sky.type = skyType;
skyType = null;
} else {
sky.removeAttribute('type');
}
}
}
});

Expand Down

0 comments on commit 4142baf

Please sign in to comment.