Convert mjmStruct to a C-struct.

PiperOrigin-RevId: 603357871
Change-Id: I27918b0030fc6a589c361cad965611adc3bf7247
This commit is contained in:
Alessio Quaglino
2024-02-01 06:56:46 -08:00
committed by Copybara-Service
parent 7a98038e88
commit b3f93d436b
7 changed files with 103 additions and 65 deletions
+3 -3
View File
@@ -1243,7 +1243,7 @@ void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) {
mjCSkin* skin = model->AddSkin(); mjCSkin* skin = model->AddSkin();
mju::sprintf_arr(txt, "%sSkin", prefix.c_str()); mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
skin->name = txt; skin->name = txt;
skin->material = skinmaterial; skin->set_material(skinmaterial);
mjuu_copyvec(skin->rgba, skinrgba, 4); mjuu_copyvec(skin->rgba, skinrgba, 4);
skin->inflate = inflate; skin->inflate = inflate;
skin->group = skingroup; skin->group = skingroup;
@@ -1845,7 +1845,7 @@ void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
mjCSkin* skin = model->AddSkin(); mjCSkin* skin = model->AddSkin();
mju::sprintf_arr(txt, "%sSkin", prefix.c_str()); mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
skin->name = txt; skin->name = txt;
skin->material = skinmaterial; skin->set_material(skinmaterial);
mjuu_copyvec(skin->rgba, skinrgba, 4); mjuu_copyvec(skin->rgba, skinrgba, 4);
skin->inflate = inflate; skin->inflate = inflate;
skin->group = skingroup; skin->group = skingroup;
@@ -1998,7 +1998,7 @@ void mjCComposite::MakeSkin3(mjCModel* model) {
mjCSkin* skin = model->AddSkin(); mjCSkin* skin = model->AddSkin();
mju::sprintf_arr(txt, "%sSkin", prefix.c_str()); mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
skin->name = txt; skin->name = txt;
skin->material = skinmaterial; skin->set_material(skinmaterial);
mjuu_copyvec(skin->rgba, skinrgba, 4); mjuu_copyvec(skin->rgba, skinrgba, 4);
skin->inflate = skininflate; skin->inflate = skininflate;
skin->group = skingroup; skin->group = skingroup;
+9 -9
View File
@@ -1878,7 +1878,7 @@ mjCSkin::mjCSkin(mjCModel* _model) {
// clear data // clear data
file.clear(); file.clear();
material.clear(); material_.clear();
rgba[0] = rgba[1] = rgba[2] = 0.5f; rgba[0] = rgba[1] = rgba[2] = 0.5f;
rgba[3] = 1.0f; rgba[3] = 1.0f;
inflate = 0; inflate = 0;
@@ -1903,7 +1903,7 @@ mjCSkin::mjCSkin(mjCModel* _model) {
// destructor // destructor
mjCSkin::~mjCSkin() { mjCSkin::~mjCSkin() {
file.clear(); file.clear();
material.clear(); material_.clear();
vert.clear(); vert.clear();
texcoord.clear(); texcoord.clear();
face.clear(); face.clear();
@@ -2005,11 +2005,11 @@ void mjCSkin::Compile(const mjVFS* vfs) {
} }
// resolve material name // resolve material name
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material); mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material_);
if (pmat) { if (pmat) {
matid = pmat->id; matid = pmat->id;
} else if (!material.empty()) { } else if (!material_.empty()) {
throw mjCError(this, "unkown material '%s' in skin", material.c_str()); throw mjCError(this, "unkown material '%s' in skin", material_.c_str());
} }
// set total vertex weights to 0 // set total vertex weights to 0
@@ -2239,7 +2239,7 @@ mjCFlex::mjCFlex(mjCModel* _model) {
group = 0; group = 0;
edgestiffness = 0; edgestiffness = 0;
edgedamping = 0; edgedamping = 0;
material.clear(); material_.clear();
rgba[0] = rgba[1] = rgba[2] = 0.5f; rgba[0] = rgba[1] = rgba[2] = 0.5f;
rgba[3] = 1.0f; rgba[3] = 1.0f;
@@ -2314,11 +2314,11 @@ void mjCFlex::Compile(const mjVFS* vfs) {
} }
// resolve material name // resolve material name
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material); mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material_);
if (pmat) { if (pmat) {
matid = pmat->id; matid = pmat->id;
} else if (!material.empty()) { } else if (!material_.empty()) {
throw mjCError(this, "unkown material '%s' in flex", material.c_str()); throw mjCError(this, "unkown material '%s' in flex", material_.c_str());
} }
// resolve body ids // resolve body ids
+17 -17
View File
@@ -653,8 +653,8 @@ void mjCModel::MakeLists(mjCBody* body) {
template <class T> template <class T>
void mjCModel::DeleteMaterial(std::vector<T*>& list, std::string_view name) { void mjCModel::DeleteMaterial(std::vector<T*>& list, std::string_view name) {
for (T* plist : list) { for (T* plist : list) {
if (name.empty() || plist->material == name) { if (name.empty() || plist->material_ == name) {
plist->material.clear(); plist->material_.clear();
} }
} }
} }
@@ -775,12 +775,12 @@ void mjCModel::IndexAssets(bool discard) {
mjCGeom* pgeom = geoms[i]; mjCGeom* pgeom = geoms[i];
// find material by name // find material by name
if (!pgeom->material.empty()) { if (!pgeom->material_.empty()) {
mjCBase* m = FindObject(mjOBJ_MATERIAL, pgeom->material); mjCBase* m = FindObject(mjOBJ_MATERIAL, pgeom->material_);
if (m) { if (m) {
pgeom->matid = m->id; pgeom->matid = m->id;
} else { } else {
throw mjCError(pgeom, "material '%s' not found in geom %d", pgeom->material.c_str(), i); throw mjCError(pgeom, "material '%s' not found in geom %d", pgeom->material_.c_str(), i);
} }
} }
@@ -822,12 +822,12 @@ void mjCModel::IndexAssets(bool discard) {
mjCSkin* pskin = skins[i]; mjCSkin* pskin = skins[i];
// find material by name // find material by name
if (!pskin->material.empty()) { if (!pskin->material_.empty()) {
mjCBase* m = FindObject(mjOBJ_MATERIAL, pskin->material); mjCBase* m = FindObject(mjOBJ_MATERIAL, pskin->material_);
if (m) { if (m) {
pskin->matid = m->id; pskin->matid = m->id;
} else { } else {
throw mjCError(pskin, "material '%s' not found in skin %d", pskin->material.c_str(), i); throw mjCError(pskin, "material '%s' not found in skin %d", pskin->material_.c_str(), i);
} }
} }
} }
@@ -837,12 +837,12 @@ void mjCModel::IndexAssets(bool discard) {
mjCSite* psite = sites[i]; mjCSite* psite = sites[i];
// find material by name // find material by name
if (!psite->material.empty()) { if (!psite->material_.empty()) {
mjCBase* m = FindObject(mjOBJ_MATERIAL, psite->material); mjCBase* m = FindObject(mjOBJ_MATERIAL, psite->get_material());
if (m) { if (m) {
psite->matid = m->id; psite->matid = m->id;
} else { } else {
throw mjCError(psite, "material '%s' not found in site %d", psite->material.c_str(), i); throw mjCError(psite, "material '%s' not found in site %d", psite->material_.c_str(), i);
} }
} }
} }
@@ -852,12 +852,12 @@ void mjCModel::IndexAssets(bool discard) {
mjCTendon* pten = tendons[i]; mjCTendon* pten = tendons[i];
// find material by name // find material by name
if (!pten->material.empty()) { if (!pten->material_.empty()) {
mjCBase* m = FindObject(mjOBJ_MATERIAL, pten->material); mjCBase* m = FindObject(mjOBJ_MATERIAL, pten->material_);
if (m) { if (m) {
pten->matid = m->id; pten->matid = m->id;
} else { } else {
throw mjCError(pten, "material '%s' not found in tendon %d", pten->material.c_str(), i); throw mjCError(pten, "material '%s' not found in tendon %d", pten->material_.c_str(), i);
} }
} }
} }
@@ -1718,7 +1718,7 @@ void mjCModel::CopyTree(mjModel* m) {
copyvec(m->site_size+3*sid, ps->size, 3); copyvec(m->site_size+3*sid, ps->size, 3);
copyvec(m->site_pos+3*sid, ps->pos, 3); copyvec(m->site_pos+3*sid, ps->pos, 3);
copyvec(m->site_quat+4*sid, ps->quat, 4); copyvec(m->site_quat+4*sid, ps->quat, 4);
copyvec(m->site_user+nuser_site*sid, ps->userdata.data(), nuser_site); copyvec(m->site_user+nuser_site*sid, ps->userdata_.data(), nuser_site);
copyvec(m->site_rgba+4*sid, ps->rgba, 4); copyvec(m->site_rgba+4*sid, ps->rgba, 4);
// determine sameframe // determine sameframe
@@ -2901,7 +2901,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
if (nuser_site == -1) { if (nuser_site == -1) {
nuser_site = 0; nuser_site = 0;
for (int i=0; i<sites.size(); i++) { for (int i=0; i<sites.size(); i++) {
nuser_site = mjMAX(nuser_site, sites[i]->spec.userdata.size()); nuser_site = mjMAX(nuser_site, sites[i]->spec_userdata_.size());
} }
} }
if (nuser_cam == -1) { if (nuser_cam == -1) {
@@ -3407,7 +3407,7 @@ bool mjCModel::CopyBack(const mjModel* m) {
copyvec(sites[i]->rgba, m->site_rgba+4*i, 4); copyvec(sites[i]->rgba, m->site_rgba+4*i, 4);
if (nuser_site) { if (nuser_site) {
copyvec(sites[i]->userdata.data(), m->site_user + nuser_site*i, nuser_site); copyvec(sites[i]->userdata_.data(), m->site_user + nuser_site*i, nuser_site);
} }
} }
+11 -8
View File
@@ -497,7 +497,7 @@ void mjCDef::Compile(const mjCModel* model) {
// enforce length of all default userdata arrays // enforce length of all default userdata arrays
joint.userdata.resize(model->nuser_jnt); joint.userdata.resize(model->nuser_jnt);
geom.userdata.resize(model->nuser_geom); geom.userdata.resize(model->nuser_geom);
site.userdata.resize(model->nuser_site); site.userdata_.resize(model->nuser_site);
camera.userdata.resize(model->nuser_cam); camera.userdata.resize(model->nuser_cam);
tendon.userdata.resize(model->nuser_tendon); tendon.userdata.resize(model->nuser_tendon);
actuator.userdata.resize(model->nuser_actuator); actuator.userdata.resize(model->nuser_actuator);
@@ -1356,7 +1356,7 @@ mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) {
density = 1000; // water density (1000 kg / m^3) density = 1000; // water density (1000 kg / m^3)
meshname.clear(); meshname.clear();
fitscale = 1; fitscale = 1;
material.clear(); material_.clear();
rgba[0] = rgba[1] = rgba[2] = 0.5f; rgba[0] = rgba[1] = rgba[2] = 0.5f;
rgba[3] = 1.0f; rgba[3] = 1.0f;
userdata.clear(); userdata.clear();
@@ -1931,14 +1931,13 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
spec.group = 0; spec.group = 0;
mjuu_setvec(spec.quat, 1, 0, 0, 0); mjuu_setvec(spec.quat, 1, 0, 0, 0);
mjuu_setvec(spec.pos, 0, 0, 0); mjuu_setvec(spec.pos, 0, 0, 0);
spec.material.clear(); spec.material = nullptr;
spec.rgba[0] = spec.rgba[1] = spec.rgba[2] = 0.5f; spec.rgba[0] = spec.rgba[1] = spec.rgba[2] = 0.5f;
spec.rgba[3] = 1.0f; spec.rgba[3] = 1.0f;
spec.fromto[0] = mjNAN; spec.fromto[0] = mjNAN;
spec.userdata.clear(); spec.userdata = nullptr;
// clear internal variables // clear internal variables
spec.material.clear();
body = 0; body = 0;
matid = -1; matid = -1;
@@ -1960,6 +1959,10 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
void mjCSite::CopyFromSpec() { void mjCSite::CopyFromSpec() {
*static_cast<mjmSite*>(this) = spec; *static_cast<mjmSite*>(this) = spec;
userdata_ = spec_userdata_;
material_ = spec_material_;
userdata = userdata_.data();
material = material_.data();
} }
@@ -1969,11 +1972,11 @@ void mjCSite::Compile(void) {
CopyFromSpec(); CopyFromSpec();
// resize userdata // resize userdata
if (userdata.size() > model->nuser_site) { if (userdata_.size() > model->nuser_site) {
throw mjCError(this, "user has more values than nuser_site in site '%s' (id = %d)", throw mjCError(this, "user has more values than nuser_site in site '%s' (id = %d)",
name.c_str(), id); name.c_str(), id);
} }
userdata.resize(model->nuser_site); userdata_.resize(model->nuser_site);
// check type // check type
if (type<0 || type>=mjNGEOMTYPES) { if (type<0 || type>=mjNGEOMTYPES) {
@@ -3500,7 +3503,7 @@ void mjCEquality::Compile(void) {
mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) { mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
// tendon defaults // tendon defaults
group = 0; group = 0;
material.clear(); material_.clear();
width = 0.003; width = 0.003;
limited = 2; limited = 2;
range[0] = 0; range[0] = 0;
+35 -6
View File
@@ -390,6 +390,9 @@ class mjCGeom : public mjCBase {
bool IsVisual(void) const { return visual_; } bool IsVisual(void) const { return visual_; }
void SetNotVisual(void) { visual_ = false; } void SetNotVisual(void) { visual_ = false; }
void set_material(std::string _material) { material_ = _material; }
std::string& get_material() { return material_; }
// Compute all coefs modeling the interaction with the surrounding fluid. // Compute all coefs modeling the interaction with the surrounding fluid.
void SetFluidCoefs(void); void SetFluidCoefs(void);
// Compute the kappa coefs of the added inertia due to the surrounding fluid. // Compute the kappa coefs of the added inertia due to the surrounding fluid.
@@ -418,7 +421,6 @@ class mjCGeom : public mjCBase {
std::string hfieldname; // hfield attached to geom std::string hfieldname; // hfield attached to geom
std::string meshname; // mesh attached to geom std::string meshname; // mesh attached to geom
double fitscale; // scale mesh uniformly double fitscale; // scale mesh uniformly
std::string material; // name of material used for rendering
std::vector<double> userdata; // user data std::vector<double> userdata; // user data
float rgba[4]; // rgba when material is omitted float rgba[4]; // rgba when material is omitted
mjtMeshType typeinertia; // selects between surface and volume inertia mjtMeshType typeinertia; // selects between surface and volume inertia
@@ -440,6 +442,7 @@ class mjCGeom : public mjCBase {
double GetRBound(void); // compute bounding sphere radius double GetRBound(void); // compute bounding sphere radius
void ComputeAABB(void); // compute axis-aligned bounding box void ComputeAABB(void); // compute axis-aligned bounding box
std::string material_; // name of material used for rendering
bool visual_; // true: geom does not collide and is unreferenced bool visual_; // true: geom does not collide and is unreferenced
int matid; // id of geom's material int matid; // id of geom's material
mjCMesh* mesh; // geom's mesh mjCMesh* mesh; // geom's mesh
@@ -461,8 +464,8 @@ typedef struct _mjmSite {
double size[3]; // geom size for rendering double size[3]; // geom size for rendering
double pos[3]; // position double pos[3]; // position
double quat[4]; // orientation double quat[4]; // orientation
std::string material; // name of material for rendering char* material; // name of material for rendering
std::vector<double> userdata; // user data double* userdata; // user data
float rgba[4]; // rgba when material is omitted float rgba[4]; // rgba when material is omitted
double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid
mjCAlternative alt; // alternative orientation specification mjCAlternative alt; // alternative orientation specification
@@ -478,12 +481,30 @@ class mjCSite : public mjCBase, private mjmSite {
public: public:
mjmSite spec; // variables set by user mjmSite spec; // variables set by user
void set_material(std::string _material) {
spec_material_ = _material;
spec.material = spec_material_.data();
}
void set_userdata(std::vector<double> _userdata) {
spec_userdata_ = _userdata;
spec.userdata = spec_userdata_.data();
}
std::vector<double>& get_userdata() { return userdata_; }
std::string& get_material() { return material_; }
// variables computed by 'compile' and 'mjCBody::addSite' // variables computed by 'compile' and 'mjCBody::addSite'
private: private:
mjCSite(mjCModel* = 0, mjCDef* = 0); // constructor mjCSite(mjCModel* = 0, mjCDef* = 0); // constructor
void Compile(void); // compiler void Compile(void); // compiler
void CopyFromSpec(); // copy spec into attributes void CopyFromSpec(); // copy spec into attributes
// variable-size data
std::string material_;
std::vector<double> userdata_;
std::string spec_material_;
std::vector<double> spec_userdata_;
mjCBody* body; // site's body mjCBody* body; // site's body
int matid; // material id for rendering int matid; // material id for rendering
}; };
@@ -573,6 +594,9 @@ class mjCFlex: public mjCBase {
friend class mjXWriter; friend class mjXWriter;
public: public:
void set_material(std::string _material) { material_ = _material; }
std::string& get_material() { return material_; }
// contact properties // contact properties
int contype; // contact type int contype; // contact type
int conaffinity; // contact affinity int conaffinity; // contact affinity
@@ -595,7 +619,6 @@ class mjCFlex: public mjCBase {
int group; // group for visualizatioh int group; // group for visualizatioh
double edgestiffness; // edge stiffness double edgestiffness; // edge stiffness
double edgedamping; // edge damping double edgedamping; // edge damping
std::string material; // name of material used for rendering
float rgba[4]; // rgba when material is omitted float rgba[4]; // rgba when material is omitted
std::vector<std::string> vertbody; // vertex body names std::vector<std::string> vertbody; // vertex body names
@@ -626,6 +649,7 @@ class mjCFlex: public mjCBase {
std::vector<int> evpair; // element-vertex pairs std::vector<int> evpair; // element-vertex pairs
std::vector<mjtNum> vertxpos; // global vertex positions std::vector<mjtNum> vertxpos; // global vertex positions
mjCBoundingVolumeHierarchy tree; // bounding volume hierarchy mjCBoundingVolumeHierarchy tree; // bounding volume hierarchy
std::string material_; // name of material used for rendering
}; };
@@ -799,9 +823,10 @@ class mjCSkin: public mjCBase {
public: public:
std::string get_file() const { return file; } std::string get_file() const { return file; }
void set_material(std::string _material) { material_ = _material; }
std::string& get_material() { return material_; }
std::string file; // skin file std::string file; // skin file
std::string material; // name of material used for rendering
float rgba[4]; // rgba when material is omitted float rgba[4]; // rgba when material is omitted
float inflate; // inflate in normal direction float inflate; // inflate in normal direction
int group; // group for visualization int group; // group for visualization
@@ -824,6 +849,7 @@ class mjCSkin: public mjCBase {
void Compile(const mjVFS* vfs); // compiler void Compile(const mjVFS* vfs); // compiler
void LoadSKN(mjResource* resource); // load skin in SKN BIN format void LoadSKN(mjResource* resource); // load skin in SKN BIN format
std::string material_; // name of material used for rendering
int matid; // material id int matid; // material id
std::vector<int> bodyid; // body ids std::vector<int> bodyid; // body ids
}; };
@@ -1059,6 +1085,9 @@ class mjCTendon : public mjCBase {
friend class mjXWriter; friend class mjXWriter;
public: public:
void set_material(std::string _material) { material_ = _material; }
std::string& get_material() { return material_; }
// API for adding wrapping objects // API for adding wrapping objects
void WrapSite(std::string name, int row=-1, int col=-1); // site void WrapSite(std::string name, int row=-1, int col=-1); // site
void WrapGeom(std::string name, std::string side, int row=-1, int col=-1); // geom void WrapGeom(std::string name, std::string side, int row=-1, int col=-1); // geom
@@ -1071,7 +1100,6 @@ class mjCTendon : public mjCBase {
// variables set by user // variables set by user
int group; // group for visualization int group; // group for visualization
std::string material; // name of material for rendering
int limited; // does tendon have limits: 0 false, 1 true, 2 auto int limited; // does tendon have limits: 0 false, 1 true, 2 auto
double width; // width for rendering double width; // width for rendering
mjtNum solref_limit[mjNREF]; // solver reference: tendon limits mjtNum solref_limit[mjNREF]; // solver reference: tendon limits
@@ -1092,6 +1120,7 @@ class mjCTendon : public mjCBase {
~mjCTendon(); // destructor ~mjCTendon(); // destructor
void Compile(void); // compiler void Compile(void); // compiler
std::string material_; // name of material for rendering
int matid; // material id for rendering int matid; // material id for rendering
std::vector<mjCWrap*> path; // wrapping objects std::vector<mjCWrap*> path; // wrapping objects
}; };
+17 -11
View File
@@ -1279,7 +1279,7 @@ void mjXReader::OneFlex(XMLElement* elem, mjCFlex* pflex) {
// read attributes // read attributes
ReadAttrTxt(elem, "name", pflex->name); ReadAttrTxt(elem, "name", pflex->name);
ReadAttr(elem, "radius", 1, &pflex->radius, text); ReadAttr(elem, "radius", 1, &pflex->radius, text);
ReadAttrTxt(elem, "material", pflex->material); ReadAttrTxt(elem, "material", pflex->get_material());
ReadAttr(elem, "rgba", 4, pflex->rgba, text); ReadAttr(elem, "rgba", 4, pflex->rgba, text);
if (MapValue(elem, "flatskin", &n, bool_map, 2)) { if (MapValue(elem, "flatskin", &n, bool_map, 2)) {
pflex->flatskin = (n==1); pflex->flatskin = (n==1);
@@ -1381,7 +1381,7 @@ void mjXReader::OneSkin(XMLElement* elem, mjCSkin* pskin) {
// read attributes // read attributes
ReadAttrTxt(elem, "name", pskin->name); ReadAttrTxt(elem, "name", pskin->name);
ReadAttrTxt(elem, "file", pskin->file); ReadAttrTxt(elem, "file", pskin->file);
ReadAttrTxt(elem, "material", pskin->material); ReadAttrTxt(elem, "material", pskin->get_material());
ReadAttrInt(elem, "group", &pskin->group); ReadAttrInt(elem, "group", &pskin->group);
if (pskin->group<0 || pskin->group>=mjNGROUP) { if (pskin->group<0 || pskin->group>=mjNGROUP) {
throw mjXError(elem, "skin group must be between 0 and 5"); throw mjXError(elem, "skin group must be between 0 and 5");
@@ -1528,7 +1528,7 @@ void mjXReader::OneGeom(XMLElement* elem, mjCGeom* pgeom) {
ReadAttrTxt(elem, "hfield", pgeom->hfieldname); ReadAttrTxt(elem, "hfield", pgeom->hfieldname);
ReadAttrTxt(elem, "mesh", pgeom->meshname); ReadAttrTxt(elem, "mesh", pgeom->meshname);
ReadAttr(elem, "fitscale", 1, &pgeom->fitscale, text); ReadAttr(elem, "fitscale", 1, &pgeom->fitscale, text);
ReadAttrTxt(elem, "material", pgeom->material); ReadAttrTxt(elem, "material", pgeom->get_material());
ReadAttr(elem, "rgba", 4, pgeom->rgba, text); ReadAttr(elem, "rgba", 4, pgeom->rgba, text);
if (MapValue(elem, "fluidshape", &n, fluid_map, 2)) { if (MapValue(elem, "fluidshape", &n, fluid_map, 2)) {
pgeom->fluid_switch = (n == 1); pgeom->fluid_switch = (n == 1);
@@ -1567,6 +1567,8 @@ void mjXReader::OneSite(XMLElement* elem, mjCSite* site) {
int n; int n;
string text; string text;
mjmSite* psite = &site->spec; mjmSite* psite = &site->spec;
std::vector<double> userdata;
std::string material;
// read attributes // read attributes
ReadAttrTxt(elem, "name", site->name); ReadAttrTxt(elem, "name", site->name);
@@ -1578,13 +1580,15 @@ void mjXReader::OneSite(XMLElement* elem, mjCSite* site) {
ReadAttrInt(elem, "group", &psite->group); ReadAttrInt(elem, "group", &psite->group);
ReadAttr(elem, "pos", 3, psite->pos, text); ReadAttr(elem, "pos", 3, psite->pos, text);
ReadQuat(elem, "quat", psite->quat, text); ReadQuat(elem, "quat", psite->quat, text);
ReadAttrTxt(elem, "material", psite->material); ReadAttrTxt(elem, "material", material);
ReadAttr(elem, "rgba", 4, psite->rgba, text); ReadAttr(elem, "rgba", 4, psite->rgba, text);
ReadAttr(elem, "fromto", 6, psite->fromto, text); ReadAttr(elem, "fromto", 6, psite->fromto, text);
ReadAlternative(elem, psite->alt); ReadAlternative(elem, psite->alt);
ReadVector(elem, "user", userdata, text);
// read userdata // set variable-size attributes
ReadVector(elem, "user", psite->userdata, text); site->set_userdata(userdata);
site->set_material(material);
GetXMLPos(elem, site); GetXMLPos(elem, site);
} }
@@ -1773,7 +1777,7 @@ void mjXReader::OneTendon(XMLElement* elem, mjCTendon* pten) {
ReadAttrTxt(elem, "name", pten->name); ReadAttrTxt(elem, "name", pten->name);
ReadAttrTxt(elem, "class", pten->classname); ReadAttrTxt(elem, "class", pten->classname);
ReadAttrInt(elem, "group", &pten->group); ReadAttrInt(elem, "group", &pten->group);
ReadAttrTxt(elem, "material", pten->material); ReadAttrTxt(elem, "material", pten->get_material());
MapValue(elem, "limited", &pten->limited, TFAuto_map, 3); MapValue(elem, "limited", &pten->limited, TFAuto_map, 3);
ReadAttr(elem, "width", 1, &pten->width, text); ReadAttr(elem, "width", 1, &pten->width, text);
ReadAttr(elem, "solreflimit", mjNREF, pten->solref_limit, text, false, false); ReadAttr(elem, "solreflimit", mjNREF, pten->solref_limit, text, false, false);
@@ -2158,7 +2162,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjCBody* pbody, mjCDef* def) {
ReadAttr(egeom, "solimp", mjNIMP, comp.def[0].geom.solimp, text, false, false); ReadAttr(egeom, "solimp", mjNIMP, comp.def[0].geom.solimp, text, false, false);
ReadAttr(egeom, "margin", 1, &comp.def[0].geom.margin, text); ReadAttr(egeom, "margin", 1, &comp.def[0].geom.margin, text);
ReadAttr(egeom, "gap", 1, &comp.def[0].geom.gap, text); ReadAttr(egeom, "gap", 1, &comp.def[0].geom.gap, text);
ReadAttrTxt(egeom, "material", comp.def[0].geom.material); ReadAttrTxt(egeom, "material", comp.def[0].geom.get_material());
ReadAttr(egeom, "rgba", 4, comp.def[0].geom.rgba, text); ReadAttr(egeom, "rgba", 4, comp.def[0].geom.rgba, text);
ReadAttr(egeom, "mass", 1, &comp.def[0].geom._mass, text); ReadAttr(egeom, "mass", 1, &comp.def[0].geom._mass, text);
ReadAttr(egeom, "density", 1, &comp.def[0].geom.density, text); ReadAttr(egeom, "density", 1, &comp.def[0].geom.density, text);
@@ -2167,11 +2171,13 @@ void mjXReader::OneComposite(XMLElement* elem, mjCBody* pbody, mjCDef* def) {
// site // site
XMLElement* esite = elem->FirstChildElement("site"); XMLElement* esite = elem->FirstChildElement("site");
if (esite) { if (esite) {
std::string material;
mjmSite& dsite = comp.def[0].site.spec; mjmSite& dsite = comp.def[0].site.spec;
ReadAttr(esite, "size", 3, dsite.size, text, false, false); ReadAttr(esite, "size", 3, dsite.size, text, false, false);
ReadAttrInt(esite, "group", &dsite.group); ReadAttrInt(esite, "group", &dsite.group);
ReadAttrTxt(esite, "material", dsite.material); ReadAttrTxt(esite, "material", material);
ReadAttr(esite, "rgba", 4, dsite.rgba, text); ReadAttr(esite, "rgba", 4, dsite.rgba, text);
comp.def[0].site.set_material(material);
} }
// joint // joint
@@ -2249,7 +2255,7 @@ void mjXReader::OneComposite(XMLElement* elem, mjCBody* pbody, mjCDef* def) {
ReadAttr(eten, "stiffness", 1, &comp.def[kind].tendon.stiffness, text); ReadAttr(eten, "stiffness", 1, &comp.def[kind].tendon.stiffness, text);
ReadAttr(eten, "damping", 1, &comp.def[kind].tendon.damping, text); ReadAttr(eten, "damping", 1, &comp.def[kind].tendon.damping, text);
ReadAttr(eten, "frictionloss", 1, &comp.def[kind].tendon.frictionloss, text); ReadAttr(eten, "frictionloss", 1, &comp.def[kind].tendon.frictionloss, text);
ReadAttrTxt(eten, "material", comp.def[kind].tendon.material); ReadAttrTxt(eten, "material", comp.def[kind].tendon.get_material());
ReadAttr(eten, "rgba", 4, comp.def[kind].tendon.rgba, text); ReadAttr(eten, "rgba", 4, comp.def[kind].tendon.rgba, text);
ReadAttr(eten, "width", 1, &comp.def[kind].tendon.width, text); ReadAttr(eten, "width", 1, &comp.def[kind].tendon.width, text);
@@ -2303,7 +2309,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjCBody* pbody) {
ReadAttr(elem, "mass", 1, &fcomp.mass, text); ReadAttr(elem, "mass", 1, &fcomp.mass, text);
ReadAttr(elem, "inertiabox", 1, &fcomp.inertiabox, text); ReadAttr(elem, "inertiabox", 1, &fcomp.inertiabox, text);
ReadAttrTxt(elem, "file", fcomp.file); ReadAttrTxt(elem, "file", fcomp.file);
ReadAttrTxt(elem, "material", fcomp.def.flex.material); ReadAttrTxt(elem, "material", fcomp.def.flex.get_material());
ReadAttr(elem, "rgba", 4, fcomp.def.flex.rgba, text); ReadAttr(elem, "rgba", 4, fcomp.def.flex.rgba, text);
if (MapValue(elem, "flatskin", &n, bool_map, 2)) { if (MapValue(elem, "flatskin", &n, bool_map, 2)) {
fcomp.def.flex.flatskin = (n==1); fcomp.def.flex.flatskin = (n==1);
+11 -11
View File
@@ -90,8 +90,8 @@ void mjXWriter::OneFlex(XMLElement* elem, mjCFlex* pflex) {
// common attributes // common attributes
WriteAttrTxt(elem, "name", pflex->name); WriteAttrTxt(elem, "name", pflex->name);
WriteAttr(elem, "radius", 1, &pflex->radius, &defflex.radius); WriteAttr(elem, "radius", 1, &pflex->radius, &defflex.radius);
if (pflex->material != defflex.material) { if (pflex->get_material() != defflex.get_material()) {
WriteAttrTxt(elem, "material", pflex->material); WriteAttrTxt(elem, "material", pflex->get_material());
} }
WriteAttr(elem, "rgba", 4, pflex->rgba, defflex.rgba); WriteAttr(elem, "rgba", 4, pflex->rgba, defflex.rgba);
WriteAttrKey(elem, "flatskin", bool_map, 2, pflex->flatskin, defflex.flatskin); WriteAttrKey(elem, "flatskin", bool_map, 2, pflex->flatskin, defflex.flatskin);
@@ -204,7 +204,7 @@ void mjXWriter::OneSkin(XMLElement* elem, mjCSkin* pskin) {
// write attributes // write attributes
WriteAttrTxt(elem, "name", pskin->name); WriteAttrTxt(elem, "name", pskin->name);
WriteAttrTxt(elem, "file", pskin->file); WriteAttrTxt(elem, "file", pskin->file);
WriteAttrTxt(elem, "material", pskin->material); WriteAttrTxt(elem, "material", pskin->get_material());
WriteAttrInt(elem, "group", pskin->group, 0); WriteAttrInt(elem, "group", pskin->group, 0);
WriteAttr(elem, "rgba", 4, pskin->rgba, mydef.geom.rgba); WriteAttr(elem, "rgba", 4, pskin->rgba, mydef.geom.rgba);
WriteAttr(elem, "inflate", 1, &pskin->inflate, &zero); WriteAttr(elem, "inflate", 1, &pskin->inflate, &zero);
@@ -396,8 +396,8 @@ void mjXWriter::OneGeom(XMLElement* elem, mjCGeom* pgeom, mjCDef* def) {
} else { } else {
WriteAttr(elem, "density", 1, &pgeom->density, &def->geom.density); WriteAttr(elem, "density", 1, &pgeom->density, &def->geom.density);
} }
if (pgeom->material != def->geom.material) { if (pgeom->get_material() != def->geom.get_material()) {
WriteAttrTxt(elem, "material", pgeom->material); WriteAttrTxt(elem, "material", pgeom->get_material());
} }
WriteAttr(elem, "rgba", 4, pgeom->rgba, def->geom.rgba); WriteAttr(elem, "rgba", 4, pgeom->rgba, def->geom.rgba);
@@ -444,16 +444,16 @@ void mjXWriter::OneSite(XMLElement* elem, mjCSite* psite, mjCDef* def) {
// defaults and regular // defaults and regular
WriteAttrInt(elem, "group", psite->group, def->site.group); WriteAttrInt(elem, "group", psite->group, def->site.group);
WriteAttrKey(elem, "type", geom_map, mjNGEOMTYPES, psite->type, def->site.type); WriteAttrKey(elem, "type", geom_map, mjNGEOMTYPES, psite->type, def->site.type);
if (psite->material != def->site.material) { if (psite->get_material() != def->site.get_material()) {
WriteAttrTxt(elem, "material", psite->material); WriteAttrTxt(elem, "material", psite->get_material());
} }
WriteAttr(elem, "rgba", 4, psite->rgba, def->site.rgba); WriteAttr(elem, "rgba", 4, psite->rgba, def->site.rgba);
// userdata // userdata
if (writingdefaults) { if (writingdefaults) {
WriteVector(elem, "user", psite->userdata); WriteVector(elem, "user", psite->get_userdata());
} else { } else {
WriteVector(elem, "user", psite->userdata, def->site.userdata); WriteVector(elem, "user", psite->get_userdata(), def->site.get_userdata());
} }
} }
@@ -636,8 +636,8 @@ void mjXWriter::OneTendon(XMLElement* elem, mjCTendon* pten, mjCDef* def) {
} }
// spatial only // spatial only
if (!fixed) { if (!fixed) {
if (pten->material!=def->tendon.material) { if (pten->get_material()!=def->tendon.get_material()) {
WriteAttrTxt(elem, "material", pten->material); WriteAttrTxt(elem, "material", pten->get_material());
} }
WriteAttr(elem, "width", 1, &pten->width, &def->tendon.width); WriteAttr(elem, "width", 1, &pten->width, &def->tendon.width);
WriteAttr(elem, "rgba", 4, pten->rgba, def->tendon.rgba); WriteAttr(elem, "rgba", 4, pten->rgba, def->tendon.rgba);