Beispiel #1
0
        private void ExportAsPng()
        {
            var dialog = new Microsoft.Win32.SaveFileDialog();

            dialog.Filter          = "PNG|*.png";
            dialog.CheckFileExists = false;
            dialog.CheckPathExists = true;

            if (dialog.ShowDialog() == true)
            {
                string path = dialog.FileName;
                byte[] bits = Node.GetPreview(Node.Width, Node.Height);

                Task.Run(() =>
                {
                    RawBitmap bmp = null;
                    if (bits != null)
                    {
                        bmp     = new RawBitmap(Node.Width, Node.Height, bits);
                        var src = bmp.ToImageSource();
                        PngBitmapEncoder encoder = new PngBitmapEncoder();
                        BitmapFrame frame        = BitmapFrame.Create(src);
                        encoder.Frames.Add(frame);

                        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
                        {
                            encoder.Save(fs);
                        }
                    }
                });
            }
        }
Beispiel #2
0
        public void UpdatePath()
        {
            var bitmap = new RawBitmap(1024, 1024);

            if (mesh != null)
            {
                if (mesh.uv != null && mesh.uv.Count == mesh.vertices.Count)
                {
                    Parallel.For(0, mesh.triangles.Count, i =>
                    {
                        Triangle t = mesh.triangles[i];

                        Vector2 uv0 = mesh.uv[t.u0];
                        Vector2 uv1 = mesh.uv[t.u1];
                        Vector2 uv2 = mesh.uv[t.u2];

                        Point p  = new Point(uv0.X * 1024, uv0.Y * 1024);
                        Point p2 = new Point(uv1.X * 1024, uv1.Y * 1024);
                        Point p3 = new Point(uv2.X * 1024, uv2.Y * 1024);

                        bitmap.DrawLine((int)p.X, (int)p.Y, (int)p2.X, (int)p2.Y, 0, 255, 255, 255);
                        bitmap.DrawLine((int)p2.X, (int)p2.Y, (int)p3.X, (int)p3.Y, 0, 255, 255, 255);
                        bitmap.DrawLine((int)p3.X, (int)p3.Y, (int)p.X, (int)p.Y, 0, 255, 255, 255);
                    });
                }
            }
            Preview.Source = bitmap.ToImageSource();
        }
Beispiel #3
0
        void RedrawHue()
        {
            for (int y = 0; y < hueBitmap.Height; y++)
            {
                float    f = y / (float)hueBitmap.Height;
                float    h = f * 359;
                HsvColor v = new HsvColor(h, 1, 1);
                D.Color  c = v.ToColor();

                for (int x = 0; x < hueBitmap.Width; x++)
                {
                    hueBitmap.SetPixel(x, y, c.R, c.G, c.B, 255);
                }
            }

            HueSelector.Source = hueBitmap.ToImageSource();
        }
Beispiel #4
0
        void RedrawSatVal()
        {
            for (int y = 0; y < svBitmap.Height; y++)
            {
                for (int x = 0; x < svBitmap.Width; x++)
                {
                    float sf = x / (float)svBitmap.Width;
                    float sv = 1.0f - y / (float)svBitmap.Height;

                    HsvColor v = new HsvColor(hsv.H, sf, sv);
                    D.Color  c = v.ToColor();

                    svBitmap.SetPixel(x, y, c.R, c.G, c.B, 255);
                }
            }

            SaturationValueSelector.Source = svBitmap.ToImageSource();
        }
Beispiel #5
0
        public void BuildHistogramImage()
        {
            if (!isLoaded)
            {
                return;
            }

            if (ActualHeight == 0 || ActualWidth == 0)
            {
                return;
            }

            RawBitmap bmp = new RawBitmap((int)ActualWidth, (int)ActualHeight);

            if (ctk != null)
            {
                ctk.Cancel();
            }

            ctk = new CancellationTokenSource();

            Task.Run(() =>
            {
                if (histograph != null && maxValue != null)
                {
                    if (mode == LevelMode.RGB)
                    {
                        for (int g = 0; g < 3; g++)
                        {
                            if (maxValue[g] != 0)
                            {
                                //gather initial points
                                List <Vector2> points = new List <Vector2>();

                                for (int x = 0; x < 256; x++)
                                {
                                    int t   = histograph[g, x];
                                    float w = (float)x / 255.0f;
                                    int ax  = (int)Math.Floor(w * ActualWidth);

                                    float p = (float)t / (float)maxValue[g];
                                    int may = (int)Math.Min((int)ActualHeight, Math.Floor(p * (int)ActualHeight));

                                    points.Add(new Vector2(ax, may));
                                }

                                List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                                Parallel.For(0, spline.Count, i =>
                                {
                                    Vector2 p = spline[i];

                                    for (int k = 0; k < p.Y; k++)
                                    {
                                        bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                    }
                                });
                            }
                        }
                    }
                    else
                    {
                        int g = (int)mode;

                        if (maxValue[g] != 0)
                        {
                            List <Vector2> points = new List <Vector2>();

                            //gather initial points
                            for (int x = 0; x < 256; x++)
                            {
                                int t   = histograph[g, x];
                                float w = (float)x / 255.0f;
                                int ax  = (int)Math.Floor(w * ActualWidth);

                                float p = (float)t / (float)maxValue[g];
                                int may = (int)Math.Min(ActualHeight, Math.Floor(p * ActualHeight));

                                points.Add(new Vector2(ax, may));
                            }

                            List <Vector2> spline = CatmullRomSpline.GetSpline(points, 8);

                            Parallel.For(0, spline.Count, i =>
                            {
                                Vector2 p = spline[i];

                                for (int k = 0; k < p.Y; k++)
                                {
                                    bmp.SetPixel((int)p.X, bmp.Height - 1 - k, 175, 175, 175, 255);
                                }
                            });
                        }
                    }
                }
            }, ctk.Token).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    return;
                }

                if (bmp == null)
                {
                    return;
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    PreviewView.Source = bmp.ToImageSource();
                });
            });
        }
Beispiel #6
0
        protected void UpdatePath()
        {
            List <MathHelpers.Point> normals = new List <MathHelpers.Point>();

            if (display == null)
            {
                display = new RawBitmap((int)CurveView.ActualWidth, (int)CurveView.ActualHeight);
            }

            Utils.Clear(display);

            if (ShowAllCurves)
            {
                for (int i = 0; i < 4; ++i)
                {
                    switch (i)
                    {
                    case 0:
                        normals = RenderPath(Points[i], display);
                        break;

                    case 1:
                        normals = RenderPath(Points[i], display, 255, 0, 0);
                        break;

                    case 2:
                        normals = RenderPath(Points[i], display, 0, 255, 0);
                        break;

                    case 3:
                        normals = RenderPath(Points[i], display, 0, 45, 255);
                        break;
                    }

                    Normalized[i] = normals;
                }
            }
            else
            {
                switch (mode)
                {
                case CurveMode.RGB:
                    normals = RenderPath(Points[0], display);
                    break;

                case CurveMode.Red:
                    normals = RenderPath(Points[1], display, 255, 0, 0);
                    break;

                case CurveMode.Green:
                    normals = RenderPath(Points[2], display, 0, 255, 0);
                    break;

                case CurveMode.Blue:
                    normals = RenderPath(Points[3], display, 0, 45, 255);
                    break;
                }

                Normalized[(int)mode] = normals;
            }

            CurvePixels.Source = display.ToImageSource();
        }
Beispiel #7
0
        protected void ExportAsUnrealEngine4(string path)
        {
            RawBitmap mroh = null;

            int i = 0;

            string name = graph.Graph.Name;

            Queue <Task> runningTasks = new Queue <Task>();

            foreach (var s in graph.Graph.OutputNodes)
            {
                Node n = null;

                if (graph.Graph.NodeLookup.TryGetValue(s, out n))
                {
                    if (n is OutputNode)
                    {
                        OutputNode on = n as OutputNode;

                        ExportStatus.Text = "Exporting " + on.OutType.ToString();

                        if (on.OutType == OutputType.basecolor)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, "ue_" + name + "_basecolor.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.normal)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, "ue_" + name + "_normal.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            if (mroh == null)
                            {
                                mroh = new RawBitmap(on.Width, on.Height);
                            }

                            byte[] bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    RawBitmap tmp = new RawBitmap(on.Width, on.Height, bits);
                                    mroh.CopyRedToBlue(tmp);
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            if (mroh == null)
                            {
                                mroh = new RawBitmap(on.Width, on.Height);
                            }

                            byte[] bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    RawBitmap tmp = new RawBitmap(on.Width, on.Height, bits);
                                    mroh.CopyRedToGreen(tmp);
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            if (mroh == null)
                            {
                                mroh = new RawBitmap(on.Width, on.Height);
                            }

                            byte[] bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    RawBitmap tmp = new RawBitmap(on.Width, on.Height, bits);
                                    mroh.CopyRedToRed(tmp);
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            if (mroh == null)
                            {
                                mroh = new RawBitmap(on.Width, on.Height);
                            }

                            byte[] bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                var t = Task.Run(() =>
                                {
                                    RawBitmap tmp = new RawBitmap(on.Width, on.Height, bits);
                                    mroh.CopyRedToAlpha(tmp);
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                    }
                }
            }

            int totalTasks = runningTasks.Count;

            ExportProgress.Minimum = 0;
            ExportProgress.Maximum = totalTasks;

            Task.Run(async() =>
            {
                while (runningTasks.Count > 0)
                {
                    i = totalTasks - runningTasks.Count + 1;

                    Task t = runningTasks.Dequeue();

                    App.Current.Dispatcher.Invoke(() =>
                    {
                        ExportStatus.Text = "Exporting " + i + " / " + totalTasks;

                        ExportProgress.Value = i;
                    });

                    if (!t.IsCompleted && !t.IsCanceled)
                    {
                        await t;
                    }
                }

                if (mroh != null)
                {
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        ExportStatus.Text = "Finalizing";
                    });

                    var src = mroh.ToImageSource();
                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                    BitmapFrame frame        = BitmapFrame.Create(src);
                    encoder.Frames.Add(frame);

                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, "ue_" + name + "_ms.png"), FileMode.OpenOrCreate))
                    {
                        encoder.Save(fs);
                    }
                }

                App.Current.Dispatcher.Invoke(() =>
                {
                    DialogResult = true;
                });
            });
        }
Beispiel #8
0
        protected void ExportAsSeparate(string path)
        {
            int i = 0;

            string name = graph.Graph.Name;

            ExportProgress.Minimum = 0;
            ExportProgress.Maximum = graph.Graph.OutputNodes.Count;

            foreach (var s in graph.Graph.OutputNodes)
            {
                Node n = null;

                if (graph.Graph.NodeLookup.TryGetValue(s, out n))
                {
                    if (n is OutputNode)
                    {
                        OutputNode on = n as OutputNode;

                        ExportStatus.Text = "Exporting " + on.OutType.ToString();

                        if (on.OutType == OutputType.basecolor)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_basecolor.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                        else if (on.OutType == OutputType.normal)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                Task.Run(() =>
                                {
                                    bmp     = new RawBitmap(on.Width, on.Height, bits);
                                    var src = bmp.ToImageSource();
                                    PngBitmapEncoder encoder = new PngBitmapEncoder();
                                    BitmapFrame frame        = BitmapFrame.Create(src);
                                    encoder.Frames.Add(frame);

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_height.png"), FileMode.OpenOrCreate))
                                    {
                                        encoder.Save(fs);
                                    }
                                });
                            }
                        }
                    }
                }

                i++;
                ExportProgress.Value = i;
            }

            DialogResult = true;
        }