Add compiler settings to mjmModel.

PiperOrigin-RevId: 608908314
Change-Id: Id3b0d8c62ca710b5b6d6e423abbbddcb7e7079a1
This commit is contained in:
Alessio Quaglino
2024-02-21 01:57:19 -08:00
committed by Copybara-Service
parent abf6d41b7f
commit 042760eba8
12 changed files with 130 additions and 91 deletions
+3 -3
View File
@@ -376,9 +376,9 @@ mjCModel* mjParseXML(const char* filename, const mjVFS* vfs,
// set reasonable default for parsing a URDF
// this is separate from the Parser to allow multiple URDFs to be loaded.
model->strippath = true;
model->fusestatic = true;
model->discardvisual = true;
model->spec.strippath = true;
model->spec.fusestatic = true;
model->spec.discardvisual = true;
parser.SetModel(model);
parser.Parse(root);
+11 -6
View File
@@ -818,7 +818,7 @@ void mjXReader::Parse(XMLElement* root) {
for (XMLElement* section = FirstChildElement(root, "compiler"); section;
section = NextSiblingElement(section, "compiler")) {
Compiler(section, model);
Compiler(section, &model->spec);
}
for (XMLElement* section = FirstChildElement(root, "option"); section;
@@ -909,7 +909,7 @@ void mjXReader::Parse(XMLElement* root) {
// compiler section parser
void mjXReader::Compiler(XMLElement* section, mjCModel* mod) {
void mjXReader::Compiler(XMLElement* section, mjmModel* mod) {
string text;
int n;
@@ -945,12 +945,17 @@ void mjXReader::Compiler(XMLElement* section, mjCModel* mod) {
memcpy(mod->euler, text.c_str(), 3);
}
if (ReadAttrTxt(section, "assetdir", text)) {
mod->meshdir = text;
mod->texturedir = text;
mjm_setString(mod->meshdir, text.c_str());
mjm_setString(mod->texturedir, text.c_str());
}
// meshdir and texturedir take precedence over assetdir
ReadAttrTxt(section, "meshdir", mod->meshdir);
ReadAttrTxt(section, "texturedir", mod->texturedir);
std::string meshdir, texturedir;
if (ReadAttrTxt(section, "meshdir", meshdir)) {
mjm_setString(mod->meshdir, meshdir.c_str());
};
if (ReadAttrTxt(section, "texturedir", texturedir)) {
mjm_setString(mod->texturedir, texturedir.c_str());
}
if (MapValue(section, "discardvisual", &n, bool_map, 2)) {
mod->discardvisual = (n==1);
}
+1 -1
View File
@@ -43,7 +43,7 @@ class mjXReader : public mjXBase {
void SetTextureDir(std::string texturedir);
// XML sections embedded in all formats
static void Compiler(tinyxml2::XMLElement* section, mjCModel* mod); // compiler section
static void Compiler(tinyxml2::XMLElement* section, mjmModel* mod); // compiler section
static void Option(tinyxml2::XMLElement* section, mjOption* opt); // option section
static void Size(tinyxml2::XMLElement* section, mjCModel* mod); // size section
+4 -4
View File
@@ -821,11 +821,11 @@ void mjXWriter::Compiler(XMLElement* root) {
WriteAttrTxt(section, "convexhull", FindValue(bool_map, 2, model->convexhull));
}
WriteAttrTxt(section, "angle", "radian");
if (!model->meshdir.empty()) {
WriteAttrTxt(section, "meshdir", model->meshdir);
if (!model->get_meshdir().empty()) {
WriteAttrTxt(section, "meshdir", model->get_meshdir());
}
if (!model->texturedir.empty()) {
WriteAttrTxt(section, "texturedir", model->texturedir);
if (!model->get_texturedir().empty()) {
WriteAttrTxt(section, "texturedir", model->get_texturedir());
}
if (!model->usethread) {
WriteAttrTxt(section, "usethread", "false");
+4 -4
View File
@@ -93,7 +93,7 @@ void mjXURDF::Parse(
if (mjc) {
XMLElement *section;
if ((section = FindSubElem(mjc, "compiler"))) {
mjXReader::Compiler(section, model);
mjXReader::Compiler(section, &model->spec);
}
if ((section = FindSubElem(mjc, "option"))) {
@@ -106,7 +106,7 @@ void mjXURDF::Parse(
}
// enforce required compiler defaults for URDF
model->degree = false;
model->spec.degree = false;
// get model name
ReadAttrTxt(root, "name", model->modelname);
@@ -310,7 +310,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
}
}
// create geom if not discarded
if (!model->discardvisual) {
if (!model->spec.discardvisual) {
pgeom = Geom(elem, pbody, false);
// save color
@@ -563,7 +563,7 @@ mjmGeom* mjXURDF::Geom(XMLElement* geom_elem, mjmBody* pbody, bool collision) {
.value_or(default_meshscale);
// strip file name if necessary
if (model->strippath) {
if (model->spec.strippath) {
meshfile = mjuu_strippath(meshfile);
}