Skip to content

Commit

Permalink
Fix #1394 Closes #1395 performance issues during transitions
Browse files Browse the repository at this point in the history
- Remove call to Renderer#clearDepth
  • Loading branch information
mistic100 committed Jul 30, 2024
1 parent 9484377 commit b4289a2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
15 changes: 12 additions & 3 deletions packages/core/src/adapters/EquirectangularAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,20 @@ export class EquirectangularAdapter extends AbstractAdapter<string, Texture, Pan
-Math.PI / 2
).scale(-1, 1, 1);

return new Mesh(geometry, new MeshBasicMaterial());
return new Mesh(geometry);
}

setTexture(mesh: EquirectangularMesh, textureData: EquirectangularTexture) {
(mesh.material as MeshBasicMaterial).map = textureData.texture;
setTexture(mesh: EquirectangularMesh, textureData: EquirectangularTexture, transition?: boolean) {
const material = new MeshBasicMaterial();

material.map = textureData.texture;

if (transition) {
material.depthTest = false;
material.depthWrite = false;
}

mesh.material = material;
}

setTextureOpacity(mesh: EquirectangularMesh, opacity: number) {
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/services/Renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@ export class Renderer extends AbstractService {

const group = new Group();
const mesh = this.viewer.adapter.createMesh();
mesh.onBeforeRender = function (renderer) {
// must be drawn on top
renderer.clearDepth();
};
this.viewer.adapter.setTexture(mesh, textureData, true);
this.viewer.adapter.setTextureOpacity(mesh, 0);
this.setPanoramaPose(textureData.panoData, mesh);
Expand Down
15 changes: 12 additions & 3 deletions packages/cubemap-adapter/src/CubemapAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ export class CubemapAdapter extends AbstractAdapter<CubemapPanorama, Texture[],
materials.push(new MeshBasicMaterial());
}

return new Mesh(geometry, materials);
return new Mesh(geometry, []);
}

setTexture(mesh: CubemapMesh, textureData: CubemapTexture) {
setTexture(mesh: CubemapMesh, textureData: CubemapTexture, transition?: boolean) {
const { texture, panoData } = textureData;

for (let i = 0; i < 6; i++) {
Expand All @@ -371,7 +371,16 @@ export class CubemapAdapter extends AbstractAdapter<CubemapPanorama, Texture[],
texture[i].rotation = Math.PI;
}

mesh.material[i].map = texture[i];
const material = new MeshBasicMaterial();

material.map = texture[i];

if (transition) {
material.depthTest = false;
material.depthWrite = false;
}

mesh.material.push(material);
}
}

Expand Down
11 changes: 8 additions & 3 deletions packages/cubemap-tiles-adapter/src/CubemapTilesAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ export class CubemapTilesAdapter extends AbstractAdapter<
setTexture(mesh: CubemapMesh, textureData: CubemapTexture, transition: boolean) {
if (transition) {
this.state.inTransition = true;
this.__setTexture(mesh, textureData);
this.__setTexture(mesh, textureData, true);
return;
}

this.__cleanup();
this.__setTexture(mesh, textureData);
this.__setTexture(mesh, textureData, false);

this.state.materials = mesh.material;
this.state.geom = mesh.geometry;
Expand All @@ -213,7 +213,7 @@ export class CubemapTilesAdapter extends AbstractAdapter<
setTimeout(() => this.__refresh());
}

private __setTexture(mesh: CubemapMesh, { texture, panoData }: CubemapTexture) {
private __setTexture(mesh: CubemapMesh, { texture, panoData }: CubemapTexture, transition: boolean) {
for (let i = 0; i < 6; i++) {
let material;
if (texture) {
Expand All @@ -227,6 +227,11 @@ export class CubemapTilesAdapter extends AbstractAdapter<
material = new MeshBasicMaterial({ opacity: 0, transparent: true });
}

if (transition) {
material.depthTest = false;
material.depthWrite = false;
}

for (let j = 0; j < NB_GROUPS_BY_FACE; j++) {
mesh.material.push(material);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,17 +270,17 @@ export class EquirectangularTilesAdapter extends AbstractAdapter<
/**
* Applies the base texture and starts the loading of tiles
*/
setTexture(mesh: EquirectangularMesh, textureData: EquirectangularTexture, transition: boolean) {
setTexture(mesh: EquirectangularMesh, textureData: EquirectangularTexture, transition?: boolean) {
const { texture } = textureData;

if (transition) {
this.state.inTransition = true;
this.__setTexture(mesh, texture);
this.__setTexture(mesh, texture, true);
return;
}

this.__cleanup();
this.__setTexture(mesh, texture);
this.__setTexture(mesh, texture, false);

this.state.materials = mesh.material;
this.state.geom = mesh.geometry;
Expand All @@ -295,14 +295,19 @@ export class EquirectangularTilesAdapter extends AbstractAdapter<
setTimeout(() => this.__refresh());
}

private __setTexture(mesh: EquirectangularMesh, texture: Texture) {
private __setTexture(mesh: EquirectangularMesh, texture: Texture, transition: boolean) {
let material;
if (texture) {
material = new MeshBasicMaterial({ map: texture });
} else {
material = new MeshBasicMaterial({ color: this.config.backgroundColor });
}

if (transition) {
material.depthTest = false;
material.depthWrite = false;
}

for (let i = 0; i < this.NB_GROUPS; i++) {
mesh.material.push(material);
}
Expand Down

0 comments on commit b4289a2

Please sign in to comment.