Esempio n. 1
0
        public virtual bool connect(int origin_slot, LGraphNode target, int target_slot)
        {
            if (graph == null)
            {
                throw (new Exception("node does not belong to a graph"));
            }
            if (graph != target.graph)
            {
                throw (new Exception("nodes do not belong to same graph"));
            }

            LSlot origin_slot_info = this.outputs[origin_slot];
            LSlot target_slot_info = target.inputs[target_slot];

            if (origin_slot_info == null || target_slot_info == null)
            {
                return(false);
            }

            if (origin_slot_info.type != target_slot_info.type && (origin_slot_info.type != DataType.NONE && target_slot_info.type != DataType.NONE))
            {
                throw (new Exception("connecting incompatible types"));
            }

            int   id   = graph.last_link_id++;
            LLink link = new LLink(id, origin_slot_info.type, this.id, origin_slot, target.id, target_slot);

            graph.links.Add(link);
            origin_slot_info.links.Add(link);
            target_slot_info.link = link;

            graph.sortByExecutionOrder();
            return(true);
        }
Esempio n. 2
0
 // Update is called once per frame
 public void runStep(float dt = 0)
 {
     for (int i = 0; i < nodes_in_execution_order.Count; ++i)
     {
         LGraphNode node = nodes_in_execution_order[i];
         node.onExecute();
     }
     time += dt;
 }
Esempio n. 3
0
        public void fromJSONText(string text)
        {
            clear();

            var root = JSON.Parse(text);

            last_node_id = root["last_node_id"].AsInt;
            last_link_id = root["last_link_id"].AsInt;

            var json_links = root["links"];

            for (int i = 0; i < json_links.Count; ++i)
            {
                var      json_node   = json_links[i];
                int      id          = json_node[0].AsInt;
                int      origin_id   = json_node[1].AsInt;
                int      origin_slot = json_node[2].AsInt;
                int      target_id   = json_node[3].AsInt;
                int      target_slot = json_node[4].AsInt;
                JSONNode json_type   = json_node[5];
                DataType type        = DataType.NONE;

                if (json_type != null && json_type.Value != "0" && Globals.stringToDataType.ContainsKey(json_type))
                {
                    type = Globals.stringToDataType[json_type];
                }

                LLink link = new LLink(id, type, origin_id, origin_slot, target_id, target_slot);
                links.Add(link);
                links_by_id[link.id] = link;
            }

            var json_nodes = root["nodes"];

            for (int i = 0; i < json_nodes.Count; ++i)
            {
                var    json_node = json_nodes[i];
                string node_type = json_node["type"];
                Debug.Log(node_type);
                LGraphNode node = LiteGraph.Globals.createNodeType(node_type);
                if (node == null)
                {
                    Debug.Log("Error: node type not found: " + node_type);
                    has_errors = true;
                    continue;
                }
                node.graph = this;
                nodes.Add(node);
                node.configure(json_node);
            }

            sortByExecutionOrder();
        }
Esempio n. 4
0
        public void add(LGraphNode node)
        {
            if (node.graph != null)
            {
                throw (new Exception("already has graph"));
            }

            node.graph = this;
            node.id    = last_node_id++;
            node.order = node.id;
            nodes.Add(node);
            nodes_by_id.Add(node.id, node);
        }
Esempio n. 5
0
        public static void test()
        {
            Debug.Log("Testing Graph...");
            LGraph     graph = new LGraph();
            LGraphNode node1 = LiteGraph.Globals.createNodeType("math/rand");

            graph.add(node1);
            LGraphNode node2 = LiteGraph.Globals.createNodeType("basic/watch");

            graph.add(node2);
            node1.connect(0, node2, 0);

            for (int i = 0; i < 100; ++i)
            {
                graph.runStep();
            }
        }