Esempio n. 1
0
            internal Bone(BinaryReaderEx br, FLVER0 flv)
            {
                Position = br.ReadVector3();
                int nameOffset = br.ReadInt32();

                Rotation             = br.ReadVector3();
                ParentIndex          = br.ReadInt16();
                ChildIndex           = br.ReadInt16();
                Scale                = br.ReadVector3();
                NextSiblingIndex     = br.ReadInt16();
                PreviousSiblingIndex = br.ReadInt16();
                BoundingBoxMin       = br.ReadVector3();
                br.AssertInt32(0);
                BoundingBoxMax = br.ReadVector3();

                for (int i = 0; i < 13; i++)
                {
                    br.AssertInt32(0);
                }

                Name = flv.Unicode ? br.GetUTF16(nameOffset) : br.GetShiftJIS(nameOffset);
            }
Esempio n. 2
0
            internal Material(BinaryReaderEx br, FLVER0 flv)
            {
                int nameOffset     = br.ReadInt32();
                int mtdOffset      = br.ReadInt32();
                int texturesOffset = br.ReadInt32();
                int layoutsOffset  = br.ReadInt32();

                br.ReadInt32(); // Data length from name offset to end of buffer layouts
                int layoutHeaderOffset = br.ReadInt32();

                br.AssertInt32(0);
                br.AssertInt32(0);

                Name = flv.Unicode ? br.GetUTF16(nameOffset) : br.GetShiftJIS(nameOffset);
                MTD  = flv.Unicode ? br.GetUTF16(mtdOffset) : br.GetShiftJIS(mtdOffset);

                br.StepIn(texturesOffset);
                {
                    byte textureCount = br.ReadByte();
                    br.AssertByte(0);
                    br.AssertByte(0);
                    br.AssertByte(0);
                    br.AssertInt32(0);
                    br.AssertInt32(0);
                    br.AssertInt32(0);

                    Textures = new List <Texture>(textureCount);
                    for (int i = 0; i < textureCount; i++)
                    {
                        Textures.Add(new Texture(br, flv));
                    }
                }
                br.StepOut();

                if (layoutHeaderOffset != 0)
                {
                    br.StepIn(layoutHeaderOffset);
                    {
                        int layoutCount = br.ReadInt32();
                        br.AssertInt32((int)br.Position + 0xC);
                        br.AssertInt32(0);
                        br.AssertInt32(0);
                        Layouts = new List <BufferLayout>(layoutCount);
                        for (int i = 0; i < layoutCount; i++)
                        {
                            int layoutOffset = br.ReadInt32();
                            br.StepIn(layoutOffset);
                            {
                                Layouts.Add(new BufferLayout(br));
                            }
                            br.StepOut();
                        }
                    }
                    br.StepOut();
                }
                else
                {
                    Layouts = new List <BufferLayout>(1);
                    br.StepIn(layoutsOffset);
                    {
                        Layouts.Add(new BufferLayout(br));
                    }
                    br.StepOut();
                }
            }
Esempio n. 3
0
            internal Mesh(BinaryReaderEx br, FLVER0 flv, int dataOffset)
            {
                Dynamic       = br.ReadByte();
                MaterialIndex = br.ReadByte();
                Unk02         = br.ReadBoolean();
                Unk03         = br.ReadByte();

                int vertexIndexCount = br.ReadInt32();
                int vertexCount      = br.ReadInt32();

                DefaultBoneIndex = br.ReadInt16();
                BoneIndices      = br.ReadInt16s(28);
                Unk46            = br.ReadInt16();
                br.ReadInt32(); // Vertex indices length
                int vertexIndicesOffset  = br.ReadInt32();
                int bufferDataLength     = br.ReadInt32();
                int bufferDataOffset     = br.ReadInt32();
                int vertexBuffersOffset1 = br.ReadInt32();
                int vertexBuffersOffset2 = br.ReadInt32();

                br.AssertInt32(0);

                if (flv.VertexIndexSize == 16)
                {
                    VertexIndices = new List <int>(vertexCount);
                    foreach (ushort index in br.GetUInt16s(dataOffset + vertexIndicesOffset, vertexIndexCount))
                    {
                        VertexIndices.Add(index);
                    }
                }
                else if (flv.VertexIndexSize == 32)
                {
                    VertexIndices = new List <int>(br.GetInt32s(dataOffset + vertexIndicesOffset, vertexIndexCount));
                }

                VertexBuffer buffer;

                // Stupid hack for old (version F?) flvers; for example DeS o9993.
                if (vertexBuffersOffset1 == 0)
                {
                    buffer = new VertexBuffer()
                    {
                        BufferLength = bufferDataLength,
                        BufferOffset = bufferDataOffset,
                        LayoutIndex  = 0,
                    };
                }
                else
                {
                    br.StepIn(vertexBuffersOffset1);
                    {
                        List <VertexBuffer> vertexBuffers1 = VertexBuffer.ReadVertexBuffers(br);
                        if (vertexBuffers1.Count == 0)
                        {
                            throw new NotSupportedException("First vertex buffer list is expected to contain at least 1 buffer.");
                        }
                        for (int i = 1; i < vertexBuffers1.Count; i++)
                        {
                            if (vertexBuffers1[i].BufferLength != 0)
                            {
                                throw new NotSupportedException("Vertex buffers after the first one in the first buffer list are expected to be empty.");
                            }
                        }
                        buffer = vertexBuffers1[0];
                    }
                    br.StepOut();
                }

                if (vertexBuffersOffset2 != 0)
                {
                    br.StepIn(vertexBuffersOffset2);
                    {
                        List <VertexBuffer> vertexBuffers2 = VertexBuffer.ReadVertexBuffers(br);
                        if (vertexBuffers2.Count != 0)
                        {
                            throw new NotSupportedException("Second vertex buffer list is expected to contain exactly 0 buffers.");
                        }
                    }
                    br.StepOut();
                }

                br.StepIn(dataOffset + buffer.BufferOffset);
                {
                    LayoutIndex = buffer.LayoutIndex;
                    BufferLayout layout = flv.Materials[MaterialIndex].Layouts[LayoutIndex];

                    float uvFactor = 1024;
                    // NB hack
                    if (!br.BigEndian)
                    {
                        uvFactor = 2048;
                    }

                    Vertices = new List <FLVER.Vertex>(vertexCount);
                    for (int i = 0; i < vertexCount; i++)
                    {
                        var vert = new FLVER.Vertex();
                        vert.Read(br, layout, uvFactor);
                        Vertices.Add(vert);
                    }
                }
                br.StepOut();
            }