Add ability to specify a material assignment to a mesh asset.
This extends both the spec and the XML definition to allow specification of a material name on a mesh. This material acts as a fallback in the case that the referencing geom element does not specify a material of it's own. PiperOrigin-RevId: 798232378 Change-Id: Iaf300c727732744ea1b613e64334ee505ac6e209
This commit is contained in:
committed by
Copybara-Service
parent
42d8454555
commit
1fb1810b07
+17
-15
@@ -1879,7 +1879,23 @@ void mjCModel::IndexAssets(bool discard) {
|
||||
for (int i=0; i < geoms_.size(); i++) {
|
||||
mjCGeom* geom = geoms_[i];
|
||||
|
||||
// find material by name
|
||||
|
||||
// find mesh by name
|
||||
if (!geom->get_meshname().empty()) {
|
||||
mjCMesh* mesh = static_cast<mjCMesh*>(FindObject(mjOBJ_MESH, geom->get_meshname()));
|
||||
if (mesh) {
|
||||
if (!geom->visual_) {
|
||||
mesh->SetNotVisual(); // reset to true by mesh->Compile()
|
||||
}
|
||||
geom->mesh = (discard && geom->visual_) ? nullptr : mesh;
|
||||
mesh->spec.needsdf |= geom->spec.type == mjGEOM_SDF;
|
||||
} else {
|
||||
throw mjCError(geom, "mesh '%s' not found in geom %d", geom->get_meshname().c_str(), i);
|
||||
}
|
||||
}
|
||||
|
||||
// find material by name, this has to happen after mesh assignment so that if
|
||||
// the geom does not specify a material but the mesh does it can fall back.
|
||||
if (!geom->get_material().empty()) {
|
||||
mjCBase* material = FindObject(mjOBJ_MATERIAL, geom->get_material());
|
||||
if (material) {
|
||||
@@ -1889,20 +1905,6 @@ void mjCModel::IndexAssets(bool discard) {
|
||||
}
|
||||
}
|
||||
|
||||
// find mesh by name
|
||||
if (!geom->get_meshname().empty()) {
|
||||
mjCBase* mesh = FindObject(mjOBJ_MESH, geom->get_meshname());
|
||||
if (mesh) {
|
||||
if (!geom->visual_) {
|
||||
((mjCMesh*)mesh)->SetNotVisual(); // reset to true by mesh->Compile()
|
||||
}
|
||||
geom->mesh = (discard && geom->visual_) ? nullptr : (mjCMesh*)mesh;
|
||||
static_cast<mjCMesh*>(mesh)->spec.needsdf |= geom->spec.type == mjGEOM_SDF;
|
||||
} else {
|
||||
throw mjCError(geom, "mesh '%s' not found in geom %d", geom->get_meshname().c_str(), i);
|
||||
}
|
||||
}
|
||||
|
||||
// find hfield by name
|
||||
if (!geom->get_hfieldname().empty()) {
|
||||
mjCBase* hfield = FindObject(mjOBJ_HFIELD, geom->get_hfieldname());
|
||||
|
||||
Reference in New Issue
Block a user