feat: trees
This commit is contained in:
parent
61389f091c
commit
9aa0ec6a3f
10 changed files with 311 additions and 10 deletions
33
AGENTS.md
33
AGENTS.md
|
|
@ -56,7 +56,9 @@ rules live in `.agents/rules/*.md`.
|
|||
`Mesh` (indexed tris), `Sprite` (Y-axis billboard), `Terrain` (procedural
|
||||
heightfield around the room: flat clearing in the center, rolling hills, tall
|
||||
edge peaks. `Terrain.ground` builds the outdoor mesh with a hole for the room;
|
||||
`Terrain.height` is the shared ground-height sampler for the player).
|
||||
`Terrain.height` is the shared ground-height sampler for the player), `Tree`
|
||||
(procedural low-poly oak/spruce geometry, sapling..full via a `growth` knob;
|
||||
`Tree.build` appends into shared trunk + foliage meshes).
|
||||
- `app/` — browser glue.
|
||||
- `main.ts` — game loop, input, preset switching, canvas blit, FPS meter.
|
||||
- `assets.ts` — load `/assets/*.png` → `Texture` (zero-copy; ImageData bytes
|
||||
|
|
@ -64,8 +66,10 @@ rules live in `.agents/rules/*.md`.
|
|||
- `level.ts` — builds the playground: a flat stone-floored room (three thick
|
||||
walls via `slab`, north side open) in the center of a big grassy `Terrain`
|
||||
world (~20x across).
|
||||
Per-texture meshes incl. the outdoor grass `ground`, `Aabb` colliders, NPC
|
||||
position, `Terrain` config + `GROUND_DIVISIONS`/`GROUND_UV`, sky/cloud config.
|
||||
Per-texture meshes incl. the outdoor grass `ground` and a scattered forest
|
||||
(`scatterTrees` → `trunks`/`oakFoliage`/`spruceFoliage`, `TREE_COUNT`/`_SEED`/
|
||||
`_REACH`), `Aabb` colliders (incl. grown-tree trunks), NPC position, `Terrain`
|
||||
config + `GROUND_DIVISIONS`/`GROUND_UV`, sky/cloud config.
|
||||
The stone floor is lifted by `FLOOR_LIFT` (a z-bias) so it stays clean over the
|
||||
terrain skirt that laps under the room edges. Room surfaces are single flat
|
||||
quads -- no subdivision needed since texturing is perspective-correct; ground
|
||||
|
|
@ -79,8 +83,9 @@ rules live in `.agents/rules/*.md`.
|
|||
`#fps` meter div (styled inline).
|
||||
- `scripts/gen-assets.ts` — procedurally draws the placeholder textures and
|
||||
writes PNGs (hand-rolled encoder via `node:zlib`). Run via `bun run assets`.
|
||||
- `assets/` — generated `floor/grass/wall/crate/npc` PNGs (`floor` = room stone,
|
||||
`grass` = outdoor ground). Swap for real art anytime;
|
||||
- `assets/` — generated `floor/grass/bark/leaf/needle/wall/crate/npc` PNGs
|
||||
(`floor` = room stone, `grass` = outdoor ground, `bark`/`leaf`/`needle` = tree
|
||||
trunk/oak/spruce). Swap for real art anytime;
|
||||
filenames are the contract.
|
||||
- `server/` — Bun server stub. `shared/` — isomorphic slot.
|
||||
|
||||
|
|
@ -88,7 +93,8 @@ rules live in `.agents/rules/*.md`.
|
|||
|
||||
`Player.update` → build `Camera` → `Camera.viewProjection` →
|
||||
`Sky.render` (fills color + resets depth, replaces a clear) →
|
||||
`Rasterizer.draw` ground, floor, walls, crate (one call per texture) →
|
||||
`Rasterizer.draw` ground, floor, walls, crate, tree trunks, oak foliage, spruce
|
||||
foliage (one call per texture) →
|
||||
`Sprite.billboard(npc)` drawn via `Rasterizer.draw` →
|
||||
`Framebuffer.quantize` → `present` (integer-scale, letterboxed blit;
|
||||
`imageSmoothingEnabled` follows `upscaleFilter`).
|
||||
|
|
@ -131,6 +137,21 @@ Both are exported presets in `app/level.ts`; the active one is set in
|
|||
branching in the cloud shader. Cost scales with sky resolution — fine at
|
||||
`standard`, heavy at `clean` (mitigate: fewer fbm octaves or half-res sky).
|
||||
|
||||
## Trees (`engine/scene/Tree.ts`)
|
||||
|
||||
Procedural low-poly geometry, faceted flat-shaded like everything else. Two
|
||||
`kind`s carry the species read purely by silhouette:
|
||||
- **`oak`** — short tapered trunk, a couple of branches, a broad cluster of
|
||||
lumpy canopy `blob`s (wider than tall, bushy).
|
||||
- **`spruce`** — tall thin trunk under stacked narrowing `cone` tiers pointing
|
||||
to a tip (taller than wide, conical).
|
||||
|
||||
`growth` (0..1) runs **sapling → full grown**: it scales height/girth and adds
|
||||
canopy blobs (oak) / tiers (spruce); `seed` gives each tree its own wobble.
|
||||
`Tree.build` appends into caller meshes so a forest batches into 3 draw calls
|
||||
(one bark trunk mesh, oak-leaf and spruce-needle foliage meshes). `app/level.ts`
|
||||
`scatterTrees` seeds the forest; add a species by extending the union + a builder.
|
||||
|
||||
## Controls
|
||||
|
||||
WASD move · **Shift** run (speed ×`RUN_MULTIPLIER` in `app/player.ts`) · mouse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue