Disallow repeated nameless assets that use the same file, except for URDFs.
PiperOrigin-RevId: 675114055 Change-Id: I142811ac2d8ef9e12bb8a06d5f3a2fdac02946da
This commit is contained in:
committed by
Copybara-Service
parent
60a1921b34
commit
015bdeb756
+33
-22
@@ -575,6 +575,9 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
|
||||
// mesh
|
||||
else if ((temp = FindSubElem(elem, "mesh"))) {
|
||||
mjsMesh* pmesh = 0;
|
||||
bool newmesh = false;
|
||||
|
||||
// set geom type and read mesh attributes
|
||||
pgeom->type = mjGEOM_MESH;
|
||||
meshfile = ReadAttrStr(temp, "filename", true).value();
|
||||
@@ -591,35 +594,43 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
std::string meshname = mjuu_strippath(meshfile);
|
||||
meshname = mjuu_stripext(meshname);
|
||||
|
||||
// look for existing mesh
|
||||
mjsMesh* mesh = mjs_asMesh(mjs_findElement(spec, mjOBJ_MESH, meshname.c_str()));
|
||||
mjsMesh* pmesh = 0;
|
||||
|
||||
// does not exist: create
|
||||
if (!mesh) {
|
||||
if (meshes.find(meshname) == meshes.end()) {
|
||||
// does not exist: create
|
||||
pmesh = mjs_addMesh(spec, 0);
|
||||
}
|
||||
meshes[meshname].push_back(pmesh);
|
||||
newmesh = true;
|
||||
} else {
|
||||
int i = 0;
|
||||
|
||||
// exists with different scale: append name with '1', create
|
||||
else if (mesh->scale[0]!=meshscale[0] ||
|
||||
mesh->scale[1]!=meshscale[1] ||
|
||||
mesh->scale[2]!=meshscale[2]) {
|
||||
pmesh = mjs_addMesh(spec, 0);
|
||||
meshname = meshname + "1";
|
||||
}
|
||||
// find if it exists with the same scale
|
||||
for (mjsMesh* mesh : meshes[meshname]) {
|
||||
if (mesh->scale[0] == meshscale[0] &&
|
||||
mesh->scale[1] == meshscale[1] &&
|
||||
mesh->scale[2] == meshscale[2]) {
|
||||
pmesh = mesh;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
// point to already existing spec
|
||||
else {
|
||||
pmesh = mesh;
|
||||
// add a new spec making an incremental new name
|
||||
if (i == meshes[meshname].size()) {
|
||||
pmesh = mjs_addMesh(spec, 0);
|
||||
meshes[meshname].push_back(pmesh);
|
||||
meshname = meshname + std::to_string(i);
|
||||
newmesh = true;
|
||||
}
|
||||
}
|
||||
|
||||
// set fields
|
||||
mjs_setString(pmesh->file, meshfile.c_str());
|
||||
mjs_setString(pmesh->name, meshname.c_str());
|
||||
if (newmesh) {
|
||||
mjs_setString(pmesh->file, meshfile.c_str());
|
||||
mjs_setString(pmesh->name, meshname.c_str());
|
||||
pmesh->scale[0] = meshscale[0];
|
||||
pmesh->scale[1] = meshscale[1];
|
||||
pmesh->scale[2] = meshscale[2];
|
||||
}
|
||||
mjs_setString(pgeom->meshname, meshname.c_str());
|
||||
pmesh->scale[0] = meshscale[0];
|
||||
pmesh->scale[1] = meshscale[1];
|
||||
pmesh->scale[2] = meshscale[2];
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#ifndef THIRD_PARTY_MUJOCO_SRC_XML_XML_URDF_
|
||||
#define THIRD_PARTY_MUJOCO_SRC_XML_XML_URDF_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -66,6 +67,7 @@ class mjXURDF : public mjXBase {
|
||||
std::vector<std::string> urMat; // material name
|
||||
std::vector<mjRGBA> urRGBA; // material RBG value
|
||||
std::unordered_set<std::string> urGeomNames; // geom name
|
||||
std::map<std::string, std::vector<mjsMesh*>> meshes; // map from name to mjsMesh
|
||||
|
||||
std::string urPrefix; // prefix to apply to all names
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user