ViewerGL: Batching Capsules with Different Sizes#1469
Conversation
Signed-off-by: JC <jumyungc@nvidia.com>
📝 WalkthroughWalkthroughDispatches capsule geometries to a new capsule-specific rendering path, adds a backend hook Changes
Sequence DiagramssequenceDiagram
participant Client
participant ViewerBase
participant Batching
participant GPU
participant Renderer
Client->>ViewerBase: log_state(model,...)
ViewerBase->>Batching: group shapes (uses geo_type)
alt capsule batch
Batching->>GPU: _capsule_build_body_scales(shape_scale, indices)
GPU-->>Batching: body_scales (r,r,half_h)
Batching->>GPU: _capsule_build_cap_xforms_and_scales(xforms, scales)
GPU-->>Batching: cap_xforms, cap_scales
Batching->>GPU: _capsule_duplicate_vec3/vec4(colors,materials)
GPU-->>Batching: duplicated attributes
Batching->>Renderer: emit capsule_body instancer + capsule_caps instancer
Renderer->>Renderer: draw cylinder bodies and sphere caps (instanced)
else non-capsule
Batching->>Renderer: emit standard instancer data
Renderer->>Renderer: draw standard instanced geometry
end
Renderer-->>Client: frame rendered
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@newton/_src/viewer/viewer_gl.py`:
- Around line 416-497: The override method log_capsules has an unused parameter
mesh causing a Ruff ARG002 warning; rename the parameter to _mesh in the
log_capsules signature (and update any internal references if present) so the
unused argument is intentionally ignored, leaving all other logic (including
calls to log_instances and creation of sphere_mesh/cylinder_mesh, cap_xforms,
cap_scales, cap_colors, cap_materials) unchanged.
In `@newton/tests/test_viewer_geometry_batching.py`:
- Around line 69-71: The test stub method log_instances currently accepts
parameters (name, mesh, xforms, scales, colors, materials, hidden=False) but
doesn't use them, triggering Ruff ARG002; update the signature of log_instances
to silence unused-argument warnings by either prefixing unused parameter names
with an underscore (e.g., _name, _mesh, etc.) or replacing the parameters with a
catch-all (*args, **kwargs), and keep the body as self.log_instances_calls += 1
so the call count remains unchanged.
eric-heiden
left a comment
There was a problem hiding this comment.
Why do capsules have the scale (r, r, half_height) here? They should be (r, h, 0) (the last entry is ignored).
Thank you @eric-heiden for the feedback! As you mentioned, model-side capsule shape_scale is stored as (radius, half_height, 0). So the (cylinder) body’s per-instance scale in the viewer is (radius, radius, half_height), following the viewer's cylinder convention. |
Signed-off-by: JC <jumyungc@nvidia.com>
Thanks @jumyungc for clarifying and adding these comments! I can see the scale refers to the xyz mesh scaling now. |
Signed-off-by: JC <jumyungc@nvidia.com>
Description
Previously, capsule-based instancing was used, which created separate instances whenever the capsule size changed. This change allows batching capsules of different sizes.
Newton Migration Guide
Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.
docs/migration.rstis up-to dateBefore your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.