private static void DeserializeCurveFromClassLegacy(BezierAnimationCurve curve, JSONNode curveJSON) { var keysJSON = curveJSON["keys"].AsArray; if (keysJSON.Count == 0) { return; } var last = -1f; foreach (JSONNode keyframeJSON in keysJSON) { var time = DeserializeFloat(keyframeJSON["time"]).Snap(); if (time == last) { continue; } last = time; var value = DeserializeFloat(keyframeJSON["value"]); var keyframe = new BezierKeyframe( time, value, CurveTypeValues.SmoothLocal ); curve.AddKey(keyframe); } }
private static void DeserializeCurveFromArray(BezierAnimationCurve curve, JSONArray curveJSON, ref bool dirty) { if (curveJSON.Count == 0) { return; } var last = -1f; foreach (JSONClass keyframeJSON in curveJSON) { try { var time = float.Parse(keyframeJSON["t"], CultureInfo.InvariantCulture).Snap(); if (time == last) { continue; } last = time; var value = DeserializeFloat(keyframeJSON["v"]); var keyframe = new BezierKeyframe { time = time, value = value, curveType = int.Parse(keyframeJSON["c"]), controlPointIn = DeserializeFloat(keyframeJSON["i"]), controlPointOut = DeserializeFloat(keyframeJSON["o"]) }; // Backward compatibility, tangents are not supported since bezier conversion. if (keyframeJSON.HasKey("ti")) { dirty = true; if (keyframe.curveType == CurveTypeValues.LeaveAsIs) { keyframe.curveType = CurveTypeValues.SmoothLocal; } } curve.AddKey(keyframe); } catch (IndexOutOfRangeException exc) { throw new InvalidOperationException($"Failed to read curve: {keyframeJSON}", exc); } } }
private static void DeserializeCurveFromStringLegacy(BezierAnimationCurve curve, JSONNode curveJSON) { var strFrames = curveJSON.Value.Split(';').Where(x => x != "").ToList(); if (strFrames.Count == 0) { return; } var last = -1f; foreach (var strFrame in strFrames) { var parts = strFrame.Split(','); try { var time = float.Parse(parts[0], CultureInfo.InvariantCulture).Snap(); if (time == last) { continue; } last = time; var value = DeserializeFloat(parts[1]); var keyframe = new BezierKeyframe { time = time, value = value, curveType = int.Parse(parts[2]) }; // Backward compatibility, tangents are not supported since bezier conversion. if (keyframe.curveType == CurveTypeValues.LeaveAsIs) { keyframe.curveType = CurveTypeValues.SmoothLocal; } curve.AddKey(keyframe); } catch (IndexOutOfRangeException exc) { throw new InvalidOperationException($"Failed to read curve: {strFrame}", exc); } } }