From 9f5280ef80be7e41324d338163745dec0fe6fd95 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sun, 3 May 2026 13:22:12 +0200 Subject: [PATCH] Add tests for foliage resource planning and LOD resolution --- tests/domain/foliage-render-batches.test.ts | 60 +++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/domain/foliage-render-batches.test.ts b/tests/domain/foliage-render-batches.test.ts index 51b10227..1b3b18bf 100644 --- a/tests/domain/foliage-render-batches.test.ts +++ b/tests/domain/foliage-render-batches.test.ts @@ -4,7 +4,9 @@ import { describe, expect, it } from "vitest"; import { createFoliageInstanceMatrix, createFoliageRenderBatches, + createFoliageRenderResourcePlan, getFoliagePrototypeRenderLods, + resolveFoliageRenderChunkLod, resolveFoliageRenderLod, shouldCullFoliageChunkByDistance } from "../../src/foliage/foliage-render-batches"; @@ -236,6 +238,64 @@ describe("foliage render batch helpers", () => { ); }); + it("creates persistent resource batches for every bundled chunk LOD", () => { + const prototype = BUNDLED_FOLIAGE_PROTOTYPES[0]!; + const plan = createFoliageRenderResourcePlan( + createScatter([ + createInstance({ prototypeId: prototype.id }), + createInstance({ prototypeId: prototype.id }) + ]), + { + [prototype.id]: prototype + } + ); + + expect(plan.chunks).toHaveLength(1); + expect(plan.batches).toHaveLength(prototype.lods.length); + expect(plan.batches.map((batch) => batch.lodLevel).sort()).toEqual([ + 0, 1, 2, 3 + ]); + expect(plan.batches.every((batch) => batch.instances.length === 2)).toBe( + true + ); + }); + + it("resolves chunk-level LOD and distance culling without rebatching", () => { + const prototype = BUNDLED_FOLIAGE_PROTOTYPES[0]!; + const plan = createFoliageRenderResourcePlan( + createScatter([createInstance({ prototypeId: prototype.id })]), + { + [prototype.id]: prototype + } + ); + const chunk = plan.chunks[0]!; + + expect( + resolveFoliageRenderChunkLod({ + chunk, + view: { + cameraPosition: { x: 8, y: 0, z: 8 } + } + })?.level + ).toBe(0); + expect( + resolveFoliageRenderChunkLod({ + chunk, + view: { + cameraPosition: { x: 60, y: 0, z: 8 } + } + })?.level + ).toBe(2); + expect( + resolveFoliageRenderChunkLod({ + chunk, + view: { + cameraPosition: { x: 500, y: 0, z: 8 } + } + }) + ).toBeNull(); + }); + it("returns no batches when foliage quality is disabled", () => { const prototype = BUNDLED_FOLIAGE_PROTOTYPES[0]!; const batches = createFoliageRenderBatches(