Ejemplo n.º 1
0
        public void Save(Stream output)
        {
            this.offSize.offset = (uint)output.Position;

            StreamHelpers.WriteStringASCII(output, this.magic);
            StreamHelpers.WriteValueU32(output, this.version);

            StreamHelpers.WriteValueU32(output, 0);
            StreamHelpers.WriteValueU32(output, 0);

            StreamHelpers.WriteValueU32(output, this.embeddedId);
            if (this.embeddedId != 0)
            {
                StreamHelpers.WriteValueU32(output, 0);
                this.mtnfChunk.Save(output);

                output.Seek(this.mtnfChunk.offSize.offset - 4, SeekOrigin.Begin);
                StreamHelpers.WriteValueU32(output, this.mtnfChunk.offSize.size);
                output.Seek(this.mtnfChunk.offSize.offset + this.mtnfChunk.offSize.size, SeekOrigin.Begin);
            }

            StreamHelpers.WriteValueU32(output, this.unk1);
            StreamHelpers.WriteValueU32(output, this.unk2);

            StreamHelpers.WriteValueU32(output, (uint)this.vertices.Count);
            StreamHelpers.WriteValueU32(output, (uint)this.vertexFormats.Count);
            for (int i = 0; i < this.vertexFormats.Count; i++)
            {
                this.vertexFormats[i].Save(output);
            }

            for (int i = 0; i < this.vertices.Count; i++)
            {
                for (int j = 0; j < this.vertexFormats.Count; j++)
                {
                    SimGeomVertexFormat vf = this.vertexFormats[j];
                    switch (vf.dataType)
                    {
                    case 1:
                        this.vertices[i].Save(output);
                        break;

                    case 2:
                        this.normals[i].Save(output);
                        break;

                    case 3:
                        this.uvs[i].Save(output);
                        break;

                    case 4:
                        StreamHelpers.WriteValueU32(output, this.bones[i]);
                        break;

                    case 5:
                        this.weights[i].Save(output);
                        break;

                    case 6:
                        this.tangentNormals[i].Save(output);
                        break;

                    case 7:
                        StreamHelpers.WriteValueU32(output, this.tagVals[i]);
                        break;

                    case 10:
                        StreamHelpers.WriteValueU32(output, this.vertexIds[i]);
                        break;
                    }
                }
            }

            StreamHelpers.WriteValueU32(output, this.faceFormatItemCount);
            StreamHelpers.WriteValueU8(output, this.faceFormatBytesPerFacePoint);

            StreamHelpers.WriteValueU32(output, (uint)(this.faces.Count * 3));
            for (int i = 0; i < this.faces.Count; i++)
            {
                switch (this.faceFormatBytesPerFacePoint)
                {
                case 2:
                    this.faces[i].Save(output);
                    break;
                }
            }

            StreamHelpers.WriteValueU32(output, this.flags);
            StreamHelpers.WriteValueU32(output, (uint)this.boneHashes.Count);
            for (int i = 0; i < this.boneHashes.Count; i++)
            {
                StreamHelpers.WriteValueU32(output, this.boneHashes[i]);
            }

            this.keytable.offset = (uint)(output.Position - this.offSize.offset) - 12;
            this.keytable.size   = 0;
            this.keytable.Save(output);

            this.offSize.size = (uint)(output.Position - this.offSize.offset);

            output.Seek(this.offSize.offset + 8, SeekOrigin.Begin);
            StreamHelpers.WriteValueU32(output, this.keytable.offset);
            StreamHelpers.WriteValueU32(output, this.keytable.size);

            output.Seek(this.offSize.offset + this.offSize.size, SeekOrigin.Begin);
        }
Ejemplo n.º 2
0
        private void loadFromStream(Stream input)
        {
            this.magic           = MadScience.StreamHelpers.ReadStringASCII(input, 4);
            this.version         = MadScience.StreamHelpers.ReadValueU32(input);
            this.keytable.offset = MadScience.StreamHelpers.ReadValueU32(input);
            this.keytable.size   = MadScience.StreamHelpers.ReadValueU32(input);

            this.embeddedId = MadScience.StreamHelpers.ReadValueU32(input);
            if (embeddedId != 0)
            {
                MadScience.StreamHelpers.ReadValueU32(input);
                this.mtnfChunk.Load(input);
            }

            this.unk1 = MadScience.StreamHelpers.ReadValueU32(input);
            this.unk2 = MadScience.StreamHelpers.ReadValueU32(input);

            uint numVerts = MadScience.StreamHelpers.ReadValueU32(input);

            uint vfCount = MadScience.StreamHelpers.ReadValueU32(input);

            vertexFormats.Clear();
            for (int i = 0; i < vfCount; i++)
            {
                vertexFormats.Add(new SimGeomVertexFormat(input));
            }

            for (int i = 0; i < numVerts; i++)
            {
                for (int j = 0; j < vertexFormats.Count; j++)
                {
                    SimGeomVertexFormat vf = (SimGeomVertexFormat)vertexFormats[j];
                    switch (vf.dataType)
                    {
                    case 1:
                        this.vertices.Add(new Vector3(input));
                        break;

                    case 2:
                        this.normals.Add(new Vector3(input));
                        break;

                    case 3:
                        this.uvs.Add(new Vector2(input));
                        break;

                    case 4:
                        this.bones.Add(MadScience.StreamHelpers.ReadValueU32(input));
                        break;

                    case 5:
                        this.weights.Add(new Vector4(input));
                        break;

                    case 6:
                        this.tangentNormals.Add(new Vector3(input));
                        break;

                    case 7:
                        this.tagVals.Add(MadScience.StreamHelpers.ReadValueU32(input));
                        break;

                    case 10:
                        this.vertexIds.Add(MadScience.StreamHelpers.ReadValueU32(input));
                        break;
                    }
                }
            }

            this.faceFormatItemCount         = MadScience.StreamHelpers.ReadValueU32(input);
            this.faceFormatBytesPerFacePoint = MadScience.StreamHelpers.ReadValueU8(input);

            uint numFacePoints = MadScience.StreamHelpers.ReadValueU32(input);

            uint numPolygons = numFacePoints / 3;

            for (int i = 0; i < numPolygons; i++)
            {
                switch (faceFormatBytesPerFacePoint)
                {
                case 2:
                    this.faces.Add(new UShort3(input));
                    break;
                }
            }

            // Tail section
            this.flags = MadScience.StreamHelpers.ReadValueU32(input);
            uint boneHashCount = MadScience.StreamHelpers.ReadValueU32(input);

            for (int i = 0; i < boneHashCount; i++)
            {
                this.boneHashes.Add(MadScience.StreamHelpers.ReadValueU32(input));
            }

            //long seekFrom = input.Position - 4;

            //input.Seek(this.keytable.offset + seekFrom, SeekOrigin.Begin);

            this.keytable.Load(input);
        }