Convert mjmStruct to a C-struct.
PiperOrigin-RevId: 603357871 Change-Id: I27918b0030fc6a589c361cad965611adc3bf7247
This commit is contained in:
committed by
Copybara-Service
parent
7a98038e88
commit
b3f93d436b
@@ -1243,7 +1243,7 @@ void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) {
|
||||
mjCSkin* skin = model->AddSkin();
|
||||
mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
|
||||
skin->name = txt;
|
||||
skin->material = skinmaterial;
|
||||
skin->set_material(skinmaterial);
|
||||
mjuu_copyvec(skin->rgba, skinrgba, 4);
|
||||
skin->inflate = inflate;
|
||||
skin->group = skingroup;
|
||||
@@ -1845,7 +1845,7 @@ void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
|
||||
mjCSkin* skin = model->AddSkin();
|
||||
mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
|
||||
skin->name = txt;
|
||||
skin->material = skinmaterial;
|
||||
skin->set_material(skinmaterial);
|
||||
mjuu_copyvec(skin->rgba, skinrgba, 4);
|
||||
skin->inflate = inflate;
|
||||
skin->group = skingroup;
|
||||
@@ -1998,7 +1998,7 @@ void mjCComposite::MakeSkin3(mjCModel* model) {
|
||||
mjCSkin* skin = model->AddSkin();
|
||||
mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
|
||||
skin->name = txt;
|
||||
skin->material = skinmaterial;
|
||||
skin->set_material(skinmaterial);
|
||||
mjuu_copyvec(skin->rgba, skinrgba, 4);
|
||||
skin->inflate = skininflate;
|
||||
skin->group = skingroup;
|
||||
|
||||
@@ -1878,7 +1878,7 @@ mjCSkin::mjCSkin(mjCModel* _model) {
|
||||
|
||||
// clear data
|
||||
file.clear();
|
||||
material.clear();
|
||||
material_.clear();
|
||||
rgba[0] = rgba[1] = rgba[2] = 0.5f;
|
||||
rgba[3] = 1.0f;
|
||||
inflate = 0;
|
||||
@@ -1903,7 +1903,7 @@ mjCSkin::mjCSkin(mjCModel* _model) {
|
||||
// destructor
|
||||
mjCSkin::~mjCSkin() {
|
||||
file.clear();
|
||||
material.clear();
|
||||
material_.clear();
|
||||
vert.clear();
|
||||
texcoord.clear();
|
||||
face.clear();
|
||||
@@ -2005,11 +2005,11 @@ void mjCSkin::Compile(const mjVFS* vfs) {
|
||||
}
|
||||
|
||||
// resolve material name
|
||||
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material);
|
||||
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material_);
|
||||
if (pmat) {
|
||||
matid = pmat->id;
|
||||
} else if (!material.empty()) {
|
||||
throw mjCError(this, "unkown material '%s' in skin", material.c_str());
|
||||
} else if (!material_.empty()) {
|
||||
throw mjCError(this, "unkown material '%s' in skin", material_.c_str());
|
||||
}
|
||||
|
||||
// set total vertex weights to 0
|
||||
@@ -2239,7 +2239,7 @@ mjCFlex::mjCFlex(mjCModel* _model) {
|
||||
group = 0;
|
||||
edgestiffness = 0;
|
||||
edgedamping = 0;
|
||||
material.clear();
|
||||
material_.clear();
|
||||
rgba[0] = rgba[1] = rgba[2] = 0.5f;
|
||||
rgba[3] = 1.0f;
|
||||
|
||||
@@ -2314,11 +2314,11 @@ void mjCFlex::Compile(const mjVFS* vfs) {
|
||||
}
|
||||
|
||||
// resolve material name
|
||||
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material);
|
||||
mjCBase* pmat = model->FindObject(mjOBJ_MATERIAL, material_);
|
||||
if (pmat) {
|
||||
matid = pmat->id;
|
||||
} else if (!material.empty()) {
|
||||
throw mjCError(this, "unkown material '%s' in flex", material.c_str());
|
||||
} else if (!material_.empty()) {
|
||||
throw mjCError(this, "unkown material '%s' in flex", material_.c_str());
|
||||
}
|
||||
|
||||
// resolve body ids
|
||||
|
||||
+17
-17
@@ -653,8 +653,8 @@ void mjCModel::MakeLists(mjCBody* body) {
|
||||
template <class T>
|
||||
void mjCModel::DeleteMaterial(std::vector<T*>& list, std::string_view name) {
|
||||
for (T* plist : list) {
|
||||
if (name.empty() || plist->material == name) {
|
||||
plist->material.clear();
|
||||
if (name.empty() || plist->material_ == name) {
|
||||
plist->material_.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -775,12 +775,12 @@ void mjCModel::IndexAssets(bool discard) {
|
||||
mjCGeom* pgeom = geoms[i];
|
||||
|
||||
// find material by name
|
||||
if (!pgeom->material.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pgeom->material);
|
||||
if (!pgeom->material_.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pgeom->material_);
|
||||
if (m) {
|
||||
pgeom->matid = m->id;
|
||||
} 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];
|
||||
|
||||
// find material by name
|
||||
if (!pskin->material.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pskin->material);
|
||||
if (!pskin->material_.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pskin->material_);
|
||||
if (m) {
|
||||
pskin->matid = m->id;
|
||||
} 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];
|
||||
|
||||
// find material by name
|
||||
if (!psite->material.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, psite->material);
|
||||
if (!psite->material_.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, psite->get_material());
|
||||
if (m) {
|
||||
psite->matid = m->id;
|
||||
} 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];
|
||||
|
||||
// find material by name
|
||||
if (!pten->material.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pten->material);
|
||||
if (!pten->material_.empty()) {
|
||||
mjCBase* m = FindObject(mjOBJ_MATERIAL, pten->material_);
|
||||
if (m) {
|
||||
pten->matid = m->id;
|
||||
} 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_pos+3*sid, ps->pos, 3);
|
||||
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);
|
||||
|
||||
// determine sameframe
|
||||
@@ -2901,7 +2901,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
|
||||
if (nuser_site == -1) {
|
||||
nuser_site = 0;
|
||||
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) {
|
||||
@@ -3407,7 +3407,7 @@ bool mjCModel::CopyBack(const mjModel* m) {
|
||||
copyvec(sites[i]->rgba, m->site_rgba+4*i, 4);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -497,7 +497,7 @@ void mjCDef::Compile(const mjCModel* model) {
|
||||
// enforce length of all default userdata arrays
|
||||
joint.userdata.resize(model->nuser_jnt);
|
||||
geom.userdata.resize(model->nuser_geom);
|
||||
site.userdata.resize(model->nuser_site);
|
||||
site.userdata_.resize(model->nuser_site);
|
||||
camera.userdata.resize(model->nuser_cam);
|
||||
tendon.userdata.resize(model->nuser_tendon);
|
||||
actuator.userdata.resize(model->nuser_actuator);
|
||||
@@ -1356,7 +1356,7 @@ mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) {
|
||||
density = 1000; // water density (1000 kg / m^3)
|
||||
meshname.clear();
|
||||
fitscale = 1;
|
||||
material.clear();
|
||||
material_.clear();
|
||||
rgba[0] = rgba[1] = rgba[2] = 0.5f;
|
||||
rgba[3] = 1.0f;
|
||||
userdata.clear();
|
||||
@@ -1931,14 +1931,13 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
|
||||
spec.group = 0;
|
||||
mjuu_setvec(spec.quat, 1, 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[3] = 1.0f;
|
||||
spec.fromto[0] = mjNAN;
|
||||
spec.userdata.clear();
|
||||
spec.userdata = nullptr;
|
||||
|
||||
// clear internal variables
|
||||
spec.material.clear();
|
||||
body = 0;
|
||||
matid = -1;
|
||||
|
||||
@@ -1960,6 +1959,10 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
|
||||
|
||||
void mjCSite::CopyFromSpec() {
|
||||
*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();
|
||||
|
||||
// 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)",
|
||||
name.c_str(), id);
|
||||
}
|
||||
userdata.resize(model->nuser_site);
|
||||
userdata_.resize(model->nuser_site);
|
||||
|
||||
// check type
|
||||
if (type<0 || type>=mjNGEOMTYPES) {
|
||||
@@ -3500,7 +3503,7 @@ void mjCEquality::Compile(void) {
|
||||
mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) {
|
||||
// tendon defaults
|
||||
group = 0;
|
||||
material.clear();
|
||||
material_.clear();
|
||||
width = 0.003;
|
||||
limited = 2;
|
||||
range[0] = 0;
|
||||
|
||||
+35
-6
@@ -390,6 +390,9 @@ class mjCGeom : public mjCBase {
|
||||
bool IsVisual(void) const { return visual_; }
|
||||
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.
|
||||
void SetFluidCoefs(void);
|
||||
// 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 meshname; // mesh attached to geom
|
||||
double fitscale; // scale mesh uniformly
|
||||
std::string material; // name of material used for rendering
|
||||
std::vector<double> userdata; // user data
|
||||
float rgba[4]; // rgba when material is omitted
|
||||
mjtMeshType typeinertia; // selects between surface and volume inertia
|
||||
@@ -440,6 +442,7 @@ class mjCGeom : public mjCBase {
|
||||
double GetRBound(void); // compute bounding sphere radius
|
||||
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
|
||||
int matid; // id of geom's material
|
||||
mjCMesh* mesh; // geom's mesh
|
||||
@@ -461,8 +464,8 @@ typedef struct _mjmSite {
|
||||
double size[3]; // geom size for rendering
|
||||
double pos[3]; // position
|
||||
double quat[4]; // orientation
|
||||
std::string material; // name of material for rendering
|
||||
std::vector<double> userdata; // user data
|
||||
char* material; // name of material for rendering
|
||||
double* userdata; // user data
|
||||
float rgba[4]; // rgba when material is omitted
|
||||
double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid
|
||||
mjCAlternative alt; // alternative orientation specification
|
||||
@@ -478,12 +481,30 @@ class mjCSite : public mjCBase, private mjmSite {
|
||||
public:
|
||||
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'
|
||||
private:
|
||||
mjCSite(mjCModel* = 0, mjCDef* = 0); // constructor
|
||||
void Compile(void); // compiler
|
||||
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
|
||||
int matid; // material id for rendering
|
||||
};
|
||||
@@ -573,6 +594,9 @@ class mjCFlex: public mjCBase {
|
||||
friend class mjXWriter;
|
||||
|
||||
public:
|
||||
void set_material(std::string _material) { material_ = _material; }
|
||||
std::string& get_material() { return material_; }
|
||||
|
||||
// contact properties
|
||||
int contype; // contact type
|
||||
int conaffinity; // contact affinity
|
||||
@@ -595,7 +619,6 @@ class mjCFlex: public mjCBase {
|
||||
int group; // group for visualizatioh
|
||||
double edgestiffness; // edge stiffness
|
||||
double edgedamping; // edge damping
|
||||
std::string material; // name of material used for rendering
|
||||
float rgba[4]; // rgba when material is omitted
|
||||
|
||||
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<mjtNum> vertxpos; // global vertex positions
|
||||
mjCBoundingVolumeHierarchy tree; // bounding volume hierarchy
|
||||
std::string material_; // name of material used for rendering
|
||||
};
|
||||
|
||||
|
||||
@@ -799,9 +823,10 @@ class mjCSkin: public mjCBase {
|
||||
|
||||
public:
|
||||
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 material; // name of material used for rendering
|
||||
float rgba[4]; // rgba when material is omitted
|
||||
float inflate; // inflate in normal direction
|
||||
int group; // group for visualization
|
||||
@@ -824,6 +849,7 @@ class mjCSkin: public mjCBase {
|
||||
void Compile(const mjVFS* vfs); // compiler
|
||||
void LoadSKN(mjResource* resource); // load skin in SKN BIN format
|
||||
|
||||
std::string material_; // name of material used for rendering
|
||||
int matid; // material id
|
||||
std::vector<int> bodyid; // body ids
|
||||
};
|
||||
@@ -1059,6 +1085,9 @@ class mjCTendon : public mjCBase {
|
||||
friend class mjXWriter;
|
||||
|
||||
public:
|
||||
void set_material(std::string _material) { material_ = _material; }
|
||||
std::string& get_material() { return material_; }
|
||||
|
||||
// API for adding wrapping objects
|
||||
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
|
||||
@@ -1071,7 +1100,6 @@ class mjCTendon : public mjCBase {
|
||||
|
||||
// variables set by user
|
||||
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
|
||||
double width; // width for rendering
|
||||
mjtNum solref_limit[mjNREF]; // solver reference: tendon limits
|
||||
@@ -1092,6 +1120,7 @@ class mjCTendon : public mjCBase {
|
||||
~mjCTendon(); // destructor
|
||||
void Compile(void); // compiler
|
||||
|
||||
std::string material_; // name of material for rendering
|
||||
int matid; // material id for rendering
|
||||
std::vector<mjCWrap*> path; // wrapping objects
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user