Add spec lookup in the attached spec array using the compiler option pointer.
This enables to find the spec associated with the compiler option stored in the objects, which do not necessarily belong to the model that owns them. PiperOrigin-RevId: 713259419 Change-Id: I579c770147ff07ed2a5edd20e7a795ee7cc27147
This commit is contained in:
committed by
Copybara-Service
parent
8a5f092081
commit
6654d63438
+25
-2
@@ -146,6 +146,9 @@ mjCModel::mjCModel() {
|
||||
defaults_.push_back(new mjCDef);
|
||||
defaults_.back()->name = "main";
|
||||
|
||||
// point to model from spec
|
||||
PointToLocal();
|
||||
|
||||
// world body
|
||||
mjCBody* world = new mjCBody(this);
|
||||
mjuu_zerovec(world->pos, 3);
|
||||
@@ -163,14 +166,15 @@ mjCModel::mjCModel() {
|
||||
// create mjCBase lists from children lists
|
||||
CreateObjectLists();
|
||||
|
||||
// point to model from spec
|
||||
PointToLocal();
|
||||
// the source spec is the model itself, overwritten in the copy constructor
|
||||
source_spec_ = &spec;
|
||||
}
|
||||
|
||||
|
||||
|
||||
mjCModel::mjCModel(const mjCModel& other) {
|
||||
CreateObjectLists();
|
||||
source_spec_ = (mjSpec*)&other.spec;
|
||||
*this = other;
|
||||
}
|
||||
|
||||
@@ -1222,6 +1226,25 @@ mjSpec* mjCModel::FindSpec(std::string name) const {
|
||||
|
||||
|
||||
|
||||
// find spec by mjsCompiler pointer
|
||||
mjSpec* mjCModel::FindSpec(const mjsCompiler* compiler_) const {
|
||||
for (auto spec : specs_) {
|
||||
if (&(static_cast<const mjCModel*>(spec->element)->GetSourceSpec()->compiler) == compiler_) {
|
||||
return spec;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get the spec from which this model was created
|
||||
mjSpec* mjCModel::GetSourceSpec() const {
|
||||
return source_spec_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------- COMPILER PHASES --------------------------------------------------
|
||||
|
||||
// make lists of objects in tree: bodies, geoms, joints, sites, cameras, lights
|
||||
|
||||
Reference in New Issue
Block a user