예제 #1
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 ushort[] ReadIndices(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 indices
            var indexStream = reader.OpenIndexBufferStream(indexBuffer, resourceStream);

            indexStream.Position = part.FirstIndexOld;
            switch (indexBuffer.Format)
            {
            case IndexBufferFormat.TriangleList:
                return(indexStream.ReadIndices(part.IndexCountOld));

            case IndexBufferFormat.TriangleStrip:
                return(indexStream.ReadTriangleStrip(part.IndexCountOld));

            default:
                throw new InvalidOperationException("Unsupported index buffer type: " + indexBuffer.Format);
            }
        }
예제 #2
0
        /// <summary>
        /// Begins a new part in the current mesh.
        /// </summary>
        /// <param name="materialIndex">Index of the material.</param>
        /// <param name="firstIndex">The first index.</param>
        /// <param name="indexCount">The index count.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <exception cref="System.InvalidOperationException">Cannot define a part if no mesh is active</exception>
        public void BeginPart(short materialIndex, ushort firstIndex, ushort indexCount, ushort vertexCount)
        {
            if (_currentMesh == null)
            {
                throw new InvalidOperationException("Cannot define a part if no mesh is active");
            }

            _currentPart = new Mesh.Part
            {
                MaterialIndex           = materialIndex,
                TransparentSortingIndex = -1,
                FirstIndexOld           = firstIndex,
                IndexCountOld           = indexCount,
                FirstSubPartIndex       = (short)(_currentMesh.Mesh.SubParts.Count - 1),
                SubPartCount            = 0,
                // TODO: Unknown values here
                VertexCount = vertexCount,
            };
        }
예제 #3
0
        public void EndPart()
        {
            if (_currentPart == null)
            {
                throw new InvalidOperationException("Cannot end a part if no part is active");
            }
            if (_currentMesh == null)
            {
                throw new InvalidOperationException("Cannot end a part if no mesh is active");
            }
            if (_currentPermutation == null)
            {
                throw new InvalidOperationException("Cannot end a part if no permutation is active");
            }

            _currentPart.SubPartCount = (short)_subparts.Count;
            _currentMesh.Mesh.SubParts.AddRange(_subparts);
            _currentMesh.Mesh.Parts.Add(_currentPart);
            _subparts.Clear();
            _currentPart = null;
        }