Exemplo n.º 1
0
        void LoadMesh(Chunk chunk, Chunk parent, BasicMesh mesh)
        {
            var prims   = new List <Primitive>();
            var indices = new List <ushort>();
            int iArrays = -1;

            Chunk child;

            for (int pos = chunk.Child; pos < chunk.Next; pos = child.Next)
            {
                child = ReadChunk(pos);
                int args = child.Args;
                switch (child.Type)
                {
                case ChunkType.SetMaterial:
                    mesh.Material = ReadIndex(args);
                    break;

                case ChunkType.BlendSubset:
                    int nIndices = ReadInt32(args);
                    mesh.BlendSubset = new int[nIndices];
                    for (int i = 0; i < nIndices; i++)
                    {
                        mesh.BlendSubset[i] = ReadIndex(args + 4 + 4 * i);
                    }
                    break;

                case ChunkType.DrawArrays:
                    iArrays = ReadIndex(args + 0);
                    int mode   = ReadInt32(args + 4);
                    int first  = indices.Count;
                    int nVerts = ReadInt32(args + 8);
                    int nPrims = ReadInt32(args + 12);
                    int total  = nVerts * nPrims;

                    var prim = new Primitive(GetDrawMode(mode), first, nVerts, 0);
                    //                    var prim = new Primitive( GetDrawMode( 2 ), first, nVerts, 0 ) ;
                    for (int i = 0; i < nPrims; i++)
                    {
                        prims.Add(prim);
                        prim.First += (ushort)nVerts;
                    }
                    bool sequential = ((mode & 0x8000) != 0);
                    int  index      = ReadUInt16(args + 16);
                    for (int i = 0; i < total; i++)
                    {
                        if (!sequential)
                        {
                            index = ReadUInt16(args + 16 + i * 2);
                        }
                        indices.Add((ushort)(index++));
                    }
                    break;
                }
            }

            if (iArrays < 0)
            {
                return;
            }
            int   pArrays = FindChild(parent, ChunkType.Arrays, iArrays);
            Chunk chunk2  = ReadChunk(pArrays);

            int args2  = chunk2.Args;
            int format = ReadInt32(args2 + 0);
            int count  = ReadInt32(args2 + 4);
            int data2  = chunk2.Data;

            VertexFormat[] formats = GetVertexFormats(format);
            int[]          offsets = GetVertexOffsets(format);
            int            stride  = GetVertexStride(format);

            //        vertexformat hack
            // for( int i = 0; i < formats.Length; i++ ){
            //     if( i == 3 || i == 4 || i == 5 ){
            //         formats[ i ] = VertexFormat.Half2;
            //     }
            // }

            mesh.VertexBuffer = new VertexBuffer(count, indices.Count, formats);
            mesh.VertexBuffer.SetIndices(indices.ToArray());
            for (int i = 0; i < formats.Length; i++)
            {
                if (formats[i] == VertexFormat.None)
                {
                    continue;
                }

                // // vertexformat hack
                // if( i == 3 || i == 4 || i == 5 ){
                //     // tex0

                //     float[] array = new float[ count * 2 ];
                //     for( int idx = 0; idx < count; idx++ ){
                //         int ofst =  data2 + offsets[ i ] + stride * idx;
                //         float u = BitConverter.ToSingle( fileImage, ofst + 0);
                //         float v = BitConverter.ToSingle( fileImage, ofst + 4);

                //         array[ idx * 2 + 0 ] = u;
                //         array[ idx * 2 + 1 ] = v;
                //         //                    array[ idx * 2 + 0 ] = (short)idx;
                //         //                    array[ idx * 2 + 1 ] = (short)idx;

                //     }
                //     mesh.VertexBuffer.SetVertices( i, array, VertexFormat.Half2,
                //                                    new Vector4( 0.0f, 0.0f, 0.0f, 0.0f),
                //                                    new Vector4( 1.0f, 1.0f, 1.0f, 1.0f) );//BitConverter.GetBytes( array ) );

                // }else{
                //     //			mesh.VertexBuffer.SetVertices( i, fileImage, data2 + offsets[ i ], stride ) ;
                //     mesh.VertexBuffer.SetVertices( i, fileImage, data2 + offsets[ i ], stride ) ;
                // }

                mesh.VertexBuffer.SetVertices(i, fileImage, data2 + offsets[i], stride);
            }
            mesh.Primitives = prims.ToArray();
        }
Exemplo n.º 2
0
 public Part(BasicMesh mesh, int drawOrder)
 {
     this.mesh      = mesh;
     this.drawOrder = drawOrder;
 }
Exemplo n.º 3
0
 public Part( BasicMesh mesh, int drawOrder )
 {
     this.mesh = mesh;
     this.drawOrder = drawOrder;
 }
Exemplo n.º 4
0
        void LoadMesh( Chunk chunk, Chunk parent, BasicMesh mesh )
        {
            var prims = new List<Primitive>() ;
            var indices = new List<ushort>() ;
            int iArrays = -1 ;

            Chunk child ;
            for ( int pos = chunk.Child ; pos < chunk.Next ; pos = child.Next ) {
            child = ReadChunk( pos ) ;
            int args = child.Args ;
            switch ( child.Type ) {
                case ChunkType.SetMaterial :
                    mesh.Material = ReadIndex( args ) ;
                    break ;
                case ChunkType.BlendSubset :
                    int nIndices = ReadInt32( args ) ;
                    mesh.BlendSubset = new int[ nIndices ] ;
                    for ( int i = 0 ; i < nIndices ; i ++ ) {
                        mesh.BlendSubset[ i ] = ReadIndex( args + 4 + 4 * i ) ;
                    }
                    break ;
                case ChunkType.DrawArrays :
                    iArrays = ReadIndex( args + 0 ) ;
                    int mode = ReadInt32( args + 4 ) ;
                    int first = indices.Count ;
                    int nVerts = ReadInt32( args + 8 ) ;
                    int nPrims = ReadInt32( args + 12 ) ;
                    int total = nVerts * nPrims ;

                    var prim = new Primitive( GetDrawMode( mode ), first, nVerts, 0 ) ;
                    //                    var prim = new Primitive( GetDrawMode( 2 ), first, nVerts, 0 ) ;
                    for ( int i = 0 ; i < nPrims ; i ++ ) {
                        prims.Add( prim ) ;
                        prim.First += (ushort)nVerts ;
                    }
                    bool sequential = ( ( mode & 0x8000 ) != 0 ) ;
                    int index = ReadUInt16( args + 16 ) ;
                    for ( int i = 0 ; i < total ; i ++ ) {
                        if ( !sequential ) index = ReadUInt16( args + 16 + i * 2 ) ;
                        indices.Add( (ushort)( index ++ ) ) ;
                    }
                    break ;
            }
            }

            if ( iArrays < 0 ) return ;
            int pArrays = FindChild( parent, ChunkType.Arrays, iArrays ) ;
            Chunk chunk2 = ReadChunk( pArrays ) ;

            int args2 = chunk2.Args ;
            int format = ReadInt32( args2 + 0 ) ;
            int count = ReadInt32( args2 + 4 ) ;
            int data2 = chunk2.Data ;

            VertexFormat[] formats = GetVertexFormats( format ) ;
            int[] offsets = GetVertexOffsets( format ) ;
            int stride = GetVertexStride( format ) ;

            //        vertexformat hack
            // for( int i = 0; i < formats.Length; i++ ){
            //     if( i == 3 || i == 4 || i == 5 ){
            //         formats[ i ] = VertexFormat.Half2;
            //     }
            // }

            mesh.VertexBuffer = new VertexBuffer( count, indices.Count, formats ) ;
            mesh.VertexBuffer.SetIndices( indices.ToArray() ) ;
            for ( int i = 0 ; i < formats.Length ; i ++ ) {
            if ( formats[ i ] == VertexFormat.None ) continue ;

            // // vertexformat hack
            // if( i == 3 || i == 4 || i == 5 ){
            //     // tex0

            //     float[] array = new float[ count * 2 ];
            //     for( int idx = 0; idx < count; idx++ ){
            //         int ofst =  data2 + offsets[ i ] + stride * idx;
            //         float u = BitConverter.ToSingle( fileImage, ofst + 0);
            //         float v = BitConverter.ToSingle( fileImage, ofst + 4);

            //         array[ idx * 2 + 0 ] = u;
            //         array[ idx * 2 + 1 ] = v;
            //         //                    array[ idx * 2 + 0 ] = (short)idx;
            //         //                    array[ idx * 2 + 1 ] = (short)idx;

            //     }
            //     mesh.VertexBuffer.SetVertices( i, array, VertexFormat.Half2,
            //                                    new Vector4( 0.0f, 0.0f, 0.0f, 0.0f),
            //                                    new Vector4( 1.0f, 1.0f, 1.0f, 1.0f) );//BitConverter.GetBytes( array ) );

            // }else{
            //     //			mesh.VertexBuffer.SetVertices( i, fileImage, data2 + offsets[ i ], stride ) ;
            //     mesh.VertexBuffer.SetVertices( i, fileImage, data2 + offsets[ i ], stride ) ;
            // }

            mesh.VertexBuffer.SetVertices( i, fileImage, data2 + offsets[ i ], stride ) ;
            }
            mesh.Primitives = prims.ToArray() ;
        }