예제 #1
0
        private static void _addLight(XmlTextWriter xml, GameObject o)
        {
            BocsCyclesLight bcl = o.GetComponent <BocsCyclesLight>();

            if (bcl == null)
            {
                return;
            }
            //Light l = o.GetComponent<Light>();
            //if (l == null) return;

            string objName = "light_" + o.GetInstanceID().ToString();

            _addShaderGraph(xml, bcl, objName);

            //BEGIN_transform(xml,o);

            xml.WriteStartElement("state");
            //xml.WriteAttributeString("interpolation","smooth");
            xml.WriteAttributeString("shader", objName + "0");

            xml.WriteStartElement("light");

            xml.WriteAttributeString("name", objName);

            //string lt = "point";
            //if (l.type == LightType.Point) lt		= "point";
            //if (l.type == LightType.Directional) lt = "distant";
            //if (l.type == LightType.Area) lt		= "area";
            //if (l.type == LightType.Spot) lt		= "spot";

            //xml.WriteAttributeString("is_enabled",bcl._enabled.ToString());

            xml.WriteAttributeString("type", bcl.Type[bcl.TypeSelected]);

            xml.WriteAttributeString("size", bcl.Size.ToString());
            xml.WriteAttributeString("dir", _positionToString(o.transform.forward));
            xml.WriteAttributeString("co", _positionToString(o.transform.position));

            xml.WriteAttributeString("max_bounces", bcl.MaxBounces.ToString());

            xml.WriteAttributeString("use_mis", bcl.UseMis.ToString());

            xml.WriteAttributeString("use_diffuse", bcl.Diffuse.ToString());
            xml.WriteAttributeString("use_glossy", bcl.Glossy.ToString());
            xml.WriteAttributeString("use_transmission", bcl.Transmission.ToString());
            xml.WriteAttributeString("use_scatter", bcl.Scatter.ToString());

            xml.WriteAttributeString("cast_shadow", bcl.Shadow.ToString());

            xml.WriteAttributeString("spot_angle", (bcl.SpotAngle * Mathf.Deg2Rad).ToString());

            xml.WriteAttributeString("is_portal", bcl.IsPortal.ToString());

            xml.WriteEndElement();//state
        }
예제 #2
0
        public static void CleanLights()
        {
            GameObject[] objs = GameObject.FindObjectsOfType <GameObject>();

            foreach (GameObject o in objs)
            {
                BocsCyclesLight l = o.GetComponent <BocsCyclesLight>();
                Object.DestroyImmediate(l);
            }
        }
예제 #3
0
        //public static void AddAllLights()
        //{
        //    BocsCyclesLight[] lights = GameObject.FindObjectsOfType<BocsCyclesLight>();
        //    for (int o = 0; o < lights.Length; o++)
        //    {
        //        if (lights[o].gameObject.GetComponent<BocsCyclesSkip>() != null) continue;
        //        AddLight(lights[o].gameObject);
        //    }
        //}

        //public static void AddAllMeshes()
        //{
        //    BocsCyclesMaterial[] meshs = GameObject.FindObjectsOfType<BocsCyclesMaterial>();
        //    for (int o = 0; o < meshs.Length; o++)
        //    {
        //        if (meshs[o].gameObject.GetComponent<BocsCyclesSkip>() != null) continue;
        //        AddMesh(meshs[o].gameObject);
        //    }
        //}

        public static void AddLight(GameObject o)
        {
            BocsCyclesLight bcl = o.GetComponent <BocsCyclesLight>();

            if (bcl == null)
            {
                return;
            }

            MemoryStream  ms  = new MemoryStream();
            XmlTextWriter xml = _xmlStart(ms);

            _addLight(xml, o);

            Cycles_xml(_xmlEnd(xml, ms));
        }
예제 #4
0
        public static void ObjectAdd(GameObject o)
        {
            ObjectDelete(o);

            BocsCyclesMaterial bcm = o.GetComponent <BocsCyclesMaterial>();
            BocsCyclesLight    bcl = o.GetComponent <BocsCyclesLight>();

            if (bcm == null && bcl == null)
            {
                return;
            }

            if (bcl)
            {
                AddLight(o);
            }
            if (bcm)
            {
                AddMesh(o);
            }
        }
예제 #5
0
        public static void UpdateObject(GameObject o)
        {
            BocsCyclesLight    bcl = o.GetComponent <BocsCyclesLight>();
            BocsCyclesMaterial bcm = o.GetComponent <BocsCyclesMaterial>();

            if (bcl == null && bcm == null)
            {
                return;
            }

            MemoryStream  ms  = new MemoryStream();
            XmlTextWriter xml = _xmlStart(ms);

            if (bcl)
            {
                _addLight(xml, o);
            }

            if (bcm)
            {
                string objName = "mesh_" + o.GetInstanceID().ToString();
                _transform(xml, o);

                xml.WriteStartElement("state");
                //xml.WriteAttributeString("interpolation",bcm._smooth ? "smooth" : "flat");
                xml.WriteAttributeString("visibility", ((int)bcm.Visibility).ToString());

                for (int i = 0; i < bcm.GetGraphCount(); i++)
                {
                    xml.WriteStartElement("object");
                    xml.WriteAttributeString("name", objName + i);
                    xml.WriteEndElement();
                }
                xml.WriteEndElement(); //state
                xml.WriteEndElement(); //Transform
            }

            Cycles_xml(_xmlEnd(xml, ms));
        }
예제 #6
0
        public static void ObjectDelete(GameObject o)
        {
            BocsCyclesMaterial bcm = o.GetComponent <BocsCyclesMaterial>();
            BocsCyclesLight    bcl = o.GetComponent <BocsCyclesLight>();

            if (bcm == null && bcl == null)
            {
                return;
            }

            MemoryStream  ms  = new MemoryStream();
            XmlTextWriter xml = _xmlStart(ms);

            string objName;

            if (bcm)
            {
                objName = "mesh_" + o.GetInstanceID().ToString();

                for (int i = 0; i < bcm.GetGraphCount(); i++)
                {
                    xml.WriteStartElement("delete");
                    xml.WriteAttributeString("name", objName + i);
                    xml.WriteEndElement();
                }
            }

            if (bcl)
            {
                objName = "light_" + o.GetInstanceID().ToString();

                xml.WriteStartElement("delete");
                xml.WriteAttributeString("name", objName);
                xml.WriteEndElement();
            }

            Cycles_xml(_xmlEnd(xml, ms));
        }
예제 #7
0
        public override void OnInspectorGUI()
        {
            BocsCyclesLight script = (BocsCyclesLight)target;

            script.AutoSync = EditorGUILayout.Toggle("Auto Sync", script.AutoSync);

            if (script.AutoSync)
            {
                return;
            }

            if (GUILayout.Button("Editor"))
            {
                EditorWindow.GetWindow <EditorNodeEdit>();
            }

            EditorGUI.BeginChangeCheck();

            GUILayout.BeginVertical(GUI.skin.box);

            //script._enabled = EditorGUILayout.Toggle("Enabled",script._enabled);
            script.TypeSelected = EditorGUILayout.Popup("Type", script.TypeSelected, script.Type);
            if (script.TypeSelected == 2)
            {
                script.SpotAngle = EditorGUILayout.FloatField("Spot Angle", script.SpotAngle);
            }

            script.Shadow       = EditorGUILayout.Toggle("Shadow", script.Shadow);
            script.UseMis       = EditorGUILayout.Toggle("Multiple Importance", script.UseMis);
            script.Size         = EditorGUILayout.FloatField("Size", script.Size);
            script.MaxBounces   = EditorGUILayout.IntField("Max Bounces", script.MaxBounces);
            script.Diffuse      = EditorGUILayout.Toggle("Diffuse", script.Diffuse);
            script.Glossy       = EditorGUILayout.Toggle("Glossy", script.Glossy);
            script.Transmission = EditorGUILayout.Toggle("Transmission", script.Transmission);
            script.Scatter      = EditorGUILayout.Toggle("Scatter", script.Scatter);

            script.IsPortal = EditorGUILayout.Toggle("Portal", script.IsPortal);

            GUILayout.EndVertical();

            bool needUpdate = false;

            if (EditorGUI.EndChangeCheck())
            {
                needUpdate = true;
            }

            if (script.transform.root.position != lastPositon)
            {
                lastPositon = script.transform.root.position;
                needUpdate  = true;
            }
            if (script.transform.root.rotation != lastRostation)
            {
                lastRostation = script.transform.root.rotation;
                needUpdate    = true;
            }
            if (script.transform.root.localScale != lastScale)
            {
                lastScale  = script.transform.root.localScale;
                needUpdate = true;
            }

            //Some Checks...

            if (script.Size < 0)
            {
                script.Size = 0;
            }
            if (script.MaxBounces < 0)
            {
                script.MaxBounces = 0;
            }

            if (needUpdate)
            {
                BocsCyclesAPI.UpdateObject(script.gameObject);
            }

            debug = EditorGUILayout.Foldout(debug, "Debug");
            if (debug)
            {
                //Debug.Log(script.GetShaderCount());
                for (int i = 0; i < script.GetGraphCount(); i++)
                {
                    //GUILayout.TextField(script._nodes);
                    GUI.skin.textArea.wordWrap = true;
                    EditorGUILayout.TextArea(script.Nodes[i]);
                }
            }
        }