feat: threads
This commit is contained in:
parent
6fb46573da
commit
46e7070b6b
18 changed files with 878 additions and 125 deletions
20
app/level.ts
20
app/level.ts
|
|
@ -39,6 +39,13 @@ export type Chunk = {
|
|||
rock: Mesh
|
||||
/** Flowers (color-atlas texture); drawn double-sided, so kept separate. */
|
||||
flowers: Mesh
|
||||
/** Cheap low-poly impostors of the same trees/boulders, drawn instead of the
|
||||
* full meshes once the chunk is past `config.lodDistance` (renderScene). Same
|
||||
* textures as bark/leaf/needle/rock. Bushes/flowers have no far version. */
|
||||
barkFar: Mesh
|
||||
leafFar: Mesh
|
||||
needleFar: Mesh
|
||||
rockFar: Mesh
|
||||
}
|
||||
|
||||
/** The playground: a flat-floored room dropped into the center of a big open
|
||||
|
|
@ -215,17 +222,26 @@ function buildChunks(trees: Tree[], boulders: Boulder[], bushes: Bush[], flowers
|
|||
const needle = mesh()
|
||||
const rock = mesh()
|
||||
const flowerMesh = mesh()
|
||||
const barkFar = mesh()
|
||||
const leafFar = mesh()
|
||||
const needleFar = mesh()
|
||||
const rockFar = mesh()
|
||||
Terrain.patch(TERRAIN, grass, x0, z0, x1, z1, TERRAIN_SUBDIV, TERRAIN_SUBDIV, GROUND_UV)
|
||||
for (const tree of trees) {
|
||||
if (inCell(tree.position, x0, z0, x1, z1)) {
|
||||
Tree.build(tree, bark, tree.kind === "oak" ? leaf : needle)
|
||||
const foliage = tree.kind === "oak" ? leaf : needle
|
||||
const foliageFar = tree.kind === "oak" ? leafFar : needleFar
|
||||
Tree.build(tree, bark, foliage)
|
||||
Tree.build(tree, barkFar, foliageFar, "impostor")
|
||||
}
|
||||
}
|
||||
for (const boulder of boulders) {
|
||||
if (inCell(boulder.position, x0, z0, x1, z1)) {
|
||||
Boulder.build(boulder, rock)
|
||||
Boulder.build(boulder, rockFar, "impostor")
|
||||
}
|
||||
}
|
||||
// Bushes share the near leaf mesh; they just drop out past lodDistance.
|
||||
for (const bush of bushes) {
|
||||
if (inCell(bush.position, x0, z0, x1, z1)) {
|
||||
Bush.build(bush, leaf)
|
||||
|
|
@ -240,7 +256,7 @@ function buildChunks(trees: Tree[], boulders: Boulder[], bushes: Bush[], flowers
|
|||
if (b === null) {
|
||||
continue
|
||||
}
|
||||
chunks.push({ ...b, grass, bark, leaf, needle, rock, flowers: flowerMesh })
|
||||
chunks.push({ ...b, grass, bark, leaf, needle, rock, flowers: flowerMesh, barkFar, leafFar, needleFar, rockFar })
|
||||
}
|
||||
}
|
||||
return chunks
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue