Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/user/user_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,20 @@ mjCModel& mjCModel::operator+=(const mjCModel& other) {
// do not copy assets for self-attach
// TODO: asset should be copied only when referenced
CopyList(meshes_, other.meshes_);
int old_nskin = skins_.size();
CopyList(skins_, other.skins_);
int new_nskin = skins_.size();

// Iterate ONLY over the newly added skins
for (int i = old_nskin; i < new_nskin; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this can't happen in mjCSkin::Namespace?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for the late reply, was busy with my endsems. actually i dont recall what and why i did but it does not,as if what i did is working in MacOS and not in windows and linux. would try from scratch and will get back to you on this

mjCSkin* skin = skins_[i];
for (std::string& bodyname : skin->bodyname_) {
if (!bodyname.empty()) {
bodyname = prefix + bodyname;
}
}
}

CopyList(hfields_, other.hfields_);
CopyList(textures_, other.textures_);
CopyList(materials_, other.materials_);
Expand Down Expand Up @@ -1921,6 +1934,7 @@ void mjCModel::IndexAssets(bool discard) {
throw mjCError(skin, "material '%s' not found in skin %d", skin->material_.c_str(), i);
}
}
skin->ResolveReferences(this);
}

// materials referenced in sites
Expand Down
23 changes: 22 additions & 1 deletion src/user/user_objects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2598,7 +2598,28 @@ void mjCBody::Compile(void) {
}



// skin attach issue fix---------
void mjCSkin::ResolveReferences(const mjCModel* m) {
// Resize the bodyid list to match the bodyname list
bodyid.resize(bodyname_.size());

for (int i = 0; i < bodyname_.size(); ++i) {
if (!bodyname_[i].empty()) {
// Find the body object using the (now prefixed) name
mjCBody* b = (mjCBody*)m->FindObject(mjOBJ_BODY, bodyname_[i]);
if (b) {
// Success! Store the numerical ID.
bodyid[i] = b->id;
} else {
// This is the error we are fixing!
throw mjCError(this, "unknown body '%s' in skin", bodyname_[i].c_str());
}
} else {
// This bone doesn't reference a body.
bodyid[i] = -1;
}
}
}
//------------------ class mjCFrame implementation -------------------------------------------------

// initialize frame
Expand Down
Loading