Skip to content
Merged
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
18 changes: 11 additions & 7 deletions src/Core_Fix_DynamicBones/Core.DynamicBonesFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ public static void AppendParticles(Transform bone, int parentIndex, float boneLe
int count = dynamicBone.m_Particles.Count;
dynamicBone.m_Particles.Add(particle);
if (!bone) return;
while (bone.childCount > 0)

bool didAppendChildren = false;
while (bone.childCount > 0) // used to traverse down children of children

{
var isNotRoll = false;
var index = 0;
for (var i = 0; i < bone.childCount; i++)
for (var i = 0; i < bone.childCount; i++) // used to loop siblings in children
{
Transform child = bone.GetChild(i);
var notValid = false;
Expand All @@ -104,18 +107,19 @@ public static void AppendParticles(Transform bone, int parentIndex, float boneLe
if (!notValid)
{
AppendParticles(child, count, boneLength, dynamicBone);
return;
didAppendChildren = true;

}
}

// we only end up here if all children were in m_Excludes or at least one child was in m_notRolls
if (isNotRoll) bone = bone.GetChild(index);
else break;
}

// we only end up here if we have broken out of the loop:
// A) because the bone doesn't have any children or B) m_Excludes contains all children
if (dynamicBone.m_EndLength > 0f || dynamicBone.m_EndOffset != Vector3.zero)
// Only add a leaf particle if this particle did not append any of its children:
// A) It does not have children or B) all children are part of m_Exclusions
if (!didAppendChildren && (dynamicBone.m_EndLength > 0f || dynamicBone.m_EndOffset != Vector3.zero))
{
// add the final "leaf" particle, based on the EndOffset
AppendParticles(null, count, boneLength, dynamicBone);
Expand Down