Add material parsing path for colliders instead of strictly visual gprims.

PiperOrigin-RevId: 814692421
Change-Id: If92a36d0382f60e0d92c7d90320dec51c20ea739
This commit is contained in:
Sam Haves
2025-10-03 07:52:00 -07:00
committed by Copybara-Service
parent 709caa0628
commit b5c35f87fc
+25 -5
View File
@@ -1384,14 +1384,19 @@ void ParseUsdGeomGprim(mjSpec* spec, const pxr::UsdPrim& gprim,
if (bound_material) { if (bound_material) {
pxr::SdfPath material_path = bound_material.GetPrim().GetPath(); pxr::SdfPath material_path = bound_material.GetPrim().GetPath();
mjsMaterial* material = nullptr; mjsMaterial* material = nullptr;
if (caches.parsed_materials.find(material_path) != if (auto iter = caches.parsed_materials.find(material_path);
caches.parsed_materials.end()) { iter != caches.parsed_materials.end()) {
material = caches.parsed_materials[material_path]; material = iter->second;
} else { } else {
material = ParseMaterial(spec, bound_material); material = ParseMaterial(spec, bound_material);
caches.parsed_materials[material_path] = material; // ParseMaterial may return a nullptr if the material is not supported.
if (material) {
caches.parsed_materials[material_path] = material;
}
}
if (material) {
mjs_setString(geom->material, mjs_getName(material->element)->c_str());
} }
mjs_setString(geom->material, mjs_getName(material->element)->c_str());
} }
if (gprim.HasAPI<pxr::MjcPhysicsImageableAPI>()) { if (gprim.HasAPI<pxr::MjcPhysicsImageableAPI>()) {
@@ -1438,6 +1443,21 @@ void ParseUsdPhysicsCollider(mjSpec* spec,
ParseMjcPhysicsMaterialAPI( ParseMjcPhysicsMaterialAPI(
geom, pxr::MjcPhysicsMaterialAPI(bound_material_prim)); geom, pxr::MjcPhysicsMaterialAPI(bound_material_prim));
} }
pxr::SdfPath material_path = bound_material_prim.GetPath();
mjsMaterial* material = nullptr;
if (auto iter = caches.parsed_materials.find(material_path);
iter != caches.parsed_materials.end()) {
material = iter->second;
} else {
material = ParseMaterial(spec, bound_material);
// ParseMaterial may return a nullptr if the material is not supported.
if (material) {
caches.parsed_materials[material_path] = material;
}
}
if (material) {
mjs_setString(geom->material, mjs_getName(material->element)->c_str());
}
} }
// Parse the Mass API after the physics material APIs since the density // Parse the Mass API after the physics material APIs since the density