Block visuals

This commit is contained in:
2026-10-13 23:52:30 -03:00
parent 55ad08266e
commit 6ad476ac18
19 changed files with 854 additions and 14 deletions
+14 -9
View File
@@ -4,8 +4,8 @@ A plan for porting all of Create to bworld as a mod, `mods/create`: its kinetics
redstone, contraptions, trains, equipment, decoration and schematics. It aims to do this with as little hand work as
possible, and to stay fast on both the server and the client when a world has thousands of moving parts.
Built so far: the importer and Create's imported blocks and items, R1, R5, S0, S7, and stonecutting from S9. Facts about
Create come from reading `ports/create1.21.1` and `ports/create1.19.3`, and facts about bworld from its source.
Built so far: the importer and Create's imported blocks and items, R1, R2, R5, S0, S7, and stonecutting from S9. Facts
about Create come from reading `ports/create1.21.1` and `ports/create1.19.3`, and facts about bworld from its source.
## Sources
@@ -235,11 +235,14 @@ it's set to something else, like NeoForge's `getUpdateTag` but per field, so a f
rest. It's saved, goes with the block, and client scripts read it with `ctx.world.get_client_data`. The display item is
its `item` field now, so there's one way to sync block data. R2's visuals will be told when a field changes.
**R2. Block visuals** (P1). `ctx.render.register_visual(block_id, factory)` in client scripts. A visual is created when
its chunk is meshed, updated when the block's client data or states change, and deleted with the block or chunk, like
Flywheel's `Visual`. Most visuals only create instances and update them on change. A visual that has to animate on the
CPU (a crank easing in, a press head) asks for a per-frame callback, like `DynamicVisual`. The engine keeps visuals per
chunk and skips whole chunks outside the frustum.
**R2. Block visuals** (P1, built). `ctx.render.register_visual(block_id, create, { replaces_model })` in client scripts,
like Flywheel's `Visual`. The chunk mesher lists the blocks with visuals in each chunk it meshes, and leaves out the
models of the ones whose visual replaces it, like `ENTITYBLOCK_ANIMATED`. A visual is made from that list, `update`d
when a client data field changes, made again when the block's states change, and deleted with the block or chunk. It
draws `rotating` and `transformed` instances of its block's model or of any model in `models/` by id, turned like a
variant. A visual that has to move on the CPU (a crank easing in, a press head) gets `on_frame`, like `DynamicVisual`.
Visuals are kept per chunk and only chunks in view are drawn. Until R3, instances are worked out on the CPU each frame
and drawn in the entity batch, behind the same API, so R3 changes no mod.
**R3. Instanced drawing** (P1). A WebGPU pipeline that draws one model many times from an instance buffer, the thing
bworld has none of today (`client/renderer/core.ts` only batches vertices). The instance types, matching Create's:
@@ -256,7 +259,8 @@ light, updated when that light changes. `rotating` is the important one: thousan
nothing per frame. See `ports/sodium` for how to keep buffer updates cheap.
**R4. Models without blocks** (P1). Any model in `models/` can be loaded by id for visuals, baked once into a GPU
buffer, and turned for whatever axis it's used on.
buffer, and turned for whatever axis it's used on. Loading by id and turning are built with R2, baked for the CPU, and
the GPU buffers come with R3.
**R5. The model format** (P0, built). Everything Create's static models use: `parent`, `x` turns, `uvlock` on variants
and parts, element `rotation` at any angle around one axis, and items drawn with models. An item's `model` draws it in
@@ -274,7 +278,8 @@ glass can use it.
their own, and drawn with the contraption's matrix each frame. Its moving parts (a drill on it, a bearing's shaft) are
instances drawn relative to it. A block change on it remeshes only it.
**R8. Render time** (P1). World ticks plus the partial tick, as a shader uniform and for client scripts.
**R8. Render time** (P1). World ticks plus the partial tick, as a shader uniform and for client scripts. Visuals get it
in `on_frame` (`ClientLevel.ticks`, which doesn't jump with `/time`), and the uniform comes with R3.
**R9. Particles** (P3). A simple GPU particle system: sprite, velocity, gravity, lifetime. Used for rotation indicators,
crushing, fan processing, steam, fluid splashes. Optional for gameplay, so it can come late.