Update USD support in MuJoCo to Newton USD schemas v0.4.0.

See changelog for more info.

PiperOrigin-RevId: 960284190
Change-Id: I89a84b1efbc22c89ee99db7436851ef27a325176
This commit is contained in:
Sam Haves
2026-08-06 07:17:01 -07:00
committed by Copybara-Service
parent 63b779042c
commit 39e4458806
13 changed files with 421 additions and 93 deletions
+11 -4
View File
@@ -25,16 +25,20 @@
#include <mujoco/experimental/usd/mjcPhysics/siteAPI.h>
#include <mujoco/experimental/usd/mjcPhysics/tendon.h>
#include <mujoco/mujoco.h>
#include "third_party/mujoco/plugin/usd_decoder/newton_tokens.h"
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/common.h>
#include <pxr/usd/usd/primRange.h>
#include <pxr/usd/usdGeom/gprim.h>
#include <pxr/usd/usdGeom/xformCache.h>
#include <pxr/usd/usdPhysics/articulationRootAPI.h>
#include <pxr/usd/usdPhysics/collisionAPI.h>
#include <pxr/usd/usdPhysics/joint.h>
#include <pxr/usd/usdPhysics/rigidBodyAPI.h>
#include <pxr/usd/usdPhysics/scene.h>
using mujoco::NewtonTokens;
bool GetJointBodies(const pxr::UsdPhysicsJoint& joint, pxr::SdfPath* from,
pxr::SdfPath* to) {
// Grab the default prim path
@@ -106,7 +110,8 @@ ExtractedPrims ExtractPrims(pxr::UsdStageRefPtr stage) {
for (auto it = range.begin(); it != range.end(); ++it) {
pxr::UsdPrim prim = *it;
bool is_body = prim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>();
bool is_body = prim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>() ||
prim.HasAPI<pxr::UsdPhysicsArticulationRootAPI>();
bool resets = xform_cache.GetResetXformStack(prim);
// Only update (push/pop) the owner stack for bodies (becomes new owner) and
// resetXformStack (reset owner to world).
@@ -155,7 +160,8 @@ ExtractedPrims ExtractPrims(pxr::UsdStageRefPtr stage) {
}
}
if (prim.HasAPI<pxr::MjcPhysicsSiteAPI>()) {
if (prim.HasAPI(NewtonTokens->NewtonSiteAPI) ||
prim.HasAPI<pxr::MjcPhysicsSiteAPI>()) {
current_node->sites.push_back(prim_path);
// Sites should not have children.
it.PruneChildren();
@@ -248,9 +254,10 @@ std::unique_ptr<Node> BuildKinematicTree(const pxr::UsdStageRefPtr stage) {
// nodes.
extraction.nodes[to_idx]->joints.push_back(joint.GetPath());
// If the joint has MjcPhysicsEqualityJointAPI, also add it to constraints
// If the joint has NewtonMimicAPI or MjcPhysicsEqualityJointAPI, also add it to constraints
// so that ParseConstraint is called to create the equality constraint.
if (joint.GetPrim().HasAPI<pxr::MjcPhysicsEqualityJointAPI>()) {
if (joint.GetPrim().HasAPI(NewtonTokens->NewtonMimicAPI) ||
joint.GetPrim().HasAPI<pxr::MjcPhysicsEqualityJointAPI>()) {
extraction.nodes[to_idx]->constraints.push_back(joint.GetPath());
}
}