Ejemplo n.º 1
0
    void Start()
    {
        var graph = MixtureDatabase.GetGraphFromTexture(graphTexture);

        graph.SetParameterValue("Source", source);
        graph.SetParameterValue("Target", target);

        // make sure compression is not enabled for the readback
        graph.outputNode.mainOutput.enableCompression = false;

        // Create the destination texture
        var       settings    = graph.outputNode.settings;
        Texture2D destination = new Texture2D(
            settings.GetResolvedWidth(graph),
            settings.GetResolvedHeight(graph),
            settings.GetGraphicsFormat(graph),
            TextureCreationFlags.None
            );

        // Process the graph
        MixtureGraphProcessor processor = new MixtureGraphProcessor(graph);

        processor.Run();

        // Readback the result
        graph.ReadbackMainTexture(destination);

        // TODO: debug
        // image.texture = debugRT;

        // Write the file at the target destination
        var bytes = ImageConversion.EncodeToPNG(destination);

        File.WriteAllBytes(outputPath, bytes);
    }
    IEnumerator GenerateScreenshots()
    {
        var          t        = Resources.Load <Texture>("DocumentationGraph");//.FirstOrDefault(g => { Debug.Log(g); return g is MixtureGraph;}) as MixtureGraph;
        MixtureGraph docGraph = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(t)).FirstOrDefault(g => g is MixtureGraph) as MixtureGraph;

        // Setup doc graph properties:
        docGraph.scale    = Vector3.one;
        docGraph.position = new Vector3(0, toolbarHeight, 0);
        docGraph.nodes.RemoveAll(n => !(n is OutputNode));

        // yield return null;

        var window = EditorWindow.CreateWindow <MixtureGraphWindow>();

        window.Show();
        window.Focus();

        window.minSize = new Vector2(1024, 1024);
        window.maxSize = new Vector2(1024, 1024);

        var nodeViews = new List <BaseNodeView>();

        foreach (var node in NodeProvider.GetNodeMenuEntries(docGraph))
        {
            if (node.path.Contains("Experimental"))
            {
                continue;
            }

            // Skip non-mixture nodes:
            if (!node.type.FullName.Contains("Mixture"))
            {
                continue;
            }

            // We'll suport loops after
            if (node.type == typeof(ForeachStart) || node.type == typeof(ForStart))
            {
                continue;
            }

            window.InitializeGraph(docGraph);
            var graphView = window.view;
            var newNode   = BaseNode.CreateFromType(node.type, new Vector2(0, toolbarHeight));
            var nodeView  = graphView.AddNode(newNode);
            nodeViews.Add(nodeView);
            graphView.Add(nodeView);
            SetupNodeIfNeeded(nodeView);

            graphView.MarkDirtyRepaint();
            graphView.UpdateViewTransform(new Vector3(0, 0, 0), Vector3.one * graphView.scale);
            graphView.Focus();

            MixtureGraphProcessor.RunOnce(docGraph);

            yield return(new WaitForEndOfFrame());

            if (window == null)
            {
                yield break;
            }

            TakeAndSaveNodeScreenshot(window, nodeView);

            GenerateNodeMarkdownDoc(nodeView);

            graphView.RemoveNodeView(nodeView);
            graphView.graph.RemoveNode(nodeView.nodeTarget);

            graphView.MarkDirtyRepaint();
            yield return(new WaitForEndOfFrame());
        }

        nodeViews.Sort((n1, n2) => n1.nodeTarget.name.CompareTo(n2.nodeTarget.name));

        GenerateNodeIndexFiles(nodeViews);

        foreach (var node in docGraph.nodes.ToList())
        {
            if (!(node is OutputNode))
            {
                docGraph.RemoveNode(node);
            }
        }

        window.Close();
    }