public static BoundingBox ReadBoundingBox(TWXmlNode node) { Vector3 min = ReadVector3(node.FindChildNode("Min")); Vector3 max = ReadVector3(node.FindChildNode("Max")); return(new BoundingBox(min, max)); }
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)); }
public static BoundingSphere ReadBoundingSphere(TWXmlNode node) { Vector3 center = ReadVector3(node.FindChildNode("Center")); float radius = float.Parse(node.ReadChildNodeValue("Radius")); return(new BoundingSphere(center, radius)); }
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); }
public static Matrix ReadMatrix(TWXmlNode node) { TWXmlNode rowMatrixNode = node.FindChildNode("MatrixRows"); float[] floats = ReadFloatArray(rowMatrixNode); Matrix mat = new Matrix( floats[0], floats[1], floats[2], floats[3], floats[4], floats[5], floats[6], floats[7], floats[8], floats[9], floats[10], floats[11], floats[12], floats[13], floats[14], floats[15]); return(mat); }
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); }