Ejemplo n.º 1
0
        public void Read(FileReader reader)
        {
            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            string Magic = reader.ReadString(4);

            if (Magic == "_M1G")
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
            }
            else
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            }

            uint Version          = reader.ReadUInt32();
            uint FileSize         = reader.ReadUInt32();
            uint firstChunkOffset = reader.ReadUInt32();
            uint padding          = reader.ReadUInt32();
            uint numChunks        = reader.ReadUInt32();

            switch (Version)
            {
            case 0x30303334: break;

            case 0x30303335: break;

            case 0x30303336: break;

            case 0x30303337: break;

            default: break;
            }

            reader.SeekBegin(firstChunkOffset);
            for (int i = 0; i < numChunks; i++)
            {
                G1MChunkCommon chunk         = new G1MChunkCommon();
                long           chunkPosition = reader.Position;
                string         chunkMagic    = reader.ReadString(4, Encoding.ASCII);
                uint           chunkVersion  = reader.ReadUInt32();
                uint           chunkSize     = reader.ReadUInt32();

                if (chunkMagic == "G1MF")
                {
                }
                else if (chunkMagic == "SM1G")
                {
                    Skeleton = new G1MS(reader);
                }
                else if (chunkMagic == "G1MS")
                {
                }
                else if (chunkMagic == "G1MM")
                {
                }
                else if (chunkMagic == "G1MG")
                {
                }
                else if (chunkMagic == "COLL")
                {
                }
                else if (chunkMagic == "HAIR")
                {
                }
                else if (chunkMagic == "NUNO")
                {
                }
                else if (chunkMagic == "NUNS")
                {
                }
                else if (chunkMagic == "NUNV")
                {
                }
                else if (chunkMagic == "EXTR")
                {
                }
                else
                {
                }



                reader.SeekBegin(chunk.ChunkPosition + chunk.ChunkSize);
            }
        }
Ejemplo n.º 2
0
        public void Read(FileReader reader)
        {
            Renderer               = new G1M_Renderer();
            Renderer.G1MFile       = this;
            DrawableContainer      = new DrawableContainer();
            DrawableContainer.Name = FileName;
            DrawableContainer.Drawables.Add(Renderer);

            reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            string Magic = reader.ReadString(4);

            if (Magic == "_M1G")
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
            }
            else
            {
                reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            }

            uint Version          = reader.ReadUInt32();
            uint FileSize         = reader.ReadUInt32();
            uint firstChunkOffset = reader.ReadUInt32();
            uint padding          = reader.ReadUInt32();
            uint numChunks        = reader.ReadUInt32();

            switch (Version)
            {
            case 0x30303334: break;

            case 0x30303335: break;

            case 0x30303336: break;

            case 0x30303337: break;

            default: break;
            }

            reader.SeekBegin(firstChunkOffset);
            for (int i = 0; i < numChunks; i++)
            {
                G1MChunkCommon chunk = new G1MChunkCommon();
                chunk.ChunkPosition = reader.Position;
                chunk.Magic         = reader.ReadString(4, Encoding.ASCII);
                chunk.ChunkVersion  = reader.ReadUInt32();
                chunk.ChunkSize     = reader.ReadUInt32();

                Console.WriteLine("chunkMagic " + chunk.Magic);
                if (chunk.Magic == "G1MF")
                {
                }
                else if (chunk.Magic == "SM1G" || chunk.Magic == "G1MS")
                {
                    G1MSkeleton       = new G1MS(reader);
                    Renderer.Skeleton = G1MSkeleton.GenericSkeleton;
                    DrawableContainer.Drawables.Add(G1MSkeleton.GenericSkeleton);

                    TreeNode skeleton = new TreeNode("Skeleton");
                    Nodes.Add(skeleton);
                    foreach (var bn in G1MSkeleton.GenericSkeleton.bones)
                    {
                        if (bn.Parent == null)
                        {
                            skeleton.Nodes.Add(bn);
                        }
                    }
                }
                else if (chunk.Magic == "G1MM")
                {
                }
                else if (chunk.Magic == "G1MG")
                {
                    Model = new G1MG(reader);
                    Renderer.Meshes.AddRange(Model.GenericMeshes);

                    meshNode = new TreeNode("Meshes");
                    Nodes.Add(meshNode);
                    foreach (var mesh in Model.GenericMeshes)
                    {
                        meshNode.Nodes.Add(mesh);
                    }

                    if (G1MSkeleton != null)
                    {
                        foreach (var mesh in Model.GenericMeshes)
                        {
                            bool isSingleBind = false;

                            if (isSingleBind)
                            {
                                for (int v = 0; v < mesh.vertices.Count; v++)
                                {
                                    var boneId    = mesh.vertices[v].boneIds[0];
                                    var transform = G1MSkeleton.GenericSkeleton.bones[boneId].Transform;
                                    mesh.vertices[v].pos = Vector3.TransformPosition(
                                        mesh.vertices[v].pos, transform);
                                    mesh.vertices[v].nrm = Vector3.TransformNormal(
                                        mesh.vertices[v].nrm, transform);
                                }
                            }
                        }
                    }
                }
                else if (chunk.Magic == "COLL")
                {
                }
                else if (chunk.Magic == "HAIR")
                {
                }
                else if (chunk.Magic == "NUNO")
                {
                    NUNO = new NUNO(reader, chunk.ChunkVersion);
                }
                else if (chunk.Magic == "NUNS")
                {
                }
                else if (chunk.Magic == "NUNV")
                {
                    NUNV = new NUNV(reader, chunk.ChunkVersion);
                }
                else if (chunk.Magic == "EXTR")
                {
                }
                else
                {
                }
                reader.SeekBegin(chunk.ChunkPosition + chunk.ChunkSize);
            }

            ComputeClothDrivers();
            SetLevelOfDetailGroups();
        }