Skip to content

Added pmxPhysicsNode - #7

Merged
sstarosz merged 13 commits into
mainfrom
feature/physics-node
Aug 10, 2026
Merged

Added pmxPhysicsNode#7
sstarosz merged 13 commits into
mainfrom
feature/physics-node

Conversation

@sstarosz

@sstarosz sstarosz commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

Native rigid-body physics node in as a registered plugin node and creates one empty pmxPhysicsNode per imported model — per the plan, the node exists but is not configured yet (no bodies/joints, no write-back — those come with the rigid-body commands PR).

What's included

C++ node (mmd/maya/nodes/)

  • physics_node.{h,cpp}pmxPhysicsNode, an MPxLocatorNode that owns the Maya-free Bullet world from mmd/core (via mmd_core). Full attribute surface (bodies/joints compound arrays, anchors, write-back offsets, outputs) + the timeline/state machine (compute()), adapted to the refined core API from Bullet physics engine #6:
    • e-prefixed PhysicsMode/ColliderType enums with explicit attribute↔engine collider mapping (the persisted attribute enum kColliderBox=1… differs from the engine's PMX-aligned eSphere=0…)
    • poseToTransform / storePose / btTransformToRowMatrix / doubleMatrixToBtTransform / rowMatrixMultiply moved to Matrix4 + bullet_bridge.hpp
    • removed the UB data() + out[0..2] write pattern (real ArrayBound findings)
  • mmd/maya/nodes/.clang-tidy — same profile as root minus three Maya-API-noise checks (copy-init, C-array decay, constant-array-index) for the adapter.
  • mmd/MayaMMD.cpp — registers pmxPhysicsNode (locator + classification) and deregisters it. No draw override yet (intentionally — being redesigned), no commands.

Python wiring (mmd/maya/pmx/)

  • rigid_body_builder.py (new) — create_physics_from_pmx_data(): creates the {model}_Physics group + one empty pmxPhysicsNode under it, gravity set to −9.8. time is deliberately not connected yet (empty bodies → compute() would fail every frame; the full builder connects it with the body population).
  • pmx_naming_manager.pyget_physics_group_name() / get_physics_solver_name().
  • pmx_scene_builder.pybuild_pmx_scene calls the builder and stamps the solver name on the model root (pmxPhysicsNode string attribute) for discovery.

@sstarosz sstarosz added the Physics Physics system label Aug 9, 2026
@sstarosz sstarosz added this to the 0.2.0 milestone Aug 9, 2026
~PhysicsNode() only called destroyWorld(), but the members self-clean:
mSim tears down the Bullet world in its PIMPL destructor, mBodies/mJoints
are plain vectors. postConstructor() was an empty no-op override. Keep
destroyWorld() — it resets to the unbuilt state for in-place rebuilds
(rebuildSimulationAtCurrentPose).

As a polymorphic MPxNode subclass, the destructor is re-declared as an
explicitly-defaulted override (defaulted out-of-line in the cpp) so the
virtual-destruction intent is documented.

Also replace clang-format-unstable multi-line NOLINTBEGIN/NOLINTEND and
a reflowed line-end NOLINT with single-line NOLINTNEXTLINE comments so
the suppressions survive formatting.
- rebuildSimulationAtCurrentPose: the pre-destroy updateKinematicAnchors()
  call ran against the old world that is discarded by destroyWorld() — its
  effect was wiped, only the post-rebuild re-apply matters. Removed.
- physics_node.h: merge the duplicated 'THE collision mask' comment block
  on aBodyMaskGroup.
- buildWorld: read gravity via one cached asDouble3() pointer instead of
  calling asDouble3() three times.
- collectDrawData: the pre-first-compute plug fallback now skips disabled
  bodies (mirrors the solved-pose path).
- integration test: drop the dead identity setAttr on anchorWorldMatrix[0]
  (immediately overwritten by the translated matrix).
@sstarosz sstarosz changed the title Node: register native pmxPhysicsNode + empty node per imported model Added pmxPhysicsNode Aug 10, 2026
@sstarosz
sstarosz merged commit 0633b63 into main Aug 10, 2026
2 checks passed
@sstarosz
sstarosz deleted the feature/physics-node branch August 10, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Physics Physics system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant