Skip to content

Integration: physics, asset references and the terrain editing foundation (Phase 0) - #145

Merged
LyeZinho merged 13 commits into
mainfrom
merge/sync-remote-branches
Nov 23, 2026
Merged

LyeZinho merged 13 commits into
mainfrom
merge/sync-remote-branches

Conversation

@LyeZinho

Copy link
Copy Markdown
Member

What

The integration branch merge/sync-remote-branches against main. It is large (13 commits, about 495 files): it carries the earlier editor and engine work of the integration branch plus the latest two commits.

The latest two commits

c9ec080 Physics (2D and 3D): fixed step at any frame rate (a force holds for the frame it is asked in), terrain collision (a static height field), contact and trigger events for 3D, the surface rule (friction by geometric mean, restitution by the larger; setSurfaceCombine brings Bullet's product back), bodies under a parent in world space, a dynamic body moved from outside follows its entity, and the 2D fixes (static colliders, circle against box, one-way platforms, triggers, thin walls, deterministic pair order). The stale 2D tests were rewritten; 64 physics test cases.

1f80b02 AssetManager and terrain editing, Phase 0:

  • AssetManager (C ABI 24): a fresh load is pinned until the handle holds it (it used to be evicted first, which made LRU evicts unreferenced assets fail), one slot per file, type and path checks, one load per asset across threads, callbacks outside the lock; resolveReference / importReference decide what a path means and import a file from outside the project. Doppio's Inspector fields, the Terrain, Water and Nature generator slots, the Material Generator image nodes and graph baking use them.
  • Terrain editing foundation (C ABI 25 to 27): the tile model in real units, the stroke engine (stamps spaced in metres, five modes, tile-by-tile undo), the native .terrain container with a lossless converter for the legacy .cterrain (old projects open as they are; Scene > Convert terrains to .terrain), regional GI (Photon sees a terrain as one object per tile, so a stroke revoxelises only the tiles it touched) and the brush cursor. Plan and report: caffeine-website/content/en/docs/doppio/terrain-editing-roadmap.md and terrain-editing-phase-0.md.

Earlier commits on the branch

Volumetric audio, weather, Photon per view, Play and scene views, the file browser, detach, the Performance tab, the generator recipes and seeded variants, Micromesh LOD, terrain masks and the biome table, Scatter on Terrain, material slots per submesh, and the scripting API expansion.

Merge order

This PR moves two submodule pointers, so merge the others first:

  1. Add the terrain converter: caf-pack --convert-terrain caf-pack#1 (8690ae1, the terrain converter)
  2. docs: terrain editing roadmap and Phase 0, physics, asset manager, script API (EN/PT) caffeine-website#5 (25084d4, the documentation)

Checked

  • CaffeineTest: 1099 test cases pass.
  • doppio: 590 tests pass (14 ignored); cargo clippy --all-targets -- -D warnings clean with and without the agent feature; cargo fmt --check; ./scripts/check-rust-ui.sh; the headless UI flows.
  • libcaffeine-capi has to be rebuilt for Doppio to see C ABI 24 to 27 (older libraries still load: the new functions are optional on the Rust side).

Behaviour to look at

  • Terrains made of chunks (the default) are now voxelised by Photon (they were skipped because they have no single mesh); the terrain has a budget of 400 000 triangles.
  • The 3D surface rule changes how bouncy and slippery contacts feel compared with Bullet's product; setSurfaceCombine("product") restores the old one.
  • New terrains save as .terrain; a scene that still points at a .cterrain keeps saving that until it is converted.

🤖 Generated with Claude Code

LyeZinho and others added 13 commits November 18, 2026 19:37
Shared key/axis/action name lookup, Dryad runtime natives, DryadHost::setInput,
caffeine.math 3D and scalar helpers, plus photoreal-world and graphics roadmaps.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…mponent, catalog

- Single API registry (src/caffeine/script/api) with a coverage test and a docs generator
- ScriptComponent: enabled, order, properties, isolated
- Dryad natives through defineNative; time/input/world/entity/hierarchy/random/physics3d
- PhysicsWorld3D raycast/forces/velocity; runtime now steps PhysicsSystem3D
- ScriptCatalog: group/subgroup classification of scripts

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- AudioService: WAV decode/cache, handles, positional 2D; runtime creates and updates it
- SceneRequests (deferred load/reload) and SessionStore (data across scenes)
- Lua caffeine.audio/scene/session and Dryad caffeine_audio_*/scene_*/session_* natives
- API registry: 232 functions in 29 namespaces

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…; engine fixes

- PIC for static deps so libcaffeine-capi links; capitalised project folders
- generator.* recipe files, kept next to baked products
- script editor: hover cards that stay under the pointer, Ctrl+click, completions
- Dryad: 58 nodes, 20 caffeine_math_* natives (documented, tested)
- bump caffeine-website (static site)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ore hash

- core/Hash.hpp (SplitMix64) with golden tests; same values pinned in Rust
- recipes carry generator_version; Nature/Terrain slots accept generator.* recipes
- cached seeded Nature variants and doppio-material variants
- gizmo snapping (X / View menu), Reseed buttons for material and texture generators
- caf-pack bump: editor-only sources are skipped
- docs updated

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keeps the asset folder resolver, Assets file management and run-time
modifiers; adopts the branch's recipes (.generator.*), project template and
submodule bumps (caf-pack editor-only sources, website scripting roadmap).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Micromesh: Morton clusters with a quadric hierarchy, carried attributes,
  GPU cull + compaction into a shared index arena, farthest-depth HZB
  occlusion, shadow cascade cuts and scene renderer integration.
- Terrain: engine masks (height, slope, curvature + stored masks, file v3)
  and the biome table as a scatter density (C ABI v14, v15).
- Scatter: scatterTerrain over a terrain region, C ABI v16
  (caffeine_session_scatter_terrain, caffeine_biome_check), the Doppio
  Scene > Scatter on Terrain action, scatter plan files and the
  scatter_on_terrain agent action.
- Water/nature fixes, RHI indirect draws, benchmarks and doc capture scripts.
- Docs: micromeshes, terrain/water/nature guides and both roadmaps updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Engine:
- Mesh Filter "Material slots": one material per sub-mesh; the renderer
  draws one MeshDraw per slot (shadows, alpha, wind and Micromesh follow).
- OBJ usemtl groups become sub-meshes; scene serializer persists slots and
  Micromesh settings (appended, older scenes still load).
- RenderDevice::serial() + Mesh3D::gpuDeviceSerial stop cached meshes from
  using GPU buffers of a destroyed device (fixes a long-run SIGSEGV).

Doppio:
- Generators work without a project (scratch workspace) and report what
  happened through a top-bar notice, Console entries and a coloured status.
- Nature: Merge parts, Micromesh and "Add to scatter plan" (composite
  classes with `part` lines); Terrain: Scatter and Edit scatter plan.
- New agent actions for each of those buttons.
- UX: preset dropdown shows the current preset, checkbox/label layout,
  larger node text without overlapping subtitles, toolbar buttons.
- Tests, headless flow generators-interconnect.json, regenerated docs
  images and updated guides/roadmaps.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…docs move to the website

- Engine: the project root is the folder with project.caffeine (was only a
  lowercase scenes/ parent), asset folders are found ignoring case, and
  set_asset_root stands in as the root without a project. Foliage gets a
  floor of scattered sky light in the lit shader.
- Nature: Place/Export write models, materials, textures, recipes and a
  .prefab; meshes are stored as project paths; Water/Terrain save their
  recipe first and the Assets pane refreshes. New Edit Library Material
  node (and "Edit this material" button, nature_edit_material action),
  leaf height maps, 1024 px library surfaces, un-stretched bark UVs,
  smaller cupped leaves, a round crown (scaffold/lift on Grow Branches)
  and a triangle budget spread across the branches.
- Docs: all Doppio documentation now lives in caffeine-website
  (content/{en,pt}/docs/doppio, captures/); doppio/docs is gone and the
  scripts, tests, AGENTS.md and README point at the website.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…scene views, assets, file browser, performance

Engine (C ABI v23)
- Volumetric audio: a device-free software mixer (delay and Doppler, distance and air absorption, occlusion and
  diffraction through oriented boxes, room probe and reverb, spherical-head ears), scene sync, weather sound
  through the mixer, output device choice, hosted by caffeine-runtime.
- Weather: 3D rain, lightning and thunder, cloud shadows, wind; Photon takes the clouds' shadow.
- Simulation switch (caffeine_session_set_simulating): a stopped scene stands still; the picture clock follows the
  game's ticks once, by whichever view draws first.
- Scene views (game and camera) with their own targets, and the game (GameSimulation: animation, effects, fluids,
  navigation, physics, scripts, UI as caffeine-runtime runs them) with keys and pointer.
- Photon: one instance per view (no more rebuilds between views of other sizes), a far field left alone while
  nothing it depends on changed and traced every other frame while only the camera moves, geometry hashed by pose
  generation. Counters in the Photon stats. Profiler scopes for the game and the views.

Doppio
- Panels: Environment, Audio, Photon, Profiler, Performance (render options and the viewport's own), PhaseShift and
  Rig 2D tabs; layout rework and the fixed Sample project template.
- Play / Pause / Stop in the top bar, Gameplay and Camera tabs; the viewport draws only on change.
- Assets: kinds and cards, richer importer (more types, per-kind report, drop to import), the shared asset picker on
  every asset field, Doppio's own file browser, detaching tabs into windows (iced daemon).
- Gizmo rotation turns about the ring's world axis, so it follows the mouse for any start rotation.
- Dev profile builds dependencies optimised: the editor lays out the whole window every tick and was a full core.
- Tests, UI flows and agent actions for all of it; docs live in caffeine-website (pointer bumped).

Known: the references/ folder (14 GB of audio sources) is not committed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…nts, 2D fixes

3D (Bullet):
- PhysicsWorld3D::step runs fixed steps (1/60 s, at most 8 per frame) with the remainder
  carried over and the pose blended between the last two steps; a force holds for the frame
  it is asked in (force x frame time), so a push is the same at any frame rate.
- Terrain collision: every TerrainComponent with buildCollisionMesh becomes a static height
  field at full resolution, rebuilt when its data revision changes, moved with its entity;
  bodies wake when it changes; fast bodies sweep so they do not tunnel through it.
- OnCollision3D / OnTrigger3D events (begin and end, not every frame); rays ignore triggers.
- Surface rule: friction by geometric mean, restitution by the larger (setSurfaceCombine
  brings Bullet's product back; exposed to Lua and Dryad); rolling friction for spheres and
  capsules; bodies under a parent are simulated in world space; a dynamic body moved from
  outside follows its entity; static and kinematic poses are pushed only when they change.

2D:
- Fixed step and the same force rule; static colliders never move; a floor that is only a
  collider holds bodies; circle against box normal fixed for both orders; one-way platforms
  hold only from above; triggers report enter and exit once; sleeping bodies wake on a force;
  fast bodies advance in slices so thin walls are not jumped; deterministic pair order;
  bodies under a parent live in world space.

The stale 2D tests (Position2D) were rewritten against Transform and RigidBody2D, and new
scenario tests cover both engines: 64 physics test cases.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ation (Phase 0)

AssetManager (C ABI 24):
- Review fixes: a fresh load is pinned until the caller's handle holds it (a tiny budget
  evicted it first), one slot per file whatever its spelling, a path that climbs out of the
  base or a file loaded as another type gives no handle, threads loading the same asset share
  one load, invalidation callbacks run outside the lock, the cache counts every kind.
- Project references: resolveReference / importReference decide what a path means (project,
  assets folder, engine assets, absolute); a file outside the project is imported into the
  folder of its kind, identical files are not duplicated. caffeine_session_asset_reference.
- Doppio: Inspector asset fields, the Terrain, Water and Nature generator slots, the Material
  Generator image nodes and graph baking keep the asset manager's form of the path; a file of
  the wrong kind is refused before anything is copied.

Terrain editing, Phase 0 (C ABI 25 to 27; plan in caffeine-website, terrain-editing-roadmap):
- terrain/edit: the tile model in real units (64-cell tiles that own disjoint vertices, dirty
  tiles, integer-centimetre coordinates, 16-bit centimetre height tiles with an exact
  fallback) and the stroke engine (stamps spaced in metres along the path, five modes, stamp
  images, falloff curves, a pressure hook, tile-by-tile undo records), pinned by golden tests.
- Native .terrain container (a caf asset of type Terrain, a CRC per tile, partial loading) and
  the lossless conversion of a legacy .cterrain (caf-pack --convert-terrain, pointer bumped);
  old projects open as they are, the editor reports them and Scene > Convert terrains converts
  them; new terrains save as .terrain.
- Regional GI: Photon sees a terrain as one object per tile with its own revision, so a stroke
  revoxelises only the tiles it touched; neighbouring terrain-tile boxes are merged.
- Brush cursor: a terrain raycast and the ring a brush makes on the relief, drawn as an overlay.
- Stroke ABI (begin, point, end, revert, reapply), Rust wrappers, agent actions
  convert_terrains and terrain_brush_cursor.

Verified: CaffeineTest 1099 cases, doppio 590 tests, clippy with and without the agent
feature, scripts/check-rust-ui.sh.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@LyeZinho
LyeZinho merged commit 2587ff4 into main Nov 23, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant