Esempio n. 1
0
        public DRW1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            Indices = new List <int>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int drw1Size   = reader.ReadInt32();
            int entryCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.DRW1Size = drw1Size;
            }

            int boolDataOffset  = reader.ReadInt32();
            int indexDataOffset = reader.ReadInt32();

            WeightTypeCheck = new List <bool>();

            reader.BaseStream.Seek(offset + boolDataOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i < entryCount; i++)
            {
                WeightTypeCheck.Add(reader.ReadBoolean());
            }

            reader.BaseStream.Seek(offset + indexDataOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i < entryCount; i++)
            {
                Indices.Add(reader.ReadInt16());
            }

            reader.BaseStream.Seek(offset + drw1Size, System.IO.SeekOrigin.Begin);
        }
Esempio n. 2
0
        public TEX1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            Textures = new List <BinaryTextureImage>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int   tex1Size = reader.ReadInt32();
            short texCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.TEX1Size = tex1Size;
            }

            int textureHeaderOffset    = reader.ReadInt32();
            int textureNameTableOffset = reader.ReadInt32();

            List <string> names = NameTableIO.Load(reader, offset + textureNameTableOffset);

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

            for (int i = 0; i < texCount; i++)
            {
                reader.BaseStream.Seek((offset + 0x20 + (0x20 * i)), System.IO.SeekOrigin.Begin);

                BinaryTextureImage img = new BinaryTextureImage(names[i]);
                img.Load(reader, (offset + 0x20 + (0x20 * i)));
                Textures.Add(img);
            }
        }
Esempio n. 3
0
        public JNT1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            BoneNameIndices = new Dictionary <string, int>();
            FlatSkeleton    = new List <Rigging.Bone>();

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

            int jnt1Size   = reader.ReadInt32();
            int jointCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.JNT1Size = jnt1Size;
            }

            int jointDataOffset   = reader.ReadInt32();
            int internTableOffset = reader.ReadInt32();
            int nameTableOffset   = reader.ReadInt32();

            List <string> names = NameTableIO.Load(reader, offset + nameTableOffset);

            int        highestRemap = 0;
            List <int> remapTable   = new List <int>();

            reader.BaseStream.Seek(offset + internTableOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i < jointCount; i++)
            {
                int test = reader.ReadInt16();
                remapTable.Add(test);

                if (test > highestRemap)
                {
                    highestRemap = test;
                }
            }

            List <Rigging.Bone> tempList = new List <Rigging.Bone>();

            reader.BaseStream.Seek(offset + jointDataOffset, System.IO.SeekOrigin.Begin);
            for (int i = 0; i <= highestRemap; i++)
            {
                tempList.Add(new Rigging.Bone(reader, names[i]));
            }

            for (int i = 0; i < jointCount; i++)
            {
                FlatSkeleton.Add(tempList[remapTable[i]]);
            }

            foreach (Rigging.Bone bone in FlatSkeleton)
            {
                BoneNameIndices.Add(bone.Name, FlatSkeleton.IndexOf(bone));
            }

            reader.BaseStream.Seek(offset + jnt1Size, System.IO.SeekOrigin.Begin);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public INF1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            FlatNodes = new List <SceneNode>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int inf1Size = reader.ReadInt32();
            int unk1     = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.INF1Size = inf1Size;
            }

            int packetCount     = reader.ReadInt32();
            int vertexCount     = reader.ReadInt32();
            int hierarchyOffset = reader.ReadInt32();

            SceneNode parent = new SceneNode(reader, null);
            SceneNode node   = null;

            Root = parent;
            FlatNodes.Add(parent);

            do
            {
                node = new SceneNode(reader, parent);

                FlatNodes.Add(node);

                if (node.Type == NodeType.OpenChild)
                {
                    SceneNode newNode = new SceneNode(reader, node.Parent);
                    FlatNodes.Add(newNode);
                    parent = newNode;
                }
                else if (node.Type == NodeType.CloseChild)
                {
                    parent = node.Parent;
                }
            } while (node.Type != NodeType.Terminator);

            reader.BaseStream.Seek(offset + inf1Size, System.IO.SeekOrigin.Begin);
        }
Esempio n. 6
0
        public EVP1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            Weights             = new List <Weight>();
            InverseBindMatrices = new List <Matrix4>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int evp1Size   = reader.ReadInt32();
            int entryCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.EVP1Size = evp1Size;
            }

            int weightCountsOffset        = reader.ReadInt32();
            int boneIndicesOffset         = reader.ReadInt32();
            int weightDataOffset          = reader.ReadInt32();
            int inverseBindMatricesOffset = reader.ReadInt32();

            List <int>   counts  = new List <int>();
            List <float> weights = new List <float>();
            List <int>   indices = new List <int>();

            for (int i = 0; i < entryCount; i++)
            {
                counts.Add(reader.ReadByte());
            }

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

            for (int i = 0; i < entryCount; i++)
            {
                for (int j = 0; j < counts[i]; j++)
                {
                    indices.Add(reader.ReadInt16());
                }
            }

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

            for (int i = 0; i < entryCount; i++)
            {
                for (int j = 0; j < counts[i]; j++)
                {
                    weights.Add(reader.ReadSingle());
                }
            }

            int totalRead = 0;

            for (int i = 0; i < entryCount; i++)
            {
                Weight weight = new Weight();

                for (int j = 0; j < counts[i]; j++)
                {
                    weight.AddWeight(weights[totalRead + j], indices[totalRead + j]);
                }

                Weights.Add(weight);
                totalRead += counts[i];
            }

            reader.BaseStream.Seek(inverseBindMatricesOffset + offset, System.IO.SeekOrigin.Begin);
            int matrixCount = (evp1Size - inverseBindMatricesOffset) / 48;

            for (int i = 0; i < matrixCount; i++)
            {
                Matrix3x4 invBind = new Matrix3x4(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(),
                                                  reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(),
                                                  reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                InverseBindMatrices.Add(new Matrix4(invBind.Row0, invBind.Row1, invBind.Row2, Vector4.UnitW));
            }

            reader.BaseStream.Seek(offset + evp1Size, System.IO.SeekOrigin.Begin);
        }
Esempio n. 7
0
        private SHP1(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
        {
            Shapes     = new List <Shape>();
            RemapTable = new List <int>();

            reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
            reader.SkipInt32();
            int shp1Size   = reader.ReadInt32();
            int entryCount = reader.ReadInt16();

            reader.SkipInt16();

            if (modelstats != null)
            {
                modelstats.SHP1Size = shp1Size;
            }

            int shapeHeaderDataOffset = reader.ReadInt32();
            int shapeRemapTableOffset = reader.ReadInt32();
            int unusedOffset          = reader.ReadInt32();
            int attributeDataOffset   = reader.ReadInt32();
            int matrixIndexDataOffset = reader.ReadInt32();
            int primitiveDataOffset   = reader.ReadInt32();
            int matrixDataOffset      = reader.ReadInt32();
            int PacketInfoDataOffset  = reader.ReadInt32();

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

            // Remap table
            for (int i = 0; i < entryCount; i++)
            {
                RemapTable.Add(reader.ReadInt16());
            }

            int highestIndex = J3DUtility.GetHighestValue(RemapTable);

            // Packet data
            List <Tuple <int, int> > packetData = new List <Tuple <int, int> >(); // <packet size, packet offset>
            int packetDataCount = (shp1Size - PacketInfoDataOffset) / 8;

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

            for (int i = 0; i < packetDataCount; i++)
            {
                packetData.Add(new Tuple <int, int>(reader.ReadInt32(), reader.ReadInt32()));
            }

            // Matrix data
            List <Tuple <int, int> > matrixData    = new List <Tuple <int, int> >(); // <index count, start index>
            List <int[]>             matrixIndices = new List <int[]>();

            int matrixDataCount = (PacketInfoDataOffset - matrixDataOffset) / 8;

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

            for (int i = 0; i < matrixDataCount; i++)
            {
                reader.SkipInt16();
                matrixData.Add(new Tuple <int, int>(reader.ReadInt16(), reader.ReadInt32()));
            }

            for (int i = 0; i < matrixDataCount; i++)
            {
                reader.BaseStream.Seek(offset + matrixIndexDataOffset + (matrixData[i].Item2 * 2), System.IO.SeekOrigin.Begin);
                int[] indices = new int[matrixData[i].Item1];

                for (int j = 0; j < matrixData[i].Item1; j++)
                {
                    indices[j] = reader.ReadInt16();
                }

                matrixIndices.Add(indices);
            }

            // Shape data
            List <Shape> tempShapeList = new List <Shape>();

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

            for (int i = 0; i < highestIndex + 1; i++)
            {
                MatrixType matrixType = (MatrixType)reader.ReadByte();
                reader.SkipByte();

                int packetCount          = reader.ReadInt16();
                int shapeAttributeOffset = reader.ReadInt16();
                int shapeMatrixDataIndex = reader.ReadInt16();
                int firstPacketIndex     = reader.ReadInt16();
                reader.SkipInt16();

                BoundingVolume shapeVol = new BoundingVolume(reader);

                long curOffset = reader.BaseStream.Position;

                ShapeVertexDescriptor descriptor = new ShapeVertexDescriptor(reader, offset + attributeDataOffset + shapeAttributeOffset);

                //Primitive lists are big endian, even on little endain byte orders
                //Get the current endianness and revert it back after primitives are read
                var fileEndianness = reader.CurrentEndian;
                reader.CurrentEndian = Endian.Big;

                List <Packet> shapePackets = new List <Packet>();
                for (int j = 0; j < packetCount; j++)
                {
                    int packetSize   = packetData[j + firstPacketIndex].Item1;
                    int packetOffset = packetData[j + firstPacketIndex].Item2;

                    Packet pack = new Packet(packetSize, packetOffset + primitiveDataOffset + offset, matrixIndices[j + firstPacketIndex]);
                    pack.ReadPrimitives(reader, descriptor);

                    shapePackets.Add(pack);
                }

                tempShapeList.Add(new Shape(descriptor, shapeVol, shapePackets, matrixType));

                //Revert the endianness back
                reader.CurrentEndian = fileEndianness;
                reader.BaseStream.Seek(curOffset, System.IO.SeekOrigin.Begin);
            }

            for (int i = 0; i < entryCount; i++)
            {
                Shapes.Add(tempShapeList[RemapTable[i]]);
            }

            reader.BaseStream.Seek(offset + shp1Size, System.IO.SeekOrigin.Begin);
        }
Esempio n. 8
0
 public static SHP1 Create(EndianBinaryReader reader, int offset, BMDInfo modelstats = null)
 {
     return(new SHP1(reader, offset, modelstats));
 }