//public void SetupBMD(BMDObjectAttrib* attrib) //{ // byte* pCom; // ElementDef* pDef; // WiiVertexComponentType format; // fixed (int* pDefData = Defs) // fixed (byte* pComData = Commands) // { // pCom = pComData; // pDef = (ElementDef*)pDefData; // while (attrib->ArrayType != GXAttribute.Null) // { // format = attrib->DataFormat; // switch (attrib->ArrayType) // { // case GXAttribute.PosNrmMtxId: // Weighted = true; // *pCom++ = (byte)DecodeOp.PosWeight; // Stride++; // break; // case GXAttribute.Tex0MtxId: // case GXAttribute.Tex1MtxId: // case GXAttribute.Tex2MtxId: // case GXAttribute.Tex3MtxId: // case GXAttribute.Tex4MtxId: // case GXAttribute.Tex5MtxId: // case GXAttribute.Tex6MtxId: // case GXAttribute.Tex7MtxId: // *pCom++ = (byte)(DecodeOp.TexMtx0 + (int)(attrib->ArrayType - GXAttribute.Tex0MtxId)); // Stride++; // break; // case GXAttribute.Position: // HasData[0] = true; // pDef->Type = 0; // Stride += (pDef->Format = (byte)((int)format < 2 ? 1 : 2)); // pDef->Output = 12; // *pCom++ = (byte)DecodeOp.ElementIndexed; // pDef++; // break; // case GXAttribute.Normal: // HasData[1] = true; // pDef->Type = 1; // Stride += (pDef->Format = (byte)((int)format < 2 ? 1 : 2)); // pDef->Output = 12; // *pCom++ = (byte)DecodeOp.ElementIndexed; // pDef++; // break; // case GXAttribute.Color0: // case GXAttribute.Color1: // int cIndex = (int)(attrib->ArrayType - GXAttribute.Color0); // HasData[cIndex + 2] = true; // pDef->Type = (byte)(cIndex + 2); // Stride += (pDef->Format = (byte)((int)format < 2 ? 1 : 2)); // pDef->Output = 4; // *pCom++ = (byte)DecodeOp.ElementIndexed; // pDef++; // break; // case GXAttribute.Tex0: // case GXAttribute.Tex1: // case GXAttribute.Tex2: // case GXAttribute.Tex3: // case GXAttribute.Tex4: // case GXAttribute.Tex5: // case GXAttribute.Tex6: // case GXAttribute.Tex7: // int uIndex = (int)(attrib->ArrayType - GXAttribute.Tex0); // HasData[uIndex + 4] = true; // pDef->Type = (byte)(uIndex + 4); // Stride += (pDef->Format = (byte)((int)format < 2 ? 1 : 2)); // pDef->Output = 8; // *pCom++ = (byte)DecodeOp.ElementIndexed; // pDef++; // break; // } // attrib++; // } // *pCom = 0; // } //} public void SetupMDL0(MDL0Object *polygon) { byte * pCom; ElementDef *pDef; CPElementSpec UVATGroups; int format; //0 for direct, 1 for byte, 2 for short //Read element descriptor from polygon display list MDL0PolygonDefs *Definitons = polygon->DefList; int fmtLo = (int)Definitons->VtxFmtLo; int fmtHi = (int)Definitons->VtxFmtHi; UVATGroups = new CPElementSpec( Definitons->UVATA, Definitons->UVATB, Definitons->UVATC); //Build extract script. //What we're doing is assigning extract commands for elements in the polygon, in true order. //This allows us to process the polygon blindly, assuming that the definition is accurate. //Theoretically, this should offer a significant speed bonus. fixed(int *pDefData = Defs) { fixed(byte *pComData = Commands) { pCom = pComData; pDef = (ElementDef *)pDefData; //Pos/Norm weight if (Weighted = (fmtLo & 1) != 0) { //Set the first command as the weight *pCom++ = (byte)DecodeOp.PosWeight; Stride++; //Increment stride by a byte (the length of the facepoints) } //Tex matrix for (int i = 0; i < 8; i++) { if (((fmtLo >> (i + 1)) & 1) != 0) { //Set the command for each texture matrix *pCom++ = (byte)(DecodeOp.TexMtx0 + i); Stride++; //Increment stride by a byte (the length of the facepoints) } } //Positions format = ((fmtLo >> 9) & 3) - 1; if (format >= 0) { HasData[0] = true; //Set the definitions input pDef->Format = (byte)format; //Set the type to Positions pDef->Type = 0; if (format == 0) { int f = (int)UVATGroups.PositionDef.DataFormat; //Clamp format to even value and add length to stride Stride += f.RoundDownToEven().Clamp(1, 4) * (!UVATGroups.PositionDef.IsSpecial ? 2 : 3); pDef->Scale = (byte)UVATGroups.PositionDef.Scale; pDef->Output = (byte)((!UVATGroups.PositionDef.IsSpecial ? (int)ElementCodec.CodecType.XY : (int)ElementCodec.CodecType.XYZ) + (byte)UVATGroups.PositionDef.DataFormat); *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 12; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } //Normals format = ((fmtLo >> 11) & 3) - 1; if (format >= 0) { HasData[1] = true; //Set the definitions input pDef->Format = (byte)format; //Set the type to Normals pDef->Type = 1; if (format == 0) { int f = (int)UVATGroups.NormalDef.DataFormat; Stride += f.RoundDownToEven().Clamp(1, 4) * 3; pDef->Scale = (byte)UVATGroups.NormalDef.Scale; pDef->Output = (byte)((int)ElementCodec.CodecType.XYZ + (byte)UVATGroups.NormalDef.DataFormat); *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 12; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } //Colors for (int i = 0; i < 2; i++) { format = ((fmtLo >> (i * 2 + 13)) & 3) - 1; if (format >= 0) { HasData[i + 2] = true; //Set the definitions input pDef->Format = (byte)format; //Set the type to Colors pDef->Type = (byte)(i + 2); if (format == 0) { //pDef->Output = pDef->Scale = 0; *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 4; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } } //UVs for (int i = 0; i < 8; i++) { format = ((fmtHi >> (i * 2)) & 3) - 1; if (format >= 0) { HasData[i + 4] = true; //Set the definitions input pDef->Format = (byte)format; //Set the type to UVs pDef->Type = (byte)(i + 4); if (format == 0) { int f = (int)UVATGroups.GetUVDef(i).DataFormat; Stride += f.RoundDownToEven().Clamp(1, 4); pDef->Output = (byte)((!UVATGroups.GetUVDef(i).IsSpecial ? (int)ElementCodec.CodecType.S : (int)ElementCodec.CodecType.ST) + (byte)UVATGroups.GetUVDef(i).DataFormat); pDef->Scale = (byte)UVATGroups.GetUVDef(i).Scale; *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 8; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } } *pCom = 0; } } }
public ElementDescriptor(MDL0Polygon *polygon) { byte * pData = (byte *)polygon->DefList; byte * pCom; ElementDef *pDef; CPElementSpec UVATGroups; int format; //1 for direct, 2 for byte, 3 for short //Create remap table for vertex weights RemapTable = new UnsafeBuffer(polygon->_numVertices * 4); RemapSize = 0; Stride = 0; NodeIds = new List <ushort>(); Addresses = new List <uint>(); //Read element descriptor from polygon display list MDL0PolygonDefs *Definitons = (MDL0PolygonDefs *)polygon->DefList; int fmtLo = (int)Definitons->VtxFmtLo; int fmtHi = (int)Definitons->VtxFmtHi; UVATGroups = new CPElementSpec( (uint)Definitons->UVATA, (uint)Definitons->UVATB, (uint)Definitons->UVATC); //Build extract script. //What we're doing is assigning extract commands for elements in the polygon, in true order. //This allows us to process the polygon blindly, assuming that the definition is accurate. //Theoretically, this should offer a significant speed bonus. fixed(int *pDefData = Defs) fixed(byte *pComData = Commands) { pCom = pComData; pDef = (ElementDef *)pDefData; //Pos/Norm weight if (Weighted = (fmtLo & 1) != 0) { //Set the first command as the weight *pCom++ = (byte)DecodeOp.PosWeight; Stride++; //Increment stride by a byte (the length of the facepoints) } //Tex matrix for (int i = 0; i < 8; i++) { if (((fmtLo >> (i + 1)) & 1) != 0) { //Set the command for each texture matrix *pCom++ = (byte)(DecodeOp.TexMtx0 + i); Stride++; //Increment stride by a byte (the length of the facepoints) } } //Positions format = ((fmtLo >> 9) & 3) - 1; if (format >= 0) { //Set the definitions input pDef->Format = (byte)format; //Set the type to Positions pDef->Type = 0; if (format == 0) { pDef->Scale = (byte)UVATGroups.PositionDef.Scale; //pDef->Output = *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 12; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } //Normals format = ((fmtLo >> 11) & 3) - 1; if (format >= 0) { //Set the definitions input pDef->Format = (byte)format; //Set the type to Normals pDef->Type = 1; if (format == 0) { pDef->Scale = (byte)UVATGroups.NormalDef.Scale; //pDef->Output = *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 12; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } //Colors for (int i = 0; i < 2; i++) { format = ((fmtLo >> (i * 2 + 13)) & 3) - 1; if (format >= 0) { //Set the definitions input pDef->Format = (byte)format; //Set the type to Colors pDef->Type = (byte)(i + 2); if (format == 0) { //pDef->Output = pDef->Scale = 0; *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 4; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } } //UVs for (int i = 0; i < 8; i++) { format = ((fmtHi >> (i * 2)) & 3) - 1; if (format >= 0) { //Set the definitions input pDef->Format = (byte)format; //Set the type to UVs pDef->Type = (byte)(i + 4); if (format == 0) { //pDef->Output = pDef->Scale = (byte)UVATGroups.GetUVDef(i).Scale; *pCom++ = (byte)DecodeOp.ElementDirect; } else { Stride += format; //Add to stride (the length of the facepoints) pDef->Output = 8; //Set the output *pCom++ = (byte)DecodeOp.ElementIndexed; } pDef++; } } *pCom = 0; } }