Fix radius sizes of geom shapes

PiperOrigin-RevId: 752750452
Change-Id: I2ac08ad4014718320f014ed8ba7cc3b87586f6c0
This commit is contained in:
Robin Alazard
2025-04-29 08:43:23 -07:00
committed by Copybara-Service
parent 3e9d130092
commit d657e628f0
2 changed files with 12 additions and 14 deletions
@@ -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<float>(size[0] * 2),
static_cast<float>(size[1] * 2),
static_cast<float>(size[2] * 2)};
pxr::GfVec3f scale = {static_cast<float>(size[0]),
static_cast<float>(size[1]),
static_cast<float>(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;
}
@@ -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"(