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); }
public virtual LSlot addOutput(string name, DataType type = DataType.NONE) { LSlot slot = new LSlot(name, type); slot.num = outputs.Count; outputs.Add(slot); return(slot); }
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; } } }
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); } }
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); }