Add recursive call to FindSpec for handling nested attachments.

PiperOrigin-RevId: 713629578
Change-Id: I23efa5a86bac187fc42eb955d29cc03cbacfd9e0
This commit is contained in:
Alessio Quaglino
2025-01-09 04:55:19 -08:00
committed by Copybara-Service
parent 40ef08c8ed
commit f7d38dac62
3 changed files with 39 additions and 7 deletions
+3
View File
@@ -151,6 +151,7 @@ mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) {
// set model, def
model = _model;
if (_model) compiler = &_model->spec.compiler;
classname = (_def ? _def->name : (_model ? "main" : ""));
// in case this body is not compiled
@@ -1981,6 +1982,7 @@ mjCSkin::mjCSkin(mjCModel* _model) {
// set model pointer
model = _model;
if (model) compiler = &model->spec.compiler;
// clear data
spec_file_.clear();
@@ -2638,6 +2640,7 @@ mjCFlex::mjCFlex(mjCModel* _model) {
// set model
model = _model;
if (_model) compiler = &_model->spec.compiler;
// clear internal variables
nvert = 0;
+8 -4
View File
@@ -236,7 +236,7 @@ void mjCModel::CopyList(std::vector<T*>& dest,
}
// copy the element from the other model to this model
source[i]->ForgetKeyframes();
mjSpec* origin = FindSpec(mjs_getString(source[i]->model->spec.modelname));
mjSpec* origin = FindSpec(source[i]->compiler);
dest.push_back(candidate);
dest.back()->model = this;
dest.back()->compiler = origin ? &origin->compiler : &spec.compiler;
@@ -1228,9 +1228,13 @@ 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;
if (&GetSourceSpec()->compiler == compiler_) {
return (mjSpec*)&spec;
}
for (auto s : specs_) {
mjSpec* source = static_cast<mjCModel*>(s->element)->FindSpec(compiler_);
if (source) {
return source;
}
}
return nullptr;