Skip to content

gl: physics bodies are drawn at their pose anywhere in the scene hierarchy - #654

Merged
transfix merged 1 commit into
masterfrom
fix/scene-binding-hierarchy
Oct 17, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/scene-binding-hierarchy

Conversation

@transfix

Copy link
Copy Markdown
Owner

Why

Joe asked whether the renderer still respects local transforms and the node hierarchy. It does:

  • each GraphicsNode caches world = parent world × local;
  • on a change, that cache cascades top-down, one multiply per node;
  • the result is handed to the node's VTK props as their user transform;
  • per frame, the scene only applies parked poses and does one coalesced bounds walk before VTK draws.

The one place that didn't respect the hierarchy was mine. physics_scene_binding (#648) wrote each body's world pose into its node's local transform, so a node under a transformed parent was drawn at parent × pose, not where physics had it.

Change

  • GraphicsNode::setWorldPoseMatrix(pose, frame = nullptr) puts the node's world matrix at frame-world × pose, with no frame meaning the scene root.
    • The local transform (inverse parent world × that) is composed on the owner thread when the pose is applied, against the hierarchy as it is then. An ancestor that moves in the same frame is therefore accounted for.
    • It shares setPoseMatrix's thread-safe, latest-wins, change-detected mailbox; the mailbox now records whether a parked pose is local or world, and its frame.
    • The frame is held weakly while parked, so a destroyed frame drops the pose.
  • GraphicsNode::getParentNode() (owner thread).
  • physics_scene_binding::set_frame(node) names the node that stands for the physics world: a render-origin offset that keeps city-scale coordinates out of float precision, or a scale. present() now poses through setWorldPoseMatrix, so bodies follow the frame, and their nodes may sit at any depth. While a frame is set but destroyed, nothing is posed.

Verified (Windows, MSVC Release)

cvcgl_physics_scene_binding passes, with two new checks:

  • test_nodes_anywhere_in_the_hierarchy_are_drawn_at_the_body: a node two levels under rotated and translated parents has world matrix = body pose (1e-9). The same holds when present() runs off the owner thread and the group moves before the pump.
  • test_a_frame_node_places_the_physics_world: under a frame translated 1000 m, child and top-level nodes are drawn at frame × pose, and a child's local transform is the plain pose. A destroyed frame poses nothing.

cvcgl_pose_matrix (the mailbox's own suite) still passes.

Next

gl::add_world_geometry (G3a, in flight) gets a parent argument in G4, so the static world and the bodies can share one frame node.

…archy

physics_scene_binding wrote each body's world pose into its node's LOCAL
transform, so a node under a transformed parent was drawn at
parent x pose, not where physics had it.

GraphicsNode::setWorldPoseMatrix(pose, frame) puts the node's WORLD
matrix at frame-world x pose (the scene root without a frame). The local
transform that achieves it is composed on the owner thread when the
pose is applied, against the hierarchy as it is then; it shares
setPoseMatrix's thread-safe, latest-wins mailbox. GraphicsNode gains
getParentNode().

physics_scene_binding::set_frame(node) names the node standing for the
physics world (a render origin, a scale); present() poses through
setWorldPoseMatrix, so bodies follow the frame and their nodes may sit
at any depth. A frame held weakly and destroyed poses nothing.
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