@@ -126,16 +126,6 @@ bool IsUniformScale(const pxr::GfVec3d& scale) {
126
126
fabs (scale[1 ] - scale[2 ]) < epsilon;
127
127
}
128
128
129
- template <typename T>
130
- void SetScale (T* element, const pxr::GfMatrix4d& world_transform,
131
- const pxr::GfVec3d& scale) {
132
- pxr::GfVec3d transform_scale =
133
- pxr::GfCompMult (GetScale (world_transform), scale);
134
- element->size [0 ] = transform_scale[0 ];
135
- element->size [1 ] = transform_scale[1 ];
136
- element->size [2 ] = transform_scale[2 ];
137
- }
138
-
139
129
template <typename T>
140
130
bool MaybeParseGeomPrimitive (const pxr::UsdPrim& prim, T* element,
141
131
pxr::UsdGeomXformCache& xform_cache) {
@@ -222,9 +212,41 @@ bool MaybeParseGeomPrimitive(const pxr::UsdPrim& prim, T* element,
222
212
return false ;
223
213
}
224
214
// MuJoCo uses half-length for box size.
225
- SetScale (element, xform_cache.GetLocalToWorldTransform (prim),
226
- pxr::GfVec3d (size / 2 ));
215
+ size = size / 2 ;
216
+ element->size [0 ] = scale[0 ] * size;
217
+ element->size [1 ] = scale[1 ] * size;
218
+ element->size [2 ] = scale[2 ] * size;
219
+ } else if (prim.IsA <pxr::UsdGeomPlane>()) {
220
+ element->type = mjGEOM_PLANE;
221
+
222
+ pxr::UsdGeomPlane plane (prim);
223
+ TfToken axis;
224
+ if (!plane.GetAxisAttr ().Get (&axis)) {
225
+ mju_error (" Could not get plane axis attr." );
226
+ return false ;
227
+ }
228
+ if (axis != pxr::UsdGeomTokens->z ) {
229
+ mju_error (" Only z-axis planes are supported." );
230
+ return false ;
231
+ }
227
232
233
+ double length;
234
+ if (!plane.GetLengthAttr ().Get (&length)) {
235
+ mju_error (" Could not get plane length attr." );
236
+ return false ;
237
+ }
238
+ double width;
239
+ if (!plane.GetWidthAttr ().Get (&width)) {
240
+ mju_error (" Could not get plane width attr." );
241
+ return false ;
242
+ }
243
+ // MuJoCo uses half-length for plane size.
244
+ width = width / 2 ;
245
+ length = length / 2 ;
246
+ // Plane geoms in mjc are always infinite. Scale is used for visualization.
247
+ element->size [0 ] = scale[0 ] * width;
248
+ element->size [1 ] = scale[1 ] * length;
249
+ element->size [2 ] = scale[2 ];
228
250
} else {
229
251
return false ;
230
252
}
@@ -1040,37 +1062,6 @@ void ParseUsdPhysicsCollider(mjSpec* spec,
1040
1062
mjs_setInt (mesh->userface , userface.data (), userface.size ());
1041
1063
1042
1064
mjs_setString (geom->meshname , mesh_name.c_str ());
1043
- } else if (prim.IsA <pxr::UsdGeomPlane>()) {
1044
- geom->type = mjGEOM_PLANE;
1045
-
1046
- pxr::UsdGeomPlane plane (prim);
1047
- TfToken axis;
1048
- if (!plane.GetAxisAttr ().Get (&axis)) {
1049
- mju_error (" Could not get plane axis attr." );
1050
- return ;
1051
- }
1052
- if (axis != pxr::UsdGeomTokens->z ) {
1053
- mju_error (" Only z-axis planes are supported." );
1054
- return ;
1055
- }
1056
-
1057
- // This block of code distributes the plane length and width along the
1058
- // scale as per the specification here:
1059
- // https://openusd.org/dev/api/class_usd_geom_plane.html#a89fa6076111984682db77fc8a4e57496.
1060
- double length;
1061
- if (!plane.GetLengthAttr ().Get (&length)) {
1062
- mju_error (" Could not get plane length attr." );
1063
- return ;
1064
- }
1065
- double width;
1066
- if (!plane.GetWidthAttr ().Get (&width)) {
1067
- mju_error (" Could not get plane width attr." );
1068
- return ;
1069
- }
1070
- // Plane geoms in mjc are always infinite. We set the scale here just
1071
- // for visualization.
1072
- SetScale (geom, xform_cache.GetLocalToWorldTransform (prim),
1073
- pxr::GfVec3d (width, length, 1 ));
1074
1065
}
1075
1066
}
1076
1067
}
0 commit comments