Skip to content

Commit

Permalink
code cleanup, some reverts from last commit, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pfcDorn committed Aug 9, 2023
1 parent 36991a2 commit b3dadcf
Showing 1 changed file with 10 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ protected virtual async Task BuildAnimationSamplers(GLTFAnimation animation, int
NumericArray output,
InterpolationType mode,
Type curveType,
ValuesConvertion getConvertedValues, bool isRotation = false)
ValuesConvertion getConvertedValues)
{


var channelCount = propertyNames.Length;
var frameCount = input.AsFloats.Length;

Expand All @@ -113,7 +111,6 @@ protected virtual async Task BuildAnimationSamplers(GLTFAnimation animation, int
keyframes[ci] = new Keyframe[frameCount];
}

Quaternion prevQuat = Quaternion.identity;
for (var i = 0; i < frameCount; ++i)
{
var time = input.AsFloats[i];
Expand All @@ -137,22 +134,6 @@ protected virtual async Task BuildAnimationSamplers(GLTFAnimation animation, int
values = getConvertedValues(output, i);
}

if (isRotation && channelCount == 4)
{
// Ensure shortest path rotation ( see https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#interpolation-slerp )
Quaternion currentQuat = new Quaternion(values[0], values[1], values[2], values[3]);
if (i == 0)
prevQuat = currentQuat;
if (Quaternion.Dot(prevQuat, currentQuat) < 0)
{
for (int iV = 0; iV < 3; iV++)
{
values[iV] = -values[iV];
}
}
prevQuat = currentQuat;
}

for (var ci = 0; ci < channelCount; ++ci)
{
if (mode == InterpolationType.CUBICSPLINE)
Expand All @@ -168,24 +149,23 @@ protected virtual async Task BuildAnimationSamplers(GLTFAnimation animation, int

for (var ci = 0; ci < channelCount; ++ci)
{
// copy all key frames data to animation curve and add it to the clip
AnimationCurve curve = new AnimationCurve(keyframes[ci]);

// For cubic spline interpolation, the inTangents and outTangents are already explicitly defined.
// For the rest, set them appropriately.
if (mode != InterpolationType.CUBICSPLINE)
{
// For cubic spline interpolation, the inTangents and outTangents are already explicitly defined.
// For the rest, set them appropriately.
for (var i = 0; i < keyframes[ci].Length; i++)
{
SetTangentMode(curve, keyframes[ci], i, mode);
SetTangentMode(keyframes[ci], i, mode);
}
}

// copy all key frames data to animation curve and add it to the clip
AnimationCurve curve = new AnimationCurve(keyframes[ci]);
clip.SetCurve(relativePath, curveType, propertyNames[ci], curve);
}
}

private static void SetTangentMode(AnimationCurve curve, Keyframe[] keyframes, int keyframeIndex, InterpolationType interpolation)
private static void SetTangentMode(Keyframe[] keyframes, int keyframeIndex, InterpolationType interpolation)
{
var key = keyframes[keyframeIndex];

Expand All @@ -201,14 +181,13 @@ private static void SetTangentMode(AnimationCurve curve, Keyframe[] keyframes, i
break;
case InterpolationType.STEP:
key.inTangent = float.PositiveInfinity;
key.outTangent = float.PositiveInfinity;
key.outTangent = 0;//float.PositiveInfinity;
break;

default:
throw new NotImplementedException();
}
if (keyframeIndex < keyframes.Length)
curve.MoveKey(keyframeIndex, key);
keyframes[keyframeIndex] = key;
}

private static float GetCurveKeyframeLeftLinearSlope(Keyframe[] keyframes, int keyframeIndex)
Expand Down Expand Up @@ -304,7 +283,7 @@ protected async Task<AnimationClip> ConstructClip(Transform root, int animationI
var rotation = data.AsVec4s[frame];
var quaternion = new GLTF.Math.Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W).ToUnityQuaternionConvert();
return new float[] { quaternion.x, quaternion.y, quaternion.z, quaternion.w };
}, true);
});

break;

Expand Down Expand Up @@ -361,12 +340,6 @@ protected async Task<AnimationClip> ConstructClip(Transform root, int animationI
return clip;
}

private static void CustomEnsureQuaternionContinuity(AnimationClip clip)
{

//foreach (var )
}

#endif

}
Expand Down

0 comments on commit b3dadcf

Please sign in to comment.