Beispiel #1
0
        public void Read(Stream input, Endian endian = Endian.Little)
        {
            RoadGraphRoadToJunctionEdgeMappingCount = input.ReadValueU16(endian);
            RoadGraphEdgeCount = input.ReadValueU16(endian);

            for (int i = 0; i < RoadGraphEdgeCount; i++)
            {
                RoadGraphEdges.Add(new Tuple <ushort, ushort>(input.ReadValueU16(endian), input.ReadValueU16(endian)));
            }

            ushort roadCount = input.ReadValueU16(endian);

            for (int i = 0; i < roadCount; i++)
            {
                var road = new RoadDefinitionDe();
                road.Read(input, endian);
                Roads.Add(road);
            }

            for (int i = 0; i < RoadGraphEdgeCount; i++)
            {
                var costMapping = new CostMapEntryDe();
                costMapping.Read(input, endian);
                CostMap.Add(costMapping);
            }

            byte magic0 = input.ReadValueU8();
            byte magic1 = input.ReadValueU8();
            byte magic2 = input.ReadValueU8();
            byte magic3 = input.ReadValueU8();

            if (magic0 != 0x11 && magic1 != 0x11 && magic2 != 0x11 && magic3 != 0)
            {
                throw new IOException($"Unexpected magic values ({magic0}, {magic1}, {magic2}, {magic3})");
            }

            ushort splineCount = input.ReadValueU16(endian);

            for (int i = 0; i < splineCount; i++)
            {
                var spline = new RoadSplineDe();
                spline.Read(input, endian);
                Splines.Add(spline);
            }

            for (int i = 0; i < roadCount * 2; i++)
            {
                RoadToCrossroadMapping.Add(input.ReadValueU16(endian));
            }

            ushort crossroadCount = input.ReadValueU16(endian);

            for (int i = 0; i < crossroadCount; i++)
            {
                var crossroad = new CrossroadDe();
                crossroad.Read(input, endian);
                Crossroads.Add(crossroad);
            }
        }
 /// <summary>
 /// Gets a TF value from a group's spline and a spline's TF
 /// </summary>
 /// <param name="spline">a spline of this group</param>
 /// <param name="splineTF">TF of the spline in the range 0..1</param>
 /// <returns>a group TF value in the range 0..1</returns>
 public float SplineToTF(CurvySpline spline, float splineTF)
 {
     if (Count == 0)
     {
         return(0);
     }
     return(((float)Splines.IndexOf(spline) / Count) + (1f / Count) * splineTF);
 }
Beispiel #3
0
    public List <Vector2> BuildEdge(List <Vector2> controlPoints, int precision)
    {
        var result = new List <Vector2> ();

        var approx = Splines.Approximate(controlPoints, precision);

        approx.ForEach(p => result.Add(Splines.ComplexMultiply(p, target - source) + source));
        result.Add(target);

        return(result);
    }
 /// <summary>
 /// Remove empty entries from the Splines array
 /// </summary>
 public void RemoveEmptySplines()
 {
     if (Splines.Count > 0)
     {
         for (int i = Splines.Count - 1; i > -1; i--)
         {
             if (Splines[i] == null)
             {
                 Splines.RemoveAt(i);
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Set the motion for this spline.
        /// </summary>
        /// <param name="target">The object the motion should target. Must be non-null and a reference type.</param>
        /// <param name="duration">How long the motion should take, in seconds.</param>
        /// <param name="points">The points that the motion should spline between.</param>
        /// <returns>A reference to this, for specifying additional parameters.</returns>
        public Spliner Spline <TTarget, TPoint>(TTarget target, float duration, params TPoint[] points) where TTarget : class
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            var targetType = target.GetType();

            if (targetType.IsValueType)
            {
                throw new ArgumentException("Target may not be a struct");
            }

            Target   = target;
            Duration = duration;

            var path  = new List <float[]>();               //	float[] here is one object's properties
            var cross = new List <float[]>();               //	float[] here is one property's value at each point

            GetDefinitions(target, points[0], out accessor, out var pointDef);
            buffer = new float[accessor.Length];

            for (int i = 0; i < points.Length; i++)
            {
                path.Add(new float[pointDef.Length]);
                for (int j = 0; j < pointDef.Length; j++)
                {
                    path[i][j] = pointDef[j].GetValue(points[i]);
                }
            }

            for (int i = 0; i < pointDef.Length; i++)
            {
                var splinePoints = new float[path.Count];
                cross.Add(splinePoints);
                for (int j = 0; j < path.Count; j++)
                {
                    splinePoints[j] = path[j][i];
                }
            }

            Splines.Clear();
            for (int i = 0; i < cross.Count; i++)
            {
                Splines.Add(new Spline(cross[i]));
            }

            return(this);
        }
Beispiel #6
0
 public Vector3 InterpolateFast(float tf)
 {
     if (Splines.Count == 0)
     {
         return(Vector3.zero);
     }
     if (Splines.Count == 1)
     {
         return(Splines[0].InterpolateFast(tf));
     }
     return(LerpAcross(
                Splines.Select(s => s.InterpolateFast(tf)),
                Splines.Count,
                Interpolant));
 }
Beispiel #7
0
 public Quaternion GetOrientationFast(float tf)
 {
     if (Splines.Count == 0)
     {
         return(Quaternion.identity);
     }
     if (Splines.Count == 1)
     {
         return(Splines[0].GetOrientationFast(tf));
     }
     return(SlerpAcross(
                Splines.Select(s => s.GetOrientationFast(tf)),
                Splines.Count,
                Interpolant));
 }
Beispiel #8
0
 public float GetNearestPointTF(Vector3 point)
 {
     if (Splines.Count == 0)
     {
         return(0f);
     }
     if (Splines.Count == 1)
     {
         return(Splines[0].GetNearestPointTF(point));
     }
     return(LerpAcross(
                Splines.Select(s => s.GetNearestPointTF(point)),
                Splines.Count,
                Interpolant));
 }
Beispiel #9
0
 public float DistanceToTF(float distance)
 {
     if (Splines.Count == 0)
     {
         return(0f);
     }
     if (Splines.Count == 1)
     {
         return(Splines[0].DistanceToTF(distance));
     }
     return(LerpAcross(
                Splines.Select(s => s.DistanceToTF(distance)),
                Splines.Count,
                Interpolant));
 }
        void OnSplineRefresh(CurvySplineEventArgs e)
        {
            if (!Splines.Contains(e.Spline))
            {
                e.Spline.OnRefresh.RemoveListener(OnSplineRefresh);
                return;
            }
            if (!mIsInitialized)
            {
                return;
            }
            doRefreshLength();
            doGetProperties();

            OnRefreshEvent(new CurvySplineEventArgs(this));
        }
 /// <summary>
 /// Remove all splines from the group
 /// </summary>
 public override void Clear()
 {
     Splines.Clear();
     SetDirtyAll();
 }
 /// <summary>
 /// Remove a spline from the group
 /// </summary>
 /// <param name="spline">the spline to remove</param>
 public void Delete(CurvySpline spline)
 {
     Splines.Remove(spline);
     SetDirtyAll();
 }
 /// <summary>
 /// Add splines to the group
 /// </summary>
 /// <param name="splines">splines to add</param>
 public void Add(params CurvySpline[] splines)
 {
     Splines.AddRange(splines);
     SetDirtyAll();
 }