Skip to content

Commit

Permalink
feat(map): reduce cost of doodad culling
Browse files Browse the repository at this point in the history
  • Loading branch information
fallenoak committed Feb 12, 2024
1 parent 33730d1 commit c9059d9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/lib/map/DoodadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,28 @@ class DoodadManager {
areaGroup.visible = areaVisible;

for (const doodad of areaGroup.children as Model[]) {
if (!areaVisible) {
doodad.hide();
continue;
}

const distance = cameraPosition.distanceTo(doodad.position);
const fade = getFade(distance, doodad.sizeCategory);

const doodadVisible =
areaVisible && fade > 0.0 && cullingFrustum.intersectsSphere(doodad.boundingSphereWorld);
if (fade === 0.0) {
doodad.hide();
continue;
}

const doodadVisible = cullingFrustum.intersectsSphere(doodad.boundingSphereWorld);

if (doodadVisible) {
doodad.show();
doodad.alpha = fade;
} else {
if (!doodadVisible) {
doodad.hide();
continue;
}

doodad.alpha = fade;
doodad.show();
}
}
}
Expand Down

0 comments on commit c9059d9

Please sign in to comment.