Skip to content

Ariadne: prototypes: and a node's use: (DEF/USE) - #1509

Merged
transfix merged 6 commits into
masterfrom
scene/prototypes
Nov 24, 2026
Merged

transfix merged 6 commits into
masterfrom
scene/prototypes

Conversation

@transfix

@transfix transfix commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

A document can now declare a whole node tree once and place it many times. assets: already shared a mesh between nodes, but a composite object, such as a lamp made of a pole and a bulb, each with its own material and transform, had to be copied out in full for every placement. This is item 6 of the Ariadne scene-format gap plan, after VRML/X3D's DEF/USE and USD's prototypes.

prototypes:
  streetlamp:
    type: group
    args: { switch: lamps.on }            # defaults for the {name} tokens below
    children:
      - node: pole
        source: { box: { size: [0.2, 0.2, 5] } }
        transform: { position: [0, 0, 2.5] }
        material: { color: [0.25, 0.25, 0.27] }
      - node: lamp
        source: { sphere: 0.4 }
        transform: { position: [0, 0, 5.2] }
        material: { color: [1.0, 0.9, 0.6] }
        visible: "{switch}"
scene:
  nodes:
    - { node: lamp_a, use: streetlamp, transform: { position: [0, 0, 0] } }
    - node: lamp_b
      use: streetlamp
      args: { switch: lamps.north }
      transform: { position: [12, 0, 0], rotation: [0, 0, 90] }

How it works

  • The instance is the prototype's node with the using node's keys laid over it, at load.
    • Each key the using node gives replaces the prototype's: its id, transform:, tags:, visible:, repeat:, or a source: of its own.
    • material: merges key by key, so material: { color } recolours one instance.
    • children: the using node gives come after the prototype's.
  • Args work as a unit's do (§6.1): {name} tokens are filled from the prototype's args: (defaults), then the using node's. A token neither gives stays as written, so use: on a repeat: node makes one instance per {i}.
  • Shared meshes. Each part that draws a file, a URI or a primitive becomes a hidden asset (prototype:<name>/<path>). The existing asset path then reads and fits it once for every instance, in every scene and every repeat: copy, and draws them all from one set of VTK arrays (GeometryNode::shareArraysFrom). The realizer is unchanged.
    • Not shared: a part whose source or fit has a {name} token, since instances may differ.
    • Also not shared: a part with body: or world:, because physics takes a primitive's shape from its source.
  • Each instance is its own node, with its own state under its id, its own transform, material and tags, so a script moves or recolours one instance alone.
  • Nesting works: a prototype's nodes may use: others. A prototype within itself, at any depth, is refused with a warning, and so is an unknown name; the node is then parsed as written.

Changes

  • Loader (src/cvc/ariadne/loader.cpp):
    • a top-level prototypes: block, kept raw like units:;
    • expand_use at the top of parse_scene_node;
    • share_proto_meshes;
    • the hidden assets go into the assets of scene: and of every scenes: entry.
    • use and args are known node keys, and prototypes a known top-level block.
  • ARIADNE.md §5.18: a "Prototypes" paragraph after "Assets".

Tests

  • ariadne_loader_test PrototypesAndUse:
    • instances take the prototype's children, their own ids and transforms, and the args' defaults or their own;
    • children: are appended and material: merged;
    • parts with no token share one hidden asset across instances and across a scenes: entry, and the asset holds the part's source;
    • parts with a body:, with an arg in their source, or with the use site's own source: keep their own;
    • nesting works with the inner prototype's defaults;
    • an unknown name and a two-prototype cycle each warn, and the node is parsed as written.
  • New cvcgl_ariadne_prototypes (headless realize_scene, 14 checks):
    • each instance is its own tree at its own transform, with its parts placed in it;
    • repeat: makes three instances;
    • two shared parts are read twice in all, for six lamps across two scenes;
    • every instance's pole draws the same point buffer and shares VTK arrays, while the bulb is its own mesh;
    • parts keep the prototype's material;
    • an arg in a source gives each instance its own size, and the use site's material applies;
    • each instance's bulb follows its own visible: key from its args.

Verified locally

Windows, MSVC, with cvcGL (no examples, no pycvc), on master 7f8326d: the full ctest suite, 8,540 tests at -j 10.

  • Pass: everything but nine, including the two new tests and cvcgl_ariadne_repeat, cvcgl_ariadne_scenes and the loader's other scene tests.
  • Already failing here: cvcgl_contour_lab and cvcgl_volume_grid_contours (this build has no cvc::planar), and cvcgl_ari_golden. Its seven goldens have the same pixel counts as master without this change.
  • Load: three tests failed under the parallel load and pass rerun alone: cvcgl_tf_binding, DistributedStateSession.PumpThreadRuns and LocksStress.LT04_FuzzedProtocolPoints.
  • Timeouts: the three plant-convergence tests passed with a longer limit and the machine otherwise idle, in 113, 154 and 238 s.

No shipped document uses use: or args: on a scene node (the matches are widget include: args and the document's own args: block), so making them known node keys changes none.

Not verified: Linux, macOS, wasm and pycvc.

Schema

#1464 (the closed schema, which every load checks) merged first, so this PR carries its own keys (4ac6016, merging master):

  • a top-level prototypes: a map of name to an object, checked only for its args:. A prototype's values may hold {name} tokens its instances fill in, as a unit's do.
  • use (string) and args (a map of scalars) on node_builtin and node_custom.

With the validator built in: ariadne_schema_test passes 13 (one skip, the without-validator case), ariadne_loader_test passes 263 including PrototypesAndUse, and cvcgl_ariadne_prototypes passes 14/14 on the merged code.

Not yet: an instance checked against $defs/node after it is expanded, as an included unit is checked as a widget. That needs a third compiled validator beside the document's and the widget's.

Not done

  • A prototype's own transform composed with the instance's: the instance's replaces it. A prototype is meant to be placed by its instance.
  • Prototypes declared in a load:ed fragment.
  • Instancing on the GPU (one draw for many instances). Every instance is still its own actor, sharing only buffers.

A document's `prototypes:` names node trees, and a node's `use: <name>`
stands for one, in any of its scenes: the prototype's node, its {name} args
filled in (its args: as defaults, then the node's), with the using node's keys
over it (material: merged key by key, children: after the prototype's). Gap
item 6 of the scene-format plan, after VRML/X3D's DEF/USE and USD's
prototypes.

Each mesh part (a file, a URI or a primitive with no {name} token in its
source or fit, and no body: or world:) becomes a hidden asset,
prototype:<name>/<path>, so it is read and fitted once for every instance and
drawn from one set of VTK arrays: the realizer is unchanged. Each instance is
its own node, with its own state, transform, material and tags. Nested
prototypes expand; a prototype within itself, or an unknown name, warns and
is parsed as written.

- loader.cpp: the prototypes block (kept raw, like units:), expand_use at the
  top of parse_scene_node, share_proto_meshes, the hidden assets added to the
  assets of scene: and every scenes: entry; use and args known node keys.
- docs/ARIADNE.md §5.18 "Prototypes".
- Tests: ariadne_loader_test PrototypesAndUse; cvcgl_ariadne_prototypes.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 23:42
loader.cpp conflicted where #1464 turned is_builtin_block into a table
(kBuiltinBlocks): its table kept, with prototypes added to it.

#1464 checks every load against the closed .ari schema, so it gains this
branch's keys:
- a top-level prototypes, a map of name to an object, checked only for its
  args: (a prototype's values may hold {name} tokens its instances fill in,
  as a unit's do);
- use (string) and args (a map of scalars) on node_builtin and node_custom.
docs/ARIADNE.md's Prototypes says what the schema checks.
known_scene_node_key conflicted where #1491 adds on_pick and this branch use
and args: all three kept. With the validator: ariadne_schema_test 13 (one
skip), ariadne_loader_test 264; cvcgl_ariadne_prototypes 14/14 and
cvcgl_ariadne_node_pick 23/23 on the merge.
…ment, #1469

# Conflicts:
#	src/cvc/ariadne/loader.cpp
#	src/cvc/tests/ariadne_loader_test.cpp
…hers

# Conflicts:
#	src/cvc/tests/ariadne_loader_test.cpp
#	src/cvcGL/CMakeLists.txt
@transfix
transfix merged commit db8230c into master Nov 24, 2026
30 checks passed
@transfix
transfix deleted the scene/prototypes branch November 24, 2026 19:55
transfix added a commit that referenced this pull request Nov 24, 2026
# Conflicts:
#	src/cvcGL/CMakeLists.txt
transfix added a commit that referenced this pull request Nov 24, 2026
Conflicts: src/cvcGL/CMakeLists.txt's 8 MB-stack list keeps both sides'
tests; volume_grid, volume_grid_contours and volume_grid_quad take master's
images (#1452 changed their documents) until CI's frames of the merge are
taken.
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