Remove physics schema authoring toggle from MJCF SdfFileFormat plugin.

PiperOrigin-RevId: 789321573
Change-Id: Ib29bb426f8598a58f7b34c048b154fa8ada589ef
This commit is contained in:
Sam Haves
2025-07-31 07:05:41 -07:00
committed by Copybara-Service
parent 9f64338b37
commit 4c288c19ac
7 changed files with 158 additions and 237 deletions
@@ -147,17 +147,9 @@ bool UsdMjcfFileFormat::CanRead(const std::string &filePath) const {
bool UsdMjcfFileFormat::ReadImpl(pxr::SdfLayer *layer, mjSpec *spec) const { bool UsdMjcfFileFormat::ReadImpl(pxr::SdfLayer *layer, mjSpec *spec) const {
auto args = layer->GetFileFormatArguments(); auto args = layer->GetFileFormatArguments();
bool toggleUsdPhysics = false;
const auto it =
args.find(UsdMjcfFileFormatTokens->ToggleUsdPhysicsArg.GetString());
if (it != args.end()) {
toggleUsdPhysics = pxr::TfUnstringify<bool>(it->second);
}
auto data = InitData(args); auto data = InitData(args);
auto success = mujoco::usd::WriteSpecToData(spec, data, toggleUsdPhysics); auto success = mujoco::usd::WriteSpecToData(spec, data);
mj_deleteSpec(spec); mj_deleteSpec(spec);
if (!success) { if (!success) {
return false; return false;
@@ -34,7 +34,6 @@ PXR_NAMESPACE_OPEN_SCOPE
((Id, "xml")) \ ((Id, "xml")) \
((Version, "1.0")) \ ((Version, "1.0")) \
((Target, "usd")) \ ((Target, "usd")) \
((ToggleUsdPhysicsArg, "usdMjcfToggleUsdPhysics"))
// clang-format on // clang-format on
TF_DECLARE_PUBLIC_TOKENS(UsdMjcfFileFormatTokens, USD_MJCF_FILE_FORMAT_TOKENS); TF_DECLARE_PUBLIC_TOKENS(UsdMjcfFileFormatTokens, USD_MJCF_FILE_FORMAT_TOKENS);
@@ -182,10 +182,7 @@ class ModelWriter {
} }
~ModelWriter() { mj_deleteModel(model_); } ~ModelWriter() { mj_deleteModel(model_); }
void Write(bool write_physics) { void Write() {
// Set working parameters.
write_physics_ = write_physics;
// Create top level class holder. // Create top level class holder.
class_path_ = CreateClassSpec(data_, pxr::SdfPath::AbsoluteRootPath(), class_path_ = CreateClassSpec(data_, pxr::SdfPath::AbsoluteRootPath(),
pxr::TfToken("__class__")); pxr::TfToken("__class__"));
@@ -211,9 +208,7 @@ class ModelWriter {
WriteMeshes(); WriteMeshes();
WriteMaterials(); WriteMaterials();
WriteBodies(); WriteBodies();
if (write_physics_) { WriteActuators();
WriteActuators();
}
WriteKeyframes(); WriteKeyframes();
} }
@@ -236,8 +231,6 @@ class ModelWriter {
std::unordered_map<std::string, pxr::SdfPath> mesh_paths_; std::unordered_map<std::string, pxr::SdfPath> mesh_paths_;
// Set of body ids that have had the articulation root API applied. // Set of body ids that have had the articulation root API applied.
std::unordered_set<int> articulation_roots_; std::unordered_set<int> articulation_roots_;
// Whether to write physics data.
bool write_physics_ = false;
// Given a name index and a parent prim path this returns a // Given a name index and a parent prim path this returns a
// token such that appending it to the parent prim path does not // token such that appending it to the parent prim path does not
@@ -376,26 +369,23 @@ class ModelWriter {
pxr::UsdGeomTokens->Mesh); pxr::UsdGeomTokens->Mesh);
mesh_paths_[*mjs_getName(mesh->element)] = subcomponent_path; mesh_paths_[*mjs_getName(mesh->element)] = subcomponent_path;
if (write_physics_) { ApplyApiSchema(data_, mesh_path, MjcPhysicsTokens->MjcMeshCollisionAPI);
ApplyApiSchema(data_, mesh_path, MjcPhysicsTokens->MjcMeshCollisionAPI);
pxr::TfToken inertia = MjcPhysicsTokens->legacy; pxr::TfToken inertia = MjcPhysicsTokens->legacy;
if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_EXACT) { if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_EXACT) {
inertia = MjcPhysicsTokens->exact; inertia = MjcPhysicsTokens->exact;
} else if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_CONVEX) { } else if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_CONVEX) {
inertia = MjcPhysicsTokens->convex; inertia = MjcPhysicsTokens->convex;
} else if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_SHELL) { } else if (mesh->inertia == mjtMeshInertia::mjMESH_INERTIA_SHELL) {
inertia = MjcPhysicsTokens->shell; inertia = MjcPhysicsTokens->shell;
}
WriteUniformAttribute(mesh_path, pxr::SdfValueTypeNames->Token,
MjcPhysicsTokens->mjcInertia, inertia);
WriteUniformAttribute(mesh_path, pxr::SdfValueTypeNames->Int,
MjcPhysicsTokens->mjcMaxhullvert,
mesh->maxhullvert);
} }
WriteUniformAttribute(mesh_path, pxr::SdfValueTypeNames->Token,
MjcPhysicsTokens->mjcInertia, inertia);
WriteUniformAttribute(mesh_path, pxr::SdfValueTypeNames->Int,
MjcPhysicsTokens->mjcMaxhullvert, mesh->maxhullvert);
// NOTE: The geometry data taken from the spec is the post-compilation // NOTE: The geometry data taken from the spec is the post-compilation
// data after it has been mjCMesh::Compile'd. So don't be surprised if // data after it has been mjCMesh::Compile'd. So don't be surprised if
// things like user defined vertices have moved due to re-centering to // things like user defined vertices have moved due to re-centering to
@@ -1652,16 +1642,15 @@ class ModelWriter {
MjcPhysicsTokens->mjcGroup, geom->group); MjcPhysicsTokens->mjcGroup, geom->group);
if (model_->geom_contype[geom_id] == 0 && if (model_->geom_contype[geom_id] == 0 &&
model_->geom_conaffinity[geom_id] == 0) { model_->geom_conaffinity[geom_id] == 0) {
// If the geom is purely visual, apply the imageable API. // If the geom is purely visual, apply the imageable API.
ApplyApiSchema(data_, geom_path, ApplyApiSchema(data_, geom_path, MjcPhysicsTokens->MjcImageableAPI);
MjcPhysicsTokens->MjcImageableAPI);
} }
// Apply the physics schemas if we are writing physics and the // Apply the physics schemas if we are writing physics and the
// geom participates in collisions. // geom participates in collisions.
if (write_physics_ && (model_->geom_contype[geom_id] != 0 || if (model_->geom_contype[geom_id] != 0 ||
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);
ApplyApiSchema(data_, geom_path, MjcPhysicsTokens->MjcCollisionAPI); ApplyApiSchema(data_, geom_path, MjcPhysicsTokens->MjcCollisionAPI);
@@ -1822,8 +1811,6 @@ class ModelWriter {
} }
void WriteJoints(mjsBody *body) { void WriteJoints(mjsBody *body) {
if (!write_physics_) return;
int body_id = mjs_getId(body->element); int body_id = mjs_getId(body->element);
if (body_id == kWorldIndex) return; if (body_id == kWorldIndex) return;
@@ -2224,50 +2211,47 @@ class ModelWriter {
} }
} }
// Apply the PhysicsRigidBodyAPI schema if we are writing physics. // If the body had a mass specified then it must have either inertia or
if (write_physics_) { // fullinertia specified per inertia element XML documentation.
// If the body had a mass specified then it must have either inertia or // Therefore it is sufficient to check if the mass is non-zero to see if
// fullinertia specified per inertia element XML documentation. // we should set inertial attributes on the body.
// Therefore it is sufficient to check if the mass is non-zero to see if //
// we should set inertial attributes on the body. // Note that if the user has NOT specified any inertial properties then
// // we don't want to pull values from the compiled model since coming back
// Note that if the user has NOT specified any inertial properties then // into Mujoco would take those values instead of computing them
// we don't want to pull values from the compiled model since coming back // automatically from the subtree.
// into Mujoco would take those values instead of computing them if (body->mass > 0) {
// automatically from the subtree. // User might have specified the inertia via fullinertia and the
if (body->mass > 0) { // compiler has extracted all values properly. So leverage those
// User might have specified the inertia via fullinertia and the // instead of doing the computation ourselves here.
// compiler has extracted all values properly. So leverage those ApplyApiSchema(data_, body_path, pxr::UsdPhysicsTokens->PhysicsMassAPI);
// instead of doing the computation ourselves here. WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Float,
ApplyApiSchema(data_, body_path, pxr::UsdPhysicsTokens->PhysicsMassAPI); pxr::UsdPhysicsTokens->physicsMass,
WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Float, (float)model_->body_mass[body_id]);
pxr::UsdPhysicsTokens->physicsMass,
(float)model_->body_mass[body_id]);
mjtNum *body_ipos = &model_->body_ipos[body_id * 3]; mjtNum *body_ipos = &model_->body_ipos[body_id * 3];
pxr::GfVec3f inertial_pos(body_ipos[0], body_ipos[1], body_ipos[2]); pxr::GfVec3f inertial_pos(body_ipos[0], body_ipos[1], body_ipos[2]);
WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Point3f, WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Point3f,
pxr::UsdPhysicsTokens->physicsCenterOfMass, pxr::UsdPhysicsTokens->physicsCenterOfMass,
inertial_pos); inertial_pos);
mjtNum *body_iquat = &model_->body_iquat[body_id * 4]; mjtNum *body_iquat = &model_->body_iquat[body_id * 4];
pxr::GfQuatf inertial_frame(body_iquat[0], body_iquat[1], body_iquat[2], pxr::GfQuatf inertial_frame(body_iquat[0], body_iquat[1], body_iquat[2],
body_iquat[3]); body_iquat[3]);
WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Quatf, WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Quatf,
pxr::UsdPhysicsTokens->physicsPrincipalAxes, pxr::UsdPhysicsTokens->physicsPrincipalAxes,
inertial_frame); inertial_frame);
mjtNum *inertia = &model_->body_inertia[body_id * 3]; mjtNum *inertia = &model_->body_inertia[body_id * 3];
pxr::GfVec3f diag_inertia(inertia[0], inertia[1], inertia[2]); pxr::GfVec3f diag_inertia(inertia[0], inertia[1], inertia[2]);
WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Float3, WriteUniformAttribute(body_path, pxr::SdfValueTypeNames->Float3,
pxr::UsdPhysicsTokens->physicsDiagonalInertia, pxr::UsdPhysicsTokens->physicsDiagonalInertia,
diag_inertia); diag_inertia);
}
ApplyApiSchema(data_, body_path,
pxr::UsdPhysicsTokens->PhysicsRigidBodyAPI);
} }
ApplyApiSchema(data_, body_path,
pxr::UsdPhysicsTokens->PhysicsRigidBodyAPI);
// Create classes if necessary // Create classes if necessary
mjsDefault *spec_default = mjs_getDefault(body->element); mjsDefault *spec_default = mjs_getDefault(body->element);
@@ -2337,8 +2321,7 @@ class ModelWriter {
namespace mujoco { namespace mujoco {
namespace usd { namespace usd {
bool WriteSpecToData(mjSpec *spec, pxr::SdfAbstractDataRefPtr &data, bool WriteSpecToData(mjSpec *spec, pxr::SdfAbstractDataRefPtr &data) {
bool write_physics) {
// Create pseudo root first. // Create pseudo root first.
data->CreateSpec(pxr::SdfPath::AbsoluteRootPath(), data->CreateSpec(pxr::SdfPath::AbsoluteRootPath(),
pxr::SdfSpecTypePseudoRoot); pxr::SdfSpecTypePseudoRoot);
@@ -2349,7 +2332,7 @@ bool WriteSpecToData(mjSpec *spec, pxr::SdfAbstractDataRefPtr &data,
return false; return false;
} }
ModelWriter(spec, model, data).Write(write_physics); ModelWriter(spec, model, data).Write();
return true; return true;
} }
@@ -25,9 +25,7 @@ namespace usd {
// Args: // Args:
// spec: mjSpec built programmatically or via parsed XML. // spec: mjSpec built programmatically or via parsed XML.
// data: SdfAbstractDataRefPtr that will be written to. // data: SdfAbstractDataRefPtr that will be written to.
// write_physics: Whether to write physics data. bool WriteSpecToData(mjSpec* spec, pxr::SdfAbstractDataRefPtr& data);
bool WriteSpecToData(mjSpec* spec, pxr::SdfAbstractDataRefPtr& data,
bool write_physics);
} // namespace usd } // namespace usd
} // namespace mujoco } // namespace mujoco
@@ -110,9 +110,8 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestClassAuthored) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/__class__"); EXPECT_PRIM_VALID(stage, "/__class__");
EXPECT_PRIM_VALID(stage, "/__class__/test"); EXPECT_PRIM_VALID(stage, "/__class__/test");
} }
@@ -131,9 +130,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestBasicMeshSources) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/mesh_test"); EXPECT_PRIM_VALID(stage, "/mesh_test");
EXPECT_PRIM_VALID(stage, "/mesh_test/test_body/tetrahedron"); EXPECT_PRIM_VALID(stage, "/mesh_test/test_body/tetrahedron");
EXPECT_PRIM_VALID(stage, "/mesh_test/test_body/tetrahedron/Mesh"); EXPECT_PRIM_VALID(stage, "/mesh_test/test_body/tetrahedron/Mesh");
@@ -149,7 +146,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsMaterials) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_PRIM_VALID( EXPECT_PRIM_VALID(
stage, "/physics_materials_test/PhysicsMaterials/geom_with_friction"); stage, "/physics_materials_test/PhysicsMaterials/geom_with_friction");
EXPECT_REL_HAS_TARGET( EXPECT_REL_HAS_TARGET(
@@ -315,8 +312,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestGeomRgba) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/test/sphere_red"); EXPECT_PRIM_VALID(stage, "/test/sphere_red");
ExpectAttributeEqual(stage, "/test/sphere_red.primvars:displayColor", ExpectAttributeEqual(stage, "/test/sphere_red.primvars:displayColor",
@@ -388,9 +384,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestFaceVaryingMeshSourcesSimpleMjcfMesh) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
auto mesh = pxr::UsdGeomMesh::Get( auto mesh = pxr::UsdGeomMesh::Get(
stage, SdfPath("/mesh_test/test_body/tetrahedron/Mesh")); stage, SdfPath("/mesh_test/test_body/tetrahedron/Mesh"));
@@ -525,9 +519,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestBody) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/body_test"); EXPECT_PRIM_VALID(stage, "/body_test");
EXPECT_PRIM_VALID(stage, "/body_test/test_body"); EXPECT_PRIM_VALID(stage, "/body_test/test_body");
@@ -548,9 +540,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestBasicParenting) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/test/root"); EXPECT_PRIM_VALID(stage, "/test/root");
EXPECT_PRIM_VALID(stage, "/test/root/root_body_1"); EXPECT_PRIM_VALID(stage, "/test/root/root_body_1");
EXPECT_PRIM_VALID(stage, "/test/root/root_body_2"); EXPECT_PRIM_VALID(stage, "/test/root/root_body_2");
@@ -578,9 +568,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestJointsDoNotAffectParenting) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/test/root"); EXPECT_PRIM_VALID(stage, "/test/root");
EXPECT_PRIM_VALID(stage, "/test/root/middle"); EXPECT_PRIM_VALID(stage, "/test/root/middle");
EXPECT_PRIM_VALID(stage, "/test/root/middle/tet"); EXPECT_PRIM_VALID(stage, "/test/root/middle/tet");
@@ -607,9 +595,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestKindAuthoring) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_KIND(stage, "/test", pxr::KindTokens->group); EXPECT_PRIM_KIND(stage, "/test", pxr::KindTokens->group);
EXPECT_PRIM_KIND(stage, "/test/root", pxr::KindTokens->component); EXPECT_PRIM_KIND(stage, "/test/root", pxr::KindTokens->component);
EXPECT_PRIM_KIND(stage, "/test/root/middle", pxr::KindTokens->subcomponent); EXPECT_PRIM_KIND(stage, "/test/root/middle", pxr::KindTokens->subcomponent);
@@ -633,8 +619,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestAttributesMatchSchemaTypes) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
for (const auto& prim : stage->TraverseAll()) { for (const auto& prim : stage->TraverseAll()) {
ExpectAllAuthoredAttributesMatchSchemaTypes(prim); ExpectAllAuthoredAttributesMatchSchemaTypes(prim);
@@ -655,8 +640,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestGeomsPrims) {
</mujoco> </mujoco>
)"; )";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml); auto stage = OpenStage(kXml);
auto stage = pxr::UsdStage::Open(layer);
// Note that all sizes are multiplied by 2 because Mujoco uses half sizes. // Note that all sizes are multiplied by 2 because Mujoco uses half sizes.
@@ -702,11 +686,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestGeomsPrims) {
static const pxr::SdfPath kPhysicsScenePrimPath("/test/PhysicsScene"); static const pxr::SdfPath kPhysicsScenePrimPath("/test/PhysicsScene");
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTimestep) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTimestep) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option timestep="0.005"> </option> <option timestep="0.005"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -715,11 +699,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTimestep) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCone) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCone) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option cone="elliptic"> </option> <option cone="elliptic"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -728,11 +712,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCone) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimWind) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimWind) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option wind="1 2 3"> </option> <option wind="1 2 3"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -741,11 +725,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimWind) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimApirate) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimApirate) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option apirate="1.2"> </option> <option apirate="1.2"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -754,11 +738,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimApirate) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimImpratio) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimImpratio) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option impratio="0.8"> </option> <option impratio="0.8"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -767,11 +751,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimImpratio) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimMagnetic) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimMagnetic) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option magnetic="1 2 3"> </option> <option magnetic="1 2 3"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -780,11 +764,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimMagnetic) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDensity) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDensity) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option density="1.2"> </option> <option density="1.2"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -793,11 +777,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDensity) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimViscosity) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimViscosity) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option viscosity="0.8"> </option> <option viscosity="0.8"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -806,11 +790,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimViscosity) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_margin) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_margin) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option o_margin="0.001"> </option> <option o_margin="0.001"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -819,11 +803,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_margin) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solref) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solref) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option o_solref="0.1 0.2"> </option> <option o_solref="0.1 0.2"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -832,11 +816,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solref) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solimp) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solimp) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option o_solimp="0.1 0.2 0.3 0.4 0.5"> </option> <option o_solimp="0.1 0.2 0.3 0.4 0.5"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -845,11 +829,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimO_solimp) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTolerance) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTolerance) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option tolerance="0.0012"> </option> <option tolerance="0.0012"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -858,11 +842,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimTolerance) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSTolerance) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSTolerance) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option ls_tolerance="0.0034"> </option> <option ls_tolerance="0.0034"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -871,11 +855,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSTolerance) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipTolerance) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipTolerance) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option noslip_tolerance="0.0056"> </option> <option noslip_tolerance="0.0056"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -884,11 +868,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipTolerance) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDTolerance) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDTolerance) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option ccd_tolerance="0.0078"> </option> <option ccd_tolerance="0.0078"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -897,11 +881,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDTolerance) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimOFriction) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimOFriction) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option o_friction="0.1 0.2 0.3 0.4 0.5"> </option> <option o_friction="0.1 0.2 0.3 0.4 0.5"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -910,11 +894,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimOFriction) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIntegrator) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIntegrator) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option integrator="RK4"> </option> <option integrator="RK4"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -923,11 +907,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIntegrator) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimJacobian) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimJacobian) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option jacobian="sparse"> </option> <option jacobian="sparse"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -936,11 +920,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimJacobian) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSolver) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSolver) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option solver="CG"> </option> <option solver="CG"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual( ExpectAttributeEqual(
stage, stage,
@@ -949,11 +933,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSolver) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIterations) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIterations) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option iterations="10"> </option> <option iterations="10"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -962,11 +946,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimIterations) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSIterations) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSIterations) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option ls_iterations="20"> </option> <option ls_iterations="20"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -975,11 +959,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimLSIterations) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipIterations) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipIterations) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option noslip_iterations="30"> </option> <option noslip_iterations="30"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -988,11 +972,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimNoslipIterations) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDIterations) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDIterations) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option ccd_iterations="40"> </option> <option ccd_iterations="40"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -1001,11 +985,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimCCDIterations) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFInitPoints) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFInitPoints) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option sdf_initpoints="50"> </option> <option sdf_initpoints="50"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -1014,11 +998,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFInitPoints) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFIterations) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFIterations) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option sdf_iterations="60"> </option> <option sdf_iterations="60"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -1027,11 +1011,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimSDFIterations) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimGravity) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimGravity) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option gravity="-123 0 0"> </option> <option gravity="-123 0 0"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -1042,11 +1026,11 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimGravity) {
pxr::UsdPhysicsTokens->physicsGravityDirection), pxr::UsdPhysicsTokens->physicsGravityDirection),
pxr::GfVec3f(-1.0f, 0.0f, 0.0f)); pxr::GfVec3f(-1.0f, 0.0f, 0.0f));
stage = pxr::UsdStage::Open(LoadLayer(R"( stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option gravity="2 3 6"> </option> <option gravity="2 3 6"> </option>
</mujoco> </mujoco>
)")); )");
ExpectAttributeEqual(stage, ExpectAttributeEqual(stage,
kPhysicsScenePrimPath.AppendProperty( kPhysicsScenePrimPath.AppendProperty(
@@ -1059,7 +1043,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimGravity) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDisableFlags) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDisableFlags) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option> <option>
<flag <flag
@@ -1083,7 +1067,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDisableFlags) {
/> />
</option> </option>
</mujoco> </mujoco>
)")); )");
const std::vector<pxr::TfToken> kFlags = { const std::vector<pxr::TfToken> kFlags = {
MjcPhysicsTokens->mjcFlagConstraint, MjcPhysicsTokens->mjcFlagConstraint,
@@ -1111,7 +1095,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimDisableFlags) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimEnableFlags) { TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimEnableFlags) {
auto stage = pxr::UsdStage::Open(LoadLayer(R"( auto stage = OpenStage(R"(
<mujoco model="test"> <mujoco model="test">
<option> <option>
<flag <flag
@@ -1124,7 +1108,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsScenePrimEnableFlags) {
/> />
</option> </option>
</mujoco> </mujoco>
)")); )");
// clang-format off // clang-format off
const std::vector<pxr::TfToken> kFlags = { const std::vector<pxr::TfToken> kFlags = {
@@ -1158,9 +1142,7 @@ static constexpr char kSiteXml[] = R"(
)"; )";
TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsAuthored) { TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsAuthored) {
pxr::SdfLayerRefPtr layer = LoadLayer(kSiteXml); auto stage = OpenStage(kSiteXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_VALID(stage, "/test/box_site"); EXPECT_PRIM_VALID(stage, "/test/box_site");
EXPECT_PRIM_IS_A(stage, "/test/box_site", pxr::UsdGeomCube); EXPECT_PRIM_IS_A(stage, "/test/box_site", pxr::UsdGeomCube);
EXPECT_PRIM_API_APPLIED(stage, "/test/box_site", pxr::MjcPhysicsSiteAPI); EXPECT_PRIM_API_APPLIED(stage, "/test/box_site", pxr::MjcPhysicsSiteAPI);
@@ -1189,9 +1171,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsAuthored) {
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsPurpose) { TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsPurpose) {
pxr::SdfLayerRefPtr layer = LoadLayer(kSiteXml); auto stage = OpenStage(kSiteXml);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_PRIM_PURPOSE(stage, "/test/box_site", pxr::UsdGeomTokens->guide); EXPECT_PRIM_PURPOSE(stage, "/test/box_site", pxr::UsdGeomTokens->guide);
EXPECT_PRIM_PURPOSE(stage, "/test/ball/sphere_site", EXPECT_PRIM_PURPOSE(stage, "/test/ball/sphere_site",
pxr::UsdGeomTokens->guide); pxr::UsdGeomTokens->guide);
@@ -1203,27 +1183,6 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestSitePrimsPurpose) {
pxr::UsdGeomTokens->guide); pxr::UsdGeomTokens->guide);
} }
TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsToggleSdfFormatArg) {
std::string xml_path = GetTestDataFilePath(kMeshObjPath);
// Test that the default is no physics.
auto stage_no_physics = pxr::UsdStage::Open(xml_path);
EXPECT_THAT(stage_no_physics, testing::NotNull());
EXPECT_PRIM_VALID(stage_no_physics, "/mesh_test/test_body");
EXPECT_PRIM_API_NOT_APPLIED(stage_no_physics, "/mesh_test/test_body",
pxr::UsdPhysicsRigidBodyAPI);
// Then test that the physics flag enables physics.
std::string xml_path_physics_flag =
xml_path + ":SDF_FORMAT_ARGS:usdMjcfToggleUsdPhysics=true";
auto stage_with_physics = pxr::UsdStage::Open(xml_path_physics_flag);
EXPECT_THAT(stage_with_physics, testing::NotNull());
EXPECT_PRIM_VALID(stage_with_physics, "/mesh_test/test_body");
EXPECT_PRIM_API_APPLIED(stage_with_physics, "/mesh_test/test_body",
pxr::UsdPhysicsRigidBodyAPI);
}
TEST_F(MjcfSdfFileFormatPluginTest, TestArticulationRootAppliedOnce) { TEST_F(MjcfSdfFileFormatPluginTest, TestArticulationRootAppliedOnce) {
static constexpr char kXml[] = R"( static constexpr char kXml[] = R"(
<mujoco model="physics_test"> <mujoco model="physics_test">
@@ -1241,9 +1200,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestArticulationRootAppliedOnce) {
</mujoco> </mujoco>
)"; )";
pxr::SdfFileFormat::FileFormatArguments args; pxr::SdfLayerRefPtr layer = LoadLayer(kXml);;
args["usdMjcfToggleUsdPhysics"] = "true";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml, args);
// This test is particular in the sense that the authoring mistake, which is // This test is particular in the sense that the authoring mistake, which is
// made on the SdfLayer level, would disappear when we access the COMPOSED // made on the SdfLayer level, would disappear when we access the COMPOSED
@@ -1280,10 +1237,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsRigidBody) {
</mujoco> </mujoco>
)"; )";
pxr::SdfFileFormat::FileFormatArguments args; auto stage = OpenStage(kXml);
args["usdMjcfToggleUsdPhysics"] = "true";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml, args);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_VALID(stage, "/physics_test"); EXPECT_PRIM_VALID(stage, "/physics_test");
@@ -1358,10 +1312,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsColliders) {
</mujoco> </mujoco>
)"; )";
pxr::SdfFileFormat::FileFormatArguments args; auto stage = OpenStage(kXml);
args["usdMjcfToggleUsdPhysics"] = "true";
pxr::SdfLayerRefPtr layer = LoadLayer(kXml, args);
auto stage = pxr::UsdStage::Open(layer);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_VALID(stage, "/test"); EXPECT_PRIM_VALID(stage, "/test");
@@ -1492,7 +1443,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsImageableAPI) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_API_APPLIED(stage, "/test/body/mesh/Mesh", EXPECT_PRIM_API_APPLIED(stage, "/test/body/mesh/Mesh",
pxr::MjcPhysicsImageableAPI); pxr::MjcPhysicsImageableAPI);
@@ -1522,7 +1473,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsCollisionAPI) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
ExpectAttributeEqual(stage, "/test/body/box.mjc:group", 4); ExpectAttributeEqual(stage, "/test/body/box.mjc:group", 4);
ExpectAttributeEqual(stage, "/test/body/box.mjc:priority", 2); ExpectAttributeEqual(stage, "/test/body/box.mjc:priority", 2);
@@ -1558,7 +1509,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsMeshCollisionAPI) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
ExpectAttributeEqual(stage, "/test/body/tet_legacy/Mesh.mjc:inertia", ExpectAttributeEqual(stage, "/test/body/tet_legacy/Mesh.mjc:inertia",
MjcPhysicsTokens->legacy); MjcPhysicsTokens->legacy);
@@ -1582,7 +1533,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMassAPIApplied) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/body"); EXPECT_PRIM_VALID(stage, "/test/body");
EXPECT_PRIM_VALID(stage, "/test/body/box"); EXPECT_PRIM_VALID(stage, "/test/body/box");
@@ -1602,7 +1553,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMassAPIAppliedToBody) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/body"); EXPECT_PRIM_VALID(stage, "/test/body");
EXPECT_PRIM_VALID(stage, "/test/body/box"); EXPECT_PRIM_VALID(stage, "/test/body/box");
@@ -1625,7 +1576,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMassAPIDensity) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
ExpectAttributeEqual(stage, "/test/body/box.physics:density", 1234.0f); ExpectAttributeEqual(stage, "/test/body/box.physics:density", 1234.0f);
} }
@@ -1666,7 +1617,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsActuator) {
</actuator> </actuator>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Actuators/general"); EXPECT_PRIM_VALID(stage, "/test/Actuators/general");
EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator); EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator);
@@ -1729,7 +1680,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsPositionActuator) {
</actuator> </actuator>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Actuators/position"); EXPECT_PRIM_VALID(stage, "/test/Actuators/position");
EXPECT_PRIM_IS_A(stage, "/test/Actuators/position", pxr::MjcPhysicsActuator); EXPECT_PRIM_IS_A(stage, "/test/Actuators/position", pxr::MjcPhysicsActuator);
@@ -1757,7 +1708,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsJointActuator) {
</actuator> </actuator>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Actuators/general"); EXPECT_PRIM_VALID(stage, "/test/Actuators/general");
EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator); EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator);
@@ -1781,7 +1732,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsBodyActuator) {
</actuator> </actuator>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Actuators/general"); EXPECT_PRIM_VALID(stage, "/test/Actuators/general");
EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator); EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator);
@@ -1809,7 +1760,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsSliderCrankActuator) {
</actuator> </actuator>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Actuators/general"); EXPECT_PRIM_VALID(stage, "/test/Actuators/general");
EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator); EXPECT_PRIM_IS_A(stage, "/test/Actuators/general", pxr::MjcPhysicsActuator);
@@ -1850,7 +1801,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsJointAPI) {
</worldbody> </worldbody>
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
const SdfPath joint_path("/test/parent/child/my_joint"); const SdfPath joint_path("/test/parent/child/my_joint");
EXPECT_PRIM_API_APPLIED(stage, joint_path, pxr::MjcPhysicsJointAPI); EXPECT_PRIM_API_APPLIED(stage, joint_path, pxr::MjcPhysicsJointAPI);
@@ -1900,7 +1851,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsFloatingAndFixedBaseBody) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
// Test that the fixed_base body has a UsdPhysicsJoint child connected to the // Test that the fixed_base body has a UsdPhysicsJoint child connected to the
@@ -1941,7 +1892,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsFixedJoint) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_IS_A(stage, "/test/parent/FixedJoint", pxr::UsdPhysicsFixedJoint); EXPECT_PRIM_IS_A(stage, "/test/parent/FixedJoint", pxr::UsdPhysicsFixedJoint);
@@ -1987,7 +1938,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsRevoluteJoint) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
// hinge_root doesn't set a type so it's the default: a revolute joint. // hinge_root doesn't set a type so it's the default: a revolute joint.
@@ -2046,7 +1997,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsPrismaticJoint) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_IS_A(stage, "/test/parent/slide_root", EXPECT_PRIM_IS_A(stage, "/test/parent/slide_root",
@@ -2098,7 +2049,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestRadianAnglesAreConvertedToDegrees) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_VALID(stage, "/test/parent/hinge"); EXPECT_PRIM_VALID(stage, "/test/parent/hinge");
@@ -2128,7 +2079,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsJointFrames) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
// Test the hinge joint. // Test the hinge joint.
@@ -2220,7 +2171,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestPhysicsUnsupportedJoint) {
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(kXml); auto stage = OpenStage(kXml);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
EXPECT_PRIM_INVALID(stage, "/test/parent/ball_joint"); EXPECT_PRIM_INVALID(stage, "/test/parent/ball_joint");
@@ -2242,7 +2193,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestMjcPhysicsKeyframe) {
<key time="2" qpos="3"/> <key time="2" qpos="3"/>
</keyframe> </keyframe>
</mujoco>)"; </mujoco>)";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/Keyframes/home"); EXPECT_PRIM_VALID(stage, "/test/Keyframes/home");
EXPECT_PRIM_VALID(stage, "/test/Keyframes/Keyframe"); EXPECT_PRIM_VALID(stage, "/test/Keyframes/Keyframe");
@@ -2277,7 +2228,7 @@ TEST_F(MjcfSdfFileFormatPluginTest, TestCompilerOptions) {
/> />
</mujoco> </mujoco>
)"; )";
auto stage = OpenStageWithPhysics(xml); auto stage = OpenStage(xml);
EXPECT_PRIM_VALID(stage, "/test/PhysicsScene"); EXPECT_PRIM_VALID(stage, "/test/PhysicsScene");
+2 -4
View File
@@ -48,10 +48,8 @@ pxr::SdfLayerRefPtr LoadLayer(
return layer; return layer;
} }
pxr::UsdStageRefPtr OpenStageWithPhysics(const std::string& xml) { pxr::UsdStageRefPtr OpenStage(const std::string& xml) {
pxr::SdfFileFormat::FileFormatArguments args; pxr::SdfLayerRefPtr layer = LoadLayer(xml);
args["usdMjcfToggleUsdPhysics"] = "true";
pxr::SdfLayerRefPtr layer = LoadLayer(xml, args);
auto stage = pxr::UsdStage::Open(layer); auto stage = pxr::UsdStage::Open(layer);
EXPECT_THAT(stage, testing::NotNull()); EXPECT_THAT(stage, testing::NotNull());
return stage; return stage;
+1 -1
View File
@@ -99,7 +99,7 @@ pxr::SdfLayerRefPtr LoadLayer(
const std::string& xml, const std::string& xml,
const pxr::SdfFileFormat::FileFormatArguments& args = {}); const pxr::SdfFileFormat::FileFormatArguments& args = {});
pxr::UsdStageRefPtr OpenStageWithPhysics(const std::string& xml); pxr::UsdStageRefPtr OpenStage(const std::string& xml);
template <typename T> template <typename T>
void ExpectAttributeEqual( void ExpectAttributeEqual(