Skip to content

Fix making breadcrumb static if it's a nested model #2593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 10, 2024
Merged
27 changes: 26 additions & 1 deletion src/systems/breadcrumbs/Breadcrumbs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,33 @@ bool Breadcrumbs::MakeStatic(Entity _entity, EntityComponentManager &_ecm)
Entity childLinkEntity = _ecm.EntityByComponents(
components::CanonicalLink(), components::ParentEntity(_entity));

// If the entity does not have a canonical link, it may be a nested model
if (childLinkEntity == kNullEntity)
return false;
{
// Find canonical link within nested model
auto findCanonicalLink = [&_ecm](Entity _parent, auto &&_findCanonicalLink)
{
auto nestedEntities = _ecm.EntitiesByComponents(
components::Model(), components::ParentEntity(_parent));
for (const auto ent : nestedEntities)
{
auto comp = _ecm.Component<components::ModelCanonicalLink>(ent);
if (comp)
{
return comp->Data();;
}
else
{
// recursively search for canonical link
return _findCanonicalLink(ent, _findCanonicalLink);
}
}
return kNullEntity;
};
childLinkEntity = findCanonicalLink(_entity, findCanonicalLink);
if (childLinkEntity == kNullEntity)
return false;
}

Entity detachableJointEntity = _ecm.CreateEntity();
_ecm.CreateComponent(detachableJointEntity,
Expand Down
Loading