Skip to content

Commit e92ce30

Browse files
havesscopybara-github
authored andcommitted
Account for scale authored on UsdMesh prims.
PiperOrigin-RevId: 784231423 Change-Id: I82b363c6c40940982ebeb0b1949e0e1e8f92199d
1 parent c597434 commit e92ce30

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/experimental/usd/usd_to_mjspec.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ bool MaybeParseGeomPrimitive(const pxr::UsdPrim& prim, T* element,
264264
return true;
265265
}
266266

267-
mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom) {
267+
mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom, pxr::UsdGeomXformCache& xform_cache) {
268268
if (!prim.IsA<pxr::UsdGeomMesh>()) {
269269
return nullptr;
270270
}
@@ -305,6 +305,12 @@ mjsMesh* ParseUsdMesh(mjSpec* spec, const pxr::UsdPrim& prim, mjsGeom* geom) {
305305

306306
mjsMesh* mesh = mjs_addMesh(spec, nullptr);
307307

308+
auto world_xform = xform_cache.GetLocalToWorldTransform(prim);
309+
auto scale = GetScale(world_xform);
310+
mesh->scale[0] = scale[0];
311+
mesh->scale[1] = scale[1];
312+
mesh->scale[2] = scale[2];
313+
308314
std::string mesh_name = usd_mesh.GetPath().GetAsString();
309315
mjs_setName(mesh->element, mesh_name.c_str());
310316
mjs_setFloat(mesh->uservert, uservert.data(), uservert.size());
@@ -1265,7 +1271,7 @@ void ParseUsdGeomGprim(mjSpec* spec, const pxr::UsdPrim& gprim,
12651271
ParseDisplayColorAndOpacity(gprim, geom);
12661272
SetLocalPoseFromPrim(gprim, body_prim, geom, caches.xform_cache);
12671273
if (!MaybeParseGeomPrimitive(gprim, geom, caches.xform_cache)) {
1268-
ParseUsdMesh(spec, gprim, geom);
1274+
ParseUsdMesh(spec, gprim, geom, caches.xform_cache);
12691275
}
12701276
}
12711277

@@ -1318,7 +1324,7 @@ void ParseUsdPhysicsCollider(mjSpec* spec,
13181324
SetLocalPoseFromPrim(prim, body_prim, geom, caches.xform_cache);
13191325

13201326
if (!MaybeParseGeomPrimitive(prim, geom, caches.xform_cache)) {
1321-
mjsMesh* mesh = ParseUsdMesh(spec, prim, geom);
1327+
mjsMesh* mesh = ParseUsdMesh(spec, prim, geom, caches.xform_cache);
13221328
if (mesh != nullptr && prim.HasAPI<pxr::MjcPhysicsMeshCollisionAPI>()) {
13231329
ParseMjcPhysicsMeshCollisionAPI(mesh,
13241330
pxr::MjcPhysicsMeshCollisionAPI(prim));

0 commit comments

Comments
 (0)