Add MeshCollisionAPI to collider Meshes with convexHull approximation.
PiperOrigin-RevId: 754014642 Change-Id: I44cff505a2b9b7120a38f8c896b2c6560ce51c43
This commit is contained in:
committed by
Copybara-Service
parent
ab63a7e824
commit
253abad210
@@ -883,6 +883,21 @@ class ModelWriter {
|
|||||||
model_->geom_conaffinity[geom_id] != 0)) {
|
model_->geom_conaffinity[geom_id] != 0)) {
|
||||||
ApplyApiSchema(data_, geom_path,
|
ApplyApiSchema(data_, geom_path,
|
||||||
pxr::UsdPhysicsTokens->PhysicsCollisionAPI);
|
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);
|
mjsDefault *spec_default = mjs_getDefault(geom->element);
|
||||||
|
|||||||
@@ -45,7 +45,9 @@
|
|||||||
#include <pxr/usd/usdGeom/sphere.h>
|
#include <pxr/usd/usdGeom/sphere.h>
|
||||||
#include <pxr/usd/usdGeom/tokens.h>
|
#include <pxr/usd/usdGeom/tokens.h>
|
||||||
#include <pxr/usd/usdPhysics/collisionAPI.h>
|
#include <pxr/usd/usdPhysics/collisionAPI.h>
|
||||||
|
#include <pxr/usd/usdPhysics/meshCollisionAPI.h>
|
||||||
#include <pxr/usd/usdPhysics/rigidBodyAPI.h>
|
#include <pxr/usd/usdPhysics/rigidBodyAPI.h>
|
||||||
|
#include <pxr/usd/usdPhysics/tokens.h>
|
||||||
|
|
||||||
PXR_NAMESPACE_OPEN_SCOPE
|
PXR_NAMESPACE_OPEN_SCOPE
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@@ -675,7 +677,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsColliders) {
|
|||||||
//
|
//
|
||||||
// body_3/body_3 [rigidbody]
|
// body_3/body_3 [rigidbody]
|
||||||
// body_3/body_3/body_3_col [] <-- Intermediate prim for mesh instancing
|
// body_3/body_3/body_3_col [] <-- Intermediate prim for mesh instancing
|
||||||
// body_3/body_3/body_3_col/Mesh [collider]
|
// body_3/body_3/body_3_col/Mesh [collider, mesh collider]
|
||||||
|
|
||||||
// ground [collider] (Static collider)
|
// ground [collider] (Static collider)
|
||||||
EXPECT_PRIM_VALID(stage, "/test/ground");
|
EXPECT_PRIM_VALID(stage, "/test/ground");
|
||||||
@@ -753,13 +755,17 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsColliders) {
|
|||||||
pxr::UsdPhysicsRigidBodyAPI);
|
pxr::UsdPhysicsRigidBodyAPI);
|
||||||
EXPECT_PRIM_API_NOT_APPLIED(stage, "/test/body_3/body_3/body_3_col",
|
EXPECT_PRIM_API_NOT_APPLIED(stage, "/test/body_3/body_3/body_3_col",
|
||||||
pxr::UsdPhysicsCollisionAPI);
|
pxr::UsdPhysicsCollisionAPI);
|
||||||
// body_3/body_3/body_3_col/Mesh [collider]
|
// body_3/body_3/body_3_col/Mesh [collider, mesh collider]
|
||||||
EXPECT_PRIM_VALID(stage, "/test/body_3/body_3/body_3_col/Mesh");
|
EXPECT_PRIM_VALID(stage, "/test/body_3/body_3/body_3_col/Mesh");
|
||||||
EXPECT_PRIM_API_NOT_APPLIED(
|
EXPECT_PRIM_API_NOT_APPLIED(stage, "/test/body_3/body_3/body_3_col/Mesh",
|
||||||
stage, "/test/body_3/body_3/body_3_col/Mesh",
|
pxr::UsdPhysicsRigidBodyAPI);
|
||||||
pxr::UsdPhysicsRigidBodyAPI);
|
|
||||||
EXPECT_PRIM_API_APPLIED(stage, "/test/body_3/body_3/body_3_col/Mesh",
|
EXPECT_PRIM_API_APPLIED(stage, "/test/body_3/body_3/body_3_col/Mesh",
|
||||||
pxr::UsdPhysicsCollisionAPI);
|
pxr::UsdPhysicsCollisionAPI);
|
||||||
|
EXPECT_PRIM_API_APPLIED(stage, "/test/body_3/body_3/body_3_col/Mesh",
|
||||||
|
pxr::UsdPhysicsMeshCollisionAPI);
|
||||||
|
ExpectAttributeEqual(
|
||||||
|
stage, "/test/body_3/body_3/body_3_col/Mesh.physics:approximation",
|
||||||
|
pxr::UsdPhysicsTokens->convexHull);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user