Fix crash when using degenerated triangle in Multi Blend 2D to properly sample animation

#2118
This commit is contained in:
Wojtek Figat
2024-01-05 11:52:28 +01:00
parent d9ca3e5b57
commit 60fd4702a6

View File

@@ -1367,33 +1367,29 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
} }
// Use 1D blend if points are on the same line (degenerated triangle) // Use 1D blend if points are on the same line (degenerated triangle)
// TODO: simplify this code struct BlendData
{
float AlphaX, AlphaY;
Animation* AnimA, *AnimB;
const Float4* AnimAd, *AnimBd;
};
BlendData blendData;
if (v1.Y >= v0.Y) if (v1.Y >= v0.Y)
{ {
if (p.Y < v0.Y && v1.Y >= v0.Y) if (p.Y < v0.Y && v1.Y >= v0.Y)
{ blendData = { p.Y, v0.Y, aAnim, bAnim, &aData, &bData };
const float alpha = p.Y / v0.Y;
value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, aAnim, bAnim, aData.W, bData.W, alpha);
}
else else
{ blendData = { p.Y - v0.Y, v1.Y - v0.Y, bAnim, cAnim, &bData, &cData };
const float alpha = (p.Y - v0.Y) / (v1.Y - v0.Y);
value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, bAnim, cAnim, bData.W, cData.W, alpha);
}
} }
else else
{ {
if (p.Y < v1.Y) if (p.Y < v1.Y)
{ blendData = { p.Y, v1.Y, aAnim, cAnim, &aData, &cData };
const float alpha = p.Y / v1.Y;
value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, aAnim, cAnim, aData.W, cData.W, alpha);
}
else else
{ blendData = { p.Y - v1.Y, v0.Y - v1.Y, cAnim, bAnim, &cData, &bData };
const float alpha = (p.Y - v1.Y) / (v0.Y - v1.Y);
value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, cAnim, bAnim, cData.W, bData.W, alpha);
}
} }
const float alpha = Math::IsZero(blendData.AlphaY) ? 0.0f : blendData.AlphaX / blendData.AlphaY;
value = SampleAnimationsWithBlend(node, loop, data.Length, startTimePos, bucket.TimePosition, newTimePos, blendData.AnimA, blendData.AnimB, blendData.AnimAd->W, blendData.AnimBd->W, alpha);
} }
else else
{ {