Beispiel #1
0
        public void ReloadChange()
        {
            selectedGraph = 0;
            bcg           = null;

            BocsCyclesNodeManager.Reset();

            if (Selection.activeGameObject != null)
            {
                bcg = Selection.activeGameObject.GetComponent <BocsCyclesMaterial>();
                if (bcg != null)
                {
                    graphType = GraphType.Material;
                    LoadNodes();
                    return;
                }

                bcg = Selection.activeGameObject.GetComponent <BocsCyclesLight>();
                if (bcg != null)
                {
                    graphType = GraphType.Light;
                    LoadNodes();
                    return;
                }

                bcg = Selection.activeGameObject.GetComponent <BocsCyclesCamera>();
                if (bcg != null)
                {
                    graphType = GraphType.World;
                    LoadNodes();
                    return;
                }
            }
        }
Beispiel #2
0
 private void SaveNodes()
 {
     if (bcg == null)
     {
         return;
     }
     bcg.SetGraph(selectedGraph, BocsCyclesNodeManager.SaveGraph());
 }
Beispiel #3
0
 private void LoadNodes()
 {
     if (bcg == null)
     {
         return;
     }
     BocsCyclesNodeManager.LoadGraph(bcg.GetGraph(selectedGraph));
 }
Beispiel #4
0
        protected void OnGUI()
        {
            if (bcg == null)
            {
                if (grid)
                {
                    GUI.DrawTextureWithTexCoords(new Rect(0, 0, 10000, 10000), grid, new Rect(0, 0, 10000 / grid.width, 10000 / grid.height));
                }
                GUI.DrawTexture(new Rect(position.width - 128, position.height - 128, 128, 128), logo, ScaleMode.ScaleToFit, true);
                return;
            }

            //GUI.skin = skin;

            UpdateEditorInput();
            DrawGUIShaderSelect();
            BocsCyclesNodeManager.ClearSlots();

            EditorGUI.BeginChangeCheck();

            Rect lr = GUILayoutUtility.GetLastRect();

            EditorZoomArea.Begin(zoomScale, new Rect(0, lr.yMax + 2, position.width, position.height - lr.yMax - 2));

            if (grid)
            {
                grid.wrapMode = TextureWrapMode.Repeat;
                GUI.DrawTextureWithTexCoords(new Rect(0, 0, 10000, 10000), grid, new Rect(0, 0, 10000 / grid.width, 10000 / grid.height));
            }

            //GUI.DrawTextureWithTexCoords(lr,_grid,new Rect(0,0,1,1),false);
            //GUI.DrawTextureWithTexCoords(new Rect(0,0,256,256),_grid,new Rect(0,0,1,1),false);

            DrawGUINodes();
            DrawGUISockets();
            DrawGUIConnections();

            DrawGUIConnectDrag();

            GUIScroll();
            GUIZoom();

            EditorZoomArea.End();

            GUIMenu();
            GUIKeys();

            if (EditorGUI.EndChangeCheck())
            {
                SaveNodes();
                //Debug.Log("GUI Change");
                cyclesNeedsUpdate = true;
            }

            UpdateCycles();
        }
Beispiel #5
0
 private void GUIKeys()
 {
     if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Delete)
     {
         BocsCyclesNodeManager.DeleteNode(BocsCyclesNodeManager.SelectedNode);
         SaveNodes();
         cyclesNeedsUpdate = true;
     }
     if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Space)
     {
         BocsCyclesNodeManager.SnapToGrid();
         SaveNodes();
     }
 }
Beispiel #6
0
        private void Callback(object obj)
        {
            if (bcg == null)
            {
                return;
            }
            if ((string)obj == "Clear")
            {
                DoPreset(string.Empty);
            }
            if ((string)obj == "Copy")
            {
                paste = bcg.GetGraph(selectedGraph);
            }
            if ((string)obj == "Paste")
            {
                DoPreset(paste);
            }

            //if (obj == "ps_") DoPreset("");
            if ((string)obj == "ps_subsurface")
            {
                DoPreset("node|t=BocsNodeOutput,x=380,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=10:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFE0BDFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=1:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0:val|n=1,s=anisotropic,v=1:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=0:val|n=1,s=sheen_tint,v=1:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_shiny")
            {
                DoPreset("node|t=BocsNodeOutput,x=380,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=10:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FF0000FF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=1:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0:val|n=1,s=anisotropic,v=0:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_chrome")
            {
                DoPreset("node|t=BocsNodeOutput,x=380,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=10:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=1:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0:val|n=1,s=anisotropic,v=0:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_brushedmetal")
            {
                DoPreset("node|t=BocsNodeOutput,x=380,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=10:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=1:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0.25:val|n=1,s=anisotropic,v=1:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=0:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=1:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_diffuse")
            {
                DoPreset("node|t=BocsNodeOutput,x=380,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=10:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0:val|n=1,s=anisotropic,v=0:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_textured")
            {
                DoPreset("node|t=BocsNodeOutput,x=590,y=10:node|t=BocsNodeTexture,x=20,y=10:node|t=BocsNodeDisneyBsdf,x=250,y=10:val|n=1,s=filename,v=:val|n=1,s=color_space,v=1:val|n=1,s=use_alpha,v=True:val|n=1,s=interpolation,v=1:val|n=1,s=extension,v=0:val|n=1,s=projection,v=0:val|n=2,s=distribution,v=0:val|n=2,s=base_color,v=FFFFFFFF:val|n=2,s=subsurface_color,v=FF0000FF:val|n=2,s=subsurface,v=0:val|n=2,s=subsurface_radius,v=1 1 1:val|n=2,s=metallic,v=0:val|n=2,s=specular,v=0:val|n=2,s=specular_tint,v=0:val|n=2,s=roughness,v=0:val|n=2,s=anisotropic,v=0.5:val|n=2,s=anisotropic_rotation,v=0:val|n=2,s=sheen,v=1:val|n=2,s=sheen_tint,v=0:val|n=2,s=clearcoat,v=0:val|n=2,s=clearcoat_gloss,v=1:val|n=2,s=ior,v=1.45:val|n=2,s=transparency,v=0:connect|n1=1,n2=2,s1=color,s2=base_color,:connect|n1=2,n2=0,s1=bsdf,s2=surface,:");
            }
            if ((string)obj == "ps_texturednormalmap")
            {
                DoPreset("node|t=BocsNodeOutput,x=590,y=10,c=0:node|t=BocsNodeTexture,x=20,y=10,c=0:node|t=BocsNodeDisneyBsdf,x=250,y=10,c=0:node|t=BocsNodeTexture,x=20,y=350,c=0:node|t=BocsNodeNormalMap,x=230,y=520,c=0:val|n=1,s=filename,v=:val|n=1,s=color_space,v=1:val|n=1,s=use_alpha,v=True:val|n=1,s=interpolation,v=1:val|n=1,s=extension,v=0:val|n=1,s=projection,v=0:val|n=2,s=distribution,v=0:val|n=2,s=base_color,v=FFFFFFFF:val|n=2,s=subsurface_color,v=FF0000FF:val|n=2,s=subsurface,v=0:val|n=2,s=subsurface_radius,v=1 1 1:val|n=2,s=metallic,v=0:val|n=2,s=specular,v=0:val|n=2,s=specular_tint,v=0:val|n=2,s=roughness,v=0:val|n=2,s=anisotropic,v=0.5:val|n=2,s=anisotropic_rotation,v=0:val|n=2,s=sheen,v=1:val|n=2,s=sheen_tint,v=0:val|n=2,s=clearcoat,v=0:val|n=2,s=clearcoat_gloss,v=1:val|n=2,s=ior,v=1.45:val|n=2,s=transparency,v=0:val|n=3,s=filename,v=:val|n=3,s=color_space,v=0:val|n=3,s=use_alpha,v=False:val|n=3,s=interpolation,v=1:val|n=3,s=extension,v=0:val|n=3,s=projection,v=0:val|n=4,s=space,v=1:val|n=4,s=attribute,v=:val|n=4,s=strength,v=1:val|n=4,s=color,v=7F7F7FFF:connect|n1=1,n2=2,s1=color,s2=base_color,:connect|n1=2,n2=0,s1=bsdf,s2=surface,:connect|n1=3,n2=4,s1=color,s2=color,:connect|n1=4,n2=2,s1=normal,s2=normal,:");
            }
            if ((string)obj == "ps_billboard")
            {
                DoPreset("node|t=BocsNodeOutput,x=730,y=10:node|t=BocsNodeTexture,x=10,y=10:node|t=BocsNodeMixShader,x=560,y=10:node|t=BocsNodeTransparentBsdf,x=270,y=100:node|t=BocsNodeDiffuseBsdf,x=250,y=210:val|n=1,s=filename,v=:val|n=1,s=color_space,v=1:val|n=1,s=use_alpha,v=True:val|n=1,s=interpolation,v=1:val|n=1,s=extension,v=0:val|n=1,s=projection,v=0:val|n=2,s=fac,v=1:val|n=3,s=color,v=FFFFFFFF:val|n=4,s=color,v=FFFFFFFF:val|n=4,s=roughness,v=0:connect|n1=1,n2=4,s1=color,s2=color,:connect|n1=1,n2=2,s1=alpha,s2=fac,:connect|n1=2,n2=0,s1=closure,s2=surface,:connect|n1=3,n2=2,s1=bsdf,s2=closure1,:connect|n1=4,n2=2,s1=bsdf,s2=closure2,:");
            }
            if ((string)obj == "ps_checker")
            {
                DoPreset("node|t=BocsNodeOutput,x=690,y=20:node|t=BocsNodeDisneyBsdf,x=350,y=20:node|t=BocsNodeCheckerTexture,x=20,y=20:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0.5:val|n=1,s=anisotropic,v=0.5:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:val|n=2,s=color1,v=848484FF:val|n=2,s=color2,v=FFFFFFFF:val|n=2,s=scale,v=1:connect|n1=1,n2=0,s1=bsdf,s2=surface,:connect|n1=2,n2=1,s1=color,s2=base_color,:");
            }
            if ((string)obj == "ps_glass")
            {
                DoPreset("node|t=BocsNodeOutput,x=350,y=10:node|t=BocsNodeDisneyBsdf,x=30,y=10:node|t=BocsNodeAbsorptionVolume,x=30,y=460:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0:val|n=1,s=anisotropic,v=0.5:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=1:val|n=2,s=color,v=FF0000FF:val|n=2,s=density,v=0:connect|n1=1,n2=0,s1=bsdf,s2=surface,:connect|n1=2,n2=0,s1=volume,s2=volume,:");
            }
            if ((string)obj == "ps_wireframe")
            {
                DoPreset("node|t=BocsNodeOutput,x=540,y=10:node|t=BocsNodeDisneyBsdf,x=40,y=120:node|t=BocsNodeWireframe,x=40,y=10:node|t=BocsNodeMixShader,x=380,y=10:node|t=BocsNodeDiffuseBsdf,x=40,y=580:val|n=1,s=distribution,v=0:val|n=1,s=base_color,v=FFFFFFFF:val|n=1,s=subsurface_color,v=FF0000FF:val|n=1,s=subsurface,v=0:val|n=1,s=subsurface_radius,v=1 1 1:val|n=1,s=metallic,v=0:val|n=1,s=specular,v=0:val|n=1,s=specular_tint,v=0:val|n=1,s=roughness,v=0.5:val|n=1,s=anisotropic,v=0.5:val|n=1,s=anisotropic_rotation,v=0:val|n=1,s=sheen,v=1:val|n=1,s=sheen_tint,v=0:val|n=1,s=clearcoat,v=0:val|n=1,s=clearcoat_gloss,v=1:val|n=1,s=ior,v=1.45:val|n=1,s=transparency,v=0:val|n=2,s=use_pixel_size,v=False:val|n=2,s=size,v=0.01:val|n=3,s=fac,v=1:val|n=4,s=color,v=FF0000FF:val|n=4,s=roughness,v=0:connect|n1=1,n2=3,s1=bsdf,s2=closure1,:connect|n1=2,n2=3,s1=fac,s2=fac,:connect|n1=3,n2=0,s1=closure,s2=surface,:connect|n1=4,n2=3,s1=bsdf,s2=closure2,:");
            }
            if ((string)obj == "ps_meshlight")
            {
                DoPreset("node|t=BocsNodeOutput,x=370,y=20:node|t=BocsNodeEmission,x=30,y=20:val|n=1,s=color,v=FAF3B5FF:val|n=1,s=strength,v=10:connect|n1=1,n2=0,s1=emission,s2=surface,:");
            }

            BocsCyclesNodeManager.CreateNode(obj.ToString(), lastMouse.x, lastMouse.y, 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);
        }