/// <summary> /// Sets the animation curves for this property. /// </summary> /// <param name="trackLogicalIndex">The index of the animation track.</param> /// <param name="curveSampler">A curve sampler, or null if the curve is to be removed.</param> public void SetCurve(int trackLogicalIndex, ICurveSampler <T> curveSampler) { Guard.MustBeGreaterThanOrEqualTo(trackLogicalIndex, 0, nameof(trackLogicalIndex)); if (curveSampler == null) { if (_Curves != null && trackLogicalIndex < _Curves.Count) { _Curves[trackLogicalIndex] = null; if (_Curves.All(item => item == null)) { _Curves = null; } } return; } if (_Curves == null) { _Curves = new List <ICurveSampler <T> >(); } while (_Curves.Count <= trackLogicalIndex) { _Curves.Add(null); } _Curves[trackLogicalIndex] = curveSampler; }
/// <summary> /// Assigns an animation curve to a given track. /// </summary> /// <param name="track">The name of the track.</param> /// <param name="curve">A <see cref="ICurveSampler{T}"/> instance, or null to remove a track.</param> public void SetTrack(string track, ICurveSampler <T> curve) { Guard.NotNullOrEmpty(track, nameof(track)); if (curve != null) { var convertible = curve as IConvertibleCurve <T>; Guard.NotNull(convertible, nameof(curve), $"Provided {nameof(ICurveSampler<T>)} {nameof(curve)} must implement {nameof(IConvertibleCurve<T>)} interface."); } // remove track if (curve == null) { if (_Tracks == null) { return; } _Tracks.Remove(track); if (_Tracks.Count == 0) { _Tracks = null; } return; } // insert track if (_Tracks == null) { _Tracks = new Dictionary <string, ICurveSampler <T> >(); } _Tracks[track] = curve; }
/// <summary> /// Assigns an animation curve to a given track. /// </summary> /// <param name="track">The name of the track.</param> /// <param name="curve"> /// A <see cref="ICurveSampler{T}"/> instance which also /// implements <see cref="IConvertibleCurve{T}"/>, /// or null to remove a track. /// </param> public void SetTrack(string track, ICurveSampler <T> curve) { Guard.NotNullOrEmpty(track, nameof(track)); // remove track if (curve == null) { if (_Tracks == null) { return; } _Tracks.Remove(track); if (_Tracks.Count == 0) { _Tracks = null; } return; } curve.GetPoint(0); // make a single evaluation to ensure it's an evaluable curve. Guard.IsTrue(curve is IConvertibleCurve <T>, nameof(curve), $"Provided {nameof(ICurveSampler<T>)} {nameof(curve)} must implement {nameof(IConvertibleCurve<T>)} interface."); // insert track if (_Tracks == null) { _Tracks = new Dictionary <string, ICurveSampler <T> >(); } _Tracks[track] = curve; }
public void SetCurve(ICurveSampler <T> curve) { if (curve is IConvertibleCurve <T> convertible) { SetCurve(convertible); } else { throw new NotImplementedException(); } }
public void AddCurve(int logicalIndex, string name, ICurveSampler <T> sampler) { Guard.NotNull(sampler, nameof(sampler)); Guard.MustBeGreaterThanOrEqualTo(logicalIndex, 0, nameof(logicalIndex)); if (_Animations == null) { _Animations = new Collections.NamedList <ICurveSampler <T> >(); } _Animations.SetValue(logicalIndex, name, sampler); }
public static CurveBuilder <T> CreateCurveBuilder <T>(ICurveSampler <T> curve) where T : struct { if (curve is Vector3CurveBuilder v3cb) { return(v3cb.Clone() as CurveBuilder <T>); } if (curve is QuaternionCurveBuilder q4cb) { return(q4cb.Clone() as CurveBuilder <T>); } if (curve is SparseCurveBuilder sscb) { return(sscb.Clone() as CurveBuilder <T>); } if (curve is SegmentCurveBuilder xscb) { return(xscb.Clone() as CurveBuilder <T>); } if (typeof(T) == typeof(Vector3)) { var cb = new Vector3CurveBuilder(); cb.SetCurve(curve as ICurveSampler <Vector3>); return(cb as CurveBuilder <T>); } if (typeof(T) == typeof(Quaternion)) { var cb = new QuaternionCurveBuilder(); cb.SetCurve(curve as ICurveSampler <Quaternion>); return(cb as CurveBuilder <T>); } if (typeof(T) == typeof(SEGMENT)) { var cb = new SegmentCurveBuilder(); cb.SetCurve(curve as ICurveSampler <SEGMENT>); return(cb as CurveBuilder <T>); } if (typeof(T) == typeof(SPARSE)) { var cb = new SparseCurveBuilder(); cb.SetCurve(curve as ICurveSampler <SPARSE>); return(cb as CurveBuilder <T>); } throw new InvalidOperationException($"{typeof(T).Name} not supported."); }
public void SetCurve(int logicalIndex, ICurveSampler <T> curveSampler) { Guard.NotNull(curveSampler, nameof(curveSampler)); Guard.MustBeGreaterThanOrEqualTo(logicalIndex, 0, nameof(logicalIndex)); if (_Curves == null) { _Curves = new List <ICurveSampler <T> >(); } while (_Curves.Count <= logicalIndex) { _Curves.Add(null); } _Curves[logicalIndex] = curveSampler; }
public static CurveBuilder <T> CreateCurveBuilder <T>(ICurveSampler <T> curve) where T : struct { if (curve is Vector3CurveBuilder v3cb) { return(v3cb.Clone() as CurveBuilder <T>); } if (curve is QuaternionCurveBuilder q4cb) { return(q4cb.Clone() as CurveBuilder <T>); } if (curve is SparseCurveBuilder sscb) { return(sscb.Clone() as CurveBuilder <T>); } throw new InvalidOperationException($"{nameof(T)} not supported."); }
/// <summary> /// Converts a sampler to a <see cref="CurveContinuity"/> value. /// </summary> private static CurveContinuity GetCurveContinuityFromSampler(ICurveSampler <Single, CubicSplineCurveKey <Single> > sampler) { if (sampler == SingleCurveCubicSplineSampler.Instance) { return(CurveContinuity.CubicSpline); } if (sampler == SingleCurveStepSampler.Instance) { return(CurveContinuity.Step); } if (sampler == SingleCurveLinearSampler.Instance) { return(CurveContinuity.Linear); } throw new ArgumentOutOfRangeException(nameof(sampler)); }
/// <summary> /// Initializes a new instance of the <see cref="Curve{TValue, TKey}"/> class. /// </summary> /// <param name="preLoop">A <see cref="CurveLoopType"/> value indicating how the curve's values are determined /// for points before the beginning of the curve.</param> /// <param name="postLoop">A <see cref="CurveLoopType"/> value indicating how the curve's values are determined /// for points after the end of the curve.</param> /// <param name="sampler">The <see cref="ICurveSampler{TValue, TKey}"/> to use when sampling this curve's values.</param> /// <param name="keys">A collection of <typeparamref name="TKey"/> objects from which to construct the curve.</param> public Curve(CurveLoopType preLoop, CurveLoopType postLoop, ICurveSampler <TValue, TKey> sampler, IEnumerable <TKey> keys) : base(preLoop, postLoop) { Contract.Require(sampler, nameof(sampler)); this.Sampler = sampler; this.Keys = new CurveKeyCollection <TValue, TKey>(keys); this.keyFirst = null; this.keyLast = null; if (this.Keys.Count > 0) { this.keyFirst = this.Keys[0].Key; this.StartPosition = this.keyFirst.Position; this.keyLast = this.Keys[this.Keys.Count - 1].Key; this.EndPosition = this.keyLast.Position; this.Length = this.EndPosition - this.StartPosition; } }
public void SetCurve(ICurveSampler <T> curve) { if (curve is IConvertibleCurve <T> convertible) { if (convertible.MaxDegree == 0) { var linear = convertible.ToStepCurve(); foreach (var p in linear) { this.SetPoint(p.Key, p.Value, false); } return; } if (convertible.MaxDegree == 1) { var linear = convertible.ToLinearCurve(); foreach (var p in linear) { this.SetPoint(p.Key, p.Value); } return; } if (convertible.MaxDegree == 3) { var spline = convertible.ToSplineCurve(); foreach (var ppp in spline) { this.SetPoint(ppp.Key, ppp.Value.Item2); this.SetIncomingTangent(ppp.Key, ppp.Value.Item1); this.SetOutgoingTangent(ppp.Key, ppp.Value.Item3); } return; } } throw new NotImplementedException(); }
/// <summary> /// Assigns an animation curve to a given track. /// </summary> /// <param name="track">The name of the track.</param> /// <param name="curve"> /// A <see cref="ICurveSampler{T}"/> instance which also /// implements <see cref="IConvertibleCurve{T}"/>, /// or null to remove a track. /// </param> public void SetTrack(string track, ICurveSampler <T> curve) { Guard.NotNullOrEmpty(track, nameof(track)); // remove track if (curve == null) { if (_Tracks == null) { return; } _Tracks.Remove(track); if (_Tracks.Count == 0) { _Tracks = null; } return; } Guard.IsFalse(curve is CurveBuilder <T>, "Use UseTrackBuilder() instead"); // clone curve var convertible = curve as IConvertibleCurve <T>; curve = convertible.Clone() as ICurveSampler <T>; // validate curve.GetPoint(0); // make a single evaluation to ensure it's an evaluable curve. Guard.NotNull(curve, $"Provided {nameof(ICurveSampler<T>)} {nameof(curve)} must implement {nameof(IConvertibleCurve<T>)} interface."); // insert track if (_Tracks == null) { _Tracks = new Dictionary <string, ICurveSampler <T> >(); } _Tracks[track] = curve; }
public void SetCurve(ICurveSampler <T> curve) { if (curve is IConvertibleCurve <T> convertible) { if (convertible.MaxDegree == 0) { var linear = convertible.ToStepCurve(); foreach (var p in linear) { this.SetPoint(p.Key, p.Value, false); } return; } if (convertible.MaxDegree == 1) { var linear = convertible.ToLinearCurve(); foreach (var p in linear) { this.SetPoint(p.Key, p.Value); } return; } if (convertible.MaxDegree > 1) { var linear = convertible.ToLinearCurve(); foreach (var p in linear) { this.SetPoint(p.Key, p.Value); } return; } } throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="CurveKeyRecord{TValue, TKey}"/> structure. /// </summary> /// <param name="key">The curve key.</param> /// <param name="samplerOverride">The curve key's sampler override.</param> public CurveKeyRecord(TKey key, ICurveSampler <TValue, TKey> samplerOverride) { this.Key = key; this.SamplerOverride = samplerOverride; }
/// <summary> /// Overrides the sampler associated with the specified keyframe. /// </summary> /// <param name="index">The index of the keyframe to override.</param> /// <param name="sampler">The override sampler to set for the specified keyframe.</param> public void OverrideKeySampler(Int32 index, ICurveSampler <TValue, TKey> sampler) { ref var record = ref storage[index];