Exemplo n.º 1
0
        public static Formats.Meshes.Mesh ParseMesh(this SsbhParser parser)
        {
            var result = new Formats.Meshes.Mesh();

            result.Magic                        = parser.ReadUInt32();
            result.VersionMajor                 = parser.ReadUInt16();
            result.VersionMinor                 = parser.ReadUInt16();
            result.ModelName                    = parser.ReadOffsetReadString();
            result.BoundingSphereCenter         = parser.ReadVector3();
            result.BoundingSphereRadius         = parser.ReadSingle();
            result.BoundingBoxMin               = parser.ReadVector3();
            result.BoundingBoxMax               = parser.ReadVector3();
            result.OrientedBoundingBoxCenter    = parser.ReadVector3();
            result.OrientedBoundingBoxTransform = parser.ReadMatrix3x3();
            result.OrientedBoundingBoxSize      = parser.ReadVector3();
            result.Unk1 = parser.ReadSingle();
            {
                // TODO: Extract this code to a method?
                long absoluteOffset   = parser.ReadRelativeGetAbsoluteOffset();
                long elementCount     = parser.ReadInt64();
                long previousPosition = parser.Position;
                parser.Seek(absoluteOffset);


                result.Objects = new Formats.Meshes.MeshObject[elementCount];
                for (int i = 0; i < elementCount; i++)
                {
                    result.Objects[i] = parser.ParseMeshObject();
                }

                parser.Seek(previousPosition);
            }
            {
                // TODO: Extract this code to a method?
                long absoluteOffset   = parser.ReadRelativeGetAbsoluteOffset();
                long elementCount     = parser.ReadInt64();
                long previousPosition = parser.Position;
                parser.Seek(absoluteOffset);

                result.BufferSizes = parser.ReadStructs <System.Int32>((int)elementCount);

                parser.Seek(previousPosition);
            }
            result.PolygonIndexSize = parser.ReadInt64();
            {
                // TODO: Extract this code to a method?
                long absoluteOffset   = parser.ReadRelativeGetAbsoluteOffset();
                long elementCount     = parser.ReadInt64();
                long previousPosition = parser.Position;
                parser.Seek(absoluteOffset);


                result.VertexBuffers = new Formats.Meshes.MeshBuffer[elementCount];
                for (int i = 0; i < elementCount; i++)
                {
                    result.VertexBuffers[i] = parser.ParseMeshBuffer();
                }

                parser.Seek(previousPosition);
            }
            {
                // TODO: Extract this code to a method?
                long absoluteOffset   = parser.ReadRelativeGetAbsoluteOffset();
                long elementCount     = parser.ReadInt64();
                long previousPosition = parser.Position;
                parser.Seek(absoluteOffset);

                result.PolygonBuffer = parser.ReadBytes((int)elementCount);

                parser.Seek(previousPosition);
            }
            {
                // TODO: Extract this code to a method?
                long absoluteOffset   = parser.ReadRelativeGetAbsoluteOffset();
                long elementCount     = parser.ReadInt64();
                long previousPosition = parser.Position;
                parser.Seek(absoluteOffset);


                result.RiggingBuffers = new Formats.Meshes.MeshRiggingGroup[elementCount];
                for (int i = 0; i < elementCount; i++)
                {
                    result.RiggingBuffers[i] = parser.ParseMeshRiggingGroup();
                }

                parser.Seek(previousPosition);
            }
            result.UnknownOffset = parser.ReadInt64();
            result.UnknownSize   = parser.ReadInt64();
            return(result);
        }