Skip to content

Added pmxRigidBody command - #8

Merged
sstarosz merged 8 commits into
mainfrom
feature/rigid-body-cmd
Aug 10, 2026
Merged

Added pmxRigidBody command#8
sstarosz merged 8 commits into
mainfrom
feature/rigid-body-cmd

Conversation

@sstarosz

@sstarosz sstarosz commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

Native C++ pmxRigidBody command — the single body-modification path for pmxPhysicsNode. Create mode only, SIMULATION IS DISABLED: writes the full body DATA and binds FOLLOW_BONE bodies to their related joint via the kinematic-anchor input. Dynamic bodies are data-only (no write-back, no stepping) — edit/query/remove and the rigid-body-constraint command are later PRs.

Changes

  • mmd/maya/cmds/rigid_body_cmd.h/.cpp — new native command (create mode only):
    • -index, -name, -nameUniversal, -bone, -shape, -size, -position, -rotation, -mass, -linearDamping, -angularDamping, -friction, -restitution, -group, -mask, -physicsMode
    • writes body data (PMX shape_size verbatim into bodyShapeSize, group/mask bools, physics mode via the core Simulation::PhysicsMode enum)
    • FOLLOW_BONE bodies: binds the related joint via anchorWorldMatrix + single groupInverseWorldMatrix + baked anchorOffset; no-bone bodies become pinned static colliders
    • bakes bodyWriteBackOffset (K) for every body (identity when no joint)
  • mmd/MayaMMD.cpp — registers pmxRigidBody (+ deregisters on unload)
  • CMakeLists.txt — adds rigid_body_cmd.cpp to the plugin target
  • tests/integration/maya/cmds/test_pmx_rigid_body_cmd_integration.py — 11 new integration tests (no PMX model needed), wired into the cmd suite
  • tests/integration/maya/run_all_integration_tests.pycmd suite now runs both native command test modules

…nchors)

Native C++ pmxRigidBody command — the single body-modification path for
pmxPhysicsNode.  Create mode only, SIMULATION IS DISABLED: writes the full
body DATA (PMX shape_size verbatim into bodyShapeSize, group/mask, physics
mode via the core Simulation::PhysicsMode enum) and binds FOLLOW_BONE bodies
to their related joint through the kinematic-anchor input.  Dynamic bodies
are data-only (no write-back, no stepping) — edit/query/remove and the
rigid-body-constraint command are later PRs.

Adapted from the PR #3 draft to the merged node schema:
  - bodyShapeSize (single float3) instead of bodyRadius/bodyExtents/bodyLength
  - core Simulation::PhysicsMode (no node-side enum)
  - single groupInverseWorldMatrix instead of per-anchor anchorParentInverseMatrix

Registration in MayaMMD.cpp + CMake source list + integration tests wired
into the 'cmd' suite (11 new tests).
Design cleanup of the pmxRigidBody command (per review):

- Rename rigid_body_cmd.h -> rigid_body_cmd.hpp and make it a PURE
  interface: all private static helpers (resolveSolver, doCreate,
  matrixFromTR, worldMatrix, connectOrReplace, jointPmxBoneIndex,
  resolveBone) moved into the .cpp's anonymous namespace.  The header now
  exposes only kName/creator/syntaxCreator/doIt/isUndoable.
- Add shared plug utilities to maya_utils.hpp (setPlugMatrixValue,
  setPlugDouble3, connectOrReplace) so the constraint command reuses them
  in the next PR instead of duplicating.
- const/constexpr pass: use physics_math deg2rad/rad2deg (constexpr),
  constexpr clamp01, const locals, 3-arg findPlug (non-deprecated).
- Bring back rigid-body population in rigid_body_builder.py: every PMX
  rigid body is now added to the node via pmxRigidBody at import (data +
  kinematic anchors for FOLLOW_BONE).  Simulation still disabled (no
  joints/write-back/time).  Dict lookups keyed by enum VALUE so a duplicate
  enum class (mayapy double-load of mmd.core) cannot break the mapping.
- Import test now asserts bodies mirror the PMX rigid bodies (count + first
  body data).
- Expand cmd integration tests: write-back K offset baked, wiring-field
  defaults, per-collider shape_size verbatim, MMD->Maya rest-pose
  conversion, kinematic anchor ordering with multiple bodies.

Verified: node/cmd/import suites pass, C++ unit tests 31/31, clang-tidy
clean, ruff/clang-format clean.
…plugin reload

mmd.maya.pmx.rigid_body_builder was missing from plugin.py's _MMD_MODULES
reload list.  In a live Maya session the module stays cached in sys.modules
with the OLD (empty-node) create_physics_from_pmx_data, so recompiling the
.mll and reloading the plugin kept importing the stale builder and bodies
never appeared on the node.

Add it to the list, BEFORE pmx_scene_builder (which imports
create_physics_from_pmx_data from it) so the fresh module is picked up when
pmx_scene_builder is reloaded.
- connectOrReplace now returns early when dst is already driven by the SAME
  source, instead of queuing a duplicate connect that fails.  This makes the
  repeated groupInverseWorldMatrix re-connect (one per kinematic body create)
  a real no-op instead of a swallowed kFailure.
- Add cmd integration tests: numeric -bone <pmxBoneIdx> resolution, query/edit
  rejection, invalid-target rejection, missing-solver-argument rejection.
- rigid_body_cmd.cpp: anchor offsets (joint-anchored AND static-collider)
  now build the world matrix directly from world-space T/R via
  matrixFromTR(worldT, worldR) instead of the group-space round-trip
  matrixFromTR(localT, localR) * groupWorld, which dropped scale from
  the offset (the exact bug the K-offset write-back comment documents).
- rigid_body_cmd.cpp: clamp -group to the PMX 0..15 range with plain
  ifs (replaces a nested ternary that tripped clang-tidy).
- rigid_body_cmd.hpp: document -group range in the header.
- test_pmx_rigid_body_cmd_integration.py: add test_group_clamped
  (-group=-5 -> 0, -group=99 -> 15); format.
@sstarosz sstarosz changed the title Cmd: add native pmxRigidBody command (create mode, data + kinematic anchors) Added pmxRigidBody command Aug 10, 2026
@sstarosz
sstarosz merged commit 29361ad into main Aug 10, 2026
2 checks passed
@sstarosz
sstarosz deleted the feature/rigid-body-cmd branch August 10, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant