private static void UpdateCurve(PawnKeyframe key, float?curvePoint, SimpleCurve simpleCurve, float frameAt) { if (curvePoint.HasValue) { simpleCurve.Add(frameAt, curvePoint.Value); } else { // No value at 0 => add points to prevent the curve from bugging out if (key.KeyIndex == 0) { simpleCurve.Add(0, 0); simpleCurve.Add(1, 0); } } }
private static void BuildAnimationKeys(PawnKeyframe key, PoseCycleDef cycle) { List <PawnKeyframe> keyframes = cycle.keyframes; List <PawnKeyframe> autoKeys = keyframes.Where(x => x.Status != KeyStatus.Manual).ToList(); List <PawnKeyframe> manualKeys = keyframes.Where(x => x.Status == KeyStatus.Manual).ToList(); float autoFrames = (float)key.KeyIndex / (autoKeys.Count - 1); float frameAt; // Distribute manual keys if (!manualKeys.NullOrEmpty()) { frameAt = (float)key.KeyIndex / (autoKeys.Count - 1); Log.Message("frameAt " + frameAt); float divider = (float)1 / (autoKeys.Count - 1); Log.Message("divider " + divider); float?shift = manualKeys.Find(x => x.KeyIndex == key.KeyIndex)?.Shift; if (shift.HasValue) { Log.Message("Shift " + shift); frameAt += divider * shift.Value; Log.Message("new frameAt " + frameAt); } } else { frameAt = (float)key.KeyIndex / (keyframes.Count - 1); } Dictionary <SimpleCurve, float?> dict = new Dictionary <SimpleCurve, float?> { { cycle.ShoulderOffsetHorizontalX, key.ShoulderOffsetHorizontalX }, { cycle.HipOffsetHorizontalX, key.HipOffsetHorizontalX }, { cycle.BodyAngle, key.BodyAngle }, { cycle.BodyAngleVertical, key.BodyAngleVertical }, { cycle.BodyOffsetZ, key.BodyOffsetZ }, { cycle.FootAngle, key.FootAngle }, { cycle.FootPositionX, key.FootPositionX }, { cycle.FootPositionZ, key.FootPositionZ }, { cycle.HandPositionX, key.HandPositionX }, { cycle.HandPositionZ, key.HandPositionZ }, { cycle.HandsSwingAngle, key.HandsSwingAngle }, { cycle.HandsSwingPosVertical, key.HandsSwingAngle }, { cycle.FrontPawAngle, key.FrontPawAngle }, { cycle.FrontPawPositionX, key.FrontPawPositionX }, { cycle.FrontPawPositionZ, key.FrontPawPositionZ } // { cycle.BodyOffsetVerticalZ, key.BodyOffsetVerticalZ }, // { cycle.FootPositionVerticalZ, key.FootPositionVerticalZ }, // { cycle.HandsSwingPosVertical, key.HandsSwingPosVertical }, // { // cycle.FrontPawPositionVerticalZ, // key.FrontPawPositionVerticalZ // } }; foreach (KeyValuePair <SimpleCurve, float?> pair in dict) { UpdateCurve(key, pair.Value, pair.Key, frameAt); } }