Skip to content

Commit

Permalink
Fix making breadcrumb static if it's a nested model (#2593)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
iche033 and ahcorde authored Sep 10, 2024
1 parent 712643f commit 9b161db
Showing 1 changed file with 26 additions and 1 deletion.
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

0 comments on commit 9b161db

Please sign in to comment.