/// <summary> /// Loads a VertexLayout based off of information in a vertex XML element. /// </summary> /// <param name="vertexElement">The vertex element to create the layout from.</param> /// <returns>The VertexLayout that was created.</returns> private static VertexLayout LoadLayout(XElement vertexElement) { // Vertex tags have the format: // <vertex type="(type index)" name="(vertex name)">(elements)</vertex> int type = XMLUtil.GetNumericAttribute(vertexElement, "type"); string name = XMLUtil.GetStringAttribute(vertexElement, "name"); VertexLayout result = new VertexLayout(type, name); result.AddElements(LoadLayoutElements(vertexElement)); return result; }
/// <summary> /// Reads vertices from a vertex buffer. /// </summary> /// <param name="reader">The stream to read from.</param> /// <param name="layout">The layout of each vertex to read.</param> /// <param name="count">The number of vertices to read.</param> /// <param name="boundingBox">The bounding box to transform vertices with. Can be null.</param> /// <param name="processor">The IVertexProcessor to send read vertices to. Can be null.</param> public static void ReadVertices(IReader reader, VertexLayout layout, int count, IModelBoundingBox boundingBox, IVertexProcessor processor) { for (int i = 0; i < count; i++) { long vertexStartPos = reader.Position; if (processor != null) processor.BeginVertex(); foreach (VertexElementLayout element in layout.Elements) { if (element.Stream == 0) // Not sure how multistream vertices work yet { reader.SeekTo(vertexStartPos + element.Offset); ReadElement(reader, element, boundingBox, processor); } } if (processor != null) processor.EndVertex(); } }