/// <summary>
        /// Converts <paramref name="skn"/> to a list of <see cref="MeshGeometry3D"/>
        /// </summary>
        /// <param name="skn">The <see cref="SKNFile"/> which should get converted to a <c>Tuple{string, MeshGeometry3D}(submeshName, submeshData)</c></param>
        /// <returns>A collection of converted <see cref="SKNSubmesh"/></returns>
        /// <remarks>Normals do not get converted</remarks>
        public static IEnumerable <Tuple <string, MeshGeometry3D> > ConvertSKN(SKNFile skn)
        {
            foreach (SKNSubmesh submesh in skn.Submeshes)
            {
                MeshGeometry3D mesh = new MeshGeometry3D();

                Int32Collection    indices  = new Int32Collection(submesh.Indices.Select(x => (int)x));
                Point3DCollection  vertices = new Point3DCollection();
                Vector3DCollection normals  = new Vector3DCollection();
                PointCollection    uvs      = new PointCollection();
                for (int i = 0; i < submesh.Vertices.Count; i++)
                {
                    SKNVertex vertex = submesh.Vertices[i];
                    vertices.Add(new Point3D(vertex.Position.X, vertex.Position.Y, vertex.Position.Z));
                    normals.Add(new Vector3D(vertex.Normal.X, vertex.Normal.Y, vertex.Normal.Z));
                    uvs.Add(new Point(vertex.UV.X, vertex.UV.Y));
                }

                mesh.TextureCoordinates = uvs;
                mesh.Positions          = vertices;
                mesh.Normals            = normals;
                mesh.TriangleIndices    = indices;

                yield return(new Tuple <string, MeshGeometry3D>(submesh.Name, mesh));
            }
        }
Beispiel #2
0
        public static void Process(string fileLocation, SKNFile skn)
        {
            string exportDirectory = string.Format(@"{0}\Uvee_{1}", Path.GetDirectoryName(fileLocation), Path.GetFileNameWithoutExtension(fileLocation));

            Directory.CreateDirectory(exportDirectory);

            foreach (SKNSubmesh submesh in skn.Submeshes)
            {
                Image         image   = CreateImage();
                List <ushort> indices = submesh.GetNormalizedIndices();

                //Loop through all submesh faces and draw the lines for them using vertex UV
                for (int i = 0; i < indices.Count;)
                {
                    SKNVertex vertex1 = submesh.Vertices[indices[i++]];
                    SKNVertex vertex2 = submesh.Vertices[indices[i++]];
                    SKNVertex vertex3 = submesh.Vertices[indices[i++]];

                    PointF[] points = new PointF[]
                    {
                        new PointF(1024 * vertex1.UV.X, 1024 * vertex1.UV.Y),
                        new PointF(1024 * vertex2.UV.X, 1024 * vertex2.UV.Y),
                        new PointF(1024 * vertex3.UV.X, 1024 * vertex3.UV.Y),
                        new PointF(1024 * vertex1.UV.X, 1024 * vertex1.UV.Y) //4th point to close the edge loop
                    };

                    DrawLines(image, points);
                }

                string submeshLocation = string.Format(@"{0}\{1}.png", exportDirectory, submesh.Name);
                image.SaveAsPng(File.Create(submeshLocation));
            }
        }