public BezierSpline(AnimationKeyframes animation) { List <CameraTransform> animKeyFrames = animation.keyframes; List <CameraTransform> currentCurve = new List <CameraTransform>(); curves = new List <BezierCurve>(); // add extra handles if (animKeyFrames.Count > 2) { // split each node in a set of triplets currentCurve.Add(animKeyFrames[0]); // loop through all keyframes except first and last for (int i = 1; i < animKeyFrames.Count - 1; i++) { Vector3 dir = animKeyFrames[i + 1].Position - animKeyFrames[i - 1].Position; Quaternion rotDiff = animKeyFrames[i + 1].Rotation - animKeyFrames[i - 1].Rotation; float fovDiff = animKeyFrames[i + 1].fovy ?? 1 - animKeyFrames[i - 1].fovy ?? 1; float divisionFactor = 6; float dist1 = Vector3.Distance(animKeyFrames[i + 1].Position, animKeyFrames[i].Position); float dist2 = Vector3.Distance(animKeyFrames[i - 1].Position, animKeyFrames[i].Position); if (Math.Min(dist1, dist2) / Math.Max(dist1, dist2) < .5f) { divisionFactor = 8; } CameraTransform handle1 = new CameraTransform( animKeyFrames[i].Position - dir / divisionFactor, // Quaternion.Lerp(keyframes[i - 1].Rotation, keyframes[i].Rotation, .5f) animKeyFrames[i].Rotation - rotDiff * .25f, animKeyFrames[i].fovy ?? 1 - fovDiff / divisionFactor ); CameraTransform handle2 = new CameraTransform( animKeyFrames[i].Position + dir / divisionFactor, // Quaternion.Lerp(keyframes[i].Rotation, keyframes[i + 1].Rotation, .5f) animKeyFrames[i].Rotation + rotDiff * .25f, animKeyFrames[i].fovy ?? 1 + fovDiff / divisionFactor ); currentCurve.Add(handle1); currentCurve.Add(animKeyFrames[i]); curves.Add(new BezierCurve(currentCurve)); currentCurve.Clear(); currentCurve.Add(animKeyFrames[i]); currentCurve.Add(handle2); } // add the last keyframe currentCurve.Add(animKeyFrames[^ 1]);
public static void SetCameraTransform(CameraTransform data) { Program.PostRequestCallback(BaseUrl + "camera_transform", null, JsonConvert.SerializeObject(data), null); }