From e92ce30732aaedff50510ae95892605ec59d8657 Mon Sep 17 00:00:00 2001 From: Sam Haves Date: Thu, 17 Jul 2025 10:28:28 -0700 Subject: [PATCH] Account for scale authored on UsdMesh prims. PiperOrigin-RevId: 784231423 Change-Id: I82b363c6c40940982ebeb0b1949e0e1e8f92199d --- src/experimental/usd/usd_to_mjspec.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/experimental/usd/usd_to_mjspec.cc b/src/experimental/usd/usd_to_mjspec.cc index 7bfbad6f..4ba2c529 100644 --- a/src/experimental/usd/usd_to_mjspec.cc +++ b/src/experimental/usd/usd_to_mjspec.cc @@ -264,7 +264,7 @@ bool MaybeParseGeomPrimitive(const pxr::UsdPrim& prim, T* element, return true; } -mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom) { +mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom, pxr::UsdGeomXformCache& xform_cache) { if (!prim.IsA()) { return nullptr; } @@ -305,6 +305,12 @@ mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom) { mjsMesh* mesh = mjs_addMesh(spec, nullptr); + auto world_xform = xform_cache.GetLocalToWorldTransform(prim); + auto scale = GetScale(world_xform); + mesh->scale[0] = scale[0]; + mesh->scale[1] = scale[1]; + mesh->scale[2] = scale[2]; + std::string mesh_name = usd_mesh.GetPath().GetAsString(); mjs_setName(mesh->element, mesh_name.c_str()); mjs_setFloat(mesh->uservert, uservert.data(), uservert.size()); @@ -1265,7 +1271,7 @@ void ParseUsdGeomGprim(mjSpec* spec, const pxr::UsdPrim& gprim, ParseDisplayColorAndOpacity(gprim, geom); SetLocalPoseFromPrim(gprim, body_prim, geom, caches.xform_cache); if (!MaybeParseGeomPrimitive(gprim, geom, caches.xform_cache)) { - ParseUsdMesh(spec, gprim, geom); + ParseUsdMesh(spec, gprim, geom, caches.xform_cache); } } @@ -1318,7 +1324,7 @@ void ParseUsdPhysicsCollider(mjSpec* spec, SetLocalPoseFromPrim(prim, body_prim, geom, caches.xform_cache); if (!MaybeParseGeomPrimitive(prim, geom, caches.xform_cache)) { - mjsMesh* mesh = ParseUsdMesh(spec, prim, geom); + mjsMesh* mesh = ParseUsdMesh(spec, prim, geom, caches.xform_cache); if (mesh != nullptr && prim.HasAPI()) { ParseMjcPhysicsMeshCollisionAPI(mesh, pxr::MjcPhysicsMeshCollisionAPI(prim));