Compile frames during compilation instead of parsing.

PiperOrigin-RevId: 625717564
Change-Id: Ib82230f6cb423bb3091efd04a7fa0b1411e7cdf1
This commit is contained in:
Alessio Quaglino
2024-04-17 09:54:57 -07:00
committed by Copybara-Service
parent a4c31c09a8
commit 4a76496533
2 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -3118,7 +3118,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
// compile objects in kinematic tree
for (int i=0; i<bodies.size(); i++) {
bodies[i]->Compile(); // also compiles joints, geoms, sites, cameras, lights
bodies[i]->Compile(); // also compiles joints, geoms, sites, cameras, lights, frames
}
// compile all other objects except for keyframes
+17 -4
View File
@@ -628,7 +628,6 @@ void mjCBase::SetFrame(mjCFrame* _frame) {
return;
}
frame = _frame;
frame->Compile();
}
@@ -735,10 +734,19 @@ mjCBody& mjCBody::operator+=(const mjCFrame& other) {
other.model->prefix = other.prefix;
other.model->suffix = other.suffix;
// map old frames to indices
// copy input frame
frames.push_back(new mjCFrame(other));
frames.back()->body = this;
frames.back()->model = model;
frames.back()->frame = other.frame;
// map input frames to index in this->frames
std::map<mjCFrame*, int> fmap;
for (int i=0; i<subtree->frames.size(); i++) {
fmap[subtree->frames[i]] = i;
for (auto frame : subtree->frames) {
if (frame == static_cast<const mjCFrame*>(&other)) {
fmap[frame] = frames.size() - 1;
break;
}
}
// copy children that are inside the input frame
@@ -1212,6 +1220,11 @@ void mjCBody::MakeInertialExplicit() {
void mjCBody::Compile(void) {
CopyFromSpec();
// compile all frames
for (int i=0; i<frames.size(); i++) {
frames[i]->Compile();
}
// resize userdata
if (userdata_.size() > model->nuser_body) {
throw mjCError(this, "user has more values than nuser_body in body '%s' (id = %d)",