Ejemplo n.º 1
0
        public static VertexDeclaration ReadVertexDeclaration(XNAGame game, TWXmlNode node)
        {
            if (node.Value == "NULL")
            {
                return(null);
            }

            TWXmlNode elementsNode = node.FindChildNode("Elements");

            VertexElement[] elements = new VertexElement[elementsNode.GetAttributeInt("count")];

            TWXmlNode[] elementNodes = elementsNode.FindChildNodes("VertexElement");
            if (elementNodes.Length != elements.Length)
            {
                throw new InvalidOperationException("Invalid XML format!");
            }
            for (int i = 0; i < elementNodes.Length; i++)
            {
                TWXmlNode     elementNode = elementNodes[i];
                VertexElement element     = new VertexElement();
                element.Offset              = short.Parse(elementNode.ReadChildNodeValue("Offset"));
                element.Stream              = short.Parse(elementNode.ReadChildNodeValue("Stream"));
                element.UsageIndex          = byte.Parse(elementNode.ReadChildNodeValue("UsageIndex"));
                element.VertexElementFormat = (VertexElementFormat)System.Enum.Parse(typeof(VertexElementFormat), elementNode.ReadChildNodeValue("VertexElementFormat"));
                element.VertexElementMethod = (VertexElementMethod)System.Enum.Parse(typeof(VertexElementMethod), elementNode.ReadChildNodeValue("VertexElementMethod"));
                element.VertexElementUsage  = (VertexElementUsage)System.Enum.Parse(typeof(VertexElementUsage), elementNode.ReadChildNodeValue("VertexElementUsage"));
                elements[i] = element;
            }

            return(new VertexDeclaration(game.GraphicsDevice, elements));
        }
Ejemplo n.º 2
0
        public static Vector2 ReadVector2(TWXmlNode node)
        {
            Vector2 v = new Vector2();

            v.X = float.Parse(node.ReadChildNodeValue("X"));
            v.Y = float.Parse(node.ReadChildNodeValue("Y"));

            return(v);
        }
Ejemplo n.º 3
0
        private static Quaternion ReadQuaternion(TWXmlNode node)
        {
            Quaternion q = new Quaternion();

            q.X = float.Parse(node.ReadChildNodeValue("X"));
            q.Y = float.Parse(node.ReadChildNodeValue("Y"));
            q.Z = float.Parse(node.ReadChildNodeValue("Z"));
            q.W = float.Parse(node.ReadChildNodeValue("W"));

            return(q);
        }
Ejemplo n.º 4
0
        public static BoundingSphere ReadBoundingSphere(TWXmlNode node)
        {
            Vector3 center = ReadVector3(node.FindChildNode("Center"));
            float   radius = float.Parse(node.ReadChildNodeValue("Radius"));

            return(new BoundingSphere(center, radius));
        }
Ejemplo n.º 5
0
        public static VertexBuffer ReadVertexBuffer(TWXmlNode node, XNAGame game)
        {
            if (node.Value == "NULL")
            {
                return(null);
            }

            BufferUsage bufferUsage = (BufferUsage)Enum.Parse(typeof(BufferUsage), node.ReadChildNodeValue("BufferUsage"));

            TWXmlNode dataNode = node.FindChildNode("Data");
            int       length   = dataNode.GetAttributeInt("length");

            byte[] data = new byte[length];
            data = Convert.FromBase64String(dataNode.ReadCData());


            VertexBuffer vb = new VertexBuffer(game.GraphicsDevice, length, bufferUsage);

            vb.SetData <byte>(data);

            return(vb);
        }