示例#1
0
        /// <summary>
        ///Creates a new MeshData object 
        /// </summary>
        /// <param name="vert">
        /// A <see cref="Vector3[]"/>
        /// </param>
        /// <param name="norm">
        /// A <see cref="Vector3[]"/>
        /// </param>
        /// <param name="tex">
        /// A <see cref="Vector2[]"/>
        /// </param>
        /// <param name="tri">
        /// A <see cref="Tri[]"/>
        /// </param>
        public MeshData(Vector3[] vert, Vector3[] norm, Vector2[] tex, Tri[] tri)
        {
            Vertices = vert;
            TexCoords = tex;
            Normals = norm;
            Tris = tri;

            Verify();
        }
示例#2
0
        // Takes an array of points and returns an array of triangles.
        // The points form an arbitrary polygon.
        private static Tri[] Triangulate(Point[] ps)
        {
            List <Tri> ts = new List <Tri>();

            if (ps.Length < 3)
            {
                throw new Exception("Invalid shape!  Must have >2 points");
            }

            Point first    = ps[0];
            Point previous = ps[1];

            for (int i = 2; i < ps.Length; i++)
            {
                Tri t = new Tri(first, previous, ps[i]);
                previous = ps[i];
                ts.Add(t);
            }
            return(ts.ToArray());
        }
示例#3
0
        // Takes an array of points and returns an array of triangles.
        // The points form an arbitrary polygon.
        private static Tri[] Triangulate(Point[] ps)
        {
            List <Tri> ts = new List <Tri>();

            if (ps.Length < 3)
            {
                throw new Exception("Invalid shape!  Must have >2 points");
            }

            Point lastButOne = ps[1];
            Point lastButTwo = ps[0];

            for (int i = 2; i < ps.Length; i++)
            {
                Tri t = new Tri(lastButTwo, lastButOne, ps[i]);
                lastButOne = ps[i];
                lastButTwo = ps[i - 1];
                ts.Add(t);
            }
            return(ts.ToArray());
        }
示例#4
0
        // Data munging for fun and profit!
        private void Ms3dTris2Tris(Ms3dTri[] tris, out Tri[] t, out Vector3[] norms, out Vector2[] texs)
        {
            Tri[] ts = new Tri[tris.Length];
            // Utter utter BS.
            for (int i = 0; i < ts.Length; i++)
            {
                ts[i] = new Tri();
            }
            List <Vector3> normals   = new List <Vector3>();
            List <Vector2> texcoords = new List <Vector2>();

            for (int i = 0; i < tris.Length; i++)
            {
                ts[i].P1.Vertex = tris[i].Verts[0];
                ts[i].P2.Vertex = tris[i].Verts[1];
                ts[i].P3.Vertex = tris[i].Verts[2];

                normals.Add(tris[i].Normals[0]);
                normals.Add(tris[i].Normals[1]);
                normals.Add(tris[i].Normals[2]);

                ts[i].P1.Normal = 3 * i;
                ts[i].P2.Normal = 3 * i + 1;
                ts[i].P3.Normal = 3 * i + 2;

                texcoords.Add(tris[i].TexCoords[0]);
                texcoords.Add(tris[i].TexCoords[1]);
                texcoords.Add(tris[i].TexCoords[2]);

                ts[i].P1.TexCoord = 3 * i;
                ts[i].P2.TexCoord = 3 * i + 1;
                ts[i].P3.TexCoord = 3 * i + 2;
            }

            t     = ts;
            norms = normals.ToArray();
            texs  = texcoords.ToArray();
        }
示例#5
0
        // Data munging for fun and profit!
        private void Ms3dTris2Tris(Ms3dTri[] tris, out Tri[] t, out Vector3[] norms, out Vector2[] texs)
        {
            Tri[] ts = new Tri[tris.Length];
            // Utter utter BS.
            for (int i = 0; i < ts.Length; i++)
            {
                ts[i] = new Tri();
            }
            List<Vector3> normals = new List<Vector3>();
            List<Vector2> texcoords = new List<Vector2>();

            for (int i = 0; i < tris.Length; i++)
            {
                ts[i].P1.Vertex = tris[i].Verts[0];
                ts[i].P2.Vertex = tris[i].Verts[1];
                ts[i].P3.Vertex = tris[i].Verts[2];

                normals.Add(tris[i].Normals[0]);
                normals.Add(tris[i].Normals[1]);
                normals.Add(tris[i].Normals[2]);

                ts[i].P1.Normal = 3 * i;
                ts[i].P2.Normal = 3 * i + 1;
                ts[i].P3.Normal = 3 * i + 2;

                texcoords.Add(tris[i].TexCoords[0]);
                texcoords.Add(tris[i].TexCoords[1]);
                texcoords.Add(tris[i].TexCoords[2]);

                ts[i].P1.TexCoord = 3 * i;
                ts[i].P2.TexCoord = 3 * i + 1;
                ts[i].P3.TexCoord = 3 * i + 2;
            }

            t = ts;
            norms = normals.ToArray();
            texs = texcoords.ToArray();
        }
示例#6
0
        // Takes an array of points and returns an array of triangles.
        // The points form an arbitrary polygon.
        private static Tri[] Triangulate(Point[] ps)
        {
            List<Tri> ts = new List<Tri>();
            if (ps.Length < 3)
            {
                throw new Exception("Invalid shape!  Must have >2 points");
            }

            Point first = ps[0];
            Point previous = ps[1];
            for (int i = 2; i < ps.Length; i++)
            {
                Tri t = new Tri(first, previous, ps[i]);
                previous = ps[i];
                ts.Add(t);
            }
            return ts.ToArray();
        }
示例#7
0
        // Takes an array of points and returns an array of triangles.
        // The points form an arbitrary polygon.
        private static Tri[] Triangulate(Point[] ps)
        {
            List<Tri> ts = new List<Tri>();
            if(ps.Length < 3) {
                throw new Exception("Invalid shape!  Must have >2 points");
            }

            Point lastButOne = ps[1];
            Point lastButTwo = ps[0];
            for(int i = 2; i < ps.Length; i++) {
                Tri t = new Tri(lastButTwo, lastButOne, ps[i]);
                lastButOne = ps[i];
                lastButTwo = ps[i-1];
                ts.Add(t);
            }
            return ts.ToArray();
        }