Skip to content

Commit 072b327

Browse files
ChuangTseucopybara-github
authored andcommitted
Fix the parsing of USD scenes that use ResetXformStack
Also add a new test for it PiperOrigin-RevId: 778114814 Change-Id: Ib019768ac45ecf7ec6d437199a3d1427557b2f06
1 parent 50de1b3 commit 072b327

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/experimental/usd/usd_to_mjspec.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#include <pxr/usd/usdPhysics/revoluteJoint.h>
6464
#include <pxr/usd/usdPhysics/rigidBodyAPI.h>
6565
#include <pxr/usd/usdPhysics/scene.h>
66-
#include <pxr/usd/usdPhysics/sphericalJoint.h>
6766
namespace {
6867

6968
using pxr::MjcPhysicsTokens;
@@ -1350,7 +1349,7 @@ void ParseCurrentAndDescendants(mjSpec* spec, const pxr::UsdPrim& prim,
13501349
if (child.HasAPI<pxr::UsdPhysicsRigidBodyAPI>()) {
13511350
continue;
13521351
}
1353-
if (xform_cache.GetResetXformStack(prim)) {
1352+
if (xform_cache.GetResetXformStack(child)) {
13541353
continue;
13551354
}
13561355
ParseCurrentAndDescendants(spec, child, prim, body, xform_cache);
@@ -1458,12 +1457,15 @@ pxr::UsdPrim GetNestingBodyPrim(const pxr::UsdPrim& prim,
14581457
}
14591458
pxr::UsdPrim previous_prim = prim.GetParent();
14601459
while (previous_prim.IsValid()) {
1461-
if (xform_cache.GetResetXformStack(previous_prim)) {
1462-
return pxr::UsdPrim();
1463-
}
1460+
// If we find a rigid body, this is our answer. The prim is nested.
14641461
if (previous_prim.HasAPI<pxr::UsdPhysicsRigidBodyAPI>()) {
14651462
return previous_prim;
14661463
}
1464+
// If we encounter a prim that resets the transform stack *before* finding
1465+
// a rigid body, the chain is broken. The prim is not nested.
1466+
if (xform_cache.GetResetXformStack(previous_prim)) {
1467+
return pxr::UsdPrim();
1468+
}
14671469
previous_prim = previous_prim.GetParent();
14681470
}
14691471
return pxr::UsdPrim();

0 commit comments

Comments
 (0)