Esempio n. 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);
        }