Exemplo n.º 1
0
        public VTX1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            Attributes     = new VertexData();
            StorageFormats = new SortedDictionary <GXVertexAttribute, Tuple <GXDataType, byte> >();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);

            reader.SkipInt32();
            int vtx1Size = reader.ReadInt32();
            int attributeHeaderOffset = reader.ReadInt32();

            if (modelstats != null)
            {
                modelstats.VTX1Size = vtx1Size;
            }

            int[] attribDataOffsets = new int[13];

            for (int i = 0; i < 13; i++)
            {
                attribDataOffsets[i] = reader.ReadInt32();
            }

            GXVertexAttribute attrib = (GXVertexAttribute)reader.ReadInt32();

            while (attrib != GXVertexAttribute.Null)
            {
                GXComponentCount componentCount     = (GXComponentCount)reader.ReadInt32();
                GXDataType       componentType      = (GXDataType)reader.ReadInt32();
                byte             fractionalBitCount = reader.ReadByte();
                StorageFormats.Add(attrib, new Tuple <GXDataType, byte>(componentType, fractionalBitCount));

                reader.Skip(3);
                long curPos = reader.BaseStream.Position;

                int attribDataSize = 0;
                int attribOffset   = GetAttributeDataOffset(attribDataOffsets, vtx1Size, attrib, out attribDataSize);
                int attribCount    = GetAttributeDataCount(attribDataSize, attrib, componentType, componentCount);
                Attributes.SetAttributeData(attrib, LoadAttributeData(reader, offset + attribOffset, attribCount, fractionalBitCount, attrib, componentType, componentCount));

                reader.BaseStream.Seek(curPos, System.IO.SeekOrigin.Begin);
                attrib = (GXVertexAttribute)reader.ReadInt32();
            }

            reader.BaseStream.Seek(offset + vtx1Size, System.IO.SeekOrigin.Begin);
        }
Exemplo n.º 2
0
        private int GetAttributeDataCount(int size, GXVertexAttribute attribute, GXDataType dataType, GXComponentCount compCount)
        {
            int compCnt    = 0;
            int compStride = 0;

            if (attribute == GXVertexAttribute.Color0 || attribute == GXVertexAttribute.Color1)
            {
                switch (dataType)
                {
                case GXDataType.RGB565:
                case GXDataType.RGBA4:
                    compCnt    = 1;
                    compStride = 2;
                    break;

                case GXDataType.RGB8:
                case GXDataType.RGBX8:
                case GXDataType.RGBA6:
                case GXDataType.RGBA8:
                    compCnt    = 4;
                    compStride = 1;
                    break;
                }
            }

            else
            {
                switch (dataType)
                {
                case GXDataType.Unsigned8:
                case GXDataType.Signed8:
                    compStride = 1;
                    break;

                case GXDataType.Unsigned16:
                case GXDataType.Signed16:
                    compStride = 2;
                    break;

                case GXDataType.Float32:
                    compStride = 4;
                    break;
                }

                switch (attribute)
                {
                case GXVertexAttribute.Position:
                    if (compCount == GXComponentCount.Position_XY)
                    {
                        compCnt = 2;
                    }
                    else if (compCount == GXComponentCount.Position_XYZ)
                    {
                        compCnt = 3;
                    }
                    break;

                case GXVertexAttribute.Normal:
                    if (compCount == GXComponentCount.Normal_XYZ)
                    {
                        compCnt = 3;
                    }
                    break;

                case GXVertexAttribute.Tex0:
                case GXVertexAttribute.Tex1:
                case GXVertexAttribute.Tex2:
                case GXVertexAttribute.Tex3:
                case GXVertexAttribute.Tex4:
                case GXVertexAttribute.Tex5:
                case GXVertexAttribute.Tex6:
                case GXVertexAttribute.Tex7:
                    if (compCount == GXComponentCount.TexCoord_S)
                    {
                        compCnt = 1;
                    }
                    else if (compCount == GXComponentCount.TexCoord_ST)
                    {
                        compCnt = 2;
                    }
                    break;
                }
            }

            return(size / (compCnt * compStride));
        }
Exemplo n.º 3
0
        public object LoadAttributeData(EndianBinaryReader reader, int offset, int count, byte frac, GXVertexAttribute attribute, GXDataType dataType, GXComponentCount compCount)
        {
            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            object final = null;

            switch (attribute)
            {
            case GXVertexAttribute.Position:
                switch (compCount)
                {
                case GXComponentCount.Position_XY:
                    final = LoadVec2Data(reader, frac, count, dataType);
                    break;

                case GXComponentCount.Position_XYZ:
                    final = LoadVec3Data(reader, frac, count, dataType);
                    break;
                }
                break;

            case GXVertexAttribute.Normal:
                switch (compCount)
                {
                case GXComponentCount.Normal_XYZ:
                    final = LoadVec3Data(reader, frac, count, dataType);
                    break;

                case GXComponentCount.Normal_NBT:
                    break;

                case GXComponentCount.Normal_NBT3:
                    break;
                }
                break;

            case GXVertexAttribute.Color0:
            case GXVertexAttribute.Color1:
                final = LoadColorData(reader, count, dataType);
                break;

            case GXVertexAttribute.Tex0:
            case GXVertexAttribute.Tex1:
            case GXVertexAttribute.Tex2:
            case GXVertexAttribute.Tex3:
            case GXVertexAttribute.Tex4:
            case GXVertexAttribute.Tex5:
            case GXVertexAttribute.Tex6:
            case GXVertexAttribute.Tex7:
                switch (compCount)
                {
                case GXComponentCount.TexCoord_S:
                    final = LoadSingleFloat(reader, frac, count, dataType);
                    break;

                case GXComponentCount.TexCoord_ST:
                    final = LoadVec2Data(reader, frac, count, dataType);
                    break;
                }
                break;
            }

            return(final);
        }