Skip to content

cvc::model keeps the file's node tree; merged() places each mesh by it - #1467

Merged
transfix merged 1 commit into
masterfrom
model/node-tree
Nov 23, 2026
Merged

transfix merged 1 commit into
masterfrom
model/node-tree

Conversation

@transfix

Copy link
Copy Markdown
Owner

cvc::model keeps a file's scene graph, and merged() places each mesh by its nodes. Until now model_of_scene never read assimp's mRootNode, and the import flags don't bake transforms into vertices. So a glTF, FBX or DAE file that positions its meshes through node transforms drew every mesh at its own origin, and a mesh several nodes share appeared once. Every reader that goes through merged() saw that: read_geometry, a scene node's source: { file }, vehicle and boxed model looks, swarms, data: entries, lod::partition_model, the nav demos and pycvc's load_model.

What changes

  • model::nodes: each node's name, its transform relative to its parent (row-major 4x4), the meshes it draws and its children; nodes[0] is the root. A model without nodes (one built in code) draws each mesh once, as before.
  • model::instances(): every drawn copy of a mesh with its transform into the model's space, depth first. A node two parents list is drawn under each. A cycle or an index out of range is skipped. The walk keeps its own stack, so a deep tree can't overflow the thread's.
  • model::placed(geometry, transform): points moved; normals by the inverse transpose and made unit; tangents turned. Under a mirror (negative determinant), triangles and quads are rewound and tangent handedness flipped, so faces keep facing out.
  • merged() and extents() draw instances. lod::partition_model partitions the placed copies.
  • Assimp import reads the node tree and keeps the file in its own axes and units. It sets IMPORT_COLLADA_IGNORE_UP_DIRECTION, IMPORT_COLLADA_IGNORE_UNIT_SIZE and IMPORT_FBX_IGNORE_UP_DIRECTION, so assimp's turn of a Z-up file to Y-up (and Collada's scale to metres) doesn't arrive through the root node now that it is applied. Readers already turn models themselves; a glTF file is +Y up.
  • Assimp export writes the node tree, so a model round-trips through .glb.
  • pycvc: the new members are %ignored in pycvc_model.i; merged() already places by them. Exposing the tree to Python is left for later.
  • Docs: docs/APP_API.md describes the tree under the file handlers.

Effect on shipped models

  • buildings.glb (scene bundles; trimesh output, 11,273 nodes): no node carries a transform, so it reads exactly as before.
  • Humvee.glb (vehicle-humvee): a Sketchfab export whose nodes compose to a proper rotation turning the raw Z-up mesh into glTF's Y-up. I ran both vehicle fits on its vertices, raw and placed:
    • The C++ fit_vehicle_geometry (vehicle looks) gives identical output, because it finds its axes from the mesh's shape.
    • pycvc's VehicleModel and the nav demos' load_vehicle_template use the same shape fit without a mirror correction. On the raw mesh's axis order they draw the Humvee mirrored (triangles inside out); placed by its nodes, it comes out correct.
    • fit_into_box takes a .glb as +Y up, which the Humvee now is.

Tests

New ModelNodes cases in model_test:

  • without nodes, each mesh is drawn once as it is;
  • nodes place and repeat a mesh, turning its normals and tangents;
  • extents are of the placed copies;
  • a mirror rewinds the face and flips handedness;
  • only the meshes a node draws are drawn;
  • a node with two parents is drawn under each;
  • cycles and indices out of range are skipped;
  • a 100,000-deep chain is walked without recursion;
  • placing leaves the source mesh alone.

With assimp:

  • a three-node glTF (TRS, quaternion and matrix nodes, one mesh drawn three times) through both read_model_from_memory and read_geometry;
  • a node tree with a mirror through a .glb write and read;
  • a Z-up, centimetre Collada file that must keep its axes and units. With the axis setting turned off, this test fails (checked).

Verified locally

Windows, MSVC 14.44, assimp 6.0, no cvcGL or pycvc: the full ctest suite, 8,198 tests, all pass (on f310173). That includes model_test (24, the 12 new ModelNodes cases among them), the LOD tile tests and the world bundle tests, which write and read .glb files.

Not verified locally: the cvcGL readers (vehicle looks, swarms, scene sources), pycvc, Linux, macOS and wasm.

Not done

model_of_scene never read assimp's root node, and the import flags do not
bake transforms into vertices, so a glTF, FBX or DAE file that positions its
meshes through node transforms drew every mesh at its own origin, and a mesh
several nodes share appeared once. Every reader through merged() saw it.

- model::nodes (name, row-major 4x4 transform, meshes, children; nodes[0]
  the root), model::instances() (every drawn copy with its transform, depth
  first on an explicit stack; cycles and bad indices skipped), and
  model::placed() (points moved, normals by the inverse transpose, tangents
  turned, triangles and quads rewound under a mirror). A model without nodes
  draws each mesh once, as before.
- merged(), extents() and lod::partition_model draw instances.
- The assimp import reads the tree and keeps the file in its own axes and
  units (Collada and FBX up direction, Collada unit size ignored); the export
  writes the tree, so a model round-trips through .glb.
- pycvc_model.i ignores the new members for now.
- docs/APP_API.md describes the tree.

Shipped models: buildings.glb has no node transforms and reads as before.
Humvee.glb's nodes turn its raw Z-up mesh to glTF's Y-up; the C++ vehicle
fit gives identical output, and pycvc's VehicleModel and the nav demos, which
drew it mirrored, now draw it the right way round.
@transfix
transfix merged commit 04d6f76 into master Nov 23, 2026
31 checks passed
@transfix
transfix deleted the model/node-tree branch November 23, 2026 06:10
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