Add Newton physics backend support#276
Draft
yuecideng wants to merge 27 commits into
Draft
Conversation
Integrate Newton-aware simulation config, manager, and rigid body adapters.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds Newton backend support to the simulation stack.