Move mjCSite attributes to mjmSite struct.
PiperOrigin-RevId: 603051589 Change-Id: I31eeeccffa15b96e7393b8e64f6be8c964fc5948
This commit is contained in:
committed by
Copybara-Service
parent
fae1f3e56d
commit
7a98038e88
@@ -137,7 +137,7 @@ void mjCComposite::SetDefault(void) {
|
|||||||
// set all deafult groups to 3
|
// set all deafult groups to 3
|
||||||
for (int i=0; i<mjNCOMPKINDS; i++) {
|
for (int i=0; i<mjNCOMPKINDS; i++) {
|
||||||
def[i].geom.group = 3;
|
def[i].geom.group = 3;
|
||||||
def[i].site.group = 3;
|
def[i].site.spec.group = 3;
|
||||||
def[i].tendon.group = 3;
|
def[i].tendon.group = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ bool mjCComposite::MakeParticle(mjCModel* model, mjCBody* body, char* error, int
|
|||||||
// add site
|
// add site
|
||||||
mjCSite* s = b->AddSite(def);
|
mjCSite* s = b->AddSite(def);
|
||||||
s->def = body->def;
|
s->def = body->def;
|
||||||
s->type = mjGEOM_SPHERE;
|
s->spec.type = mjGEOM_SPHERE;
|
||||||
mju::sprintf_arr(txt, "%sS%d", prefix.c_str(), i);
|
mju::sprintf_arr(txt, "%sS%d", prefix.c_str(), i);
|
||||||
s->name = txt;
|
s->name = txt;
|
||||||
|
|
||||||
@@ -607,7 +607,7 @@ bool mjCComposite::MakeGrid(mjCModel* model, mjCBody* body, char* error, int err
|
|||||||
// add site
|
// add site
|
||||||
mjCSite* s = b->AddSite(def);
|
mjCSite* s = b->AddSite(def);
|
||||||
s->def = body->def;
|
s->def = body->def;
|
||||||
s->type = mjGEOM_SPHERE;
|
s->spec.type = mjGEOM_SPHERE;
|
||||||
mju::sprintf_arr(txt, "%sS%d_%d", prefix.c_str(), ix, iy);
|
mju::sprintf_arr(txt, "%sS%d_%d", prefix.c_str(), ix, iy);
|
||||||
s->name = txt;
|
s->name = txt;
|
||||||
|
|
||||||
@@ -871,8 +871,8 @@ mjCBody* mjCComposite::AddCableBody(mjCModel* model, mjCBody* body, int ix, mjtN
|
|||||||
mjCSite* site = body->AddSite(def);
|
mjCSite* site = body->AddSite(def);
|
||||||
site->def = body->def;
|
site->def = body->def;
|
||||||
site->name = txt_site;
|
site->name = txt_site;
|
||||||
mjuu_setvec(site->pos, last ? length : 0, 0, 0);
|
mjuu_setvec(site->spec.pos, last ? length : 0, 0, 0);
|
||||||
mjuu_setvec(site->quat, 1, 0, 0, 0);
|
mjuu_setvec(site->spec.quat, 1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return body;
|
return body;
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ void mjCModel::MakeLists(mjCBody* body) {
|
|||||||
|
|
||||||
// delete material with given name or all materials if the name is omitted
|
// delete material with given name or all materials if the name is omitted
|
||||||
template <class T>
|
template <class T>
|
||||||
static void 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();
|
||||||
@@ -660,6 +660,7 @@ static void DeleteMaterial(std::vector<T*>& list, std::string_view name = "") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// delete texture with given name or all textures if the name is omitted
|
// delete texture with given name or all textures if the name is omitted
|
||||||
template <class T>
|
template <class T>
|
||||||
static void DeleteTexture(std::vector<T*>& list, std::string_view name = "") {
|
static void DeleteTexture(std::vector<T*>& list, std::string_view name = "") {
|
||||||
@@ -2900,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]->userdata.size());
|
nuser_site = mjMAX(nuser_site, sites[i]->spec.userdata.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nuser_cam == -1) {
|
if (nuser_cam == -1) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -192,6 +193,9 @@ class mjCModel {
|
|||||||
template<class T> // if asset name is missing, set to filename
|
template<class T> // if asset name is missing, set to filename
|
||||||
void SetDefaultNames(std::vector<T*>& assets);
|
void SetDefaultNames(std::vector<T*>& assets);
|
||||||
|
|
||||||
|
template <class T> // delete material from object
|
||||||
|
void DeleteMaterial(std::vector<T*>& list, std::string_view name = "");
|
||||||
|
|
||||||
//------------------------ compile phases
|
//------------------------ compile phases
|
||||||
void MakeLists(mjCBody* body); // make lists of bodies, geoms, joints, sites
|
void MakeLists(mjCBody* body); // make lists of bodies, geoms, joints, sites
|
||||||
void IndexAssets(bool discard); // convert asset names into indices
|
void IndexAssets(bool discard); // convert asset names into indices
|
||||||
|
|||||||
+23
-11
@@ -1926,24 +1926,28 @@ void mjCGeom::Compile(void) {
|
|||||||
// initialize default site
|
// initialize default site
|
||||||
mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
|
mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
|
||||||
// set defaults
|
// set defaults
|
||||||
type = mjGEOM_SPHERE;
|
spec.type = mjGEOM_SPHERE;
|
||||||
mjuu_setvec(size, 0.005, 0.005, 0.005);
|
mjuu_setvec(spec.size, 0.005, 0.005, 0.005);
|
||||||
group = 0;
|
spec.group = 0;
|
||||||
mjuu_setvec(quat, 1, 0, 0, 0);
|
mjuu_setvec(spec.quat, 1, 0, 0, 0);
|
||||||
mjuu_setvec(pos, 0, 0, 0);
|
mjuu_setvec(spec.pos, 0, 0, 0);
|
||||||
material.clear();
|
spec.material.clear();
|
||||||
rgba[0] = rgba[1] = rgba[2] = 0.5f;
|
spec.rgba[0] = spec.rgba[1] = spec.rgba[2] = 0.5f;
|
||||||
rgba[3] = 1.0f;
|
spec.rgba[3] = 1.0f;
|
||||||
fromto[0] = mjNAN;
|
spec.fromto[0] = mjNAN;
|
||||||
userdata.clear();
|
spec.userdata.clear();
|
||||||
|
|
||||||
// clear internal variables
|
// clear internal variables
|
||||||
material.clear();
|
spec.material.clear();
|
||||||
body = 0;
|
body = 0;
|
||||||
matid = -1;
|
matid = -1;
|
||||||
|
|
||||||
|
// initialize private attributes
|
||||||
|
CopyFromSpec();
|
||||||
|
|
||||||
// reset to default if given
|
// reset to default if given
|
||||||
if (_def) {
|
if (_def) {
|
||||||
|
_def->site.CopyFromSpec();
|
||||||
*this = _def->site;
|
*this = _def->site;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1954,8 +1958,16 @@ mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void mjCSite::CopyFromSpec() {
|
||||||
|
*static_cast<mjmSite*>(this) = spec;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// compiler
|
// compiler
|
||||||
void mjCSite::Compile(void) {
|
void mjCSite::Compile(void) {
|
||||||
|
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)",
|
||||||
|
|||||||
+13
-9
@@ -455,15 +455,7 @@ class mjCGeom : public mjCBase {
|
|||||||
//------------------------- class mjCSite ----------------------------------------------------------
|
//------------------------- class mjCSite ----------------------------------------------------------
|
||||||
// Describes a site on a body
|
// Describes a site on a body
|
||||||
|
|
||||||
class mjCSite : public mjCBase {
|
typedef struct _mjmSite {
|
||||||
friend class mjCDef;
|
|
||||||
friend class mjCBody;
|
|
||||||
friend class mjCModel;
|
|
||||||
friend class mjXWriter;
|
|
||||||
friend class mjXURDF;
|
|
||||||
|
|
||||||
public:
|
|
||||||
// variables set by user
|
|
||||||
mjtGeom type; // geom type for rendering
|
mjtGeom type; // geom type for rendering
|
||||||
int group; // group id, used for visualization
|
int group; // group id, used for visualization
|
||||||
double size[3]; // geom size for rendering
|
double size[3]; // geom size for rendering
|
||||||
@@ -474,11 +466,23 @@ class mjCSite : public mjCBase {
|
|||||||
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
|
||||||
|
} mjmSite;
|
||||||
|
|
||||||
|
class mjCSite : public mjCBase, private mjmSite {
|
||||||
|
friend class mjCDef;
|
||||||
|
friend class mjCBody;
|
||||||
|
friend class mjCModel;
|
||||||
|
friend class mjXWriter;
|
||||||
|
friend class mjXURDF;
|
||||||
|
|
||||||
|
public:
|
||||||
|
mjmSite spec; // variables set by user
|
||||||
|
|
||||||
// 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
|
||||||
|
|
||||||
mjCBody* body; // site's body
|
mjCBody* body; // site's body
|
||||||
int matid; // material id for rendering
|
int matid; // material id for rendering
|
||||||
|
|||||||
@@ -1563,13 +1563,14 @@ void mjXReader::OneGeom(XMLElement* elem, mjCGeom* pgeom) {
|
|||||||
|
|
||||||
|
|
||||||
// site element parser
|
// site element parser
|
||||||
void mjXReader::OneSite(XMLElement* elem, mjCSite* psite) {
|
void mjXReader::OneSite(XMLElement* elem, mjCSite* site) {
|
||||||
int n;
|
int n;
|
||||||
string text;
|
string text;
|
||||||
|
mjmSite* psite = &site->spec;
|
||||||
|
|
||||||
// read attributes
|
// read attributes
|
||||||
ReadAttrTxt(elem, "name", psite->name);
|
ReadAttrTxt(elem, "name", site->name);
|
||||||
ReadAttrTxt(elem, "class", psite->classname);
|
ReadAttrTxt(elem, "class", site->classname);
|
||||||
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
||||||
psite->type = (mjtGeom)n;
|
psite->type = (mjtGeom)n;
|
||||||
}
|
}
|
||||||
@@ -1585,7 +1586,7 @@ void mjXReader::OneSite(XMLElement* elem, mjCSite* psite) {
|
|||||||
// read userdata
|
// read userdata
|
||||||
ReadVector(elem, "user", psite->userdata, text);
|
ReadVector(elem, "user", psite->userdata, text);
|
||||||
|
|
||||||
GetXMLPos(elem, psite);
|
GetXMLPos(elem, site);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2166,10 +2167,11 @@ 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) {
|
||||||
ReadAttr(esite, "size", 3, comp.def[0].site.size, text, false, false);
|
mjmSite& dsite = comp.def[0].site.spec;
|
||||||
ReadAttrInt(esite, "group", &comp.def[0].site.group);
|
ReadAttr(esite, "size", 3, dsite.size, text, false, false);
|
||||||
ReadAttrTxt(esite, "material", comp.def[0].site.material);
|
ReadAttrInt(esite, "group", &dsite.group);
|
||||||
ReadAttr(esite, "rgba", 4, comp.def[0].site.rgba, text);
|
ReadAttrTxt(esite, "material", dsite.material);
|
||||||
|
ReadAttr(esite, "rgba", 4, dsite.rgba, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
// joint
|
// joint
|
||||||
|
|||||||
Reference in New Issue
Block a user