Parent epic
#19
Problem
Distant objects are rendered at full polygon count even when individual triangles are sub-pixel. This wastes GPU vertex throughput. Three.js provides THREE.LOD but there is no shared helper to configure it consistently across scenes.
Goal
A composable LOD factory in packages/threejs/src/ that makes distance-based mesh swapping trivial to adopt, including an "impostor" tier (billboard sprite) for maximum-distance objects.
Plan
1. packages/threejs/src/lod.ts
/**
* Creates a THREE.LOD object from an ordered array of mesh+distance pairs.
* @param levels - array of { mesh, distance } sorted near → far
* @returns THREE.LOD ready to add to the scene
*/
export const createLOD = (levels: LODLevel[]): THREE.LOD => { … }
/**
* Creates a billboard impostor sprite from a texture for the lowest LOD tier.
*/
export const createImpostorSprite = (texture: THREE.Texture, size: number): THREE.Sprite => { … }
- Validates that levels are sorted ascending by distance
- JSDoc on all exports (required by
jsdoc/require-jsdoc rule)
2. Export from packages/threejs/src/index.ts
3. Apply in one existing scene
- Target:
ContinuousWorld or ForestGame — both have distant repeated objects
- Replace furthest-tier objects with impostor sprites
- Verify triangle count drops in the stats panel at distance
4. Tests (packages/threejs/src/lod.test.ts)
createLOD assigns the correct distances to each level
- Levels added in wrong order throw or warn
createImpostorSprite returns a THREE.Sprite
Acceptance criteria
Parent epic
#19
Problem
Distant objects are rendered at full polygon count even when individual triangles are sub-pixel. This wastes GPU vertex throughput. Three.js provides
THREE.LODbut there is no shared helper to configure it consistently across scenes.Goal
A composable LOD factory in
packages/threejs/src/that makes distance-based mesh swapping trivial to adopt, including an "impostor" tier (billboard sprite) for maximum-distance objects.Plan
1.
packages/threejs/src/lod.tsjsdoc/require-jsdocrule)2. Export from
packages/threejs/src/index.ts3. Apply in one existing scene
ContinuousWorldorForestGame— both have distant repeated objects4. Tests (
packages/threejs/src/lod.test.ts)createLODassigns the correct distances to each levelcreateImpostorSpritereturns aTHREE.SpriteAcceptance criteria
createLODandcreateImpostorSpriteexported from@webgamekit/threejs