예제 #1
0
        private void DrawGUIConnectDrag()
        {
            if (dragSlot != null)
            {
                Rect cp = new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0);
                DrawNodeCurve(dragSlot.SlotRect, cp);
            }

            if (Event.current.type == EventType.Repaint && !leftMouseDown && dragSlot != null)
            {
                foreach (BocsSlotBase s in BocsCyclesNodeManager.Slots)
                {
                    if (s.SlotRect.Contains(Event.current.mousePosition))
                    {
                        if (s.SlotType == BocsSlotBase.BocsSlotType.Input)
                        {
                            if (s.Node != dragSlot.Node)
                            {
                                //if (s._slotValType == _dragSlot._slotValType)
                                {
                                    s.RemoveConnection();
                                    dragSlot.AddConnection(s);
                                    SaveNodes();
                                    cyclesNeedsUpdate = true;
                                }
                            }
                        }
                    }
                }
                dragSlot = null;
            }
        }
 public static int FindSlotInNode(BocsNodeBase nb, BocsSlotBase sb)
 {
     for (int i = 0; i < nb.Slots.Count; i++)
     {
         if (nb.Slots[i] == sb)
         {
             return(i);
         }
     }
     return(-1);
 }
 public static int FindNodeFromSlot(BocsSlotBase s)
 {
     for (int i = 0; i < BocsCyclesNodeManager.Nodes.Count; i++)
     {
         foreach (BocsSlotBase c in BocsCyclesNodeManager.Nodes[i].Slots)
         {
             if (c == s)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
예제 #4
0
        private void DrawGUISockets()
        {
            foreach (BocsSlotBase s in BocsCyclesNodeManager.Slots)
            {
                s.DrawSlotSocket();
                if (leftMouseDown && dragSlot == null && s.SlotType == BocsSlotBase.BocsSlotType.Input && s.InputSlot != null && s.SlotRect.Contains(Event.current.mousePosition))
                {
                    s.RemoveConnection();
                    SaveNodes();
                    cyclesNeedsUpdate = true;
                }

                if (leftMouseDown && dragSlot == null && s.SlotType == BocsSlotBase.BocsSlotType.Output && s.SlotRect.Contains(Event.current.mousePosition))
                {
                    dragSlot = s;
                }
            }
        }
예제 #5
0
        public void AddConnection(BocsSlotBase slot)
        {
            if (slot == this)
            {
                return;
            }
            if (Node == slot.Node)
            {
                return;
            }

            slot.InputSlot = this;
            foreach (BocsSlotBase s in OutputSlots)
            {
                //if (s._slotType ==	BocsSlotType.)
                if (s == slot)
                {
                    return;
                }
            }
            OutputSlots.Add(slot);
        }
예제 #6
0
        private static void _addShaderGraph(XmlTextWriter xml, BocsCyclesGraphBase graph, string name)
        {
            string saved = BocsCyclesNodeManager.SaveGraph();

            for (int graphIndex = 0; graphIndex < graph.GetGraphCount(); graphIndex++)
            {
                BocsCyclesNodeManager.LoadGraph(graph.GetGraph(graphIndex));

                if (name != string.Empty)
                {
                    xml.WriteStartElement("shader");
                    xml.WriteAttributeString("name", name + graphIndex);
                }

                for (int nid = 0; nid < BocsCyclesNodeManager.Nodes.Count; nid++)
                {
                    BocsNodeBase n = BocsCyclesNodeManager.Nodes[nid];

                    if (n.NodeName == "output")
                    {
                        continue;                        //shaders have one by default
                    }
                    xml.WriteStartElement(n.NodeName);
                    xml.WriteAttributeString("name", n.NodeName + nid);
                    for (int sid = 0; sid < n.Slots.Count; sid++)
                    {
                        BocsSlotBase slot = n.Slots[sid];
                        string       val  = slot.GetXML();
                        if (val != string.Empty)
                        {
                            xml.WriteAttributeString(slot.SlotName, val);
                        }
                    }
                    xml.WriteEndElement();
                }
                for (int nid = 0; nid < BocsCyclesNodeManager.Nodes.Count; nid++)
                {
                    BocsNodeBase n = BocsCyclesNodeManager.Nodes[nid];
                    for (int sid = 0; sid < n.Slots.Count; sid++)
                    {
                        BocsSlotBase slot = n.Slots[sid];
                        foreach (BocsSlotBase c in slot.OutputSlots)
                        {
                            int          toID      = BocsCyclesNodeManager.FindNodeFromSlot(c);
                            BocsNodeBase toNode    = BocsCyclesNodeManager.Nodes[toID];
                            string       toConnect = "output";
                            if (toNode.NodeName != "output")
                            {
                                toConnect = toNode.NodeName + toID;
                            }

                            xml.WriteStartElement("connect");
                            xml.WriteAttributeString("from", n.NodeName + nid + " " + slot.SlotName);
                            xml.WriteAttributeString("to", toConnect + " " + c.SlotName);
                            xml.WriteEndElement();
                        }
                    }
                }

                if (name != string.Empty)
                {
                    xml.WriteEndElement();
                }
            }

            BocsCyclesNodeManager.LoadGraph(saved);
        }
        public static void LoadGraph(string g)
        {
            //Debug.Log("LoadGraph");
            Reset();

            if (g == null)
            {
                return;
            }

            string[] sn = g.Split(':');

            foreach (string n in sn)
            {
                //Debug.Log(n);
                string[] s = n.Split('|');
                //foreach(string ts in s) Debug.Log(ts);

                if (s.Length > 0)
                {
                    if (s[0] == "node")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    x = 0;
                        int    y = 0;
                        int    c = 0;
                        string t = string.Empty;
                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "t")
                                {
                                    t = v[1];
                                }
                                if (v[0] == "x")
                                {
                                    x = int.Parse(v[1]);
                                }
                                if (v[0] == "y")
                                {
                                    y = int.Parse(v[1]);
                                }
                                if (v[0] == "c")
                                {
                                    c = int.Parse(v[1]);
                                }
                            }
                        }
                        CreateNode(t, x, y, c);
                    }

                    if (s[0] == "val")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    ni = -1;
                        string ss = string.Empty;
                        string sv = string.Empty;

                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "n")
                                {
                                    ni = int.Parse(v[1]);
                                }
                                if (v[0] == "s")
                                {
                                    ss = v[1];
                                }
                                if (v[0] == "v")
                                {
                                    sv = v[1];
                                }
                            }
                        }

                        if (ni >= 0 && ni < BocsCyclesNodeManager.Nodes.Count)
                        {
                            BocsNodeBase nb = BocsCyclesNodeManager.Nodes[ni];
                            if (nb != null)
                            {
                                foreach (BocsSlotBase us in nb.Slots)
                                {
                                    if (us.SlotName == ss)
                                    {
                                        us.SetString(sv);
                                    }
                                }
                            }
                        }
                    }
                    if (s[0] == "connect")
                    {
                        string[] p = s[1].Split(',');
                        //foreach(string ts in p) Debug.Log(ts);

                        int    n1 = -1;
                        int    n2 = -1;
                        string s1 = string.Empty;
                        string s2 = string.Empty;

                        foreach (string ts in p)
                        {
                            string[] v = ts.Split('=');
                            if (v.Length > 1)
                            {
                                if (v[0] == "n1")
                                {
                                    n1 = int.Parse(v[1]);
                                }
                                if (v[0] == "n2")
                                {
                                    n2 = int.Parse(v[1]);
                                }
                                if (v[0] == "s1")
                                {
                                    s1 = v[1];
                                }
                                if (v[0] == "s2")
                                {
                                    s2 = v[1];
                                }
                            }
                        }

                        if (n1 != -1 && n2 != -1 && s1 != string.Empty && s2 != string.Empty && n1 < Nodes.Count && n2 < Nodes.Count)
                        {
                            BocsSlotBase f = FindOutputSlotFromString(BocsCyclesNodeManager.Nodes[n1], s1);
                            BocsSlotBase t = FindInputSlotFromString(BocsCyclesNodeManager.Nodes[n2], s2);
                            if (f != null && t != null)
                            {
                                f.AddConnection(t);
                            }
                        }
                    }
                }
            }
        }