예제 #1
0
        public override void ExportSync(string path)
        {
            string name = graph.Name;

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

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

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

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.normal)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

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

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.thickness)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                        else if (on.OutType == OutputType.emission)
                        {
                            RawBitmap bmp  = null;
                            byte[]    bits = on.GetPreview(on.Width, on.Height);

                            if (bits != null)
                            {
                                bmp = new RawBitmap(on.Width, on.Height, bits);
                                var src = bmp.ToBitmap();

                                using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_emission.png"), FileMode.OpenOrCreate))
                                {
                                    src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                }

                                src.Dispose();
                            }
                        }
                    }
                }
            }
        }
예제 #2
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;
                });
            });
        }
예제 #3
0
        public override Task Export(string path)
        {
            int i = 0;

            string name = graph.Name;

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

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

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

                        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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_color.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_normal.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.metallic)
                        {
                            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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_metallic.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.roughness)
                        {
                            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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_roughness.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.occlusion)
                        {
                            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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_occlusion.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.height)
                        {
                            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.ToBitmap();

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

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                        else if (on.OutType == OutputType.thickness)
                        {
                            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.ToBitmap();

                                    using (FileStream fs = new FileStream(System.IO.Path.Combine(path, name + "_thickness.png"), FileMode.OpenOrCreate))
                                    {
                                        src.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
                                    }

                                    src.Dispose();
                                });
                                runningTasks.Enqueue(t);
                            }
                        }
                    }
                }
            }

            int totalTasks = runningTasks.Count;

            ProgressChanged(0, totalTasks, 0);

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

                    Task t = runningTasks.Dequeue();

                    ProgressChanged(i, totalTasks, (float)i / (float)totalTasks);

                    if (!t.IsCompleted && !t.IsCanceled)
                    {
                        await t;
                    }
                }
            }));
        }
예제 #4
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;
        }