Skip to content

Commit

Permalink
Set camera layer in update loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kpal81xd committed Dec 9, 2024
1 parent 8f49c95 commit 5f608db
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/esm/grid-renderer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,10 @@ class GridRenderer extends Script {

const targetLayer = layer ?? GridRenderer.createLayer(this.app, undefined, 1);

const cameras = [];
this.app.scene.on('prerender:layer', (camera, layer, transparent) => {
if (!camera.layers.includes(targetLayer.id)) {
camera.layers = camera.layers.concat(targetLayer.id);
if (!cameras.includes(camera)) {
cameras.push(camera);
}

if (layer !== targetLayer || transparent) {
Expand Down Expand Up @@ -382,6 +383,14 @@ class GridRenderer extends Script {
this._device.setBlendState(BlendState.NOWRITE);
this._quadRender.render();
});

this.app.on('update', () => {
for (const camera of cameras) {
if (!camera.layers.includes(targetLayer.id)) {
camera.layers = camera.layers.concat(targetLayer.id);
}
}
});
}

/**
Expand Down

0 comments on commit 5f608db

Please sign in to comment.