示例#1
0
 private void HandleMeshImport()
 {
     // Render mesh
     renderData.SetMesh(mesh);
     renderManager.SetData(renderData);
     //renderManager.Initialize();
 }
示例#2
0
        private void HandleMeshImport()
        {
            // Render mesh
            renderData.SetMesh(mesh);
            renderManager.SetData(renderData);
            //renderManager.Initialize();

            // Update window caption
            this.Text = "Triangle.NET - Mesh Explorer - " + settings.CurrentFile;

            // Update Statistic view
            statisticView.HandleMeshImport(input, mesh);

            // Set refine mode
            btnMesh.Enabled = true;
            btnMesh.Text    = "Refine";

            settings.RefineMode = true;

            HandleMeshChange();
        }
示例#3
0
        /// <summary>
        /// Export the mesh to PNG format.
        /// </summary>
        /// <param name="mesh">The current mesh.</param>
        /// <param name="filename">The PNG filename.</param>
        /// <param name="width">The desired width (pixel) of the image.</param>
        public void Export(Mesh mesh, string filename, int width)
        {
            // Get mesh data -- TODO: Use RenderControl's RenderData
            RenderData data = new RenderData();

            data.SetMesh(mesh);

            // Check file name
            if (String.IsNullOrEmpty(filename))
            {
                filename = String.Format("mesh-{0}.png", DateTime.Now.ToString("yyyy-M-d-hh-mm-ss"));
            }

            Bitmap bitmap;

            // Check if the specified width is reasonable
            if (width < 2 * Math.Sqrt(mesh.Vertices.Count))
            {
                bitmap = new Bitmap(400, 200);
                Graphics g = Graphics.FromImage(bitmap);
                g.Clear(colors.Background);

                string message = String.Format("Sorry, I won't render {0} points on such a small image!", mesh.Vertices.Count);

                SizeF sz = g.MeasureString(message, SystemFonts.DefaultFont);

                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.DrawString(message, SystemFonts.DefaultFont, colors.Point,
                             200 - sz.Width / 2, 100 - sz.Height / 2);

                g.Dispose();
            }
            else
            {
                var bounds = data.Bounds;
                // World margin on each side
                float margin = (float)bounds.Height * 0.05f;
                float scale  = width / ((float)bounds.Width + 2 * margin);

                var target = new Rectangle(0, 0, width, (int)((bounds.Height + 2 * margin) * scale));

                bitmap = new Bitmap(width, target.Height, PixelFormat.Format32bppPArgb);

                ScreenTrans zoom = new ScreenTrans();
                zoom.Initialize(target, bounds);

                Graphics g = Graphics.FromImage(bitmap);
                g.Clear(colors.Background);

                g.SmoothingMode = SmoothingMode.HighQuality;

                MeshRenderer meshRenderer = new MeshRenderer(data, colors);
                meshRenderer.Render(g, zoom);

                g.Dispose();
            }

            if (Path.GetExtension(filename) != ".png")
            {
                filename += ".png";
            }

            bitmap.Save(filename, ImageFormat.Png);
        }