Skip to content

Commit

Permalink
chore(map): reduce cost of culling doodads
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 2, 2024
1 parent 2ce8a37 commit 7e0b863
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/map/DoodadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class DoodadManager {
areaGroup.visible = areaVisible;

for (const doodad of areaGroup.children as Model[]) {
const doodadVisible = areaVisible && cullingFrustum.intersectsObject(doodad);
const doodadVisible =
areaVisible && cullingFrustum.intersectsSphere(doodad.boundingSphereWorld);

if (doodadVisible) {
doodad.show();
Expand Down
12 changes: 12 additions & 0 deletions src/lib/model/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Model extends THREE.Object3D {
#mesh: THREE.Mesh;
#skinned: boolean;

#boundingSphereWorld = new THREE.Sphere();

constructor(
geometry: THREE.BufferGeometry,
materials: THREE.Material[],
Expand Down Expand Up @@ -56,6 +58,10 @@ class Model extends THREE.Object3D {
return this.#mesh.geometry.boundingSphere;
}

get boundingSphereWorld() {
return this.#boundingSphereWorld;
}

get skinned() {
return this.#skinned;
}
Expand All @@ -82,6 +88,12 @@ class Model extends THREE.Object3D {
this.animation.resume();
}

updateMatrixWorld(force?: boolean) {
super.updateMatrixWorld(force);

this.#boundingSphereWorld.copy(this.boundingSphere).applyMatrix4(this.matrixWorld);
}

#onBeforeRender(
renderer: THREE.WebGLRenderer,
scene: THREE.Scene,
Expand Down

0 comments on commit 7e0b863

Please sign in to comment.