Skip to content

Comments

Rigid and Affine Body Dynamics#184

Draft
zfergus wants to merge 62 commits intomainfrom
dynamics
Draft

Rigid and Affine Body Dynamics#184
zfergus wants to merge 62 commits intomainfrom
dynamics

Conversation

@zfergus
Copy link
Member

@zfergus zfergus commented Aug 18, 2025

Description

This pull request introduces support for rigid body dynamics simulation.

Rigid body dynamics support in Python bindings

  • Added a new dynamics module with subfolder rigid, including Simulator, RigidBodies, Pose, and Poses classes, and exposed them via pybind11 in the Python bindings

Improvements to CMake dependency management

  • Updated CPM versions and refactored third-party recipes to use the OPTIONS argument for configuration, improving clarity and maintainability.
  • Added a new CMake recipe for TinyGLTF and integrated it into the build.

Python usability improvements and new examples

  • Added a new example script demonstrating rigid body simulation and visualization using ipctk, meshio, and polyscope (python/examples/rigid.py).

Minor Python binding improvements

  • Changed save_obj method to write_obj in Candidates Python bindings for clarity.
  • Made CollisionMesh Python class use std::shared_ptr for better memory management.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

zfergus and others added 17 commits May 31, 2024 00:41
- Added InertialTerm class for computing energy, gradient, and Hessian of rigid bodies.
- Implemented mass properties computation for 2D and 3D meshes, including point clouds.
- Created pose representation with rotation vector and matrix conversions.
- Developed RigidBodies class to manage multiple rigid bodies from mesh data.
- Implemented ImplicitEuler time integrator for updating positions and velocities.
- Added unit tests for mass properties and pose transformations using Catch2 framework.
- Updated finite-diff package from version 1.0.1 to 1.0.3 in CMake configuration.
- Remove template from Pose.
- Modified RigidBody and related classes to use the updated Pose structure.
- Added unit tests for RigidBody construction and transformations.
- Update CPM to 0.42.0
- Add TinyGLTF dependency
- Rename save_obj to write_candidates_obj
- Add write_gltf
@zfergus zfergus added the enhancement New feature or request label Aug 18, 2025
@zfergus zfergus added this to the v1.5.0 milestone Aug 18, 2025
@codecov
Copy link

codecov bot commented Aug 18, 2025

Codecov Report

❌ Patch coverage is 68.37505% with 796 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.42%. Comparing base (f43c48e) to head (18a0e90).

Files with missing lines Patch % Lines
src/ipc/io/write_gltf.cpp 0.00% 249 Missing ⚠️
src/ipc/dynamics/rigid/simulator.cpp 0.00% 154 Missing ⚠️
src/ipc/dynamics/rigid/pose.hpp 13.48% 77 Missing ⚠️
src/ipc/dynamics/rigid/rigid_candidates.cpp 0.00% 44 Missing ⚠️
src/ipc/dynamics/rigid/rigid_bodies.hpp 15.55% 38 Missing ⚠️
src/ipc/collisions/tangential/plane_vertex.cpp 0.00% 36 Missing ⚠️
src/ipc/dynamics/rigid/mass.cpp 80.92% 29 Missing ⚠️
src/ipc/dynamics/affine/inertial_term.cpp 0.00% 22 Missing ⚠️
src/ipc/dynamics/rigid/time_integrator.hpp 50.00% 20 Missing ⚠️
src/ipc/io/read_gltf.cpp 80.76% 20 Missing ⚠️
... and 22 more

❌ Your patch check has failed because the patch coverage (68.37%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #184      +/-   ##
==========================================
- Coverage   96.95%   94.42%   -2.54%     
==========================================
  Files         158      184      +26     
  Lines       24663    26225    +1562     
  Branches      883     1044     +161     
==========================================
+ Hits        23912    24762     +850     
- Misses        751     1463     +712     
Flag Coverage Δ
unittests 94.42% <68.37%> (-2.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Introduce new overloads for build methods across various classes, allowing for the use of precomputed AABBs.
- Update related documentation and ensure consistent handling of vertex boxes and edges.
- Improve voxel size suggestion logic based on bounding box dimensions.
- q_hat and Q_hat should be force and torque in BodyForces
Replace many Eigen vector/matrix parameters with Eigen::ConstRef to
avoid unnecessary copies and clarify ownership. Also add const
correctness to various methods (e.g. BodyForces operator(), gradient),
rename forces/torques to m_forces/m_torques, add test_body_forces.
- Add Pose::inverse
- Fix Pose::operator*
- Update tests to use finite_jacobian_tensor
Add checks in BodyForces to skip translational and rotational
computations when force or torque is zero, avoiding unnecessary
dot/jacobian/hessian work. Also add test diagnostics: include iostream
and print analytical vs numerical gradient/hessian on comparison
failures to aid debugging.
- Updated the return types of tangent basis Jacobian functions to reflect correct matrix dimensions.
- Modified the corresponding test cases to use auto for Jacobian variable declarations for improved readability.
- Added new test cases for point-point, point-edge, edge-edge, and point-triangle relative velocity matrix Jacobians, ensuring analytical and numerical Jacobians are compared.
- Included necessary headers for finite difference calculations in the test files.
- Implemented GroundContact class for handling ground interaction in rigid body dynamics.
- Added methods for energy computation, gradient, and Hessian in GroundContact.
- Updated rigid body simulator to include body forces and integrate ground contact dynamics.
- Refactored rigid body initialization to apply centering pose correctly.
- Added tests for GroundContact energy, gradient, and Hessian calculations.
- Enhanced pose class with methods for transforming vertices and computing Jacobians and Hessians.
- Updated existing tests to ensure compatibility with new features and validate correctness.
@zfergus zfergus added this to the v2.0.0 milestone Feb 4, 2026
Delete maybe_parallel_for.hpp and maybe_parallel_for.tpp from src/ipc/utils/CMakeLists.txt SOURCES list. This updates the build to no longer include these files (they may have been removed or relocated), preventing build errors from missing source entries.
Change the simulator API to return a success state (bool) and pass a bool to the per-step callback; step() now returns bool and run() returns false if simulation is complete or a step failed. Add convergence warning when solver hits iteration limit and preserve behavior notes; add has_time_remaining helper for robust time checks. Fix CollisionMesh initialization (use setConstant) and log a warning for non-manifold edges instead of asserting. Adjust RigidBodies indexing math for body-local edges/faces. Update Python example to load multiple meshes and set up multiple rigid bodies. Extend mass tests to cover multiple meshes/densities using igl::moments, add test_simulator and include it in CMake, and update the ipc-toolkit-tests-data GIT_TAG.
- Implemented zero-initialization for Hessian matrix in InertialTerm.
- Added handling for zero rotation in Pose struct to return identity quaternion.
- Introduced plane detection in RigidBodies construction from meshes, allowing conversion of flat bodies to planes.
- Updated RigidBodies class to accommodate plane bodies and modified build_from_meshes method accordingly.
- Added read_gltf function to import rigid body scenes from GLTF files, supporting plane conversion.
- Created write_gltf function to export rigid body states to GLTF format, including analytic planes.
- Removed GroundContact class and related tests, streamlining the dynamics module.
- Added unit tests for GLTF reading functionality, verifying correct body and plane extraction.
Clamp pose rotation vectors to [-π, π] to prevent angle drift
and improve optimizer convergence.

Tighten barrier params (dhat 0.1→0.001, kappa 10→1).
Enable area-weighting and use IMPROVED_MAX_APPROX collisions.
Remove GroundContact from simulator and energy/gradient/hessian.

Add numeric checks (assert finite) and verify energy after
collision updates; cap Newton iterations (max_iters=100) and
improve log messages.

Update tests to add a ground plane for contact.
Replace the custom Plane struct and implicit plane implementation with
Eigen::Hyperplane across the codebase. Remove implicits plane sources
and
CMake entries, update C++ code, Python bindings, tests, and GLTF IO to
use
the Hyperplane API (normal, offset, origin helper) and fix related
includes.
Big refactor of rigid/affine dynamics: remove the old AffineBody type and adapt affine potentials to work with rigid::RigidBodies and per-body RigidBody DOFs. Add affine inertial term (inertial_term.{cpp,hpp}) that uses the time integrator state. Introduce an abstract RigidPotential base class (rigid_potential.{hpp,cpp}) to consolidate cumulative -> per-body dispatch; make BodyForces and InertialTerm inherit and implement per-body indexed interfaces. Update OrthogonalityPotential to use RigidBodies, per-body vectors, tbb::parallel_reduce, and PSD projection for hessians. Add Pose transform/J and Jacobian helpers, expose volume/density in RigidBody (compute volume in ctor), and expose x_hat() in the time integrator. Update CMakeLists and tests to reflect the new APIs and validate gradients with finite differences. Misc: adjust includes and parallelization patterns.
Set GIT_TAG for ipc_toolkit_tests_data to
5f455c16f461e56d68e9241fa038bd20d95bce0a (was
9061bb85b30b7e410db736f6e16de234d5b0555a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant