diff --git a/src/lib/map/DoodadManager.ts b/src/lib/map/DoodadManager.ts index 2e94b12..e13eafe 100644 --- a/src/lib/map/DoodadManager.ts +++ b/src/lib/map/DoodadManager.ts @@ -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(); diff --git a/src/lib/model/Model.ts b/src/lib/model/Model.ts index 01e7472..54236c5 100644 --- a/src/lib/model/Model.ts +++ b/src/lib/model/Model.ts @@ -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[], @@ -56,6 +58,10 @@ class Model extends THREE.Object3D { return this.#mesh.geometry.boundingSphere; } + get boundingSphereWorld() { + return this.#boundingSphereWorld; + } + get skinned() { return this.#skinned; } @@ -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,