Add MeshCollisionAPI to collider Meshes with convexHull approximation.

PiperOrigin-RevId: 754014642
Change-Id: I44cff505a2b9b7120a38f8c896b2c6560ce51c43
This commit is contained in:
Robin Alazard
2025-05-02 08:34:28 -07:00
committed by Copybara-Service
parent ab63a7e824
commit 253abad210
2 changed files with 26 additions and 5 deletions
@@ -883,6 +883,21 @@ class ModelWriter {
model_->geom_conaffinity[geom_id] != 0)) {
ApplyApiSchema(data_, geom_path,
pxr::UsdPhysicsTokens->PhysicsCollisionAPI);
// For meshes, also apply PhysicsMeshCollisionAPI and set the
// approximation attribute.
if (geom->type == mjGEOM_MESH) {
ApplyApiSchema(data_, geom_path,
pxr::UsdPhysicsTokens->PhysicsMeshCollisionAPI);
// Note: MuJoCo documentation states that for collision purposes, meshes
// are always replaced with their convex hulls. Therefore, we set the
// approximation attribute to convexHull explicitly.
pxr::SdfPath approximation_attr = CreateAttributeSpec(
data_, geom_path, pxr::UsdPhysicsTokens->physicsApproximation,
pxr::SdfValueTypeNames->Token, pxr::SdfVariabilityUniform);
SetAttributeDefault(data_, approximation_attr,
pxr::UsdPhysicsTokens->convexHull);
}
}
mjsDefault *spec_default = mjs_getDefault(geom->element);