Skip to content

geometry::merge grows face materials in place, so model::merged stays linear - #881

Merged
transfix merged 1 commit into
masterfrom
fix/merge-materials-linear
Oct 30, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/merge-materials-linear

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

cvcdbg's demo3 took 75-86 s to open its window on any physics plant (dynamic, dynamic4w, humvee) and 9 s on the kinematic one, printing nothing in between. Nearly all of the difference is cvc::world::load_city_bundle, which demo3 calls to give the plant the bundle's buildings:

step (austin_south, 978,242 faces in 11,272 meshes) before after
read_model(buildings.glb) 1.06 s 0.85 s
model::merged() with a material on every face 56.1 s 0.11 s
model::merged() without materials 0.03 s 0.03 s
load_city_bundle (terrain and buildings) 55.3 s 0.80 s

geometry::merge rebuilt the whole face-material array on every call, so model::merged(), which folds the file's meshes in one at a time, did about n^2/2 copies: roughly 5.5 billion for austin_south.

What changes

merge() grows our material array in place instead. Its triangles' materials go in after ours, which moves only our quads' entries; its quads' go at the end; a side without materials contributes zeros. The face order and the results are the same as before. A self-merge copies its materials first, since they are the ones that grow.

Measured

  • demo3, time to window (native Windows build of CVC-DBG/cvcdbg main with --radio csma, against this cvc.dll):

    plant before after
    dynamic4w 75-86 s 12.3 s
    dynamic 85 s 11.8 s
    humvee 80 s 14.1 s
    kinematic 9 s 7.5 s
  • Tests (MSVC Release): geometry_height_field_test, geometry_test, geometry_attributes_test, model_test, world_geometry_test, lod_tiles_test and nav_world_planes_test all pass. The new GeometryFaceMaterials.AFoldOfManyMergesKeepsEveryFacesMaterial folds 300 meshes, with and without materials and with and without a quad, and checks every face's material against the documented order.

The wasm demo loads the same bundle the same way, so its physics plants should start faster too. That hasn't been measured in a browser yet.

… linear

merge() rebuilt the whole face-material array on every call, so folding n meshes
into one was quadratic in the face count. load_city_bundle merges austin_south's
11272 building meshes after giving each its material: merged() took 56 s, and
every physics plant in cvcdbg's demo3 waited on it before its window opened.

Ours now grow in place: its triangles' materials go in after ours (moving only
our quads'), its quads' at the end, zeros for a side without them. Same order,
same results; merged() takes 0.11 s and load_city_bundle 0.8 s.
@transfix
transfix merged commit ba54cb3 into master Oct 30, 2026
20 of 26 checks passed
@transfix
transfix deleted the fix/merge-materials-linear branch October 30, 2026 02: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