Exemple #1
0
        void Setup()
        {
            int count = 0;

            if (GraphInst.InputNodes.Count > 0)
            {
                count = GraphInst.InputNodes.Count;
                for (int i = 0; i < count; i++)
                {
                    string id = GraphInst.InputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        InputNode inp = (InputNode)n;
                        NodeInput np  = new NodeInput(NodeType.Color | NodeType.Gray, this, inp.Name);

                        inp.SetInput(np);
                        Inputs.Add(np);
                    }
                }
            }

            if (GraphInst.OutputNodes.Count > 0)
            {
                count = GraphInst.OutputNodes.Count;
                for (int i = 0; i < count; i++)
                {
                    string id = GraphInst.OutputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        OutputNode op = (OutputNode)n;

                        NodeOutput ot;

                        ot = new NodeOutput(NodeType.Color | NodeType.Gray, n, op.Name);
                        //we add to our graph instance outputs so things can actually connect
                        //to the output
                        Outputs.Add(ot);
                        op.SetOutput(ot);

                        n.OnUpdate += N_OnUpdate;
                    }
                }
            }

            //name map used in parameter mapping for quicker lookup
            count = GraphInst.CustomParameters.Count;
            for (int i = 0; i < count; i++)
            {
                var param = GraphInst.CustomParameters[i];
                nameMap[param.Name] = param;
            }
        }
Exemple #2
0
        void Setup()
        {
            if (GraphInst.InputNodes.Count > 0)
            {
                foreach (string id in GraphInst.InputNodes)
                {
                    Node n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        InputNode inp = (InputNode)n;
                        NodeInput np  = new NodeInput(NodeType.Color | NodeType.Gray, this, inp.Name);

                        inp.SetInput(np);
                        Inputs.Add(np);
                    }
                }
            }

            if (GraphInst.OutputNodes.Count > 0)
            {
                foreach (string id in GraphInst.OutputNodes)
                {
                    Node n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        OutputNode op = (OutputNode)n;

                        NodeOutput ot;

                        ot = new NodeOutput(NodeType.Color | NodeType.Gray, n, op.Name);
                        //we add to our graph instance outputs so things can actually connect
                        //to the output
                        Outputs.Add(ot);
                        op.SetOutput(ot);

                        n.OnUpdate += N_OnUpdate;
                    }
                }
            }

            //TODO:
            //setup paramater links later
        }
        void Setup()
        {
            var inputsConnections = GetParentConnections();
            var outputConnections = GetConnections();

            List <NodeInput>  previousInputs  = new List <NodeInput>();
            List <NodeOutput> previousOutputs = new List <NodeOutput>();

            foreach (NodeInput inp in Inputs)
            {
                inp.Reference?.Remove(inp);
                previousInputs.Add(inp);
            }

            foreach (NodeOutput op in Outputs)
            {
                previousOutputs.Add(op);
                RemovedOutput(op);
            }

            Inputs.Clear();
            Outputs.Clear();

            int count = 0;

            if (GraphInst.InputNodes.Count > 0)
            {
                count = GraphInst.InputNodes.Count;
                for (int i = 0; i < count; ++i)
                {
                    string id = GraphInst.InputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        InputNode inp = (InputNode)n;
                        inp.Inputs.Clear();
                        NodeInput np = new NodeInput(NodeType.Color | NodeType.Gray, this, inp, inp.Name);
                        Inputs.Add(np);
                        inp.Inputs.Add(np);
                    }
                }
            }

            if (GraphInst.OutputNodes.Count > 0)
            {
                count = GraphInst.OutputNodes.Count;
                for (int i = 0; i < count; ++i)
                {
                    string id = GraphInst.OutputNodes[i];
                    Node   n;
                    if (GraphInst.NodeLookup.TryGetValue(id, out n))
                    {
                        OutputNode op = (OutputNode)n;
                        op.Outputs.Clear();
                        NodeOutput ot = new NodeOutput(NodeType.Color | NodeType.Gray, n, this, op.Name);
                        Outputs.Add(ot);
                        op.Outputs.Add(ot);
                    }
                }
            }

            //name map used in parameter mapping for quicker lookup
            count = GraphInst.CustomParameters.Count;
            for (int i = 0; i < count; ++i)
            {
                var param = GraphInst.CustomParameters[i];
                nameMap[param.Name] = param;
            }

            SetConnections(parentGraph.NodeLookup, outputConnections, true);

            //set individual input connections from parent node
            foreach (var con in inputsConnections)
            {
                Node n = null;
                if (parentGraph.NodeLookup.TryGetValue(con.parent, out n))
                {
                    n.SetConnection(this, con, true);
                }
            }

            count = Inputs.Count;
            for (int i = 0; i < count; ++i)
            {
                if (i < previousInputs.Count)
                {
                    AddedInput(Inputs[i], previousInputs[i]);
                }
                else
                {
                    AddedInput(Inputs[i]);
                }
            }

            if (count < previousInputs.Count)
            {
                for (int i = count; i < previousInputs.Count; ++i)
                {
                    RemovedInput(previousInputs[i]);
                }
            }
            count = Outputs.Count;
            for (int i = 0; i < count; ++i)
            {
                if (i < previousOutputs.Count)
                {
                    AddedOutput(Outputs[i], previousOutputs[i]);
                }
                else
                {
                    AddedOutput(Outputs[i]);
                }
            }
        }