Skip to content

Add Newton physics backend support#276

Draft
yuecideng wants to merge 27 commits into
mainfrom
feature/newton-physics-backend
Draft

Add Newton physics backend support#276
yuecideng wants to merge 27 commits into
mainfrom
feature/newton-physics-backend

Conversation

@yuecideng
Copy link
Copy Markdown
Contributor

This adds Newton backend support to the simulation stack.

  • Introduces Newton-aware simulation configuration and manager setup
  • Adds a Newton rigid-body adapter for pose and velocity access
  • Updates rigid object handling to route reads and writes through Newton when available
  • Keeps the existing default backend path unchanged

yuecideng added 2 commits May 21, 2026 17:16
Integrate Newton-aware simulation config, manager, and rigid body adapters.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yuecideng yuecideng added the physics Things related to physics label May 22, 2026
yuecideng and others added 25 commits May 24, 2026 01:22
…on backend

Wire DexSim Newton's new `NewtonRigidDataType` enum values (MASS,
INERTIA_DIAGONAL, FRICTION, RESTITUTION) through the backend adapter
layer, enabling runtime set/get of mass, friction, and inertia on the
Newton physics backend.

Changes:
- backends/base.py: Add 8 abstract methods for physical property
  fetch/apply (mass, inertia_diagonal, friction, restitution)
- backends/newton.py: Implement via batch_fetch/apply_rigid_body_data;
  add `_fetch_scalar` helper; fix body ID resolution to be lazy so IDs
  are correct after Newton finalization in multi-object scenes
- backends/default.py: Implement all new abstract methods via per-entity
  PhysX API
- rigid_object.py: Route set/get_mass, set/get_friction, set/get_inertia
  through body_view when ready; make gpu_indices a property for lazy
  body ID resolution; add _mass/_inertia/_friction data buffers
- sim_manager.py: Remove redundant _has_reset_newton_entities_after_finalize
  flag; add _newton_lifecycle_state() helper; simplify finalize_newton_physics()
- test_rigid_object.py: Assert set/get round-trips for mass, friction,
  inertia on Newton backend; fix initial inertia expectation to use
  actual Newton-computed values
- docs/sim_manager.md: Add Newton Physics Backend section with supported
  operations table

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
## Newton backend optimizations (backends/newton.py)
- Pass GPU int32 body_ids tensor directly to DexSim; remove per-call
  .detach().cpu().tolist() synchronization on every fetch/apply
- Pass torch buffers directly to batch_fetch/apply_rigid_body_data;
  drop manual wp.from_torch wrapping (DexSim handles it internally)
- Remove dead code: _entity_indices, _fetch_com_local_pose_from_entities,
  _apply_com_local_pose_to_entities, unused _fetch_vec3/_fetch_scalar helpers
- Remove now-unused imports (numpy, warp, convert_quat)

## Test coverage additions (test_rigid_object.py)
- test_geometry_data: get_triangles shape/dtype + get_vertices(scale=True)
- test_enable_collision: toggle collision on/off, partial env_ids
- test_reset: full and partial reset restores pose + clears dynamics
- test_local_pose_matrix: get_local_pose(to_matrix=True) shape, last row,
  orthogonality; consistency with 7-vec form
- test_body_data_vel_clear: body_data.vel combined (N,6) shape, partial
  clear_dynamics zeroing only the requested env

All 63 tests pass (CPU / CUDA / Newton).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physics Things related to physics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant