public Vector3Group() { X = new BfresAnimationTrack() { Name = "X", ChannelIndex = 0 }; Y = new BfresAnimationTrack() { Name = "Y", ChannelIndex = 1 }; Z = new BfresAnimationTrack() { Name = "Z", ChannelIndex = 2 }; }
public static void GenerateKeys(BfresAnimationTrack track, AnimCurve curve, bool valuesAsInts = false) { //Use the curve's post wrap. track.WrapMode = STLoopMode.Clamp; if (curve.PostWrap == WrapMode.Repeat) { track.WrapMode = STLoopMode.Repeat; } if (curve.PostWrap == WrapMode.Mirror) { track.WrapMode = STLoopMode.Mirror; } float valueScale = curve.Scale > 0 ? curve.Scale : 1; for (int i = 0; i < curve.Frames.Length; i++) { var frame = curve.Frames[i]; switch (curve.CurveType) { case AnimCurveType.Cubic: { track.InterpolationType = STInterpoaltionType.Hermite; //Important to not offset the other 3 values, just the first one! var value = curve.Keys[i, 0] * valueScale + curve.Offset; var coef1 = curve.Keys[i, 1] * valueScale; var coef2 = curve.Keys[i, 2] * valueScale; var coef3 = curve.Keys[i, 3] * valueScale; var slopes = GetSlopes(curve, i); track.KeyFrames.Add(new STHermiteKeyFrame() { Frame = frame, Value = value, TangentIn = slopes[0], TangentOut = slopes[1], }); /* track.KeyFrames.Add(new STHermiteCubicKeyFrame() * { * Frame = frame, * Value = value, * Coef1 = coef1, * Coef2 = coef2, * Coef3 = coef3, * TangentIn = slopes[0], * TangentOut = slopes[1], * });*/ } break; case AnimCurveType.Linear: { track.InterpolationType = STInterpoaltionType.Linear; var value = curve.Keys[i, 0] * valueScale + curve.Offset; var delta = curve.Keys[i, 1]; track.KeyFrames.Add(new STKeyFrame() { Frame = frame, Value = value, }); } break; case AnimCurveType.StepBool: { track.InterpolationType = STInterpoaltionType.Step; track.KeyFrames.Add(new STKeyFrame() { Frame = frame, Value = curve.KeyStepBoolData[i] ? 1 : 0, }); } break; default: { track.InterpolationType = STInterpoaltionType.Step; var value = curve.Keys[i, 0] + curve.Offset; if (valuesAsInts) { value = (int)curve.Keys[i, 0] + curve.Offset; } track.KeyFrames.Add(new STKeyFrame() { Frame = frame, Value = value, }); } break; } } }