Replace name attribute with setters and getters in the C API of mjSpec.
PiperOrigin-RevId: 778816015 Change-Id: Ieffb7a5bce37e887ff009f9a02d2434435e79ca1
This commit is contained in:
committed by
Copybara-Service
parent
1c5d47c94b
commit
594e17074a
@@ -1355,7 +1355,7 @@ void mjXReader::OneFlex(XMLElement* elem, mjsFlex* flex) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(flex->name, name.c_str());
|
||||
mjs_setName(flex->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "material", material)) {
|
||||
mjs_setString(flex->material, material.c_str());
|
||||
@@ -1446,7 +1446,7 @@ void mjXReader::OneMesh(XMLElement* elem, mjsMesh* mesh, const mjVFS* vfs) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
*mesh->name = name;
|
||||
mjs_setName(mesh->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
*mesh->content_type = content_type;
|
||||
@@ -1521,7 +1521,7 @@ void mjXReader::OneSkin(XMLElement* elem, mjsSkin* skin, const mjVFS* vfs) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(skin->name, name.c_str());
|
||||
mjs_setName(skin->element, name.c_str());
|
||||
}
|
||||
auto file = ReadAttrFile(elem, "file", vfs, AssetDir());
|
||||
if (file.has_value()) {
|
||||
@@ -1611,7 +1611,7 @@ void mjXReader::OneMaterial(XMLElement* elem, mjsMaterial* material) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(material->name, name.c_str());
|
||||
mjs_setName(material->element, name.c_str());
|
||||
}
|
||||
|
||||
bool tex_attributes_found = false;
|
||||
@@ -1660,7 +1660,7 @@ void mjXReader::OneJoint(XMLElement* elem, mjsJoint* joint) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(joint->name, name.c_str());
|
||||
mjs_setName(joint->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, joint_map, joint_sz)) {
|
||||
joint->type = (mjtJoint)n;
|
||||
@@ -1708,7 +1708,7 @@ void mjXReader::OneGeom(XMLElement* elem, mjsGeom* geom) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(geom->name, name.c_str());
|
||||
mjs_setName(geom->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
||||
geom->type = (mjtGeom)n;
|
||||
@@ -1780,7 +1780,7 @@ void mjXReader::OneSite(XMLElement* elem, mjsSite* site) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(site->name, name.c_str());
|
||||
mjs_setName(site->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
||||
site->type = (mjtGeom)n;
|
||||
@@ -1813,7 +1813,7 @@ void mjXReader::OneCamera(XMLElement* elem, mjsCamera* camera) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(camera->name, name.c_str());
|
||||
mjs_setName(camera->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "target", targetbody)) {
|
||||
mjs_setString(camera->targetbody, targetbody.c_str());
|
||||
@@ -1868,7 +1868,7 @@ void mjXReader::OneLight(XMLElement* elem, mjsLight* light) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(light->name, name.c_str());
|
||||
mjs_setName(light->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "texture", texture)) {
|
||||
mjs_setString(light->texture, texture.c_str());
|
||||
@@ -1929,7 +1929,7 @@ void mjXReader::OnePair(XMLElement* elem, mjsPair* pair) {
|
||||
|
||||
// read other parameters
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(pair->name, name.c_str());
|
||||
mjs_setName(pair->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "condim", &pair->condim);
|
||||
ReadAttr(elem, "solref", mjNREF, pair->solref, text, false, false);
|
||||
@@ -1957,7 +1957,7 @@ void mjXReader::OneEquality(XMLElement* elem, mjsEquality* equality) {
|
||||
// regular only
|
||||
if (!readingdefaults) {
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(equality->name, name.c_str());
|
||||
mjs_setName(equality->element, name.c_str());
|
||||
}
|
||||
|
||||
switch (equality->type) {
|
||||
@@ -2093,7 +2093,7 @@ void mjXReader::OneTendon(XMLElement* elem, mjsTendon* tendon) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(tendon->name, name.c_str());
|
||||
mjs_setName(tendon->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &tendon->group);
|
||||
if (ReadAttrTxt(elem, "material", material)) {
|
||||
@@ -2136,7 +2136,7 @@ void mjXReader::OneActuator(XMLElement* elem, mjsActuator* actuator) {
|
||||
|
||||
// common attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(actuator->name, name.c_str());
|
||||
mjs_setName(actuator->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &actuator->group);
|
||||
MapValue(elem, "ctrllimited", &actuator->ctrllimited, TFAuto_map, 3);
|
||||
@@ -2884,7 +2884,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(numeric->name, elname.c_str());
|
||||
mjs_setName(numeric->element, elname.c_str());
|
||||
if (ReadAttrInt(elem, "size", &numeric->size)) {
|
||||
int sz = numeric->size < 500 ? numeric->size : 500;
|
||||
for (int i=0; i < sz; i++) {
|
||||
@@ -2915,7 +2915,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(text->name, elname.c_str());
|
||||
mjs_setName(text->element, elname.c_str());
|
||||
ReadAttrTxt(elem, "data", str, true);
|
||||
if (str.empty()) {
|
||||
throw mjXError(elem, "text field cannot be empty");
|
||||
@@ -2935,7 +2935,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(tuple->name, elname.c_str());
|
||||
mjs_setName(tuple->element, elname.c_str());
|
||||
|
||||
// read objects and add
|
||||
XMLElement* obj = FirstChildElement(elem);
|
||||
@@ -3151,7 +3151,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
texture->colorspace = (mjtColorSpace)n;
|
||||
}
|
||||
if (ReadAttrTxt(elem, "name", texname)) {
|
||||
mjs_setString(texture->name, texname.c_str());
|
||||
mjs_setName(texture->element, texname.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
mjs_setString(texture->content_type, content_type.c_str());
|
||||
@@ -3243,7 +3243,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
// read attributes
|
||||
string name, content_type;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(hfield->name, name.c_str());
|
||||
mjs_setName(hfield->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
mjs_setString(hfield->content_type, content_type.c_str());
|
||||
@@ -3406,7 +3406,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(joint->name, name.c_str());
|
||||
mjs_setName(joint->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &joint->group);
|
||||
MapValue(elem, "align", &joint->align, TFAuto_map, 3);
|
||||
@@ -3478,7 +3478,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name, childclass;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(pframe->name, name.c_str());
|
||||
mjs_setName(pframe->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "childclass", childclass)) {
|
||||
mjs_setString(pframe->childclass, childclass.c_str());
|
||||
@@ -3579,7 +3579,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name, childclass;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(child->name, name.c_str());
|
||||
mjs_setName(child->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "childclass", childclass)) {
|
||||
mjs_setString(child->childclass, childclass.c_str());
|
||||
@@ -3688,7 +3688,7 @@ void mjXReader::Contact(XMLElement* section) {
|
||||
|
||||
// read name and body names
|
||||
if (ReadAttrTxt(elem, "name", exname)) {
|
||||
mjs_setString(exclude->name, exname.c_str());
|
||||
mjs_setName(exclude->element, exname.c_str());
|
||||
}
|
||||
ReadAttrTxt(elem, "body1", exbody1, true);
|
||||
mjs_setString(exclude->bodyname1, exbody1.c_str());
|
||||
@@ -3870,7 +3870,7 @@ void mjXReader::Sensor(XMLElement* section) {
|
||||
|
||||
// read name, noise, userdata
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(sensor->name, name.c_str());
|
||||
mjs_setName(sensor->element, name.c_str());
|
||||
}
|
||||
ReadAttr(elem, "cutoff", 1, &sensor->cutoff, text);
|
||||
ReadAttr(elem, "noise", 1, &sensor->noise, text);
|
||||
@@ -4215,7 +4215,7 @@ void mjXReader::Keyframe(XMLElement* section) {
|
||||
|
||||
// read name, time
|
||||
ReadAttrTxt(elem, "name", name);
|
||||
mjs_setString(key->name, name.c_str());
|
||||
mjs_setName(key->element, name.c_str());
|
||||
ReadAttr(elem, "time", 1, &key->time, text);
|
||||
|
||||
// read qpos
|
||||
|
||||
+13
-13
@@ -216,7 +216,7 @@ void mjXURDF::Parse(
|
||||
// if the mass is 0, assume the object is static
|
||||
if (!static_body && pbody->mass > 0) {
|
||||
mjsJoint* pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, (urName[i] + "_free_joint").c_str());
|
||||
mjs_setName(pjoint->element, (urName[i] + "_free_joint").c_str());
|
||||
pjoint->type = mjJNT_FREE;
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
||||
mjXUtil::ReadAttrTxt(elem, "name", geom_name);
|
||||
name = GetPrefixedName(name);
|
||||
if (urGeomNames.find(geom_name) == urGeomNames.end()) {
|
||||
mjs_setString(pgeom->name, geom_name.c_str());
|
||||
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
|
||||
@@ -350,7 +350,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
||||
mjXUtil::ReadAttrTxt(elem, "name", geom_name);
|
||||
geom_name = GetPrefixedName(geom_name);
|
||||
if (urGeomNames.find(geom_name) == urGeomNames.end()) {
|
||||
mjs_setString(pgeom->name, geom_name.c_str());
|
||||
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
|
||||
@@ -420,7 +420,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
case 0: // revolute
|
||||
case 1: // continuous
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_HINGE;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -428,7 +428,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 2: // prismatic
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_SLIDE;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -439,7 +439,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 4: // floating
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_FREE;
|
||||
break;
|
||||
|
||||
@@ -450,7 +450,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct slider along x
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, (jntname + "_TX").c_str());
|
||||
mjs_setName(pjoint->element, (jntname + "_TX").c_str());
|
||||
pjoint->type = mjJNT_SLIDE;
|
||||
tmpaxis[0] = mat[0];
|
||||
tmpaxis[1] = mat[3];
|
||||
@@ -460,7 +460,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct slider along y
|
||||
pjoint1 = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint1->name, (jntname + "_TY").c_str());
|
||||
mjs_setName(pjoint1->element, (jntname + "_TY").c_str());
|
||||
pjoint1->type = mjJNT_SLIDE;
|
||||
tmpaxis[0] = mat[1];
|
||||
tmpaxis[1] = mat[4];
|
||||
@@ -470,7 +470,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct hinge around z = locaxis
|
||||
pjoint2 = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint2->name, (jntname + "_RZ").c_str());
|
||||
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);
|
||||
@@ -478,7 +478,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 6: // ball joint
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_BALL;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -530,7 +530,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
|
||||
// add BOX geom, modify type later
|
||||
mjsGeom* pgeom = mjs_addGeom(pbody, 0);
|
||||
mjs_setString(pgeom->name, "");
|
||||
mjs_setName(pgeom->element, "");
|
||||
pgeom->type = mjGEOM_BOX;
|
||||
if (collision) {
|
||||
pgeom->contype = 1;
|
||||
@@ -624,7 +624,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
// set fields
|
||||
if (newmesh) {
|
||||
mjs_setString(pmesh->file, meshfile.c_str());
|
||||
mjs_setString(pmesh->name, meshname.c_str());
|
||||
mjs_setName(pmesh->element, meshname.c_str());
|
||||
pmesh->scale[0] = meshscale[0];
|
||||
pmesh->scale[1] = meshscale[1];
|
||||
pmesh->scale[2] = meshscale[2];
|
||||
@@ -726,7 +726,7 @@ void mjXURDF::AddToTree(int n) {
|
||||
// add this body
|
||||
if (urName[n] != "world") {
|
||||
child = mjs_addBody(parent, 0);
|
||||
mjs_setString(child->name, urName[n].c_str());
|
||||
mjs_setName(child->element, urName[n].c_str());
|
||||
}
|
||||
|
||||
// add children recursively
|
||||
|
||||
Reference in New Issue
Block a user