/// <inheritdoc/> public override CubicSplineSingleCurve Process(ContentManager manager, IContentProcessorMetadata metadata, XDocument input) { var asset = input.Root.Element("Asset"); if (asset == null || asset.AttributeValueString("Type") != "Framework:Curve") { throw new InvalidDataException(UltravioletStrings.InvalidCurveData); } var preLoop = asset.ElementValue <CurveLoopType>("PreLoop"); var postLoop = asset.ElementValue <CurveLoopType>("PostLoop"); const Int32 ComponentsPerKey = 5; var keysString = asset.ElementValueString("Keys"); var keysComponents = keysString.Split((Char[])null, StringSplitOptions.RemoveEmptyEntries); if (keysComponents.Length % ComponentsPerKey != 0) { throw new InvalidDataException(UltravioletStrings.InvalidCurveData); } var curveKeyCollection = new List <CubicSplineCurveKey <Single> >(); var curveKeyContinuities = new List <CurveContinuity>(); for (int i = 0; i < keysComponents.Length; i += ComponentsPerKey) { var position = Single.Parse(keysComponents[i + 0]); var value = Single.Parse(keysComponents[i + 1]); var tangentIn = Single.Parse(keysComponents[i + 2]); var tangentOut = Single.Parse(keysComponents[i + 3]); var continuity = (CurveContinuity)Enum.Parse(typeof(CurveContinuity), keysComponents[i + 4]); curveKeyCollection.Add(new CubicSplineCurveKey <Single>(position, value, tangentIn, tangentOut)); curveKeyContinuities.Add(continuity); } var curve = SingleCurve.CubicSpline(preLoop, postLoop, curveKeyCollection); for (int i = 0; i < curveKeyContinuities.Count; i++) { var curveKeyContinuity = curveKeyContinuities[i]; if (curveKeyContinuity == CurveContinuity.CubicSpline) { continue; } curve.Keys.OverrideKeySampler(i, GetSamplerFromCurveContinuity(curveKeyContinuity)); } return(curve); }
/// <inheritdoc/> public override CubicSplineSingleCurve ImportPreprocessed(ContentManager manager, IContentProcessorMetadata metadata, BinaryReader reader) { var preLoop = (CurveLoopType)reader.ReadInt32(); var postLoop = (CurveLoopType)reader.ReadInt32(); var keyCount = reader.ReadInt32(); var keyContinuities = new List <CurveContinuity>(); var keyCollection = new List <CubicSplineCurveKey <Single> >(); for (int i = 0; i < keyCount; i++) { var keyPosition = reader.ReadSingle(); var keyValue = reader.ReadSingle(); var keyTangentIn = reader.ReadSingle(); var keyTangentOut = reader.ReadSingle(); var keyContinuity = (CurveContinuity)reader.ReadInt32(); keyCollection.Add(new CubicSplineCurveKey <Single>(keyPosition, keyValue, keyTangentIn, keyTangentOut)); keyContinuities.Add(keyContinuity); } return(SingleCurve.CubicSpline(preLoop, postLoop, keyCollection)); }