Ejemplo 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);
        }
Ejemplo n.º 2
0
        public virtual vec3 getInputData(int slot_num, vec3 default_value)
        {
            LLink link = inputs[slot_num].link;

            if (link != null)
            {
                return(link.data_vec3);
            }
            return(default_value);
        }
Ejemplo n.º 3
0
        public virtual string getInputData(int slot_num, string default_value)
        {
            LLink link = inputs[slot_num].link;

            if (link != null)
            {
                return(link.data_string);
            }
            return(default_value);
        }
Ejemplo n.º 4
0
        public virtual float getInputData(int slot_num, float default_value)
        {
            LLink link = inputs[slot_num].link;

            if (link != null)
            {
                return(link.data_float);
            }
            return(default_value);
        }
Ejemplo n.º 5
0
        public virtual bool getInputData(int slot_num, bool default_value)
        {
            LLink link = inputs[slot_num].link;

            if (link != null)
            {
                return(link.data_bool);
            }
            return(default_value);
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        public virtual void transferData(int input_slot_num, int output_slot_num)
        {
            LLink input_link = inputs[input_slot_num].link;

            if (input_link == null)
            {
                return;
            }

            if (outputs.Count <= output_slot_num)
            {
                return;
            }
            LSlot slot = outputs[output_slot_num];

            if (slot == null)
            {
                return;
            }
            for (int i = 0; i < slot.links.Count; ++i)
            {
                LLink link = slot.links[i];
                if (link == null)
                {
                    return;
                }
                switch (input_link.data_type)
                {
                case DataType.BOOL: link.setData(input_link.data_bool); break;

                case DataType.NUMBER: link.setData(input_link.data_float); break;

                case DataType.STRING: link.setData(input_link.data_string); break;

                case DataType.VEC2: link.setData(input_link.data_vec2); break;

                case DataType.VEC3: link.setData(input_link.data_vec3); break;
                }
            }
        }
Ejemplo n.º 8
0
        public virtual void setOutputData(int slot_num, vec3 v)
        {
            if (outputs.Count <= slot_num)
            {
                return;
            }
            LSlot slot = outputs[slot_num];

            if (slot == null)
            {
                return;
            }
            for (int i = 0; i < slot.links.Count; ++i)
            {
                LLink link = slot.links[i];
                if (link == null)
                {
                    return;
                }
                link.setData(v);
            }
        }
Ejemplo n.º 9
0
        public virtual void configure(JSONNode json_node)
        {
            this.id    = json_node["id"].AsInt;
            this.order = json_node["order"].AsInt;

            //inputs
            var json_inputs = json_node["inputs"];

            if (json_inputs != null)
            {
                JSONNode.Enumerator it = json_inputs.GetEnumerator();
                int i = 0;
                while (it.MoveNext())
                {
                    JSONNode json_slot = it.Current;
                    string   str_type  = json_slot["type"];
                    DataType type      = DataType.NONE;
                    if (str_type != null && Globals.stringToDataType.ContainsKey(str_type))
                    {
                        type = Globals.stringToDataType[str_type];
                    }
                    LSlot slot = null;
                    if (inputs.Count > i)
                    {
                        slot = inputs[i];
                    }
                    if (slot == null)
                    {
                        slot = this.addInput(json_slot["name"], type);
                    }
                    JSONNode json_link = json_slot["link"];
                    if (json_link != null)
                    {
                        slot.link = graph.links_by_id[json_link.AsInt];
                    }
                    ++i;
                }
            }

            //outputs
            var json_outputs = json_node["outputs"];

            if (json_outputs != null)
            {
                JSONNode.Enumerator it = json_outputs.GetEnumerator();
                int i = 0;
                while (it.MoveNext())
                {
                    JSONNode json_slot = it.Current;
                    string   str_type  = json_slot["type"];
                    DataType type      = DataType.NONE;
                    if (str_type != null && Globals.stringToDataType.ContainsKey(str_type))
                    {
                        type = Globals.stringToDataType[str_type];
                    }
                    LSlot slot = null;
                    if (outputs.Count > i)
                    {
                        slot = outputs[i];
                    }
                    if (slot == null)
                    {
                        slot = this.addOutput(json_slot["name"], type);
                    }

                    JSONNode json_links = json_slot["links"];
                    if (json_links != null)
                    {
                        JSONNode.Enumerator it2 = json_links.GetEnumerator();
                        while (it2.MoveNext())
                        {
                            JSONNode json_link_id = it2.Current;
                            LLink    link         = graph.links_by_id[json_link_id.AsInt];
                            if (link != null)
                            {
                                slot.links.Add(link);
                            }
                            else
                            {
                                Debug.LogError("Link ID not found!: " + json_link_id);
                            }
                        }
                    }
                    ++i;
                }
            }

            //custom data (properties)
            this.onConfigure(json_node);
        }