From 24789f8fe59cc61e404c43e7caf8a56441deb2bc Mon Sep 17 00:00:00 2001
From: Sam Haves
Date: Thu, 26 Jun 2025 11:06:07 -0700
Subject: [PATCH] Apply articulation API to the correct body when converting to
USD.
PiperOrigin-RevId: 776206773
Change-Id: I84b5687a9900b42fd208124414ac98feaaa9f8c4
---
.../usd/plugins/mjcf/mujoco_to_usd.cc | 18 +++++++------
.../usd/plugins/mjcf/mjcf_file_format_test.cc | 25 +++++++++++++------
2 files changed, 29 insertions(+), 14 deletions(-)
diff --git a/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc b/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc
index a3a21d17..bac02a5e 100644
--- a/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc
+++ b/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc
@@ -1821,6 +1821,17 @@ class ModelWriter {
: pxr::KindTokens->subcomponent;
SetPrimKind(data_, body_path, kind);
+ // If the parent is not the world body, but is child of the world body
+ // then we need to apply the articulation root API.
+ if (parent_id != kWorldIndex) {
+ int parent_parent_id =
+ mjs_getId(mjs_getParent(parent->element)->element);
+ if (parent_parent_id == kWorldIndex) {
+ ApplyApiSchema(data_, parent_path,
+ pxr::UsdPhysicsTokens->PhysicsArticulationRootAPI);
+ }
+ }
+
// Apply the PhysicsRigidBodyAPI schema if we are writing physics.
if (write_physics_) {
// If the body had a mass specified then it must have either inertia or
@@ -1926,13 +1937,6 @@ class ModelWriter {
pxr::UsdGeomTokens->Xform);
SetPrimKind(data_, world_group_path, pxr::KindTokens->group);
- if (write_physics_) {
- // Apply the PhysicsArticulationRootAPI to the world body so that
- // everything under it is automatically considered an articulation.
- ApplyApiSchema(data_, world_group_path,
- pxr::UsdPhysicsTokens->PhysicsArticulationRootAPI);
- }
-
return world_group_path;
}
};
diff --git a/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc b/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc
index a0698ef4..5faec4f7 100644
--- a/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc
+++ b/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc
@@ -1139,6 +1139,9 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsRigidBody) {
+
+