Beispiel #1
0
 /// <summary>
 /// Opens an index buffer stream on one of the mesh's index buffers.
 /// </summary>
 /// <param name="definition">The index buffer definition.</param>
 /// <param name="baseStream">The stream open on the mesh's resource data to use as a base stream.</param>
 /// <returns>The index buffer stream if successful, or <c>null</c> otherwise.</returns>
 public IndexBufferStream OpenIndexBufferStream(IndexBufferDefinition definition, Stream baseStream)
 {
     if (definition.Data.Address.Type != CacheAddressType.Resource)
     {
         return(null); // Don't bother supporting non-resource addresses
     }
     baseStream.Position = definition.Data.Address.Offset;
     return(new IndexBufferStream(baseStream));
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MeshReader"/> class.
 /// </summary>
 /// <param name="version">The engine version to target.</param>
 /// <param name="mesh">The mesh.</param>
 /// <param name="definition">The mesh's definition data.</param>
 public MeshReader(DefinitionSet version, Mesh mesh, RenderGeometryResourceDefinition definition)
 {
     _version      = version;
     Mesh          = mesh;
     Definition    = definition;
     VertexStreams = new VertexBufferDefinition[StreamCount];
     IndexBuffers  = new IndexBufferDefinition[IndexBufferCount];
     BindVertexStreams();
     BindIndexBuffers();
 }
        public static IndexBufferDefinition CreateIndexBuffer(int count)
        {
            var newIndexBuffer = new IndexBufferDefinition
            {
                Format = IndexBufferFormat.TriangleStrip,
                Data   = new TagData()
            };

            using (var stream = new MemoryStream())
                using (var writer = new EndianWriter(stream, EndianFormat.LittleEndian))
                {
                    for (var j = 0; j < count; j++)
                    {
                        writer.Write((short)j);
                    }
                    newIndexBuffer.Data.Data = stream.ToArray();
                }
            return(newIndexBuffer);
        }
        public static void ConvertIndexBuffer(CacheVersion inVersion, CacheVersion outVersion, IndexBufferDefinition indexBuffer)
        {
            using (var outputStream = new MemoryStream())
                using (var inputStream = new MemoryStream(indexBuffer.Data.Data))
                {
                    var inIndexStream  = new IndexBufferStream(inputStream, CacheVersionDetection.IsLittleEndian(inVersion) ? EndianFormat.LittleEndian : EndianFormat.BigEndian);
                    var outIndexStream = new IndexBufferStream(outputStream, CacheVersionDetection.IsLittleEndian(outVersion) ? EndianFormat.LittleEndian : EndianFormat.BigEndian);
                    var indexCount     = indexBuffer.Data.Data.Length / 2;
                    for (var j = 0; j < indexCount; j++)
                    {
                        outIndexStream.WriteIndex(inIndexStream.ReadIndex());
                    }

                    indexBuffer.Data.Data = outputStream.ToArray();
                }
        }
Beispiel #5
0
        /// <summary>
        /// Opens an index buffer stream on one of the mesh's index buffers.
        /// </summary>
        /// <param name="definition">The index buffer definition.</param>
        /// <returns>The index buffer stream if successful, or <c>null</c> otherwise.</returns>
        public IndexBufferStream OpenIndexBufferStream(IndexBufferDefinition definition)
        {
            var stream = new MemoryStream(definition.Data.Data);

            return(new IndexBufferStream(stream));
        }