Esempio n. 1
0
        public RenderObject(Scene scene, string name, string src)
            : base(scene, name, src)
        {
            textures = new List<Texture>();

            pos = new Vector3(0, 0, 0);
            rot = new Quaternion(0, 0, 0, 1.0f);
            scale = new Vector3(1.0f, 1.0f, 1.0f);
            worldMatrix = new Matrix4();

            try
            {
                XmlDocument roXML = new XmlDocument();
                roXML.Load(src);

                foreach( XmlAttribute attrib in roXML.DocumentElement.Attributes )
                {
                    if( attrib.Name == "pos")
                    {
                        string[] values = attrib.Value.Split(',');
                        pos = new Vector3(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]));
                    }
                    else if( attrib.Name == "rot")
                    {
                        string[] values = attrib.Value.Split(',');
                        rot = new Quaternion(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]), Convert.ToSingle(values[3]));
                    }
                    else if( attrib.Name == "scale" )
                    {
                        string[] values = attrib.Value.Split(',');
                        scale = new Vector3(Convert.ToSingle(values[0]), Convert.ToSingle(values[1]), Convert.ToSingle(values[2]));
                    }
                    else if( attrib.Name == "update" )
                    {
                        updateCallback = Program.TheForm.FindUpdateFunction(attrib.Value);
                    }
                }

                foreach( XmlNode child in roXML.DocumentElement.ChildNodes )
                {
                    if( child.NodeType == XmlNodeType.Element )
                    {
                        string nodeName = child.Attributes.GetNamedItem("name").Value;
                        string nodeSrc = child.Attributes.GetNamedItem("src").Value;
                        if (child.Name == "mesh")
                        {
                            mesh = scene.GetMesh(nodeName, nodeSrc);
                        }
                        else if (child.Name == "shader")
                        {
                            shader = scene.GetShader(nodeName, nodeSrc);
                        }
                        else if (child.Name == "texture")
                        {
                            Texture tex = null;
                            if( nodeSrc == "frameBuffer" )
                            {
                                var depthTexture = false;
                                XmlAttribute dtAttr = (XmlAttribute)child.Attributes.GetNamedItem("depthTexture");
                                if( dtAttr != null )
                                    depthTexture = (dtAttr.Value == "true");

                                FrameBuffer fb = scene.GetFrameBuffer(nodeName, null);
                                if( fb != null )
                                {
                                    if( depthTexture )
                                        tex = fb.depthTexture;
                                    else
                                        tex = fb.colorTexture;
                                }
                            }
                            else
                            {
                                // Normal texture
                                tex = scene.GetTexture(nodeName, nodeSrc);
                            }

                            if( tex != null )
                            {
                                var texIndex = 0;
                                XmlAttribute index = (XmlAttribute)child.Attributes.GetNamedItem("texIndex");
                                if( index != null)
                                    texIndex = Convert.ToInt32(index.Value);

                                while (textures.Count <= texIndex)
                                    textures.Add(null);
                                textures[texIndex] = tex;
                            }
                        }
                        else if (child.Name == "shadowCamera")
                        {
                            shadowCamera = scene.GetCamera(nodeName, nodeSrc);
                        }
                    }
                }
            }
            catch(Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Failed to load render object: " + src + "\r\n" + e.Message);
            }

            UpdateWorldMatrix();
        }
Esempio n. 2
0
        public Camera GetCamera(string name, string src)
        {
            for (var i = 0; i < cameras.Count; i++)
            {
                if( cameras[i].name == name )
                    return cameras[i];
            }

            // Doesnt exist, load it now
            Camera camera = new Camera(this, name, src);
            cameras.Add(camera);
            return camera;
        }
Esempio n. 3
0
        public RenderPass(Scene scene, string name, string src)
            : base(scene, name, src)
        {
            // Load the source
            try
            {
                XmlDocument rpXML = new XmlDocument();
                rpXML.Load(src);

                // Get the attribute properties
                foreach( XmlAttribute attrib in rpXML.DocumentElement.Attributes )
                {
                    switch( attrib.Name )
                    {
                        case "sortMode":
                            sortMode = attrib.Value;
                            break;
                        case "clearMode":
                            string clearMode = attrib.Value;
                            clearColor = (clearMode.IndexOf("color") >= 0);
                            clearDepth = (clearMode.IndexOf("depth") >= 0);
                            clearStencil = (clearMode.IndexOf("stencil") >= 0);
                            break;
                        case "clearDepth":
                            clearDepthValue = Convert.ToSingle(attrib.Value);
                            break;
                        case "clearStencil":
                            clearStencilValue = Convert.ToSingle(attrib.Value);
                            break;
                        case "clearColor":
                            string[] clearColors = attrib.Value.Split(',');
                            clearColorRed = Convert.ToSingle(clearColors[0]) / 255.0f;
                            clearColorGreen = Convert.ToSingle(clearColors[1]) / 255.0f;
                            clearColorBlue = Convert.ToSingle(clearColors[2]) / 255.0f;
                            break;
                        default:
                            break;
                    }
                }

                foreach( XmlNode child in rpXML.DocumentElement.ChildNodes )
                {
                    if (child.NodeType == XmlNodeType.Element)
                    {
                        string objName = child.Attributes.GetNamedItem("name").Value;
                        string objSrc = child.Attributes.GetNamedItem("src").Value;
                        if (child.Name == "viewport")
                        {
                            viewport = scene.GetViewport(objName, objSrc);
                        }
                        else if (child.Name == "camera")
                        {
                            camera = scene.GetCamera(objName, objSrc);
                        }
                        else if (child.Name == "frameBuffer")
                        {
                            frameBuffer = scene.GetFrameBuffer(objName, objSrc);
                        }
                        else if (child.Name == "overrideShader")
                        {
                            overrideShader = scene.GetShader(objName, objSrc);
                        }
                    }
                }
            }
            catch(Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Failed to load render pass: "******"\r\n" + e.Message);
            }
        }