Skip to content

World themes: model buildings and trees in the generated world, with LOD - #1582

Merged
transfix merged 2 commits into
masterfrom
world-asset-archetypes
Nov 27, 2026
Merged

transfix merged 2 commits into
masterfrom
world-asset-archetypes

Conversation

@transfix

Copy link
Copy Markdown
Owner

Generated worlds can now build textured model buildings and plant model trees, chosen by world themes, and draw every placed copy with level of detail. The models come from the new cy-pca asset packages in cy-pca/graphics-assets#22.

World side (GL-free, deterministic)

  • Model assets (cvc/world/model_assets.h).
    • model_asset is parsed from <name>.asset.json (schema cvc-model-asset/1). It holds the kind, tags, extents turned from glTF's +Y-up / front +Z into the world's +Z-up / front +Y, and a LOD ladder: file, triangles and world_error_m per rung.
    • model_catalog scans directories for those sidecars. model_catalog_of(app) is filled from the same places find_vehicle_model looks (cvcpkg prefixes' share/cvc-scenes/shared, the nav bundle's shared/), plus CVC_MODEL_PATH.
  • World themes (cvc/world/world_theme.h). A theme is data, not code:
    • Building archetypes: asset, weight, urbanity band, scale range, and span (how many street lots it may take).
    • Tree archetypes: asset, weight, scale range, and a biome_rule (height over water, slope, distance to water).
    • Themes are registered per app like the terrain and city generators, and read and written as JSON.
    • Built-ins: temperate_town, coastal_town (palms on the coast, oaks inland) and tropical.
    • pick_building and pick_tree are exposed for tests and other generators. Every draw is keyed on the spot, using a new lsys::stream::theme appended at the end of the enum, so existing salts don't move.
  • generated_world_params::theme. Empty is the old world, unchanged; the params JSON leaves the key out, so existing bundles keep their bytes.
    • With a theme, a share of lots take a building archetype that fits the lot at real size, or the lot plus its neighbour for the two-lot office. The front goes on the setback line. On a slope the model stands on the lot's high ground over a concrete plinth, up to 6 m of relief.
    • The scatter's trees become tree archetypes where their biome holds. The distance to water comes from an EDT of the raster.
    • The world records model_assets and models (asset, x, y, z, yaw, scale).
    • The model buildings collide as boxes (model_buildings, collide + navigate); the trees are drawn only.
    • Bundles carry the models in models.json, and world_from_bundle reads them back.
    • The .ari node takes theme: (live as world.theme), and pycvc's generate_world takes a theme key.

Render side: LOD

  • cvc/gl/ariadne/world_models.{h,cpp}:
    • Each asset is read once, with assimp, merged and turned into the world frame, into a cvc::lod::mesh_pyramid whose rungs are the asset's LOD glbs, with their base-colour textures and the sidecar's errors. It is cached by file.
    • Every placed copy is a LodGraphicsNode posed by its instance transform, with its errors scaled by its scale. Its rungs draw from the first copy's arrays and texture (shareArraysFrom, shareTexture), so a hundred palms hold one palm's buffers. Each copy picks its rung from its own distance, the same cvc::lod::select_rung path the props and terrain use.
  • world_nodes.cpp:
    • The world's job reads the assets off the frame thread.
    • A new install stage puts in the instances a few dozen a piece, under <id>_models.
    • The instances swap, retire and hide with the rest of the world, and choose their rungs each frame.
  • The packages ship the full-resolution model as LOD 0. The coarser rungs were baked with libcvc's own build_mesh_pyramid / simplify through pycvc, which needed one binding addition: geometry.triangle_indices(), a read-only (T,3) copy. pycvc's generated_world also gains models().

Tests

  • New world_theme_test (17 tests), covering:
    • parsing sidecars and refusing bad ones;
    • catalog scanning;
    • reading an asset's LOD glbs with read_model;
    • the per-app catalog and themes, and theme JSON round trips with validation;
    • building selection: urbanity bands, fit, the two-lot span, share, determinism, and uninstalled assets left out;
    • palms on the coast and oaks inland, and inclusive biome bounds;
    • a themed world placing model buildings and trees (on the ground, palms low, boxes collide), deterministic;
    • a theme without its assets building the plain world;
    • an unknown theme throwing;
    • theme appearing in the params JSON only when set;
    • a bundle round trip of the models.
  • New cvcgl_world_models (headless):
    • the frame turn and the instance matrix;
    • loading a two-rung asset from glbs, with the cache, a missing coarse rung, and a missing LOD 0;
    • instances sharing arrays, scaling their errors, and choosing their rungs by their own distance.
  • Locally on Windows, in a fresh build tree from the shared .deps prefix:
    • world_theme_test 17/17 and cvcgl_world_models pass;
    • ctest -R "World|Bundle|Lsys|lsys|Theme|Scatter|Sites|generated|world_|cvcgl_lod|ariadne_scene": 652/652 pass (world, bundle, lsys, scatter, sites, generated-world, scene-world, cvcGL LOD and world tests, pycvc world tests).

Renders

Before and after, from the same build and camera: seed 5, half 450, the urban preset, amp 15, a shore edge. "Before" is theme: ""; "after" is theme: coastal_town with the packages' files on CVC_MODEL_PATH. Out of 99 buildings, 50 are model buildings (27 corner shops, 22 brownstones, 1 office). The 121 model trees are 87 palms on the coast and 34 oaks inland. The renders were sent to Joe directly.

Not done

  • The packages aren't published yet (cy-pca/graphics-assets#22 needs staging plus a publish dispatch, on Joe's OK). Until then, CVC_MODEL_PATH points at the baked files.
  • The shipping container is packaged, but no theme places it yet. A port theme with a container yard is the obvious next archetype kind.
  • LOD 0 of the young oak is 7.7M triangles (260 MB glb). It loads on the job thread, but a world using it takes a while to load; the built-ins weight it low.
  • No wasm check: the model install path reads glbs from the catalog's directories, which a browser page doesn't have.

A generated world can now build textured model buildings and plant model
trees, chosen by a world theme (generated_world_params::theme, the
node's `theme:`), and draw every placed copy with level of detail.

- cvc/world/model_assets.h: model assets read from <name>.asset.json
  (schema cvc-model-asset/1: kind, tags, bounds, a LOD ladder with each
  rung's world_error_m), turned into the world frame, and the app's
  catalog of them (model_catalog_of), scanned from the cvcpkg prefixes'
  share/cvc-scenes/shared, the nav bundle's shared/ and CVC_MODEL_PATH.
- cvc/world/world_theme.h: themes as data. Building archetypes (asset,
  weight, urbanity band, scale range, lots spanned) and tree archetypes
  (asset, weight, scale range, a biome rule: height over the water,
  slope, distance to water); registered per app, read and written as
  JSON; built-ins temperate_town, coastal_town and tropical. Every draw
  is keyed on its spot (a new lsys::stream::theme, appended).
- generated_world: a themed city fits building archetypes to lots (two
  lots for the office), fronts on the setback line, a plinth on slopes;
  the scatter's trees become tree archetypes where their biome holds.
  The world records model_assets and models; the model buildings collide
  as boxes; bundles carry them in models.json. No theme: the world as
  before, and its params JSON and bundle bytes unchanged.
- cvc/gl/ariadne/world_models.h: each asset read once into a mesh
  pyramid of its LOD glbs (cached by file, off the frame thread); every
  copy a LodGraphicsNode posed by its transform whose rungs share the
  first copy's arrays and texture, choosing its rung by its own distance.
  world_nodes installs, swaps and retires them with the world.
- pycvc: geometry.triangle_indices() (what the asset LOD baker reads
  rungs back out with), generated_world.models(), generate_world's theme.
- Tests: world_theme_test (assets, catalog, glb reading, themes, the
  draws, biomes, a themed world, bundles) and cvcgl_world_models (the
  frames, loading a ladder, shared instances choosing their rungs).
The singleton scan refuses function-local statics. The built-in theme
list is now built per call (builtin_world_themes returns by value), and
the model-mesh cache lives on the app (slot cvc.gl.ariadne.model_meshes),
like the model catalog. Formatting follows CI's clang-format 18.1.8.
@transfix
transfix enabled auto-merge (squash) November 27, 2026 07:14
@transfix
transfix merged commit 2952adb into master Nov 27, 2026
30 checks passed
@transfix
transfix deleted the world-asset-archetypes branch November 27, 2026 13:33
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