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
|
||||
|
||||
Reference in New Issue
Block a user