protected void ReadVertex(XmlNode node, XmlVertexData vertexData, int vertexIndex) { int textureIndex = 0; foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "position": ReadVector(childNode, vertexData.positionData, vertexIndex); break; case "normal": ReadVector(childNode, vertexData.normalData, vertexIndex); break; case "colour_diffuse": ReadColour(childNode, vertexData.diffuseData, vertexIndex); break; case "colour_specular": ReadColour(childNode, vertexData.specularData, vertexIndex); break; case "texcoord": ReadTexCoord(childNode, vertexData.GetTextureData(textureIndex), vertexIndex); textureIndex++; break; default: DebugMessage(childNode); break; } } }
protected void ReadVertexBuffer(XmlNode node, VertexData vertexData, XmlVertexData xmlVertexData) { bool positions = false; bool normals = false; bool colours_diffuse = false; bool colours_specular = false; int texture_coords = 0; foreach (XmlAttribute attr in node.Attributes) { switch (attr.Name) { case "positions": if (attr.Value == "true") { positions = true; xmlVertexData.positionData = new float[xmlVertexData.vertexCount, 3]; } break; case "normals": if (attr.Value == "true") { normals = true; xmlVertexData.normalData = new float[xmlVertexData.vertexCount, 3]; } break; case "colours_diffuse": if (attr.Value == "true") { colours_diffuse = true; xmlVertexData.diffuseData = new uint[xmlVertexData.vertexCount]; } break; case "colours_specular": if (attr.Value == "true") { colours_specular = true; xmlVertexData.specularData = new uint[xmlVertexData.vertexCount]; } break; case "texture_coords": texture_coords = int.Parse(attr.Value); break; case "texture_coord_dimensions_0": case "texture_coord_dimensions_1": case "texture_coord_dimensions_2": case "texture_coord_dimensions_3": case "texture_coord_dimensions_4": case "texture_coord_dimensions_5": case "texture_coord_dimensions_6": case "texture_coord_dimensions_7": break; default: DebugMessage(node, attr); break; } } for (int i = 0; i < texture_coords; ++i) { string key = string.Format("texture_coord_dimensions_{0}", i); XmlNode attrNode = node.Attributes.GetNamedItem(key); if (attrNode != null) xmlVertexData.AddTexture(int.Parse(attrNode.Value)); else xmlVertexData.AddTexture(2); } int vertexIndex = 0; foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "vertex": ReadVertex(childNode, xmlVertexData, vertexIndex++); break; default: DebugMessage(childNode); break; } } if (positions) AllocateBuffer(vertexData, VertexElementType.Float3, VertexElementSemantic.Position, xmlVertexData.bindIdx++, 0, xmlVertexData.positionData); if (normals) AllocateBuffer(vertexData, VertexElementType.Float3, VertexElementSemantic.Normal, xmlVertexData.bindIdx++, 0, xmlVertexData.normalData); if (colours_diffuse) AllocateBuffer(vertexData, VertexElementType.Color, VertexElementSemantic.Diffuse, xmlVertexData.bindIdx++, 0, xmlVertexData.diffuseData); if (colours_specular) AllocateBuffer(vertexData, VertexElementType.Color, VertexElementSemantic.Specular, xmlVertexData.bindIdx++, 0, xmlVertexData.specularData); for (int i = 0; i < texture_coords; ++i) { int dim = xmlVertexData.GetTextureData(i).GetLength(1); AllocateBuffer(vertexData, VertexElement.MultiplyTypeCount(VertexElementType.Float1, dim), VertexElementSemantic.TexCoords, xmlVertexData.bindIdx++, i, xmlVertexData.GetTextureData(i)); } // We have read the textures for this vertex buffer node. xmlVertexData.textureOffset += texture_coords; }
protected void ReadVertexBuffer(XmlNode node, VertexData vertexData, XmlVertexData xmlVertexData) { bool positions = false; bool normals = false; bool colours_diffuse = false; bool colours_specular = false; int texture_coords = 0; foreach (XmlAttribute attr in node.Attributes) { switch (attr.Name) { case "positions": if (attr.Value == "true") { positions = true; xmlVertexData.positionData = new float[xmlVertexData.vertexCount, 3]; } break; case "normals": if (attr.Value == "true") { normals = true; xmlVertexData.normalData = new float[xmlVertexData.vertexCount, 3]; } break; case "colours_diffuse": if (attr.Value == "true") { colours_diffuse = true; xmlVertexData.diffuseData = new uint[xmlVertexData.vertexCount]; } break; case "colours_specular": if (attr.Value == "true") { colours_specular = true; xmlVertexData.specularData = new uint[xmlVertexData.vertexCount]; } break; case "texture_coords": texture_coords = int.Parse(attr.Value); break; case "texture_coord_dimensions_0": case "texture_coord_dimensions_1": case "texture_coord_dimensions_2": case "texture_coord_dimensions_3": case "texture_coord_dimensions_4": case "texture_coord_dimensions_5": case "texture_coord_dimensions_6": case "texture_coord_dimensions_7": break; default: DebugMessage(node, attr); break; } } for (int i = 0; i < texture_coords; ++i) { string key = string.Format("texture_coord_dimensions_{0}", i); XmlNode attrNode = node.Attributes.GetNamedItem(key); if (attrNode != null) { xmlVertexData.AddTexture(int.Parse(attrNode.Value)); } else { xmlVertexData.AddTexture(2); } } int vertexIndex = 0; foreach (XmlNode childNode in node.ChildNodes) { switch (childNode.Name) { case "vertex": ReadVertex(childNode, xmlVertexData, vertexIndex++); break; default: DebugMessage(childNode); break; } } if (positions) { AllocateBuffer(vertexData, VertexElementType.Float3, VertexElementSemantic.Position, xmlVertexData.bindIdx++, 0, xmlVertexData.positionData); } if (normals) { AllocateBuffer(vertexData, VertexElementType.Float3, VertexElementSemantic.Normal, xmlVertexData.bindIdx++, 0, xmlVertexData.normalData); } if (colours_diffuse) { AllocateBuffer(vertexData, VertexElementType.Color, VertexElementSemantic.Diffuse, xmlVertexData.bindIdx++, 0, xmlVertexData.diffuseData); } if (colours_specular) { AllocateBuffer(vertexData, VertexElementType.Color, VertexElementSemantic.Specular, xmlVertexData.bindIdx++, 0, xmlVertexData.specularData); } for (int i = 0; i < texture_coords; ++i) { int dim = xmlVertexData.GetTextureData(i).GetLength(1); AllocateBuffer(vertexData, VertexElement.MultiplyTypeCount(VertexElementType.Float1, dim), VertexElementSemantic.TexCoords, xmlVertexData.bindIdx++, i, xmlVertexData.GetTextureData(i)); } // We have read the textures for this vertex buffer node. xmlVertexData.textureOffset += texture_coords; }