Rename model to spec in xml_native_reader.cc.
PiperOrigin-RevId: 651780148 Change-Id: I476c79af4b47bf763f1f3cb166d3f0897554a207
This commit is contained in:
committed by
Copybara-Service
parent
a0df72f43f
commit
e76f3ce1e3
+2
-2
@@ -37,14 +37,14 @@ using tinyxml2::XMLElement;
|
|||||||
|
|
||||||
// base constructor
|
// base constructor
|
||||||
mjXBase::mjXBase() {
|
mjXBase::mjXBase() {
|
||||||
model = NULL;
|
spec = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// set model field
|
// set model field
|
||||||
void mjXBase::SetModel(const mjSpec* _model) {
|
void mjXBase::SetModel(const mjSpec* _model) {
|
||||||
model = (mjSpec*)_model;
|
spec = (mjSpec*)_model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ class mjXBase : public mjXUtil {
|
|||||||
static int ReadAlternative(tinyxml2::XMLElement* elem, mjsOrientation& alt);
|
static int ReadAlternative(tinyxml2::XMLElement* elem, mjsOrientation& alt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mjSpec* model; // internally-allocated model
|
mjSpec* spec; // internally-allocated model
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MUJOCO_SRC_XML_XML_BASE_H_
|
#endif // MUJOCO_SRC_XML_XML_BASE_H_
|
||||||
|
|||||||
@@ -826,31 +826,31 @@ void mjXReader::Parse(XMLElement* root, const mjVFS* vfs) {
|
|||||||
// get model name
|
// get model name
|
||||||
string modelname;
|
string modelname;
|
||||||
if (ReadAttrTxt(root, "model", modelname)) {
|
if (ReadAttrTxt(root, "model", modelname)) {
|
||||||
mjs_setString(model->modelname, modelname.c_str());
|
mjs_setString(spec->modelname, modelname.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// get comment
|
// get comment
|
||||||
if (root->FirstChild() && root->FirstChild()->ToComment()) {
|
if (root->FirstChild() && root->FirstChild()->ToComment()) {
|
||||||
mjs_setString(model->comment, root->FirstChild()->Value());
|
mjs_setString(spec->comment, root->FirstChild()->Value());
|
||||||
} else {
|
} else {
|
||||||
mjs_setString(model->comment, "");
|
mjs_setString(spec->comment, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------- parse MuJoCo sections embedded in all XML formats
|
//------------------- parse MuJoCo sections embedded in all XML formats
|
||||||
|
|
||||||
for (XMLElement* section = FirstChildElement(root, "compiler"); section;
|
for (XMLElement* section = FirstChildElement(root, "compiler"); section;
|
||||||
section = NextSiblingElement(section, "compiler")) {
|
section = NextSiblingElement(section, "compiler")) {
|
||||||
Compiler(section, model);
|
Compiler(section, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XMLElement* section = FirstChildElement(root, "option"); section;
|
for (XMLElement* section = FirstChildElement(root, "option"); section;
|
||||||
section = NextSiblingElement(section, "option")) {
|
section = NextSiblingElement(section, "option")) {
|
||||||
Option(section, &model->option);
|
Option(section, &spec->option);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (XMLElement* section = FirstChildElement(root, "size"); section;
|
for (XMLElement* section = FirstChildElement(root, "size"); section;
|
||||||
section = NextSiblingElement(section, "size")) {
|
section = NextSiblingElement(section, "size")) {
|
||||||
Size(section, model);
|
Size(section, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------ parse MJCF-specific sections
|
//------------------ parse MJCF-specific sections
|
||||||
@@ -924,7 +924,7 @@ void mjXReader::Parse(XMLElement* root, const mjVFS* vfs) {
|
|||||||
|
|
||||||
for (XMLElement* section = FirstChildElement(root, "worldbody"); section;
|
for (XMLElement* section = FirstChildElement(root, "worldbody"); section;
|
||||||
section = NextSiblingElement(section, "worldbody")) {
|
section = NextSiblingElement(section, "worldbody")) {
|
||||||
Body(section, mjs_findBody(model, "world"), nullptr);
|
Body(section, mjs_findBody(spec, "world"), nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1278,14 +1278,14 @@ void mjXReader::Statistic(XMLElement* section) {
|
|||||||
string text;
|
string text;
|
||||||
|
|
||||||
// read statistics
|
// read statistics
|
||||||
ReadAttr(section, "meaninertia", 1, &model->stat.meaninertia, text);
|
ReadAttr(section, "meaninertia", 1, &spec->stat.meaninertia, text);
|
||||||
ReadAttr(section, "meanmass", 1, &model->stat.meanmass, text);
|
ReadAttr(section, "meanmass", 1, &spec->stat.meanmass, text);
|
||||||
ReadAttr(section, "meansize", 1, &model->stat.meansize, text);
|
ReadAttr(section, "meansize", 1, &spec->stat.meansize, text);
|
||||||
ReadAttr(section, "extent", 1, &model->stat.extent, text);
|
ReadAttr(section, "extent", 1, &spec->stat.extent, text);
|
||||||
if (mjuu_defined(model->stat.extent) && model->stat.extent<=0) {
|
if (mjuu_defined(spec->stat.extent) && spec->stat.extent<=0) {
|
||||||
throw mjXError(section, "extent must be strictly positive");
|
throw mjXError(section, "extent must be strictly positive");
|
||||||
}
|
}
|
||||||
ReadAttr(section, "center", 3, model->stat.center, text);
|
ReadAttr(section, "center", 3, spec->stat.center, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1370,10 +1370,10 @@ void mjXReader::OneMesh(XMLElement* elem, mjsMesh* pmesh) {
|
|||||||
|
|
||||||
// read attributes
|
// read attributes
|
||||||
if (ReadAttrTxt(elem, "name", name)) {
|
if (ReadAttrTxt(elem, "name", name)) {
|
||||||
mjs_setString(pmesh->name, name.c_str());
|
*pmesh->name = name;
|
||||||
}
|
}
|
||||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||||
mjs_setString(pmesh->content_type, content_type.c_str());
|
*pmesh->content_type = content_type;
|
||||||
}
|
}
|
||||||
auto file = ReadAttrFile(elem, "file", MeshDir());
|
auto file = ReadAttrFile(elem, "file", MeshDir());
|
||||||
if (file) {
|
if (file) {
|
||||||
@@ -2480,7 +2480,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjsBody* pbody, mjsDefault* def)
|
|||||||
|
|
||||||
// make composite
|
// make composite
|
||||||
char error[200];
|
char error[200];
|
||||||
bool res = comp.Make(model, pbody, error, 200);
|
bool res = comp.Make(spec, pbody, error, 200);
|
||||||
|
|
||||||
// throw error
|
// throw error
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@@ -2606,7 +2606,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* pbody) {
|
|||||||
|
|
||||||
// make flexcomp
|
// make flexcomp
|
||||||
char error[200];
|
char error[200];
|
||||||
bool res = fcomp.Make(model, pbody, error, 200);
|
bool res = fcomp.Make(spec, pbody, error, 200);
|
||||||
|
|
||||||
// throw error
|
// throw error
|
||||||
if (!res) {
|
if (!res) {
|
||||||
@@ -2626,10 +2626,10 @@ void mjXReader::OnePlugin(XMLElement* elem, mjsPlugin* plugin) {
|
|||||||
mjs_setString(plugin->name, name.c_str());
|
mjs_setString(plugin->name, name.c_str());
|
||||||
mjs_setString(plugin->instance_name, instance_name.c_str());
|
mjs_setString(plugin->instance_name, instance_name.c_str());
|
||||||
if (instance_name.empty()) {
|
if (instance_name.empty()) {
|
||||||
plugin->instance = mjs_addPlugin(model)->instance;
|
plugin->instance = mjs_addPlugin(spec)->instance;
|
||||||
ReadPluginConfigs(elem, plugin);
|
ReadPluginConfigs(elem, plugin);
|
||||||
} else {
|
} else {
|
||||||
model->hasImplicitPluginElem = true;
|
spec->hasImplicitPluginElem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2651,12 +2651,12 @@ void mjXReader::Default(XMLElement* section, const mjsDefault* def) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (def) {
|
if (def) {
|
||||||
def = mjs_addDefault(model, text.c_str(), def);
|
def = mjs_addDefault(spec, text.c_str(), def);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
throw mjXError(section, "repeated default class name");
|
throw mjXError(section, "repeated default class name");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
if (!text.empty() && text != "main") {
|
if (!text.empty() && text != "main") {
|
||||||
throw mjXError(section, "top-level default class 'main' cannot be renamed");
|
throw mjXError(section, "top-level default class 'main' cannot be renamed");
|
||||||
}
|
}
|
||||||
@@ -2765,12 +2765,12 @@ void mjXReader::Extension(XMLElement* section) {
|
|||||||
XMLElement* child = FirstChildElement(elem);
|
XMLElement* child = FirstChildElement(elem);
|
||||||
while (child) {
|
while (child) {
|
||||||
if (std::string(child->Value())=="instance") {
|
if (std::string(child->Value())=="instance") {
|
||||||
if (model->hasImplicitPluginElem) {
|
if (spec->hasImplicitPluginElem) {
|
||||||
throw mjXError(
|
throw mjXError(
|
||||||
child, "explicit plugin instance must appear before implicit plugin elements");
|
child, "explicit plugin instance must appear before implicit plugin elements");
|
||||||
}
|
}
|
||||||
string name;
|
string name;
|
||||||
mjsPlugin* p = mjs_addPlugin(model);
|
mjsPlugin* p = mjs_addPlugin(spec);
|
||||||
mjs_setString(p->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(p->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
ReadAttrTxt(child, "name", name, /* required = */ true);
|
ReadAttrTxt(child, "name", name, /* required = */ true);
|
||||||
mjs_setString(p->name, name.c_str());
|
mjs_setString(p->name, name.c_str());
|
||||||
@@ -2788,7 +2788,7 @@ void mjXReader::Extension(XMLElement* section) {
|
|||||||
elem = NextSiblingElement(elem);
|
elem = NextSiblingElement(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
mjs_setActivePlugins(model, &active_plugins);
|
mjs_setActivePlugins(spec, &active_plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2809,7 +2809,7 @@ void mjXReader::Custom(XMLElement* section) {
|
|||||||
// numeric
|
// numeric
|
||||||
if (name=="numeric") {
|
if (name=="numeric") {
|
||||||
// create custom
|
// create custom
|
||||||
mjsNumeric* pnum = mjs_addNumeric(model);
|
mjsNumeric* pnum = mjs_addNumeric(spec);
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
mjs_setString(pnum->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(pnum->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
@@ -2840,7 +2840,7 @@ void mjXReader::Custom(XMLElement* section) {
|
|||||||
// text
|
// text
|
||||||
else if (name=="text") {
|
else if (name=="text") {
|
||||||
// create custom
|
// create custom
|
||||||
mjsText* pte = mjs_addText(model);
|
mjsText* pte = mjs_addText(spec);
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
mjs_setString(pte->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(pte->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
@@ -2860,7 +2860,7 @@ void mjXReader::Custom(XMLElement* section) {
|
|||||||
// tuple
|
// tuple
|
||||||
else if (name=="tuple") {
|
else if (name=="tuple") {
|
||||||
// create custom
|
// create custom
|
||||||
mjsTuple* ptu = mjs_addTuple(model);
|
mjsTuple* ptu = mjs_addTuple(spec);
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
mjs_setString(ptu->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(ptu->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
@@ -2919,7 +2919,7 @@ void mjXReader::Custom(XMLElement* section) {
|
|||||||
void mjXReader::Visual(XMLElement* section) {
|
void mjXReader::Visual(XMLElement* section) {
|
||||||
string text, name;
|
string text, name;
|
||||||
XMLElement* elem;
|
XMLElement* elem;
|
||||||
mjVisual* vis = &model->visual;
|
mjVisual* vis = &spec->visual;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
// iterate over child elements
|
// iterate over child elements
|
||||||
@@ -3063,13 +3063,13 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// texture sub-element
|
// texture sub-element
|
||||||
if (name=="texture") {
|
if (name=="texture") {
|
||||||
// create texture
|
// create texture
|
||||||
mjsTexture* ptex = mjs_addTexture(model);
|
mjsTexture* ptex = mjs_addTexture(spec);
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
mjs_setString(ptex->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(ptex->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
@@ -3137,28 +3137,28 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
|||||||
// material sub-element
|
// material sub-element
|
||||||
else if (name=="material") {
|
else if (name=="material") {
|
||||||
// create material and parse
|
// create material and parse
|
||||||
mjsMaterial* pmat = mjs_addMaterial(model, def);
|
mjsMaterial* pmat = mjs_addMaterial(spec, def);
|
||||||
OneMaterial(elem, pmat);
|
OneMaterial(elem, pmat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mesh sub-element
|
// mesh sub-element
|
||||||
else if (name=="mesh") {
|
else if (name=="mesh") {
|
||||||
// create mesh and parse
|
// create mesh and parse
|
||||||
mjsMesh* pmesh = mjs_addMesh(model, def);
|
mjsMesh* pmesh = mjs_addMesh(spec, def);
|
||||||
OneMesh(elem, pmesh);
|
OneMesh(elem, pmesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// skin sub-element... deprecate ???
|
// skin sub-element... deprecate ???
|
||||||
else if (name=="skin") {
|
else if (name=="skin") {
|
||||||
// create skin and parse
|
// create skin and parse
|
||||||
mjsSkin* pskin = mjs_addSkin(model);
|
mjsSkin* pskin = mjs_addSkin(spec);
|
||||||
OneSkin(elem, pskin);
|
OneSkin(elem, pskin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hfield sub-element
|
// hfield sub-element
|
||||||
else if (name=="hfield") {
|
else if (name=="hfield") {
|
||||||
// create hfield
|
// create hfield
|
||||||
mjsHField* phf = mjs_addHField(model);
|
mjsHField* phf = mjs_addHField(spec);
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
mjs_setString(phf->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(phf->info, ("line " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
@@ -3231,7 +3231,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// store child spec in model
|
// store child spec in model
|
||||||
mjs_addSpec(model, child);
|
mjs_addSpec(spec, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance to next element
|
// advance to next element
|
||||||
@@ -3376,8 +3376,8 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
// read childdef
|
// read childdef
|
||||||
mjsDefault* childdef = 0;
|
mjsDefault* childdef = 0;
|
||||||
if (ReadAttrTxt(elem, "childclass", text)) {
|
if (ReadAttrTxt(elem, "childclass", text)) {
|
||||||
childdef = mjs_findDefault(model, text.c_str());
|
childdef = mjs_findDefault(spec, text.c_str());
|
||||||
mjs_findDefault(model, text.c_str());
|
mjs_findDefault(spec, text.c_str());
|
||||||
if (!childdef) {
|
if (!childdef) {
|
||||||
throw mjXError(elem, "unknown default childclass");
|
throw mjXError(elem, "unknown default childclass");
|
||||||
}
|
}
|
||||||
@@ -3420,13 +3420,13 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
alt.type = mjORIENTATION_EULER;
|
alt.type = mjORIENTATION_EULER;
|
||||||
mjuu_copyvec(alt.euler, euler, 3);
|
mjuu_copyvec(alt.euler, euler, 3);
|
||||||
double rotation[4] = {1, 0, 0, 0};
|
double rotation[4] = {1, 0, 0, 0};
|
||||||
mjs_resolveOrientation(rotation, model->degree, model->eulerseq, &alt);
|
mjs_resolveOrientation(rotation, spec->degree, spec->eulerseq, &alt);
|
||||||
|
|
||||||
// read childdef
|
// read childdef
|
||||||
mjsDefault* childdef = 0;
|
mjsDefault* childdef = 0;
|
||||||
if (ReadAttrTxt(elem, "childclass", text)) {
|
if (ReadAttrTxt(elem, "childclass", text)) {
|
||||||
childdef = mjs_findDefault(model, text.c_str());
|
childdef = mjs_findDefault(spec, text.c_str());
|
||||||
mjs_findDefault(model, text.c_str());
|
mjs_findDefault(spec, text.c_str());
|
||||||
if (!childdef) {
|
if (!childdef) {
|
||||||
throw mjXError(elem, "unknown default childclass");
|
throw mjXError(elem, "unknown default childclass");
|
||||||
}
|
}
|
||||||
@@ -3451,7 +3451,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
alt.euler[0] = i*euler[0];
|
alt.euler[0] = i*euler[0];
|
||||||
alt.euler[1] = i*euler[1];
|
alt.euler[1] = i*euler[1];
|
||||||
alt.euler[2] = i*euler[2];
|
alt.euler[2] = i*euler[2];
|
||||||
mjs_resolveOrientation(quat, model->degree, model->eulerseq, &alt);
|
mjs_resolveOrientation(quat, spec->degree, spec->eulerseq, &alt);
|
||||||
mjuu_setvec(pframe->quat, quat[0], quat[1], quat[2], quat[3]);
|
mjuu_setvec(pframe->quat, quat[0], quat[1], quat[2], quat[3]);
|
||||||
|
|
||||||
// process suffix
|
// process suffix
|
||||||
@@ -3463,12 +3463,12 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
|
|
||||||
// attach to parent
|
// attach to parent
|
||||||
if (mjs_attachFrame(pbody, pframe, /*prefix=*/"", suffix.c_str()) != 0) {
|
if (mjs_attachFrame(pbody, pframe, /*prefix=*/"", suffix.c_str()) != 0) {
|
||||||
throw mjXError(elem, mjs_getError(model));
|
throw mjXError(elem, mjs_getError(spec));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete subtree
|
// delete subtree
|
||||||
mjs_detachBody(model, subtree);
|
mjs_detachBody(spec, subtree);
|
||||||
}
|
}
|
||||||
|
|
||||||
// body sub-element
|
// body sub-element
|
||||||
@@ -3476,8 +3476,8 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
// read childdef
|
// read childdef
|
||||||
mjsDefault* childdef = 0;
|
mjsDefault* childdef = 0;
|
||||||
if (ReadAttrTxt(elem, "childclass", text)) {
|
if (ReadAttrTxt(elem, "childclass", text)) {
|
||||||
childdef = mjs_findDefault(model, text.c_str());
|
childdef = mjs_findDefault(spec, text.c_str());
|
||||||
mjs_findDefault(model, text.c_str());
|
mjs_findDefault(spec, text.c_str());
|
||||||
if (!childdef) {
|
if (!childdef) {
|
||||||
throw mjXError(elem, "unknown default childclass");
|
throw mjXError(elem, "unknown default childclass");
|
||||||
}
|
}
|
||||||
@@ -3528,11 +3528,11 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
ReadAttrTxt(elem, "body", body_name);
|
ReadAttrTxt(elem, "body", body_name);
|
||||||
ReadAttrTxt(elem, "prefix", prefix);
|
ReadAttrTxt(elem, "prefix", prefix);
|
||||||
|
|
||||||
mjsBody* child = mjs_findBody(model, (prefix+body_name).c_str());
|
mjsBody* child = mjs_findBody(spec, (prefix+body_name).c_str());
|
||||||
mjsFrame* pframe = frame ? frame : mjs_addFrame(pbody, nullptr);
|
mjsFrame* pframe = frame ? frame : mjs_addFrame(pbody, nullptr);
|
||||||
|
|
||||||
if (!child) {
|
if (!child) {
|
||||||
mjSpec* asset = mjs_findSpec(model, model_name.c_str());
|
mjSpec* asset = mjs_findSpec(spec, model_name.c_str());
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
throw mjXError(0, "could not find model '%s'", model_name.c_str());
|
throw mjXError(0, "could not find model '%s'", model_name.c_str());
|
||||||
}
|
}
|
||||||
@@ -3542,7 +3542,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) {
|
|||||||
}
|
}
|
||||||
if (mjs_attachBody(pframe, child, prefix.c_str(), "") != 0) {
|
if (mjs_attachBody(pframe, child, prefix.c_str(), "") != 0) {
|
||||||
mj_deleteSpec(asset);
|
mj_deleteSpec(asset);
|
||||||
throw mjXError(elem, mjs_getError(model));
|
throw mjXError(elem, mjs_getError(spec));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// only set frame to existing body
|
// only set frame to existing body
|
||||||
@@ -3576,19 +3576,19 @@ void mjXReader::Contact(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// geom pair to include
|
// geom pair to include
|
||||||
if (name=="pair") {
|
if (name=="pair") {
|
||||||
// create pair and parse
|
// create pair and parse
|
||||||
mjsPair* ppair = mjs_addPair(model, def);
|
mjsPair* ppair = mjs_addPair(spec, def);
|
||||||
OnePair(elem, ppair);
|
OnePair(elem, ppair);
|
||||||
}
|
}
|
||||||
|
|
||||||
// body pair to exclude
|
// body pair to exclude
|
||||||
else if (name=="exclude") {
|
else if (name=="exclude") {
|
||||||
mjsExclude* pexclude = mjs_addExclude(model);
|
mjsExclude* pexclude = mjs_addExclude(spec);
|
||||||
string exname, exbody1, exbody2;
|
string exname, exbody1, exbody2;
|
||||||
|
|
||||||
// write error info
|
// write error info
|
||||||
@@ -3621,11 +3621,11 @@ void mjXReader::Equality(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create equality constraint and parse
|
// create equality constraint and parse
|
||||||
mjsEquality* pequality = mjs_addEquality(model, def);
|
mjsEquality* pequality = mjs_addEquality(spec, def);
|
||||||
OneEquality(elem, pequality);
|
OneEquality(elem, pequality);
|
||||||
|
|
||||||
// advance to next element
|
// advance to next element
|
||||||
@@ -3649,20 +3649,20 @@ void mjXReader::Deformable(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// flex sub-element
|
// flex sub-element
|
||||||
if (name=="flex") {
|
if (name=="flex") {
|
||||||
// create flex and parse
|
// create flex and parse
|
||||||
mjsFlex* pflex = mjs_addFlex(model);
|
mjsFlex* pflex = mjs_addFlex(spec);
|
||||||
OneFlex(elem, pflex);
|
OneFlex(elem, pflex);
|
||||||
}
|
}
|
||||||
|
|
||||||
// skin sub-element
|
// skin sub-element
|
||||||
else if (name=="skin") {
|
else if (name=="skin") {
|
||||||
// create skin and parse
|
// create skin and parse
|
||||||
mjsSkin* pskin = mjs_addSkin(model);
|
mjsSkin* pskin = mjs_addSkin(spec);
|
||||||
OneSkin(elem, pskin);
|
OneSkin(elem, pskin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3685,11 +3685,11 @@ void mjXReader::Tendon(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create equality constraint and parse
|
// create equality constraint and parse
|
||||||
mjsTendon* pten = mjs_addTendon(model, def);
|
mjsTendon* pten = mjs_addTendon(spec, def);
|
||||||
OneTendon(elem, pten);
|
OneTendon(elem, pten);
|
||||||
|
|
||||||
// process wrap sub-elements
|
// process wrap sub-elements
|
||||||
@@ -3751,11 +3751,11 @@ void mjXReader::Actuator(XMLElement* section) {
|
|||||||
// get class if specified, otherwise use default0
|
// get class if specified, otherwise use default0
|
||||||
mjsDefault* def = GetClass(elem);
|
mjsDefault* def = GetClass(elem);
|
||||||
if (!def) {
|
if (!def) {
|
||||||
def = mjs_getSpecDefault(model);
|
def = mjs_getSpecDefault(spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create actuator and parse
|
// create actuator and parse
|
||||||
mjsActuator* pact = mjs_addActuator(model, def);
|
mjsActuator* pact = mjs_addActuator(spec, def);
|
||||||
OneActuator(elem, pact);
|
OneActuator(elem, pact);
|
||||||
|
|
||||||
// advance to next element
|
// advance to next element
|
||||||
@@ -3771,7 +3771,7 @@ void mjXReader::Sensor(XMLElement* section) {
|
|||||||
XMLElement* elem = FirstChildElement(section);
|
XMLElement* elem = FirstChildElement(section);
|
||||||
while (elem) {
|
while (elem) {
|
||||||
// create sensor, get string type
|
// create sensor, get string type
|
||||||
mjsSensor* psen = mjs_addSensor(model);
|
mjsSensor* psen = mjs_addSensor(spec);
|
||||||
string type = elem->Value();
|
string type = elem->Value();
|
||||||
string text, name, objname, refname;
|
string text, name, objname, refname;
|
||||||
std::vector<double> userdata;
|
std::vector<double> userdata;
|
||||||
@@ -4111,7 +4111,7 @@ void mjXReader::Keyframe(XMLElement* section) {
|
|||||||
string text, name = "";
|
string text, name = "";
|
||||||
|
|
||||||
// add keyframe
|
// add keyframe
|
||||||
mjsKey* pk = mjs_addKey(model);
|
mjsKey* pk = mjs_addKey(spec);
|
||||||
|
|
||||||
// read name, time
|
// read name, time
|
||||||
ReadAttrTxt(elem, "name", name);
|
ReadAttrTxt(elem, "name", name);
|
||||||
@@ -4167,7 +4167,7 @@ mjsDefault* mjXReader::GetClass(XMLElement* section) {
|
|||||||
mjsDefault* def = nullptr;
|
mjsDefault* def = nullptr;
|
||||||
|
|
||||||
if (ReadAttrTxt(section, "class", text)) {
|
if (ReadAttrTxt(section, "class", text)) {
|
||||||
def = mjs_findDefault(model, text.c_str());
|
def = mjs_findDefault(spec, text.c_str());
|
||||||
if (!def) {
|
if (!def) {
|
||||||
throw mjXError(
|
throw mjXError(
|
||||||
section,
|
section,
|
||||||
|
|||||||
+17
-17
@@ -62,7 +62,7 @@ mjXURDF::~mjXURDF() {
|
|||||||
|
|
||||||
// clear internal variables
|
// clear internal variables
|
||||||
void mjXURDF::Clear(void) {
|
void mjXURDF::Clear(void) {
|
||||||
model = 0;
|
spec = 0;
|
||||||
|
|
||||||
urName.clear();
|
urName.clear();
|
||||||
urParent.clear();
|
urParent.clear();
|
||||||
@@ -96,25 +96,25 @@ void mjXURDF::Parse(
|
|||||||
if (mjc) {
|
if (mjc) {
|
||||||
XMLElement *section;
|
XMLElement *section;
|
||||||
if ((section = FindSubElem(mjc, "compiler"))) {
|
if ((section = FindSubElem(mjc, "compiler"))) {
|
||||||
mjXReader::Compiler(section, model);
|
mjXReader::Compiler(section, spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((section = FindSubElem(mjc, "option"))) {
|
if ((section = FindSubElem(mjc, "option"))) {
|
||||||
mjXReader::Option(section, &model->option);
|
mjXReader::Option(section, &spec->option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((section = FindSubElem(mjc, "size"))) {
|
if ((section = FindSubElem(mjc, "size"))) {
|
||||||
mjXReader::Size(section, model);
|
mjXReader::Size(section, spec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// enforce required compiler defaults for URDF
|
// enforce required compiler defaults for URDF
|
||||||
model->degree = false;
|
spec->degree = false;
|
||||||
|
|
||||||
// get model name
|
// get model name
|
||||||
std::string modelname;
|
std::string modelname;
|
||||||
if (ReadAttrTxt(root, "name", modelname)) {
|
if (ReadAttrTxt(root, "name", modelname)) {
|
||||||
mjs_setString(model->modelname, modelname.c_str());
|
mjs_setString(spec->modelname, modelname.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// find and register all materials
|
// find and register all materials
|
||||||
@@ -208,7 +208,7 @@ void mjXURDF::Parse(
|
|||||||
// override the pose for the base link and add a free joint
|
// override the pose for the base link and add a free joint
|
||||||
for (int i = 0; i < (int)urName.size(); i++) {
|
for (int i = 0; i < (int)urName.size(); i++) {
|
||||||
if (urParent[i] < 0) {
|
if (urParent[i] < 0) {
|
||||||
mjsBody* world = mjs_findBody(model, "world");
|
mjsBody* world = mjs_findBody(spec, "world");
|
||||||
mjsBody* pbody = mjs_findChild(world, urName[i].c_str());
|
mjsBody* pbody = mjs_findChild(world, urName[i].c_str());
|
||||||
mjuu_copyvec(pbody->pos, pos, 3);
|
mjuu_copyvec(pbody->pos, pos, 3);
|
||||||
mjuu_copyvec(pbody->quat, quat, 4);
|
mjuu_copyvec(pbody->quat, quat, 4);
|
||||||
@@ -234,7 +234,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
|||||||
// get body name and pointer to mjsBody
|
// get body name and pointer to mjsBody
|
||||||
ReadAttrTxt(body_elem, "name", name, true);
|
ReadAttrTxt(body_elem, "name", name, true);
|
||||||
name = GetPrefixedName(name);
|
name = GetPrefixedName(name);
|
||||||
world = mjs_findBody(model, "world");
|
world = mjs_findBody(spec, "world");
|
||||||
pbody = mjs_findChild(world, name.c_str());
|
pbody = mjs_findChild(world, name.c_str());
|
||||||
if (!pbody) {
|
if (!pbody) {
|
||||||
throw mjXError(body_elem, "URDF body not found"); // SHOULD NOT OCCUR
|
throw mjXError(body_elem, "URDF body not found"); // SHOULD NOT OCCUR
|
||||||
@@ -316,7 +316,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create geom if not discarded
|
// create geom if not discarded
|
||||||
if (!model->discardvisual) {
|
if (!spec->discardvisual) {
|
||||||
pgeom = Geom(elem, pbody, false);
|
pgeom = Geom(elem, pbody, false);
|
||||||
|
|
||||||
// save color
|
// save color
|
||||||
@@ -392,7 +392,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
|||||||
elem = FindSubElem(joint_elem, "parent", true);
|
elem = FindSubElem(joint_elem, "parent", true);
|
||||||
ReadAttrTxt(elem, "link", name, true);
|
ReadAttrTxt(elem, "link", name, true);
|
||||||
name = GetPrefixedName(name);
|
name = GetPrefixedName(name);
|
||||||
world = mjs_findBody(model, "world");
|
world = mjs_findBody(spec, "world");
|
||||||
parent = mjs_findChild(world, name.c_str());
|
parent = mjs_findChild(world, name.c_str());
|
||||||
if (!parent) { // SHOULD NOT OCCUR
|
if (!parent) { // SHOULD NOT OCCUR
|
||||||
throw mjXError(elem, "invalid parent name in URDF joint definition");
|
throw mjXError(elem, "invalid parent name in URDF joint definition");
|
||||||
@@ -402,7 +402,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
|||||||
elem = FindSubElem(joint_elem, "child", true);
|
elem = FindSubElem(joint_elem, "child", true);
|
||||||
ReadAttrTxt(elem, "link", name, true);
|
ReadAttrTxt(elem, "link", name, true);
|
||||||
name = GetPrefixedName(name);
|
name = GetPrefixedName(name);
|
||||||
world = mjs_findBody(model, "world");
|
world = mjs_findBody(spec, "world");
|
||||||
pbody = mjs_findChild(world, name.c_str());
|
pbody = mjs_findChild(world, name.c_str());
|
||||||
if (!pbody) { // SHOULD NOT OCCUR
|
if (!pbody) { // SHOULD NOT OCCUR
|
||||||
throw mjXError(elem, "invalid child name in URDF joint definition");
|
throw mjXError(elem, "invalid child name in URDF joint definition");
|
||||||
@@ -583,7 +583,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
|||||||
.value_or(default_meshscale);
|
.value_or(default_meshscale);
|
||||||
|
|
||||||
// strip file name if necessary
|
// strip file name if necessary
|
||||||
if (model->strippath) {
|
if (spec->strippath) {
|
||||||
meshfile = mjuu_strippath(meshfile);
|
meshfile = mjuu_strippath(meshfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,19 +592,19 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
|||||||
meshname = mjuu_stripext(meshname);
|
meshname = mjuu_stripext(meshname);
|
||||||
|
|
||||||
// look for existing mesh
|
// look for existing mesh
|
||||||
mjsMesh* mesh = mjs_findMesh(model, meshname.c_str());
|
mjsMesh* mesh = mjs_findMesh(spec, meshname.c_str());
|
||||||
mjsMesh* pmesh = 0;
|
mjsMesh* pmesh = 0;
|
||||||
|
|
||||||
// does not exist: create
|
// does not exist: create
|
||||||
if (!mesh) {
|
if (!mesh) {
|
||||||
pmesh = mjs_addMesh(model, 0);
|
pmesh = mjs_addMesh(spec, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// exists with different scale: append name with '1', create
|
// exists with different scale: append name with '1', create
|
||||||
else if (mesh->scale[0]!=meshscale[0] ||
|
else if (mesh->scale[0]!=meshscale[0] ||
|
||||||
mesh->scale[1]!=meshscale[1] ||
|
mesh->scale[1]!=meshscale[1] ||
|
||||||
mesh->scale[2]!=meshscale[2]) {
|
mesh->scale[2]!=meshscale[2]) {
|
||||||
pmesh = mjs_addMesh(model, 0);
|
pmesh = mjs_addMesh(spec, 0);
|
||||||
meshname = meshname + "1";
|
meshname = meshname + "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -703,14 +703,14 @@ void mjXURDF::AddToTree(int n) {
|
|||||||
// get pointer to parent in mjCModel tree
|
// get pointer to parent in mjCModel tree
|
||||||
mjsBody *parent = 0, *child = 0, *world = 0;
|
mjsBody *parent = 0, *child = 0, *world = 0;
|
||||||
if (urParent[n]>=0) {
|
if (urParent[n]>=0) {
|
||||||
world = mjs_findBody(model, "world");
|
world = mjs_findBody(spec, "world");
|
||||||
parent = mjs_findChild(world, urName[urParent[n]].c_str());
|
parent = mjs_findChild(world, urName[urParent[n]].c_str());
|
||||||
|
|
||||||
if (!parent)
|
if (!parent)
|
||||||
throw mjXError(0, "URDF body parent should already be in tree: %s",
|
throw mjXError(0, "URDF body parent should already be in tree: %s",
|
||||||
urName[urParent[n]].c_str()); // SHOULD NOT OCCUR
|
urName[urParent[n]].c_str()); // SHOULD NOT OCCUR
|
||||||
} else {
|
} else {
|
||||||
parent = mjs_findBody(model, "world");
|
parent = mjs_findBody(spec, "world");
|
||||||
}
|
}
|
||||||
|
|
||||||
// add this body
|
// add this body
|
||||||
|
|||||||
Reference in New Issue
Block a user