Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeshReader"/> class.
 /// </summary>
 /// <param name="mesh">The mesh.</param>
 /// <param name="definition">The mesh's definition data.</param>
 public MeshReader(Mesh mesh, RenderGeometryResourceDefinition definition)
 {
     Mesh = mesh;
     Definition = definition;
     VertexStreams = new VertexBufferDefinition[StreamCount];
     IndexBuffers = new IndexBufferDefinition[IndexBufferCount];
     BindVertexStreams();
     BindIndexBuffers();
 }
Beispiel #2
0
        /// <summary>
        /// Reads the index buffer data and converts it into a triangle list if necessary.
        /// </summary>
        /// <param name="reader">The mesh reader to use.</param>
        /// <param name="part">The mesh part to read.</param>
        /// <param name="resourceStream">A stream open on the resource data.</param>
        /// <returns>The index buffer converted into a triangle list.</returns>
        private static uint[] ReadIndexes(MeshReader reader, Mesh.Part part, Stream resourceStream)
        {
            // Use index buffer 0
            var indexBuffer = reader.IndexBuffers[0];
            if (indexBuffer == null)
                throw new InvalidOperationException("Index buffer 0 is null");

            // Read the indexes
            var indexStream = reader.OpenIndexBufferStream(indexBuffer, resourceStream);
            indexStream.Position = part.FirstIndex;
            switch (indexBuffer.Type)
            {
                case PrimitiveType.TriangleList:
                    return indexStream.ReadIndexes(part.IndexCount);
                case PrimitiveType.TriangleStrip:
                    return indexStream.ReadTriangleStrip(part.IndexCount);
                default:
                    throw new InvalidOperationException("Unsupported index buffer type: " + indexBuffer.Type);
            }
        }