Add childclass support to frames.
PiperOrigin-RevId: 615487831 Change-Id: I0e4d2efd52211701b4286a0b0de84424470a3a47
This commit is contained in:
committed by
Copybara-Service
parent
0d16587135
commit
bda03af49a
+3
-1
@@ -156,7 +156,7 @@ typedef struct _mjmPlugin { // plugin specification
|
||||
typedef struct _mjmBody { // body specification
|
||||
mjElement element; // internal, do not modify
|
||||
mjString name; // name
|
||||
mjString classname; // childclass name
|
||||
mjString childclass; // childclass name
|
||||
|
||||
// body frame
|
||||
double pos[3]; // frame position
|
||||
@@ -183,6 +183,8 @@ typedef struct _mjmBody { // body specification
|
||||
|
||||
typedef struct _mjmFrame { // frame specification
|
||||
mjElement element; // internal, do not modify
|
||||
mjString name; // name
|
||||
mjString childclass; // childclass name
|
||||
double pos[3]; // position
|
||||
double quat[4]; // orientation
|
||||
mjmOrientation alt; // alternative orientation
|
||||
|
||||
+17
-11
@@ -636,6 +636,7 @@ void mjCModel::MakeLists(mjCBody* body) {
|
||||
for (int i=0; i<body->sites.size(); i++) sites.push_back(body->sites[i]);
|
||||
for (int i=0; i<body->cameras.size(); i++) cameras.push_back(body->cameras[i]);
|
||||
for (int i=0; i<body->lights.size(); i++) lights.push_back(body->lights[i]);
|
||||
for (int i=0; i<body->frames.size(); i++) frames.push_back(body->frames[i]);
|
||||
|
||||
// recursive call to all child bodies
|
||||
for (int i=0; i<body->bodies.size(); i++) MakeLists(body->bodies[i]);
|
||||
@@ -2679,18 +2680,20 @@ static void reassignid(vector<T*>& list) {
|
||||
template <class T>
|
||||
static void processlist(mjListKeyMap& ids, vector<T*>& list,
|
||||
mjtObj type, bool checkrepeat = true) {
|
||||
// loop over list elements
|
||||
for (size_t i=0; i < list.size(); i++) {
|
||||
// check for incompatible id setting; SHOULD NOT OCCUR
|
||||
if (list[i]->id!=-1 && list[i]->id!=i) {
|
||||
throw mjCError(list[i], "incompatible id in %s array, position %d", mju_type2Str(type), i);
|
||||
// assign ids for regular elements
|
||||
if (type < mjNOBJECT) {
|
||||
for (size_t i=0; i < list.size(); i++) {
|
||||
// check for incompatible id setting; SHOULD NOT OCCUR
|
||||
if (list[i]->id!=-1 && list[i]->id!=i) {
|
||||
throw mjCError(list[i], "incompatible id in %s array, position %d", mju_type2Str(type), i);
|
||||
}
|
||||
|
||||
// id equals position in array
|
||||
list[i]->id = i;
|
||||
|
||||
// add to ids map
|
||||
ids[type][list[i]->name] = i;
|
||||
}
|
||||
|
||||
// id equals position in array
|
||||
list[i]->id = i;
|
||||
|
||||
// add to ids map
|
||||
ids[type][list[i]->name] = i;
|
||||
}
|
||||
|
||||
// check for repeated names
|
||||
@@ -2855,6 +2858,9 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
|
||||
}
|
||||
}
|
||||
|
||||
// check repeated names in meta elements
|
||||
processlist(ids, frames, mjOBJ_FRAME);
|
||||
|
||||
// delete visual assets
|
||||
if (discardvisual) {
|
||||
DeleteAll(materials);
|
||||
|
||||
@@ -250,6 +250,7 @@ class mjCModel : private mjSpec {
|
||||
std::vector<mjCSite*> sites; // list of sites attached to this body
|
||||
std::vector<mjCCamera*> cameras; // list of cameras
|
||||
std::vector<mjCLight*> lights; // list of lights
|
||||
std::vector<mjCFrame*> frames; // list of frames
|
||||
|
||||
// array of pointers to each object list (enumerated by type)
|
||||
std::array<std::vector<mjCBase*>*, mjNOBJECT> object_lists;
|
||||
|
||||
@@ -765,7 +765,7 @@ mjCBody& mjCBody::operator=(const mjCBody& other) {
|
||||
void mjCBody::PointToLocal() {
|
||||
spec.element = (mjElement)this;
|
||||
spec.name = (mjString)&name;
|
||||
spec.classname = (mjString)&classname;
|
||||
spec.childclass = (mjString)&classname;
|
||||
spec.userdata = (mjDoubleVec)&spec_userdata_;
|
||||
spec.plugin.name = (mjString)&plugin_name;
|
||||
spec.plugin.instance_name = (mjString)&plugin_instance_name;
|
||||
@@ -1375,6 +1375,8 @@ mjCFrame& mjCFrame::operator=(const mjCFrame& other) {
|
||||
|
||||
void mjCFrame::PointToLocal() {
|
||||
spec.element = (mjElement)this;
|
||||
spec.name = (mjString)&name;
|
||||
spec.childclass = (mjString)&classname;
|
||||
spec.info = (mjString)&info;
|
||||
}
|
||||
|
||||
|
||||
@@ -321,6 +321,8 @@ class mjCFrame : public mjCFrame_, private mjmFrame {
|
||||
|
||||
public:
|
||||
mjmFrame spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::classname;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
|
||||
Reference in New Issue
Block a user