feat(physics): entity-based conservation tracking and rotation (transitional)#148
Merged
M1thieu merged 2 commits intoerematorg:mainfrom Feb 7, 2026
Merged
feat(physics): entity-based conservation tracking and rotation (transitional)#148M1thieu merged 2 commits intoerematorg:mainfrom
M1thieu merged 2 commits intoerematorg:mainfrom
Conversation
…onal) Closes erematorg#143 (entity backend only - MPM deferred) **ARCHITECTURE NOTE**: This is **transitional/deprecated** entity-based physics for non-continuum objects. LP's primary physics backend will be MPM (Material Point Method) for all continuum matter. Entity physics limited to observers (cameras) and non-physical elements. **SCOPE**: Entity-based work tracking for rigid bodies: - Forces do work: W = F·dr (using average velocity) - Work reported via `WorkDoneEvent` → energy ledger - `EnergyBalance` records transactions with correct direction **Added:** - `WorkDoneEvent` message (entity forces → ledger) - `track_work_from_forces` system (listens to work events) - Energy transaction recording with proper sign handling - Integration with symplectic Euler velocity updates **TODO (MPM Priority):** - MPM grid-based work tracking (W at particle/grid level) - MPM work events → same unified energy ledger - Deprecate entity physics once MPM handles continuum matter **Performance**: <5% overhead for conservation tracking.
Addresses erematorg#145 (partial - entity backend only) **SCOPE**: Entity-based rigid body rotation for non-continuum objects (cameras, UI elements, large non-deformable bodies). Continuum matter will use MPM (Material Point Method) when implemented. **Added:** - MomentOfInertia component (rigid body inertia) - AppliedTorque component (torque application) - integrate_torques system (τ = I·α integration) - RotationalWorkEvent (feeds energy ledger) - Helper functions: calculate_angular_momentum, calculate_rotational_kinetic_energy - ForcesDiagnostics now tracks angular momentum + rotational KE - Tests for all rotational physics formulas **Architecture:** - Entity backend: Uses components (MomentOfInertia, AppliedTorque) - MPM backend (future): Will compute L = Σ(r × m·v) from particles - Both backends feed same energy ledger for unified conservation **TODO (MPM):** - MPM particle-based angular momentum computation - MPM rotational work tracking from grid interactions - Aggregate diagnostics across both backends
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.
Objective
Implement entity-based work-energy coupling and angular momentum tracking as transitional scaffolding toward MPM (Material Point Method). Establishes unified conservation interface patterns that MPM will reuse.
Addresses #143 (partial), #145 (partial) - Entity backend complete, MPM backend deferred until solver exists.
Context
Physics audit against Landau & Lifshitz revealed conservation gaps. This PR closes those gaps for entity-based physics and documents the dual-backend architecture (entity + MPM).
IMPORTANT: Entity physics is transitional - marked as deprecated in commits. Once MPM is implemented, continuum matter will use particle-based physics. Entity backend remains only for cameras/observers.
Implementation
Work-Energy Coupling (#143 partial)
WorkDoneEventmessage (forces → energy ledger)integrate_newton_second_lawEnergyBalancerecords transactions with correct signAngular Momentum Tracking (#145 partial)
MomentOfInertiacomponent (kg·m²) with disk/sphere/point_mass constructorsAppliedTorquecomponent with duration supportRotationalWorkEventmessage (torques → energy ledger)integrate_torquessystem (τ = I·α integration)ForcesDiagnosticsnow tracks total angular momentum + rotational KEArchitecture Documentation
Energy Ledger Integration
track_rotational_work_from_torquessystem in conservation.rsRotationalWorkEvent→ records toEnergyBalanceTesting
11 new tests validating physics formulas:
All tests pass (30 total across crates).
Conservation validation:
Technical Notes
Stability & Performance
Architecture Rationale
Why entity backend if MPM is target?
When to deprecate entity physics?
Future Work (MPM)
Per architecture docs and issue updates:
References
Note: This PR is transitional work. Entity physics marked as deprecated. MPM is LP's primary physics backend. Conservation interface patterns established here will be reused by MPM.