feat: robins
This commit is contained in:
parent
a4490f7a20
commit
bd88d3cbd6
12 changed files with 159 additions and 54 deletions
|
|
@ -24,7 +24,7 @@ export type Scene = {
|
|||
npc: { position: Vec3; size: Vec2 }
|
||||
/** Canonical local-space mob meshes, one per kind, built once + shared by every
|
||||
* instance (each instance differs only by its per-frame model matrix). */
|
||||
mobMesh: { frog: Mesh; bee: Mesh }
|
||||
mobMesh: Record<MobKind, Mesh>
|
||||
/** How many mobs the sim has -- sizes the worker's shared transform buffer. */
|
||||
mobCount: number
|
||||
sky: SkyConfig
|
||||
|
|
@ -36,7 +36,11 @@ export type Scene = {
|
|||
* `renderBand` (single-thread) or packed into the shared `mobState` buffer and
|
||||
* rebuilt in each worker. `MOB_FLOATS` is that packed layout's stride. */
|
||||
export type MobDraw = { kind: MobKind; x: number; y: number; z: number; heading: number; scale: number }
|
||||
export const MOB_FLOATS = 6 // kind(0/1), x, y, z, heading, scale
|
||||
export const MOB_FLOATS = 6 // kind index, x, y, z, heading, scale
|
||||
/** Canonical kind order -- the index packed into the shared `mobState` buffer
|
||||
* (main packs `indexOf`, each worker reads it back). Keep frog/bee first so the
|
||||
* existing indices don't shift. */
|
||||
export const MOB_KINDS: MobKind[] = ["frog", "bee", "robin"]
|
||||
|
||||
/** Chunk indices whose bounding box is inside the view frustum. Computed once on
|
||||
* the main thread and shared with every worker (so they don't each re-cull). */
|
||||
|
|
@ -122,10 +126,8 @@ export function renderBand(
|
|||
// own model matrix (viewProj x model). Drawn double-sided (cull off) -- they're
|
||||
// small and few, so the winding-correct backface cull isn't worth the fuss.
|
||||
for (const m of mobDraws) {
|
||||
const mesh = m.kind === "bee" ? scene.mobMesh.bee : scene.mobMesh.frog
|
||||
const texture = m.kind === "bee" ? tx.bee : tx.frog
|
||||
const mvp = Mat4.multiply(viewProj, Mat4.compose(m.x, m.y, m.z, m.heading, m.scale))
|
||||
Rasterizer.draw(fb, mesh, texture, mvp, config, false, y0, y1)
|
||||
Rasterizer.draw(fb, scene.mobMesh[m.kind], tx[m.kind], mvp, config, false, y0, y1)
|
||||
}
|
||||
Framebuffer.quantize(fb, config, y0, y1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue