From d657e628f0fc224874d83f4bbaf40b3dfe1e6b0e Mon Sep 17 00:00:00 2001 From: Robin Alazard Date: Tue, 29 Apr 2025 08:43:23 -0700 Subject: [PATCH] Fix radius sizes of geom shapes PiperOrigin-RevId: 752750452 Change-Id: I2ac08ad4014718320f014ed8ba7cc3b87586f6c0 --- .../usd/plugins/mjcf/mujoco_to_usd.cc | 18 ++++++++---------- .../usd/plugins/mjcf/mjcf_file_format_test.cc | 8 ++++---- 2 files changed, 12 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 e443149c..8ddba52d 100644 --- a/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc +++ b/src/experimental/usd/plugins/mjcf/mujoco_to_usd.cc @@ -673,15 +673,15 @@ class ModelWriter { pxr::SdfPath capsule_path = CreatePrimSpec(data_, body_path, name, pxr::UsdGeomTokens->Capsule); - // MuJoCo uses half sizes. pxr::SdfPath radius_attr_path = CreateAttributeSpec(data_, capsule_path, pxr::UsdGeomTokens->radius, pxr::SdfValueTypeNames->Float); - SetAttributeDefault(data_, radius_attr_path, size[0] * 2); + SetAttributeDefault(data_, radius_attr_path, size[0]); pxr::SdfPath height_attr_path = CreateAttributeSpec(data_, capsule_path, pxr::UsdGeomTokens->height, pxr::SdfValueTypeNames->Float); + // MuJoCo uses half sizes. SetAttributeDefault(data_, height_attr_path, size[1] * 2); return capsule_path; } @@ -701,15 +701,15 @@ class ModelWriter { pxr::SdfPath cylinder_path = CreatePrimSpec(data_, body_path, name, pxr::UsdGeomTokens->Cylinder); - // MuJoCo uses half sizes. pxr::SdfPath radius_attr_path = CreateAttributeSpec(data_, cylinder_path, pxr::UsdGeomTokens->radius, pxr::SdfValueTypeNames->Float); - SetAttributeDefault(data_, radius_attr_path, size[0] * 2); + SetAttributeDefault(data_, radius_attr_path, size[0]); pxr::SdfPath height_attr_path = CreateAttributeSpec(data_, cylinder_path, pxr::UsdGeomTokens->height, pxr::SdfValueTypeNames->Float); + // MuJoCo uses half sizes. SetAttributeDefault(data_, height_attr_path, size[1] * 2); return cylinder_path; } @@ -729,11 +729,10 @@ class ModelWriter { pxr::SdfPath ellipsoid_path = CreatePrimSpec(data_, body_path, name, pxr::UsdGeomTokens->Sphere); - pxr::GfVec3f scale = {static_cast(size[0] * 2), - static_cast(size[1] * 2), - static_cast(size[2] * 2)}; + pxr::GfVec3f scale = {static_cast(size[0]), + static_cast(size[1]), + static_cast(size[2])}; - // MuJoCo uses half sizes. pxr::SdfPath radius_attr_path = CreateAttributeSpec(data_, ellipsoid_path, pxr::UsdGeomTokens->radius, pxr::SdfValueTypeNames->Float); @@ -760,11 +759,10 @@ class ModelWriter { pxr::SdfPath sphere_path = CreatePrimSpec(data_, body_path, name, pxr::UsdGeomTokens->Sphere); - // MuJoCo uses half sizes. pxr::SdfPath radius_attr_path = CreateAttributeSpec(data_, sphere_path, pxr::UsdGeomTokens->radius, pxr::SdfValueTypeNames->Float); - SetAttributeDefault(data_, radius_attr_path, size[0] * 2); + SetAttributeDefault(data_, radius_attr_path, size[0]); return sphere_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 f144da6e..78f10f46 100644 --- a/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc +++ b/test/experimental/usd/plugins/mjcf/mjcf_file_format_test.cc @@ -472,16 +472,16 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestGeomsPrims) { // Sphere EXPECT_PRIM_VALID(stage, "/test/sphere_geom"); EXPECT_PRIM_IS_A(stage, "/test/sphere_geom", pxr::UsdGeomSphere); - ExpectAttributeEqual(stage, "/test/sphere_geom.radius", 2 * 10.0); + ExpectAttributeEqual(stage, "/test/sphere_geom.radius", 10.0); // Capsule EXPECT_PRIM_VALID(stage, "/test/capsule_geom"); EXPECT_PRIM_IS_A(stage, "/test/capsule_geom", pxr::UsdGeomCapsule); - ExpectAttributeEqual(stage, "/test/capsule_geom.radius", 2 * 10.0); + ExpectAttributeEqual(stage, "/test/capsule_geom.radius", 10.0); ExpectAttributeEqual(stage, "/test/capsule_geom.height", 2 * 20.0); // Cylinder EXPECT_PRIM_VALID(stage, "/test/cylinder_geom"); EXPECT_PRIM_IS_A(stage, "/test/cylinder_geom", pxr::UsdGeomCylinder); - ExpectAttributeEqual(stage, "/test/cylinder_geom.radius", 2 * 10.0); + ExpectAttributeEqual(stage, "/test/cylinder_geom.radius", 10.0); ExpectAttributeEqual(stage, "/test/cylinder_geom.height", 2 * 20.0); // Ellipsoid EXPECT_PRIM_VALID(stage, "/test/ellipsoid_geom"); @@ -490,7 +490,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestGeomsPrims) { EXPECT_PRIM_IS_A(stage, "/test/ellipsoid_geom", pxr::UsdGeomSphere); ExpectAttributeEqual(stage, "/test/ellipsoid_geom.radius", 1.0); ExpectAttributeEqual(stage, "/test/ellipsoid_geom.xformOp:scale", - pxr::GfVec3f(2.0 * 10.0, 2.0 * 20.0, 2.0 * 30.0)); + pxr::GfVec3f(10.0, 20.0, 30.0)); } static constexpr char kSiteXml[] = R"(