Beispiel #1
0
        private static Primitive ExtractPrimitive(ref VoidPtr address, ElementFlags entryInfo, ushort[] nodeBuffer, ref int nodeIndex)
        {
Top:
            PrimitiveHeader * header = (PrimitiveHeader *)address;
            GLPrimitiveType type;

            switch (header->Type)
            {
            case WiiPrimitiveType.BoneDef1:
            {
                if (*(bushort *)header->Data == 0xB000)
                {
                    nodeIndex = 0;
                }
                nodeBuffer[nodeIndex++] = header->Entries;

                //nodeBuffer[(*(bushort*)header->Data - 0xB000) / 0x0C] = header->Entries;
                address += 5;
                goto Top;
            }

            case WiiPrimitiveType.BoneDef2:
            case WiiPrimitiveType.BoneDef3:
            { address += 5; goto Top; }

            case WiiPrimitiveType.Lines: { type = GLPrimitiveType.Lines; break; }

            case WiiPrimitiveType.LineStrip: { type = GLPrimitiveType.LineStrip; break; }

            case WiiPrimitiveType.Points: { type = GLPrimitiveType.Points; break; }

            case WiiPrimitiveType.Quads: { type = GLPrimitiveType.Quads; break; }

            case WiiPrimitiveType.TriangleFan: { type = GLPrimitiveType.TriangleFan; break; }

            case WiiPrimitiveType.Triangles: { type = GLPrimitiveType.Triangles; break; }

            case WiiPrimitiveType.TriangleStrip: { type = GLPrimitiveType.TriangleStrip; break; }

            default: return(null);
            }

            Primitive primitive = new Primitive();

            primitive._type = GLPrimitiveType.Triangles;


            int   entries = primitive._elementCount = header->Entries;
            int   stride  = entryInfo.Stride;
            byte *data    = (byte *)header->Data;

            //Pos matrices
            if (entryInfo.PosNormMatrixIndex)
            {
                primitive._weightIndices = ParseWeights(data, entries, stride, nodeBuffer);
                data += 1;
            }

            //Tex matrices
            for (int i = 0; i < 8; i++)
            {
                if (entryInfo.TexMatrixIndex[i])
                {
                    data++;
                }
            }

            XFDataFormat *fPtr = &entryInfo.PositionFormat;

            primitive._vertexIndices = ParseElement(ref data, *fPtr++, entries, stride);
            primitive._normalIndices = ParseElement(ref data, *fPtr++, entries, stride);

            //Color Data
            for (int i = 0; i < 2;)
            {
                primitive._colorIndices[i++] = ParseElement(ref data, *fPtr++, entries, stride);
            }

            //UV Data
            for (int i = 0; i < 8;)
            {
                primitive._uvIndices[i++] = ParseElement(ref data, *fPtr++, entries, stride);
            }

            address += stride * entries + 3;

            return(primitive);
        }
        //public static GLPrimitive ExtractPrimitive(ref VoidPtr address, EntrySize entryInfo, GLPolygon parent, ushort[] nodeBuffer, ref int nodeIndex)
        //{
        //Top:
        //    PrimitiveHeader* header = (PrimitiveHeader*)address;
        //    GLPrimitiveType type;
        //    switch (header->Type)
        //    {
        //        case WiiPrimitiveType.PosMtx: //0x20
        //            {
        //                if (*(bushort*)header->Data == 0xB000)
        //                    nodeIndex = 0;
        //                nodeBuffer[nodeIndex++] = header->Entries;

        //                //nodeBuffer[(*(bushort*)header->Data - 0xB000) / 0x0C] = header->Entries;
        //                address += 5;
        //                goto Top;
        //            }
        //        case WiiPrimitiveType.NorMtx: //0x28
        //        case WiiPrimitiveType.TexMtx: //0x30
        //        case WiiPrimitiveType.LightMtx: //0x38
        //            { address += 5; goto Top; }
        //        case WiiPrimitiveType.Lines: { type = GLPrimitiveType.Lines; break; } //0xA8
        //        case WiiPrimitiveType.LineStrip: { type = GLPrimitiveType.LineStrip; break; } //0xB0
        //        case WiiPrimitiveType.Points: { type = GLPrimitiveType.Points; break; } //0xB8
        //        case WiiPrimitiveType.Quads: { type = GLPrimitiveType.Quads; break; } //0x80
        //        case WiiPrimitiveType.TriangleFan: { type = GLPrimitiveType.TriangleFan; break; } //0xA0
        //        case WiiPrimitiveType.Triangles: { type = GLPrimitiveType.Triangles; break; } //0x90
        //        case WiiPrimitiveType.TriangleStrip: { type = GLPrimitiveType.TriangleStrip; break; } //0x98
        //        default:
        //            return null;
        //    }

        //    GLPrimitive primitive = new GLPrimitive();
        //    primitive._type = type;
        //    primitive._elements = header->Entries;
        //    primitive._parent = parent;

        //    int entries = primitive._elements;
        //    int stride = entryInfo._totalLen;
        //    VoidPtr data = header->Data;

        //    //Weight indices
        //    primitive._nodeIndices = ParseWeights(data, entries, entryInfo._extraLen, stride, nodeBuffer);
        //    data += entryInfo._extraLen;

        //    //Vertex Data
        //    primitive._vertexIndices = ParseIndices(data, entries, entryInfo._vertexLen, stride);
        //    data += entryInfo._vertexLen;

        //    //Normal Data
        //    primitive._normalIndices = ParseIndices(data, entries, entryInfo._normalLen, stride);
        //    data += entryInfo._normalLen;

        //    //Color Data
        //    for (int i = 0; i < 2; data += entryInfo._colorLen[i++])
        //        primitive._colorIndices[i] = ParseIndices(data, entries, entryInfo._colorLen[i++], stride);

        //    //UV Data
        //    for (int i = 0; i < 8; data += entryInfo._uvLen[i++])
        //        primitive._uvIndices[i] = ParseIndices(data, entries, entryInfo._uvLen[i], stride);

        //    address += (entryInfo._totalLen * entries) + 3;

        //    return primitive;
        //}

        private static Primitive ExtractPrimitive(ref VoidPtr address, EntrySize entryInfo, ushort[] nodeBuffer, ref int nodeIndex)
        {
Top:
            PrimitiveHeader * header = (PrimitiveHeader *)address;
            GLPrimitiveType type;

            switch (header->Type)
            {
            case WiiPrimitiveType.PosMtx:     //0x20
            {
                if (*(bushort *)header->Data == 0xB000)
                {
                    nodeIndex = 0;
                }
                nodeBuffer[nodeIndex++] = header->Entries;

                //nodeBuffer[(*(bushort*)header->Data - 0xB000) / 0x0C] = header->Entries;
                address += 5;
                goto Top;
            }

            case WiiPrimitiveType.NorMtx:     //0x28
            case WiiPrimitiveType.TexMtx:     //0x30
            case WiiPrimitiveType.LightMtx:   //0x38
            { address += 5; goto Top; }

            case WiiPrimitiveType.Lines: { type = GLPrimitiveType.Lines; break; }                 //0xA8

            case WiiPrimitiveType.LineStrip: { type = GLPrimitiveType.LineStrip; break; }         //0xB0

            case WiiPrimitiveType.Points: { type = GLPrimitiveType.Points; break; }               //0xB8

            case WiiPrimitiveType.Quads: { type = GLPrimitiveType.Quads; break; }                 //0x80

            case WiiPrimitiveType.TriangleFan: { type = GLPrimitiveType.TriangleFan; break; }     //0xA0

            case WiiPrimitiveType.Triangles: { type = GLPrimitiveType.Triangles; break; }         //0x90

            case WiiPrimitiveType.TriangleStrip: { type = GLPrimitiveType.TriangleStrip; break; } //0x98

            default:
                return(null);
            }

            Primitive primitive = new Primitive();

            primitive._type = type;

            int     entries = primitive._elementCount = header->Entries;
            int     stride  = entryInfo._totalLen;
            VoidPtr data    = header->Data;

            //Weight indices
            primitive._weightIndices = ParseWeights(data, entries, entryInfo._extraLen, stride, nodeBuffer);
            data += entryInfo._extraLen;

            //Vertex Data
            primitive._vertexIndices = ParseIndices(data, entries, entryInfo._vertexLen, stride);
            data += entryInfo._vertexLen;

            //Normal Data
            primitive._normalIndices = ParseIndices(data, entries, entryInfo._normalLen, stride);
            data += entryInfo._normalLen;

            //Color Data
            for (int i = 0; i < 2; data += entryInfo._colorLen[i++])
            {
                primitive._colorIndices[i] = ParseIndices(data, entries, entryInfo._colorLen[i], stride);
            }

            //UV Data
            for (int i = 0; i < 8; data += entryInfo._uvLen[i++])
            {
                primitive._uvIndices[i] = ParseIndices(data, entries, entryInfo._uvLen[i], stride);
            }

            address += (entryInfo._totalLen * entries) + 3;

            return(primitive);
        }