Exemplo n.º 1
0
        private void OnFragmentTreeItemDrag(object sender, ItemDragEventArgs e)
        {
            if (e != null)
            {
                if (e.Item is Aga.Controls.Tree.TreeNodeAdv[])
                {
                    var array = (Aga.Controls.Tree.TreeNodeAdv[])e.Item;
                    foreach (var a in array)
                    {
                        if (a.Tag is TreeViewArchiveModel.ShaderFragmentItem)
                        {
                            var item = (TreeViewArchiveModel.ShaderFragmentItem)a.Tag;

                            var archiveName = item.ArchiveName;
                            if (archiveName != null && archiveName.Length > 0)
                            {
                                var fn = ShaderFragmentArchive.Archive.GetFunction(archiveName);
                                if (fn != null)
                                {
                                    this.DoDragDrop(ShaderFragmentNodeCreator.CreateNode(fn, archiveName, graphControl, _document), DragDropEffects.Copy);
                                }
                            }
                        }
                        else if (a.Tag is TreeViewArchiveModel.ParameterStructItem)
                        {
                            var item = (TreeViewArchiveModel.ParameterStructItem)a.Tag;

                            var archiveName = item.ArchiveName;
                            if (archiveName != null && archiveName.Length > 0)
                            {
                                var fn = ShaderFragmentArchive.Archive.GetParameterStruct(archiveName);
                                if (fn != null)
                                {
                                    this.DoDragDrop(ShaderFragmentNodeCreator.CreateParameterNode(fn, archiveName, ShaderFragmentArchive.Parameter.SourceType.Material), DragDropEffects.Copy);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void AddToHyperGraph(ShaderPatcherLayer.NodeGraph nodeGraph, HyperGraph.GraphControl graphControl, ShaderDiagram.Document doc)
        {
            //
            //      Convert from the "ShaderPatcherLayer" representation back to
            //      our graph control nodes.
            //
            //      This is required for robust serialisation. We can't easily
            //      serialise in and out the graph control objects directly, because
            //      it risks problems if the rendering code or shader fragment objects
            //      change. That is, it's not very version-robust.
            //
            //      It's better to serialise a slightly higher level representation
            //      that just contains the node names and connections. That way, we
            //      can adapt to changes in the tool and data.
            //
            {
                // --------< Basic Nodes >--------
                var newNodes            = new Dictionary <int, Node>();
                var nodeIdToControlNode = new Dictionary <UInt64, Node>();
                foreach (var n in nodeGraph.Nodes)
                {
                    if (!newNodes.ContainsKey(n.VisualNodeId))
                    {
                        if (n.NodeType == ShaderPatcherLayer.Node.Type.Procedure)
                        {
                            var fn = ShaderFragmentArchive.Archive.GetFunction(n.FragmentArchiveName);
                            if (fn != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode    = ShaderFragmentNodeCreator.CreateNode(fn, n.FragmentArchiveName, graphControl, doc);
                                newNode.Location              = visualNode.Location;
                                newNode.Collapsed             = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId]      = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                        else
                        {
                            var ps = ShaderFragmentArchive.Archive.GetParameterStruct(n.FragmentArchiveName);
                            if (ps != null)
                            {
                                var visualNode = nodeGraph.VisualNodes[n.VisualNodeId];
                                var newNode    = ShaderFragmentNodeCreator.CreateParameterNode(ps, n.FragmentArchiveName, AsSourceType(n.NodeType));
                                newNode.Location              = visualNode.Location;
                                newNode.Collapsed             = visualNode.State == ShaderPatcherLayer.VisualNode.StateType.Collapsed;
                                newNodes[n.VisualNodeId]      = newNode;
                                nodeIdToControlNode[n.NodeId] = newNode;
                            }
                        }
                    }
                }

                graphControl.AddNodes(newNodes.Values);

                // --------< Node Connections >--------
                foreach (var c in nodeGraph.NodeConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.InputNodeID) && nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var inputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.InputNodeID],
                                                             (item) => (item.Output != null && item.Output.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.InputParameterName)),
                                                             () => new ShaderFragmentNodeItem("return", c.InputType, null, false, true));

                        var outputItem = FindOrCreateNodeItem(nodeIdToControlNode[c.OutputNodeID],
                                                              (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                                                              () => new ShaderFragmentNodeItem(c.OutputParameterName, c.OutputType, null, true, false));

                        graphControl.Connect(inputItem.Output, outputItem.Input);
                    }
                }

                // --------< Node Constant Connections >--------
                foreach (var c in nodeGraph.NodeConstantConnections)
                {
                    if (nodeIdToControlNode.ContainsKey(c.OutputNodeID))
                    {
                        var node       = nodeIdToControlNode[c.OutputNodeID];
                        var outputItem = FindOrCreateNodeItem(node,
                                                              (item) => (item.Input != null && item.Input.Enabled && item is ShaderFragmentNodeItem && ((ShaderFragmentNodeItem)item).Name.Equals(c.OutputParameterName)),
                                                              () => new ShaderFragmentNodeItem(c.OutputParameterName, "float", null, true, false));

                        var connection = new NodeConnection();
                        connection.To   = outputItem.Input;
                        connection.Name = c.Value;
                        node.AddConnection(connection);
                    }
                }
            }
        }