Ejemplo n.º 1
0
            public void BatchExport(object sender, EventArgs args)
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.Multiselect = true;
                ofd.Filter      = "Supported Formats|*.bin";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                FolderSelectDialog folderDlg = new FolderSelectDialog();

                if (folderDlg.ShowDialog() == DialogResult.OK)
                {
                    foreach (var file in ofd.FileNames)
                    {
                        MKAGPDX_Model model  = new MKAGPDX_Model();
                        var           stream = File.Open(file, FileMode.Open);
                        model.Load(stream);
                        stream.Dispose();

                        string Path = System.IO.Path.Combine(folderDlg.SelectedPath,
                                                             System.IO.Path.GetFileNameWithoutExtension(file) + ".dae");

                        model.ExportModel(Path, new DAE.ExportSettings());
                        model.Unload();
                    }
                }
            }
Ejemplo n.º 2
0
            public void BatchExportCombined(object sender, EventArgs args)
            {
                OpenFileDialog ofd = new OpenFileDialog();

                ofd.Multiselect = true;
                ofd.Filter      = "Supported Formats|*.bin";
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                SaveFileDialog sfd = new SaveFileDialog();

                sfd.Filter = "Supported Formats|*.dae";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    List <STGenericObject>   Objects   = new List <STGenericObject>();
                    STSkeleton               Skeleton  = new STSkeleton();
                    List <STGenericMaterial> Materials = new List <STGenericMaterial>();

                    int MatIndex = 0;
                    foreach (var file in ofd.FileNames)
                    {
                        MKAGPDX_Model model  = new MKAGPDX_Model();
                        var           stream = File.Open(file, FileMode.Open);
                        model.Load(stream);
                        stream.Dispose();

                        foreach (STGenericMaterial mat in model.Nodes[0].Nodes)
                        {
                            mat.Text = $"Material {MatIndex++}";
                            Materials.Add(mat);
                        }

                        Skeleton.bones.AddRange(((STSkeleton)model.DrawableContainer.Drawables[0]).bones);
                        Objects.AddRange(((GenericModelRenderer)model.DrawableContainer.Drawables[1]).Meshes);

                        model.Unload();
                    }

                    ExportModelSettings settings = new ExportModelSettings();
                    if (settings.ShowDialog() == DialogResult.OK)
                    {
                        DAE.Export(sfd.FileName, settings.Settings, Objects, Materials, new List <STGenericTexture>(), Skeleton);
                    }
                }
            }
Ejemplo n.º 3
0
            public void Read(FileReader reader, MKAGPDX_Model root)
            {
                Skeleton         = new STSkeleton();
                DrawableRenderer = new GenericModelRenderer();
                root.DrawableContainer.Drawables.Add(Skeleton);
                root.DrawableContainer.Drawables.Add(DrawableRenderer);

                reader.ReadSignature(4, "BIKE");
                ushort Type    = reader.ReadUInt16();
                ushort Unknown = reader.ReadUInt16();

                if (Type == 0)
                {
                }
                else if ((Type == 1))
                {
                    throw new Exception("Animation files not supported yet!");
                }
                else
                {
                    throw new Exception("Unknown type found! " + Type);
                }

                Alignment = reader.ReadUInt32();
                uint Padding       = reader.ReadUInt32();
                uint MaterialCount = reader.ReadUInt32();

                HeaderSize = reader.ReadUInt32();
                uint TextureMapsCount  = reader.ReadUInt32();
                uint TextureMapsOffset = reader.ReadUInt32();

                uint BoneCount       = reader.ReadUInt32();
                uint BoneOffset      = reader.ReadUInt32();
                uint FirstNodeOffset = reader.ReadUInt32(); //Either an offset or the total size of section up to the node
                uint LinkNodeCount   = reader.ReadUInt32();
                uint LinkNodeOffset  = reader.ReadUInt32();
                uint TotalNodeCount  = reader.ReadUInt32();
                uint TotalNodeOffset = reader.ReadUInt32();
                uint Padding2        = reader.ReadUInt32();

                uint[] Unknowns = reader.ReadUInt32s(10);

                root.Nodes.Add("Materials");
                root.Nodes.Add("Root");
                root.Nodes.Add("All Nodes");

                long pos = reader.Position;

                if (TextureMapsOffset != 0)
                {
                    reader.SeekBegin(TextureMapsOffset);
                    for (int i = 0; i < TextureMapsCount; i++)
                    {
                        TextureMaps.Add(reader.ReadNameOffset(false, typeof(uint)));
                    }
                }

                reader.SeekBegin(pos);
                for (int i = 0; i < MaterialCount; i++)
                {
                    Material mat = new Material();
                    mat.Read(reader);
                    Materials.Add(mat);

                    var genericMat = new STGenericMaterial();
                    genericMat.Text = $"Material {i}";

                    for (int t = 0; t < mat.TextureIndices.Length; t++)
                    {
                        if (mat.TextureIndices[t] != -1)
                        {
                            Console.WriteLine("TextureIndices " + mat.TextureIndices[t]);
                            string Texture = TextureMaps[mat.TextureIndices[t]];

                            var textureMap = new STGenericMatTexture();
                            textureMap.Name = Texture;
                            genericMat.TextureMaps.Add(textureMap);

                            if (Texture.EndsWith("col.dds"))
                            {
                                textureMap.Type = STGenericMatTexture.TextureType.Diffuse;
                            }
                            if (Texture.EndsWith("col.mot"))
                            {
                                textureMap.Type = STGenericMatTexture.TextureType.Diffuse;
                            }
                        }
                    }

                    root.Nodes[0].Nodes.Add(genericMat);
                }


                if (TotalNodeCount != 0)
                {
                    for (int i = 0; i < TotalNodeCount; i++)
                    {
                        reader.SeekBegin(TotalNodeOffset + (i * 8));

                        string NodeName = reader.ReadNameOffset(false, typeof(uint));
                        uint   Offset   = reader.ReadUInt32();

                        if (Offset != 0)
                        {
                            reader.SeekBegin(Offset);
                            Node node = new Node();
                            node.Name = NodeName;
                            node.Read(reader);
                            TotalNodes.Add(node);
                        }
                    }
                }

                if (BoneCount != 0)
                {
                    for (int i = 0; i < BoneCount; i++)
                    {
                        reader.SeekBegin(BoneOffset + (i * 8));

                        string NodeName = reader.ReadNameOffset(false, typeof(uint));
                        uint   Offset   = reader.ReadUInt32();

                        if (Offset != 0)
                        {
                            reader.SeekBegin(Offset);
                            Node node = new Node();
                            node.Name = NodeName;
                            node.Read(reader);
                            BoneList.Add(node); //This list is for mapping to meshes
                        }
                    }
                }

                foreach (var node in TotalNodes)
                {
                    // TreeNode lowerWrapper = new TreeNode($"{node.Name}");
                    // root.Nodes[3].Nodes.Add(lowerWrapper);

                    LoadChildern(TotalNodes, node, root.Nodes[2]);
                }

                if (FirstNodeOffset != 0)
                {
                    reader.SeekBegin(FirstNodeOffset);
                    uint NodeOffset = reader.ReadUInt32();
                    reader.SeekBegin(NodeOffset);
                    Node node = new Node();
                    node.Name = GetNodeName(TotalNodes, node);
                    node.Read(reader);

                    LoadBones(TotalNodes, node, root.Nodes[1]);
                }



                if (LinkNodeCount != 0)
                {
                    root.Nodes.Add("Links");

                    for (int i = 0; i < LinkNodeCount; i++)
                    {
                        TreeNode linkWrapper = new TreeNode($"Link {i}");
                        root.Nodes[3].Nodes.Add(linkWrapper);

                        reader.SeekBegin(LinkNodeOffset + (i * 12));

                        uint NodeOffset1 = reader.ReadUInt32();
                        uint NodeOffset2 = reader.ReadUInt32();
                        uint Index       = reader.ReadUInt32();

                        reader.SeekBegin(NodeOffset1);
                        Node node1 = new Node();
                        node1.Name = GetNodeName(TotalNodes, node1);
                        node1.Read(reader);

                        reader.SeekBegin(NodeOffset2);
                        Node node2 = new Node();
                        node2.Name = GetNodeName(TotalNodes, node1);
                        node2.Read(reader);

                        //  LoadChildern(TotalNodes, node1, linkWrapper);
                        // LoadChildern(TotalNodes, node2, linkWrapper);

                        LinkNodes.Add(Tuple.Create(node1, node2));
                    }
                }

                Skeleton.update();
                Skeleton.reset();
            }