| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <array> |
| | #include <cstdlib> |
| | #include <cstring> |
| | #include <iostream> |
| | #include <string> |
| | #include <vector> |
| |
|
| | #include <mujoco/mjmodel.h> |
| | #include <mujoco/mjspec.h> |
| | #include "user/user_api.h" |
| | #include "user/user_util.h" |
| | #include "xml/xml_native_reader.h" |
| | #include "xml/xml_urdf.h" |
| | #include "xml/xml_util.h" |
| | #include "tinyxml2.h" |
| |
|
| | using tinyxml2::XMLElement; |
| |
|
| | |
| | static const int urJoint_sz = 7; |
| | static const mjMap urJoint_map[urJoint_sz] = { |
| | {"revolute", 0}, |
| | {"continuous", 1}, |
| | {"prismatic", 2}, |
| | {"fixed", 3}, |
| | {"floating", 4}, |
| | {"planar", 5}, |
| | {"spherical", 6} |
| | }; |
| |
|
| |
|
| |
|
| | |
| |
|
| | |
| | mjXURDF::mjXURDF() { |
| | Clear(); |
| | } |
| |
|
| |
|
| |
|
| | |
| | mjXURDF::~mjXURDF() { |
| | Clear(); |
| | } |
| |
|
| |
|
| | |
| | void mjXURDF::Clear(void) { |
| | spec = 0; |
| |
|
| | urName.clear(); |
| | urParent.clear(); |
| | urChildren.clear(); |
| | urMat.clear(); |
| | urRGBA.clear(); |
| | urGeomNames.clear(); |
| | } |
| |
|
| | std::string mjXURDF::GetPrefixedName(const std::string& name) { |
| | if (name.empty()) { |
| | return name; |
| | } |
| | if (urPrefix.empty()) { |
| | return name; |
| | } |
| | return urPrefix + "/" + name; |
| | } |
| |
|
| | |
| | void mjXURDF::Parse( |
| | XMLElement* root, const std::string& prefix, double* pos, double* quat, |
| | const bool static_body) { |
| | std::string name, text; |
| | XMLElement *elem, *temp; |
| | int id_parent, id_child; |
| | urPrefix = prefix; |
| |
|
| | |
| | XMLElement* mjc = FindSubElem(root, "mujoco"); |
| | if (mjc) { |
| | XMLElement *section; |
| | if ((section = FindSubElem(mjc, "compiler"))) { |
| | mjXReader::Compiler(section, spec); |
| | } |
| |
|
| | if ((section = FindSubElem(mjc, "option"))) { |
| | mjXReader::Option(section, &spec->option); |
| | } |
| |
|
| | if ((section = FindSubElem(mjc, "size"))) { |
| | mjXReader::Size(section, spec); |
| | } |
| | } |
| |
|
| | |
| | spec->compiler.degree = false; |
| |
|
| | |
| | std::string modelname; |
| | if (ReadAttrTxt(root, "name", modelname)) { |
| | mjs_setString(spec->modelname, modelname.c_str()); |
| | } |
| |
|
| | |
| | MakeMaterials(root); |
| |
|
| | |
| | elem = root->FirstChildElement(); |
| | while (elem) { |
| | |
| | name = elem->Value(); |
| | if (name == "link") { |
| | ReadAttrTxt(elem, "name", text, true); |
| | text = GetPrefixedName(text); |
| | AddBody(text); |
| | } |
| |
|
| | |
| | elem = elem->NextSiblingElement(); |
| | } |
| |
|
| | |
| | elem = root->FirstChildElement(); |
| | while (elem) { |
| | |
| | name = elem->Value(); |
| | if (name == "joint") { |
| | |
| | temp = FindSubElem(elem, "parent", true); |
| | ReadAttrTxt(temp, "link", text, true); |
| | text = GetPrefixedName(text); |
| | id_parent = FindName(text, urName); |
| |
|
| | |
| | temp = FindSubElem(elem, "child", true); |
| | ReadAttrTxt(temp, "link", text, true); |
| | text = GetPrefixedName(text); |
| | id_child = FindName(text, urName); |
| |
|
| | |
| | if (id_parent < 0 || id_child < 0) { |
| | throw mjXError(elem, "URDF joint parent or child missing"); |
| | } |
| |
|
| | |
| | if (urParent[id_child] >= 0) { |
| | throw mjXError(elem, "URDF body has multiple parents:", urName[id_child].c_str()); |
| | } |
| |
|
| | |
| | urParent[id_child] = id_parent; |
| | urChildren[id_parent].push_back(id_child); |
| | } |
| |
|
| | |
| | elem = elem->NextSiblingElement(); |
| | } |
| |
|
| | |
| | for (int i=0; i < (int)urName.size(); i++) { |
| | if (urParent[i] < 0) { |
| | AddToTree(i); |
| | } |
| | } |
| |
|
| | |
| | elem = root->FirstChildElement(); |
| | while (elem) { |
| | |
| | name = elem->Value(); |
| | if (name == "link") { |
| | Body(elem); |
| | } |
| |
|
| | |
| | elem = elem->NextSiblingElement(); |
| | } |
| |
|
| | |
| | elem = root->FirstChildElement(); |
| | while (elem) { |
| | |
| | name = elem->Value(); |
| | if (name == "joint") { |
| | Joint(elem); |
| | } |
| |
|
| | |
| | elem = elem->NextSiblingElement(); |
| | } |
| |
|
| | |
| | for (int i = 0; i < (int)urName.size(); i++) { |
| | if (urParent[i] < 0) { |
| | mjsBody* world = mjs_findBody(spec, "world"); |
| | mjsBody* pbody = mjs_findChild(world, urName[i].c_str()); |
| | mjuu_copyvec(pbody->pos, pos, 3); |
| | mjuu_copyvec(pbody->quat, quat, 4); |
| |
|
| | |
| | |
| | if (!static_body && pbody->mass > 0) { |
| | mjsJoint* pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, (urName[i] + "_free_joint").c_str()); |
| | pjoint->type = mjJNT_FREE; |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | void mjXURDF::Body(XMLElement* body_elem) { |
| | std::string name, text; |
| | XMLElement *elem, *temp, *temp1; |
| | mjsBody *pbody, *world; |
| | mjsGeom* pgeom; |
| |
|
| | |
| | ReadAttrTxt(body_elem, "name", name, true); |
| | name = GetPrefixedName(name); |
| | world = mjs_findBody(spec, "world"); |
| | pbody = mjs_findChild(world, name.c_str()); |
| | if (!pbody) { |
| | throw mjXError(body_elem, "URDF body not found"); |
| | } |
| | |
| | if ((elem = FindSubElem(body_elem, "inertial"))) { |
| | pbody->explicitinertial = true; |
| | |
| | Origin(elem, pbody->ipos, pbody->iquat); |
| |
|
| | |
| | temp = FindSubElem(elem, "mass", true); |
| | ReadAttr(temp, "value", 1, &pbody->mass, text, true); |
| |
|
| | |
| | temp = FindSubElem(elem, "inertia", true); |
| | ReadAttr(temp, "ixx", 1, pbody->fullinertia+0, text, true); |
| | ReadAttr(temp, "iyy", 1, pbody->fullinertia+1, text, true); |
| | ReadAttr(temp, "izz", 1, pbody->fullinertia+2, text, true); |
| | ReadAttr(temp, "ixy", 1, pbody->fullinertia+3, text, true); |
| | ReadAttr(temp, "ixz", 1, pbody->fullinertia+4, text, true); |
| | ReadAttr(temp, "iyz", 1, pbody->fullinertia+5, text, true); |
| |
|
| | |
| | bool inertia_defined = false; |
| | for (int i = 0; i < 6; ++i) { |
| | if (pbody->fullinertia[i] != 0) { |
| | inertia_defined = true; |
| | break; |
| | } |
| | } |
| | if (!inertia_defined) { |
| | pbody->fullinertia[0] = mjNAN; |
| | } |
| |
|
| | |
| | |
| | double lquat[4] = {1, 0, 0, 0}; |
| | double tmpquat[4] = {1, 0, 0, 0}; |
| | const char* altres = mjuu_fullInertia(lquat, nullptr, pbody->fullinertia); |
| |
|
| | |
| | (void) altres; |
| |
|
| | |
| | mjuu_mulquat(tmpquat, pbody->iquat, lquat); |
| | mjuu_copyvec(pbody->iquat, tmpquat, 4); |
| | } |
| |
|
| | |
| | mjuu_setvec(pbody->pos, 0, 0, 0); |
| | mjuu_setvec(pbody->quat, 1, 0, 0, 0); |
| |
|
| | |
| | float rgba[4] = {-1, 0, 0, 0}; |
| | std::string geom_name; |
| |
|
| | elem = body_elem->FirstChildElement(); |
| | while (elem) { |
| | name = elem->Value(); |
| |
|
| | |
| | if (name == "visual") { |
| | |
| | if ((temp = FindSubElem(elem, "material"))) { |
| | |
| | if ((temp1 = FindSubElem(temp, "color"))) { |
| | ReadAttr(temp1, "rgba", 4, rgba, text, true); |
| | } |
| |
|
| | |
| | else { |
| | ReadAttrTxt(temp, "name", name, true); |
| | name = GetPrefixedName(name); |
| | int imat = FindName(name, urMat); |
| | if (imat >= 0) { |
| | std::memcpy(rgba, urRGBA[imat].val, 4*sizeof(float)); |
| | } |
| | } |
| | } |
| | |
| | if (!spec->compiler.discardvisual) { |
| | pgeom = Geom(elem, pbody, false); |
| |
|
| | |
| | if (rgba[0] >= 0) { |
| | std::memcpy(pgeom->rgba, rgba, 4*sizeof(float)); |
| | } |
| |
|
| | |
| | mjXUtil::ReadAttrTxt(elem, "name", geom_name); |
| | name = GetPrefixedName(name); |
| | if (urGeomNames.find(geom_name) == urGeomNames.end()) { |
| | mjs_setName(pgeom->element, geom_name.c_str()); |
| | urGeomNames.insert(geom_name); |
| | } else if (!geom_name.empty()) { |
| | std::cerr << "WARNING: Geom with duplicate name '" << geom_name |
| | << "' encountered in URDF, creating an unnamed geom." |
| | << std::endl; |
| | } |
| | } |
| | } |
| |
|
| | |
| | else if (name == "collision") { |
| | pgeom = Geom(elem, pbody, true); |
| |
|
| | |
| | if (rgba[0] >= 0) { |
| | std::memcpy(pgeom->rgba, rgba, 4*sizeof(float)); |
| | } |
| |
|
| | |
| | mjXUtil::ReadAttrTxt(elem, "name", geom_name); |
| | geom_name = GetPrefixedName(geom_name); |
| | if (urGeomNames.find(geom_name) == urGeomNames.end()) { |
| | mjs_setName(pgeom->element, geom_name.c_str()); |
| | urGeomNames.insert(geom_name); |
| | } else if (!geom_name.empty()) { |
| | std::cerr << "WARNING: Geom with duplicate name '" << geom_name |
| | << "' encountered in URDF, creating an unnamed geom." |
| | << std::endl; |
| | } |
| | } |
| | |
| | elem = elem->NextSiblingElement(); |
| | } |
| | } |
| |
|
| | void mjXURDF::Parse(XMLElement* root, const mjVFS* vfs) { |
| | double pos[3] = {0}; |
| | mjuu_setvec(pos, 0, 0, 0); |
| | double quat[4] = {1, 0, 0, 0}; |
| | mjuu_setvec(quat, 1, 0, 0, 0); |
| | Parse(root, "", pos, quat, true); |
| | } |
| |
|
| | |
| | void mjXURDF::Joint(XMLElement* joint_elem) { |
| | std::string jntname, name, text; |
| | XMLElement *elem; |
| | mjsBody *pbody, *parent, *world; |
| | mjsJoint *pjoint=0, *pjoint1=0, *pjoint2=0; |
| | int jointtype; |
| |
|
| | |
| | ReadAttrTxt(joint_elem, "type", text, true); |
| | jointtype = FindKey(urJoint_map, urJoint_sz, text); |
| | if (jointtype < 0) { |
| | throw mjXError(joint_elem, "invalid joint type in URDF joint definition"); |
| | } |
| | ReadAttrTxt(joint_elem, "name", jntname, true); |
| | jntname = GetPrefixedName(jntname); |
| | |
| | elem = FindSubElem(joint_elem, "parent", true); |
| | ReadAttrTxt(elem, "link", name, true); |
| | name = GetPrefixedName(name); |
| | world = mjs_findBody(spec, "world"); |
| | parent = mjs_findChild(world, name.c_str()); |
| | if (!parent) { |
| | throw mjXError(elem, "invalid parent name in URDF joint definition"); |
| | } |
| |
|
| | |
| | elem = FindSubElem(joint_elem, "child", true); |
| | ReadAttrTxt(elem, "link", name, true); |
| | name = GetPrefixedName(name); |
| | world = mjs_findBody(spec, "world"); |
| | pbody = mjs_findChild(world, name.c_str()); |
| | if (!pbody) { |
| | throw mjXError(elem, "invalid child name in URDF joint definition"); |
| | } |
| |
|
| | |
| | double axis[3] = {1, 0, 0}; |
| | Origin(joint_elem, pbody->pos, pbody->quat); |
| | if ((elem = FindSubElem(joint_elem, "axis"))) { |
| | ReadAttr(elem, "xyz", 3, axis, text, true); |
| | } |
| |
|
| | |
| | double mat[9], quat[4], tmpaxis[3]; |
| | switch (jointtype) { |
| | case 0: |
| | case 1: |
| | pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, jntname.c_str()); |
| | pjoint->type = mjJNT_HINGE; |
| | mjuu_setvec(pjoint->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint->axis, axis, 3); |
| | break; |
| |
|
| | case 2: |
| | pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, jntname.c_str()); |
| | pjoint->type = mjJNT_SLIDE; |
| | mjuu_setvec(pjoint->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint->axis, axis, 3); |
| | break; |
| |
|
| | case 3: |
| | return; |
| |
|
| | case 4: |
| | pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, jntname.c_str()); |
| | pjoint->type = mjJNT_FREE; |
| | break; |
| |
|
| | case 5: |
| | |
| | mjuu_z2quat(quat, axis); |
| | mjuu_quat2mat(mat, quat); |
| |
|
| | |
| | pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, (jntname + "_TX").c_str()); |
| | pjoint->type = mjJNT_SLIDE; |
| | tmpaxis[0] = mat[0]; |
| | tmpaxis[1] = mat[3]; |
| | tmpaxis[2] = mat[6]; |
| | mjuu_setvec(pjoint->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint->axis, tmpaxis, 3); |
| |
|
| | |
| | pjoint1 = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint1->element, (jntname + "_TY").c_str()); |
| | pjoint1->type = mjJNT_SLIDE; |
| | tmpaxis[0] = mat[1]; |
| | tmpaxis[1] = mat[4]; |
| | tmpaxis[2] = mat[7]; |
| | mjuu_setvec(pjoint1->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint1->axis, tmpaxis, 3); |
| |
|
| | |
| | pjoint2 = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint2->element, (jntname + "_RZ").c_str()); |
| | pjoint2->type = mjJNT_HINGE; |
| | mjuu_setvec(pjoint2->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint2->axis, axis, 3); |
| | break; |
| |
|
| | case 6: |
| | pjoint = mjs_addJoint(pbody, 0); |
| | mjs_setName(pjoint->element, jntname.c_str()); |
| | pjoint->type = mjJNT_BALL; |
| | mjuu_setvec(pjoint->pos, 0, 0, 0); |
| | mjuu_copyvec(pjoint->axis, axis, 3); |
| | } |
| |
|
| | |
| | if ((elem = FindSubElem(joint_elem, "dynamics"))) { |
| | ReadAttr(elem, "damping", 1, &pjoint->damping, text); |
| | ReadAttr(elem, "friction", 1, &pjoint->frictionloss, text); |
| |
|
| | |
| | if (pjoint1) { |
| | pjoint1->damping = pjoint2->damping = pjoint->damping; |
| | pjoint1->frictionloss = pjoint2->frictionloss = pjoint->frictionloss; |
| | } |
| | } |
| |
|
| | |
| | if ((elem = FindSubElem(joint_elem, "limit"))) { |
| | bool haslower = ReadAttr(elem, "lower", 1, pjoint->range, text); |
| | bool hasupper = ReadAttr(elem, "upper", 1, pjoint->range+1, text); |
| |
|
| | |
| | bool bad_range = (haslower != hasupper) || pjoint->range[0] > pjoint->range[1]; |
| | if (bad_range) { |
| | pjoint->limited = mjLIMITED_FALSE; |
| | } |
| |
|
| | |
| | double effort = 0; |
| | ReadAttr(elem, "effort", 1, &effort, text); |
| | effort = std::abs(effort); |
| | if (effort > 0) { |
| | pjoint->actfrcrange[0] = -effort; |
| | pjoint->actfrcrange[1] = effort; |
| | } |
| | } |
| | } |
| |
|
| |
|
| |
|
| | |
| | mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) { |
| | XMLElement *elem, *temp; |
| | std::string text, meshfile; |
| |
|
| | |
| | elem = FindSubElem(geom_elem, "geometry", true); |
| |
|
| | |
| | mjsGeom* pgeom = mjs_addGeom(pbody, 0); |
| | mjs_setName(pgeom->element, ""); |
| | pgeom->type = mjGEOM_BOX; |
| | if (collision) { |
| | pgeom->contype = 1; |
| | pgeom->conaffinity = 1; |
| | } else { |
| | pgeom->contype = 0; |
| | pgeom->conaffinity = 0; |
| | pgeom->group = 1; |
| | pgeom->density = 0; |
| | } |
| |
|
| | |
| | if ((temp = FindSubElem(elem, "box"))) { |
| | ReadAttr(temp, "size", 3, pgeom->size, text, true, true); |
| | for (int i=0; i < 3; i++) { |
| | pgeom->size[i] /= 2; |
| | } |
| | } |
| |
|
| | |
| | else if ((temp = FindSubElem(elem, "cylinder"))) { |
| | pgeom->type = mjGEOM_CYLINDER; |
| | ReadAttr(temp, "radius", 1, pgeom->size, text, true, true); |
| | ReadAttr(temp, "length", 1, pgeom->size+1, text, true, true); |
| | pgeom->size[1] /= 2; |
| | } |
| |
|
| | |
| | else if ((temp = FindSubElem(elem, "sphere"))) { |
| | pgeom->type = mjGEOM_SPHERE; |
| | ReadAttr(temp, "radius", 1, pgeom->size, text, true, true); |
| | } |
| |
|
| | |
| | else if ((temp = FindSubElem(elem, "capsule"))) { |
| | pgeom->type = mjGEOM_CAPSULE; |
| | ReadAttr(temp, "radius", 1, pgeom->size, text, true, true); |
| | ReadAttr(temp, "length", 1, pgeom->size+1, text, true, true); |
| | pgeom->size[1] /= 2; |
| | } |
| |
|
| | |
| | else if ((temp = FindSubElem(elem, "mesh"))) { |
| | mjsMesh* pmesh = 0; |
| | bool newmesh = false; |
| |
|
| | |
| | pgeom->type = mjGEOM_MESH; |
| | meshfile = ReadAttrStr(temp, "filename", true).value(); |
| | std::array<double, 3> default_meshscale = {1, 1, 1}; |
| | std::array<double, 3> meshscale = ReadAttrArr<double, 3>(temp, "scale") |
| | .value_or(default_meshscale); |
| |
|
| | |
| | if (spec->strippath) { |
| | meshfile = mjuu_strippath(meshfile); |
| | } |
| |
|
| | |
| | std::string meshname = mjuu_strippath(meshfile); |
| | meshname = mjuu_stripext(meshname); |
| |
|
| | if (meshes.find(meshname) == meshes.end()) { |
| | |
| | pmesh = mjs_addMesh(spec, 0); |
| | meshes[meshname].push_back(pmesh); |
| | newmesh = true; |
| | } else { |
| | int i = 0; |
| |
|
| | |
| | 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++; |
| | } |
| |
|
| | |
| | if (i == meshes[meshname].size()) { |
| | pmesh = mjs_addMesh(spec, 0); |
| | meshes[meshname].push_back(pmesh); |
| | meshname = meshname + std::to_string(i); |
| | newmesh = true; |
| | } |
| | } |
| |
|
| | |
| | if (newmesh) { |
| | mjs_setString(pmesh->file, meshfile.c_str()); |
| | mjs_setName(pmesh->element, 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()); |
| | } |
| |
|
| | else { |
| | throw mjXError(elem, "visual geometry specification not found"); |
| | } |
| |
|
| | |
| | Origin(geom_elem, pgeom->pos, pgeom->quat); |
| |
|
| | return pgeom; |
| | } |
| |
|
| |
|
| |
|
| | |
| | void mjXURDF::Origin(XMLElement* origin_elem, double* pos, double* quat) { |
| | XMLElement* temp; |
| | std::string text; |
| |
|
| | |
| | mjuu_setvec(pos, 0, 0, 0); |
| | mjuu_setvec(quat, 1, 0, 0, 0); |
| |
|
| | |
| | if ((temp = FindSubElem(origin_elem, "origin"))) { |
| | |
| | ReadAttr(temp, "xyz", 3, pos, text); |
| |
|
| | |
| | mjsOrientation alt; |
| | mjs_defaultOrientation(&alt); |
| | if (ReadAttr(temp, "rpy", 3, alt.euler, text)) { |
| | alt.type = mjORIENTATION_EULER; |
| | mjs_resolveOrientation(quat, 0, "XYZ", &alt); |
| | } |
| | } |
| | } |
| |
|
| |
|
| |
|
| | |
| | int mjXURDF::FindName(std::string name, std::vector<std::string>& list) { |
| | for (unsigned int i=0; i < list.size(); i++) |
| | if (list[i] == name) { |
| | return i; |
| | } |
| |
|
| | return -1; |
| | } |
| |
|
| |
|
| |
|
| | |
| | void mjXURDF::AddName(std::string name, std::vector<std::string>& list) { |
| | |
| | if (FindName(name, list) >= 0) { |
| | throw mjXError(0, "repeated URDF name: ", name.c_str()); |
| | } |
| |
|
| | list.push_back(name); |
| | } |
| |
|
| |
|
| |
|
| | |
| | void mjXURDF::AddBody(std::string name) { |
| | |
| | AddName(name, urName); |
| |
|
| | |
| | urParent.push_back(-1); |
| | std::vector<int> children; |
| | children.clear(); |
| | urChildren.push_back(children); |
| | } |
| |
|
| |
|
| |
|
| | |
| | void mjXURDF::AddToTree(int n) { |
| | |
| | mjsBody *parent = 0, *child = 0, *world = 0; |
| | if (urParent[n] >= 0) { |
| | world = mjs_findBody(spec, "world"); |
| | parent = mjs_findChild(world, urName[urParent[n]].c_str()); |
| |
|
| | if (!parent) |
| | throw mjXError(0, "URDF body parent should already be in tree: %s", |
| | urName[urParent[n]].c_str()); |
| | } else { |
| | parent = mjs_findBody(spec, "world"); |
| | } |
| |
|
| | |
| | if (urName[n] != "world") { |
| | child = mjs_addBody(parent, 0); |
| | mjs_setName(child->element, urName[n].c_str()); |
| | } |
| |
|
| | |
| | for (int i=0; i < (int)urChildren[n].size(); i++) { |
| | AddToTree(urChildren[n][i]); |
| | } |
| | } |
| |
|
| |
|
| |
|
| | |
| | void mjXURDF::MakeMaterials(XMLElement* elem) { |
| | std::string name, text; |
| | XMLElement* color = 0; |
| | mjRGBA rgba; |
| |
|
| | |
| | if (!std::strcmp(elem->Value(), "material")) { |
| | |
| | if (ReadAttrTxt(elem, "name", name)) { |
| | |
| | if (FindName(name, urMat) < 0) { |
| | |
| | if ((color = FindSubElem(elem, "color"))) { |
| | ReadAttr(color, "rgba", 4, rgba.val, text, true); |
| | AddName(name, urMat); |
| | urRGBA.push_back(rgba); |
| | } |
| | } |
| | } |
| | } |
| |
|
| | |
| | elem = elem->FirstChildElement(); |
| | while (elem) { |
| | MakeMaterials(elem); |
| | elem = elem->NextSiblingElement(); |
| | } |
| | } |
| |
|