示例#1
0
        public void ExportAs(object sender, EventArgs args)
        {
            using (var sfd = new SaveFileDialog())
            {
                sfd.Filter = "Source Model|*.smd|" +
                             "All Files (*.*)|*.*";

                sfd.DefaultExt = "smd";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    GXVertexDecompressor decom = new GXVertexDecompressor(Root);
                    SMD smd = new SMD();
                    smd.Bones = RenderBones;

                    foreach (MeleeDataObjectNode n in DataObjects.Nodes)
                    {
                        int[]           ind;
                        List <GXVertex> verts;
                        n.GetVerticesAsTriangles(out ind, out verts);

                        for (int i = 0; i < ind.Length; i += 3)
                        {
                            SMDTriangle t = new SMDTriangle();
                            t.Material = "defaultmaterial";
                            t.v1       = GXVertexToSMDVertex(verts[ind[i]]);
                            t.v2       = GXVertexToSMDVertex(verts[ind[i + 1]]);
                            t.v3       = GXVertexToSMDVertex(verts[ind[i + 2]]);
                            smd.Triangles.Add(t);
                        }
                    }

                    smd.Save(sfd.FileName);
                }
            }
        }
示例#2
0
        public static void ExportIOModelAsSMD(string FileName, IOModel Model)
        {
            SMD file = new SMD();

            if (Model.HasSkeleton)
            {
                var bonelist = new List <SBBone>(Model.Skeleton.Bones);
                var frame    = new SMDSkeletonFrame();
                file.skeleton.Add(frame);
                frame.time = 0;
                foreach (var bone in bonelist)
                {
                    file.nodes.Add(new SMDNode()
                    {
                        Name = bone.Name, ID = bonelist.IndexOf(bone), ParentID = bonelist.IndexOf(bone.Parent)
                    });
                    frame.skeletons.Add(new SMDSkeleton()
                    {
                        BoneID = bonelist.IndexOf(bone), Position = bone.Translation, Rotation = bone.RotationEuler
                    });
                }
            }

            if (Model.HasMeshes)
            {
                Dictionary <string, int> UniqueMeshNames = new Dictionary <string, int>();

                foreach (var mesh in Model.Meshes)
                {
                    if (!UniqueMeshNames.ContainsKey(mesh.Name))
                    {
                        UniqueMeshNames.Add(mesh.Name, 0);
                    }

                    string Name = mesh.Name + (UniqueMeshNames[mesh.Name] == 0 ? "" : "_" + UniqueMeshNames[mesh.Name]);
                    UniqueMeshNames[mesh.Name]++;

                    for (int i = 0; i < mesh.Indices.Count; i += 3)
                    {
                        var triangle = new SMDTriangle();
                        triangle.Material = Name;
                        triangle.vertex1  = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 0]]);
                        triangle.vertex2  = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 1]]);
                        triangle.vertex3  = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 2]]);
                        file.triangles.Add(triangle);
                    }
                }
            }

            file.Save(FileName);
        }
示例#3
0
        public void ExportSBAnimation(string FileName, SBAnimation animation, SBSkeleton skeleton)
        {
            SMD file = new SMD();

            var bonelist = new List <SBBone>(skeleton.Bones);

            foreach (var bone in bonelist)
            {
                file.nodes.Add(new SMDNode()
                {
                    Name = bone.Name, ID = bonelist.IndexOf(bone), ParentID = bonelist.IndexOf(bone.Parent)
                });
            }

            for (int i = 0; i < animation.FrameCount; i++)
            {
                var group = new SMDSkeletonFrame();
                group.time = i;
                file.skeleton.Add(group);

                foreach (var bone in bonelist)
                {
                    bool found = false;
                    foreach (var animbone in animation.TransformNodes)
                    {
                        if (animbone.Name.Equals(bone.Name))
                        {
                            var tempBone = new SBBone();
                            tempBone.Transform = animbone.GetTransformAt(i, skeleton);
                            group.skeletons.Add(new SMDSkeleton()
                            {
                                BoneID = bonelist.IndexOf(bone), Position = tempBone.Translation, Rotation = tempBone.RotationEuler
                            });
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        group.skeletons.Add(new SMDSkeleton()
                        {
                            BoneID = bonelist.IndexOf(bone), Position = bone.Translation, Rotation = bone.RotationEuler
                        });
                    }
                }
            }

            file.Save(FileName);
        }
示例#4
0
            private void ExportAllAction(object sender, EventArgs args)
            {
                OnExpand();

                List <string> Formats = new List <string>();

                Formats.Add("SMD (.smd)");
                Formats.Add("SEANIM (.seanim)");

                FolderSelectDialog sfd = new FolderSelectDialog();

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    string folderPath = sfd.SelectedPath;

                    BatchFormatExport form = new BatchFormatExport(Formats);
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        foreach (TreeNode node in Nodes)
                        {
                            Console.WriteLine($"node {node}");
                            if (!(node is IAnimationContainer))
                            {
                                continue;
                            }

                            var    anim = ((IAnimationContainer)node).AnimationController;
                            string name = Path.GetFileNameWithoutExtension(node.Text);

                            if (form.Index == 0)
                            {
                                SMD.Save((STSkeletonAnimation)anim, $"{folderPath}/{name}.smd");
                            }
                            if (form.Index == 1)
                            {
                                SEANIM.Save((STSkeletonAnimation)anim, $"{folderPath}/{name}.seanim");
                            }
                        }
                    }
                }
            }
示例#5
0
        public override void Export(string FileName)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfska")
            {
                if (GetResFileU() != null)
                {
                    SkeletalAnimU.Export(FileName, GetResFileU());
                }
                else
                {
                    SkeletalAnim.Export(FileName, GetResFile());
                }
            }
            else if (ext == ".chr0")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (SkeletalAnimU != null)
                {
                    BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.FSKAConvertWiiUToSwitch(SkeletalAnimU), FileName);
                }
                else
                {
                    BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName);
                }
            }
            else if (ext == ".smd")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    SMD.Save(this, skeleton, FileName);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
            else if (ext == ".anim")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    ANIM.CreateANIM(FileName, this, skeleton);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
            else if (ext == ".seanim")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    SEANIM.SaveAnimation(FileName, this, skeleton);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
            else if (ext == ".json")
            {
                if (SkeletalAnimU != null)
                {
                    System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnimU,
                                                                                                      Newtonsoft.Json.Formatting.Indented));
                }
                else
                {
                    System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnim,
                                                                                                      Newtonsoft.Json.Formatting.Indented));
                }
            }
        }
示例#6
0
        private void Open(string infile)
        {
            FileAttributes fileAttributes = File.GetAttributes(infile);

            if (fileAttributes.HasFlag(FileAttributes.Directory))
            {
                if (ModifierKeys == Keys.Control)
                {
                    AddLine(richTextBox1, $"Building Arc from {Path.GetFileName(infile)}...");
                    FEArc.PackArc(infile, Alignment, enablePaddingToolStripMenuItem.Checked);
                    AddLine(richTextBox1, "Done");
                }
                else if (ModifierKeys == Keys.Shift)
                {
                    AddLine(richTextBox1, $"Building BCH from {Path.GetFileName(infile)}...");

                    if (infile.EndsWith("_"))
                    {
                        infile = infile.Substring(0, infile.Length - "_".Length);
                    }

                    if (File.Exists(infile + ".bch"))
                    {
                        File.Delete(infile + ".bch");
                    }

                    List <string> files = Directory.GetFiles(infile, "*.*", SearchOption.AllDirectories).ToList();
                    H3D           Scene = new H3D();
                    Scene.ConverterVersion      = 44139;
                    Scene.BackwardCompatibility = 34;
                    Scene.ForwardCompatibility  = 35;
                    foreach (string file in files)
                    {
                        Bitmap texture;
                        try
                        {
                            texture = (Bitmap)Bitmap.FromFile(file);
                        }
                        catch (OutOfMemoryException)
                        {
                            Console.WriteLine("invalid image format, skipping");
                            continue;
                        }
                        Scene.Textures.Add(new H3DTexture(Path.GetFileNameWithoutExtension(file), texture, SPICA.PICA.Commands.PICATextureFormat.RGBA8));
                    }

                    if (Scene.Textures.Count <= 0)
                    {
                        AddLine(richTextBox1, "Error");
                        AddLine(richTextBox1, $"No images found in {Path.GetFileName(infile)}");
                    }
                    else
                    {
                        H3D.Save($"{infile}.bch", Scene);
                        AddLine(richTextBox1, "Done");
                    }
                    return;
                }
                else if (ModifierKeys == Keys.Alt)
                {
                    AddLine(richTextBox1, $"Building CTPK from {Path.GetFileName(infile)}...");
                    CTPK.MakeCTPK(infile);
                    AddLine(richTextBox1, "Done");
                }
                else
                {
                    foreach (string p in (new DirectoryInfo(infile)).GetFiles().Select(f => f.FullName))
                    {
                        Open(p);
                    }
                    foreach (string p in (new DirectoryInfo(infile)).GetDirectories().Select(f => f.FullName))
                    {
                        Open(p);
                    }
                }
            }
            else
            {
                byte[] data    = File.ReadAllBytes(infile);
                string magic   = FEIO.GetMagic(data);
                string ext     = Path.GetExtension(infile);
                string outpath = ext.Length == 0 ? infile : infile.Replace(ext, "");

                if (ModifierKeys == Keys.Control || batchCompressToolStripMenuItem.Checked) // Compression Method
                {
                    byte[] cmp;
                    if (lZ10CompressionToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz10...");
                        try
                        {
                            cmp = FEIO.LZ10Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (lZ11ToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz11...");
                        try
                        {
                            cmp = FEIO.LZ11Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (lZ13ToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz13...");
                        try
                        {
                            cmp = FEIO.LZ13Compress(data);
                        }
                        catch (Exception ex)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile + ".lz", cmp);
                        AddLine(richTextBox1, "Done");
                    }
                    else
                    {
                        AddLine(richTextBox1, "No Compression Method Selected, How did this even happen?");
                    }
                }
                else if (ext == ".lz" || magic == "Yaz0" || ext == ".cms" || ext == ".cmp") // Decompress Method
                {
                    byte[] dcmp;
                    if (data[0] == 0x10)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz10...");
                        try
                        {
                            dcmp = FEIO.LZ10Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ10
                    else if (data[0] == 0x11)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz11...");
                        try
                        {
                            dcmp = FEIO.LZ11Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ11
                    else if (data[0] == 0x13 && data[4] == 0x11)
                    {
                        AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz13...");
                        try
                        {
                            dcmp = FEIO.LZ13Decompress(data);
                        }
                        catch (Exception e)
                        {
                            AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}");
                            return;
                        }
                        File.WriteAllBytes(infile.Replace(".lz", ""), dcmp);
                        AddLine(richTextBox1, "Done");
                    } //LZ13
                    else if (magic == "Yaz0")
                    {
                        AddLine(richTextBox1, "Yaz0 Method not implemented");
                        return;
                    } //Yaz0
                    if (File.Exists(infile.Replace(".lz", "")) && autoExtractToolStripMenuItem.Checked)
                    {
                        Open(infile.Replace(".lz", ""));
                    }
                }
                else if (ext == ".arc") //Archive file
                {
                    AddLine(richTextBox1, $"Extract Files from {Path.GetFileName(infile)}...");
                    FEArc.ExtractArc(outpath, data);
                    AddLine(richTextBox1, "Done");
                }
                else if (magic == "BCH" || magic == "CGFX") //BCH / Bcres file
                {
                    H3D Scene = new H3D();
                    if (magic == "CGFX")
                    {
                        Scene = Gfx.Open(infile).ToH3D();
                    }
                    else
                    {
                        Scene = H3D.Open(data);
                    }

                    if (Directory.Exists(outpath))
                    {
                        Directory.Delete(outpath, true);
                    }
                    if (File.Exists(outpath))
                    {
                        outpath = outpath + "_";
                    }

                    //Export method for textures, this is always enabled by default
                    if (Scene.Textures.Count > 0)
                    {
                        AddLine(richTextBox1, $"Extracting Textures from {Path.GetFileName(infile)}...");
                        if (!Directory.Exists(outpath))
                        {
                            Directory.CreateDirectory(outpath);
                        }

                        foreach (var texture in Scene.Textures)
                        {
                            Image img = texture.ToBitmap();
                            img.Save($"{outpath}\\{texture.Name}.png", System.Drawing.Imaging.ImageFormat.Png);
                        }
                        AddLine(richTextBox1, "Done");
                    }
                    if (exportDaeToolStripMenuItem.Checked || exportSMDToolStripMenuItem.Checked && Scene.Models.Count > 0)
                    {
                        AddLine(richTextBox1, $"Extracting Models from {Path.GetFileName(infile)}...");
                        if (!Directory.Exists(outpath))
                        {
                            Directory.CreateDirectory(outpath);
                        }

                        for (int i = 0; i < Scene.Models.Count; i++)
                        {
                            if (exportDaeToolStripMenuItem.Checked)
                            {
                                DAE dae = new DAE(Scene, i);
                                dae.Save($"{outpath}\\{Scene.Models[i].Name}.dae");
                            }
                            if (exportSMDToolStripMenuItem.Checked)
                            {
                                SMD smd = new SMD(Scene, i);
                                smd.Save($"{outpath}\\{Scene.Models[i].Name}.smd");
                            }
                        }
                        AddLine(richTextBox1, "Done");
                    }
                }
                else if (magic == "CTPK") //CTPK file
                {
                    AddLine(richTextBox1, $"Extract Textures from {Path.GetFileName(infile)}...");
                    CTPK.ExtractCTPK(infile);
                    AddLine(richTextBox1, "Done");
                }
                else if (ext == ".bin")
                {
                    if (FEIO.ReadStringFromArray(data, Encoding.UTF8, 0x20).Contains("MESS_ARCHIVE"))
                    {
                        AddLine(richTextBox1, $"Extracting Message Archive {Path.GetFileName(infile)}...");
                        FEMessage.ExtractMessage(infile.Replace(ext, ".txt"), data);
                        AddLine(richTextBox1, "Done");
                    }
                    else if (enableBinDecomplingToolStripMenuItem.Checked)
                    {
                        AddLine(richTextBox1, $"Decompiling {Path.GetFileName(infile)} to txt...");
                        FEBin.ExtractBin(infile);
                        AddLine(richTextBox1, "Done");
                    }
                }
                if (deleteAfterProcessingToolStripMenuItem.Checked)
                {
                    File.Delete(infile);
                }
            }
        }
示例#7
0
        public override void Export(string FileName)
        {
            string ext = Utils.GetExtension(FileName);

            if (ext == ".bfska")
            {
                if (GetResFileU() != null)
                {
                    SkeletalAnimU.Export(FileName, GetResFileU());
                }
                else
                {
                    SkeletalAnim.Export(FileName, GetResFile());
                }
            }
            else if (ext == ".chr0")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (SkeletalAnimU != null)
                {
                    BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.FSKAConvertWiiUToSwitch(SkeletalAnimU), FileName);
                }
                else
                {
                    BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName);
                }

                //  BrawlboxHelper.FSKAConverter.Fska2Chr0(this, skeleton, FileName);
            }
            else if (ext == ".smd")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    SMD.Save(this, skeleton, FileName);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
            else if (ext == ".anim")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    ANIM.CreateANIM(FileName, this, skeleton);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
            else if (ext == ".seanim")
            {
                STSkeleton skeleton = GetActiveSkeleton();

                if (skeleton != null)
                {
                    SEANIM.SaveAnimation(FileName, this, skeleton);
                }
                else
                {
                    throw new Exception("No skeleton found to assign!");
                }
            }
        }