(world: WorldData, ctx: InstantiateContext)
| 119 | // when present. Water and river rendering depend on engine additions that |
| 120 | // land in later tasks; for now they are no-ops with TODO warnings. |
| 121 | export function instantiateWorld(world: WorldData, ctx: InstantiateContext): InstantiateResult { |
| 122 | const result: InstantiateResult = { |
| 123 | entityHandles: new Map<string, SceneNodeHandle>(), |
| 124 | terrainHandle: 0, |
| 125 | warnings: [], |
| 126 | }; |
| 127 | |
| 128 | // Apply environment first so the first frame renders with correct lighting. |
| 129 | applyEnvironment(world); |
| 130 | |
| 131 | // Terrain before entities so entities can drop onto it visually. |
| 132 | if (world.terrain) { |
| 133 | result.terrainHandle = spawnTerrain(world); |
| 134 | if (result.terrainHandle !== 0 && ctx.onTerrainSpawned) { |
| 135 | ctx.onTerrainSpawned(result.terrainHandle); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | // Spawn each entity. Prefab entities are expanded into a root group node |
| 140 | // with one child per leaf glb. |
| 141 | for (let i = 0; i < world.entities.length; i++) { |
| 142 | const entity = world.entities[i]; |
| 143 | const handle = spawnEntity(entity, ctx, result.warnings); |
| 144 | if (handle !== 0) { |
| 145 | result.entityHandles.set(entity.id, handle); |
| 146 | if (ctx.onEntitySpawned) { |
| 147 | ctx.onEntitySpawned(entity.id, handle); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (world.water.length > 0) { |
| 153 | result.warnings.push( |
| 154 | 'world has ' + world.water.length + ' water volume(s) — water rendering pending engine Q8 shader', |
| 155 | ); |
| 156 | } |
| 157 | if (world.rivers.length > 0) { |
| 158 | result.warnings.push( |
| 159 | 'world has ' + world.rivers.length + ' river(s) — river rendering pending engine Q9 spline ribbon helper', |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | return result; |
| 164 | } |
| 165 | |
| 166 | // Build the terrain mesh from the heightmap grid and upload it to a dedicated |
| 167 | // scene node. Called once per world load; the editor's brush tool re-uploads |
nothing calls this directly
no test coverage detected