Ejemplo n.º 1
0
        public void Draw(UVMesh mesh, int imageSize, string texturePath, string exportPath, bool enableDrawBackground)
        {
            using (var texture = !File.Exists(texturePath) ? null : IsTGA(texturePath) ? new TGASharpLib.TGA(texturePath).ToBitmap() : new Bitmap(texturePath))
            {
                var textureRepeatCount = CalcTextureRepeatCount(mesh);
                var unitSize           = CalcUnitSize(imageSize, texture?.Width ?? imageSize, texture?.Height ?? imageSize);

                using (var bmp = new Bitmap(unitSize.X * textureRepeatCount.X, unitSize.Y * textureRepeatCount.Y))
                    using (var background = texture != null && enableDrawBackground ? CreateBackgroundImage(texture, textureRepeatCount) : null)
                    {
                        DrawMesh(bmp, background, mesh, unitSize);
                        bmp.Save(exportPath, ImageFormat.Png);
                    }
            }
        }
Ejemplo n.º 2
0
        private static void DrawMesh(Bitmap drawTartget, Bitmap background, UVMesh mesh, Point unitSize)
        {
            var uvDrawOffset = new Point(-mesh.MinBound.X, -mesh.MinBound.Y);
            var imagePosMesh = mesh.Mesh.Select(e => e.Add(uvDrawOffset.X, uvDrawOffset.Y).Mul(unitSize.X - 1, unitSize.Y - 1));

            using (var graph = Graphics.FromImage(drawTartget))
                using (var pen = new Pen(Color.Black)
                {
                    Width = 1
                })
                {
                    graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;

                    if (background != null)
                    {
                        graph.DrawImage(background, 0, 0, drawTartget.Width, drawTartget.Height);
                    }

                    foreach (var edge in imagePosMesh)
                    {
                        graph.DrawLine(pen, edge.UV[0], edge.UV[1]);
                    }
                }
        }
Ejemplo n.º 3
0
 public Point CalcTextureRepeatCount(UVMesh mesh) =>
 new Point(mesh.MaxBound.X - mesh.MinBound.X, mesh.MaxBound.Y - mesh.MinBound.Y);
Ejemplo n.º 4
0
        internal void ExportUVImage(int imageSize, string exportPath, bool drawTexture)
        {
            var uvMesh = new ExportUV.UVMesh(Current.Material.Vertices, Current.Material.Faces);

            new ExportUV.GDIUVDrawer().Draw(uvMesh, imageSize, Current.Material.TexFullPath, exportPath, drawTexture);
        }