コード例 #1
0
        /// <summary>
        /// Instantiates a spline from an individual OBJ file which contains a set of vertices representing the individual points of the spline.
        /// </summary>
        /// <param name="path">An OBJ file containing the points of the spline as vertices.</param>
        public static Spline *MakeSpline(string path)
        {
            // Store newly created Spline
            Spline spline = new Spline();

            // Parse individual spline file.
            ObjParser parser = new ObjParser(path);

            // Spline Information
            spline.Enabler          = 1;
            spline.SplineType       = parser.GetSplineType();
            spline.NumberOfVertices = (ushort)parser.Vertices.Count;

            // Get vertices & calculate total length
            SplineVertex[] vertices = MakeSplineVertices(ref parser);
            spline.TotalSplineLength = vertices.Sum(x => x.DistanceToNextVertex);

            // Write vertices to unmanaged memory
            int    structSize            = Marshal.SizeOf(vertices[0]) * vertices.Length;
            IntPtr splineVerticesPointer = Marshal.AllocHGlobal(structSize);

            MarshalUtilities.StructureArrayToPointer(vertices, splineVerticesPointer);
            spline.VertexList = (SplineVertex *)splineVerticesPointer;

            // Write spline to unmanaged memory
            int    splineSize    = Marshal.SizeOf(spline);
            IntPtr splinePointer = Marshal.AllocHGlobal(splineSize);

            Marshal.StructureToPtr(spline, splinePointer, true);

            return((Spline *)splinePointer);
        }
コード例 #2
0
        /// <summary>
        /// Instantiates a spline from an individual OBJ file which contains a set of vertices representing the individual points of the spline.
        /// </summary>
        /// <param name="path">An OBJ file containing the points of the spline as vertices.</param>
        public static BobsledSpline *MakeSpline(string path)
        {
            // Store newly created Spline
            BobsledSpline spline = new BobsledSpline();

            // Parse individual spline file.
            ObjParser parser = new ObjParser(path);

            // Spline Information
            spline.Enabler          = 0;
            spline.Null             = 0;
            spline.NumberOfVertices = (ushort)parser.Vertices.Count;

            // Get vertices & calculate total length
            Vector[] vertices = parser.Vertices.ToArray();

            spline.TotalSplineLength = 0;
            for (int i = 0; i < vertices.Length - 1; i++)
            {
                spline.TotalSplineLength += SplineVertexExtensions.Distance(vertices[i], vertices[i + 1]);
            }

            // Write vertices to unmanaged memory
            int    structSize            = Marshal.SizeOf(vertices[0]) * vertices.Length;
            IntPtr splineVerticesPointer = Marshal.AllocHGlobal(structSize);

            MarshalUtilities.StructureArrayToPointer(vertices, splineVerticesPointer);
            spline.VertexList = (Vector *)splineVerticesPointer;

            // Write spline to unmanaged memory
            int    splineSize    = Marshal.SizeOf(spline);
            IntPtr splinePointer = Marshal.AllocHGlobal(splineSize);

            Marshal.StructureToPtr(spline, splinePointer, true);

            return((BobsledSpline *)splinePointer);
        }