Ejemplo n.º 1
0
        public static Color ReadColor(TWXmlNode node)
        {
            node = node.FindChildNode("Color");
            Color c = new Color((byte)node.GetAttributeInt("R"), (byte)node.GetAttributeInt("G"), (byte)node.GetAttributeInt("B")
                                , (byte)node.GetAttributeInt("A"));


            return(c);
        }
Ejemplo n.º 2
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.º 3
0
        public static Vector3[] ReadVector3Array(TWXmlNode node)
        {
            if (node.Value == "NULL")
            {
                return(null);
            }
            int count = node.GetAttributeInt("Count");

            Vector3[] array = new Vector3[count];

            TWXmlNode[] vectorNodes = node.GetChildNodes();
            int         i           = 0;

            foreach (TWXmlNode nodeVector in vectorNodes)
            {
                Vector3 v = new Vector3();
                v.X = float.Parse(nodeVector.GetAttribute("X"));
                v.Y = float.Parse(nodeVector.GetAttribute("Y"));
                v.Z = float.Parse(nodeVector.GetAttribute("Z"));

                array[i] = v;
                i++;
            }

            return(array);
        }
Ejemplo n.º 4
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);
        }