Skip to content

Commit

Permalink
Bake in blend curves as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ammaraskar committed May 9, 2024
1 parent 9222f64 commit be73b02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static void CreateBlendCurveForIkWeight(AnimationClip clip, AnimResource
clip.SetCurve(property, typeof(TwoBoneIKConstraint), "m_Data.m_TargetPositionWeight", curve);
}

private static void CreateBlendCurveForChannel(AnimationClip clip, AnimResourceConstBlock.SharedChannel channel,
public static void CreateBlendCurveForChannel(AnimationClip clip, AnimResourceConstBlock.SharedChannel channel,
string relativePathToBlend)
{
if (channel.Type != AnimResourceConstBlock.ChannelType.Float1)
Expand Down
19 changes: 17 additions & 2 deletions Assets/Scripts/OpenTS2/Engine/Tests/SimAnimationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ IEnumerator PlayClipFrameDelayed(string animName, ScenegraphAnimationAsset anim)

_sim.AdjustInverseKinematicWeightsForAnimation(anim.AnimResource);

yield return BakeAnimationIntoNewAnimation(animName);
yield return BakeAnimationIntoNewAnimation(animName, anim);
}

private ScenegraphAnimationAsset UpdateAnimationsListAndGetSelection()
Expand All @@ -112,7 +112,7 @@ private ScenegraphAnimationAsset UpdateAnimationsListAndGetSelection()
return tenMatchedAnimations.Length == 0 ? null : tenMatchedAnimations[0].Value;
}

IEnumerator BakeAnimationIntoNewAnimation(string animName)
IEnumerator BakeAnimationIntoNewAnimation(string animName, ScenegraphAnimationAsset anim)
{
var bakedName = $"{animName}_baked";
if (_animationObj.GetClip(bakedName) != null)
Expand Down Expand Up @@ -168,6 +168,21 @@ IEnumerator BakeAnimationIntoNewAnimation(string animName)
bakedClip.SetCurve(relativeBonePath, typeof(Transform), "localRotation.w", new AnimationCurve(posAndRot.QuatW.ToArray()));
}

// Add curves for blend channels.
foreach (var target in anim.AnimResource.AnimTargets)
{
foreach (var channel in target.Channels)
{
if (!_sim.Scenegraph.BlendNamesToRelativePaths.TryGetValue(channel.ChannelName,
out var relativePathsToBlend)) continue;

foreach (var blendRelativePath in relativePathsToBlend)
{
ScenegraphAnimationAsset.CreateBlendCurveForChannel(bakedClip, channel, blendRelativePath);
}
}
}

_animationObj.AddClip(bakedClip, bakedName);
baking = false;
}
Expand Down

0 comments on commit be73b02

Please sign in to comment.