예제 #1
0
        public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton)
        {
            using (SBCustomDialog d = new SBCustomDialog(Settings))
            {
                d.ShowDialog();
            }

            return(ImportSBAnimation(FileName, skeleton, Settings.JVCPath));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void ExportAnimationToFile(object sender, EventArgs args)
        {
            if (viewportPanel.LoadedScene == null)
            {
                MessageBox.Show("No scene is selected");
                return;
            }

            SBAnimAttachment anim = viewportPanel.GetAttachment <SBAnimAttachment>();
            SBAnimation      animation;

            if (anim != null)
            {
                animation = anim.GetAnimation();
            }
            else
            {
                MessageBox.Show("No animation is loaded in the scene");
                return;
            }

            string Filter = "";

            //Create filter
            Dictionary <string, IExportableAnimation> extensionToExporter = new Dictionary <string, IExportableAnimation>();

            foreach (IExportableAnimation exporter in AnimationExporters)
            {
                string Extension = exporter.Extension;
                Filter += $"*{Extension};";
                extensionToExporter.Add(Extension, exporter);
            }

            string FileName;

            if (Tools.FileTools.TrySaveFile(out FileName, "Supported Files|" + Filter))
            {
                foreach (var extension in extensionToExporter.Keys)
                {
                    if (FileName.ToLower().EndsWith(extension))
                    {
                        DialogResult Result = DialogResult.OK;
                        if (extensionToExporter[extension].Settings != null)
                        {
                            using (var dialog = new SBCustomDialog(extensionToExporter[extension].Settings))
                                Result = dialog.ShowDialog();
                        }

                        if (Result == DialogResult.OK)
                        {
                            extensionToExporter[extension].ExportSBAnimation(FileName, animation, (SBSkeleton)viewportPanel.LoadedScene.Skeleton);
                        }
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static SBScene LoadScene(string filePath, SBScene loadedScene)
        {
            IImportableModelType modelType = GetModelTypeFromPath(filePath);

            if (modelType == null)
            {
                return(null);
            }

            DialogResult Result = DialogResult.OK;

            if (modelType.Settings != null)
            {
                using (var dialog = new SBCustomDialog(modelType.Settings))
                    Result = dialog.ShowDialog();
            }

            if (Result == DialogResult.OK)
            {
                var ioModel = modelType.ImportIOModel(filePath);

                SBScene scene;
                if (loadedScene == null)
                {
                    SBConsole.WriteLine("No scene loaded, defaulted to Smash Ultimate scene");
                    scene = new SBSceneSSBH();

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.NewImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.NewImportSettings.NUMATLB != null && SBSceneSSBH.NewImportSettings.NUMATLB != "")
                        {
                            MATL_Loader.Open(SBSceneSSBH.NewImportSettings.NUMATLB, scene);
                        }

                        if (SBSceneSSBH.NewImportSettings.NUSKTFile != null && SBSceneSSBH.NewImportSettings.NUSKTFile != "")
                        {
                            ioModel.Skeleton = SKEL_Loader.Open(SBSceneSSBH.NewImportSettings.NUSKTFile, scene);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }
                else
                {
                    scene = loadedScene;

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.ImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.ImportSettings.UseExistingSkeleton)
                        {
                            ioModel.ConvertToSkeleton((SBSkeleton)scene.Skeleton);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }

                scene.FromIOModel(ioModel);
                return(scene);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static SBScene LoadScene(string filePath, SBScene loadedScene)
        {
            DialogResult Result = DialogResult.OK;

            var settings = new IONET.ImportSettings();

            using (SBCustomDialog d = new SBCustomDialog(settings))
                Result = d.ShowDialog();

            if (Result == DialogResult.OK)
            {
                var ioModel = IONET.IOManager.LoadScene(filePath, settings);

                SBScene scene;
                if (loadedScene == null)
                {
                    SBConsole.WriteLine("No scene loaded, defaulted to Smash Ultimate scene");
                    scene = new SBSceneSSBH();

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.NewImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.NewImportSettings.NUMATLB != null && SBSceneSSBH.NewImportSettings.NUMATLB != "")
                        {
                            MATL_Loader.Open(SBSceneSSBH.NewImportSettings.NUMATLB, scene);
                        }

                        if (SBSceneSSBH.NewImportSettings.NUSKTFile != null && SBSceneSSBH.NewImportSettings.NUSKTFile != "")
                        {
                            ioModel.Models[0].Skeleton = SKEL_Loader.Open(SBSceneSSBH.NewImportSettings.NUSKTFile, scene).ToIOSkeleton();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }
                else
                {
                    scene = loadedScene;

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.ImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.ImportSettings.UseExistingSkeleton)
                        {
                            ioModel.Models[0].Skeleton = ((SBSkeleton)scene.Skeleton).ToIOSkeleton();
                            //ioModel.ConvertToSkeleton((SBSkeleton)scene.Skeleton);
                            // ionet uses bone names so no need to convert bone mapping indices
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }

                scene.FromIOModel(ioModel);
                return(scene);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public SBDobjAttachment()
        {
            Text = "DOBJ List";
            Dock = DockStyle.Fill;
            //this.s
            ApplicationSettings.SkinControl(this);

            dobjList               = new SBTreeView();
            dobjList.Dock          = DockStyle.Top;
            dobjList.Size          = new Size(200, 200);
            dobjList.CheckBoxes    = true;
            dobjList.HideSelection = false;
            dobjList.AfterCheck   += (sender, args) =>
            {
                if (args.Node != null && args.Node.Tag is SBHsdMesh mesh)
                {
                    mesh.Visible = args.Node.Checked;
                }
            };
            dobjList.AfterSelect += (sender, args) =>
            {
                foreach (TreeNode v in dobjList.Nodes)
                {
                    if (v.Tag is SBHsdMesh mesh)
                    {
                        mesh.Selected = false;
                    }
                }
                propertyGrid.SelectedObject = null;
                if (dobjList.SelectedNode != null)
                {
                    if (dobjList.SelectedNode.Tag is SBHsdMesh mesh)
                    {
                        mesh.Selected = true;
                    }
                    propertyGrid.SelectedObject = dobjList.SelectedNode.Tag;
                }
            };

            propertyGrid      = new PropertyGrid();
            propertyGrid.Dock = DockStyle.Fill;
            propertyGrid.Size = new Size(200, 400);
            propertyGrid.SelectedObjectsChanged += (sender, args) =>
            {
                removeTexture.Visible = propertyGrid.SelectedObject is HSD_TOBJ;
                exportTexture.Visible = propertyGrid.SelectedObject is HSD_TOBJ;
                importTexture.Visible = propertyGrid.SelectedObject != null;
            };


            clearTextures        = new SBButton("Clear Textures");
            clearTextures.Dock   = DockStyle.Top;
            clearTextures.Click += (sender, args) =>
            {
                if (scene != null)
                {
                    if (scene.HasMaterialAnimations)
                    {
                        MessageBox.Show("Eror: DATs with material animations must keep their textures intact");
                    }
                    else
                    {
                        if (MessageBox.Show("Are you sure? This cannot be undone", "Clear Textures", MessageBoxButtons.OKCancel) != DialogResult.OK)
                        {
                            return;
                        }
                        //TODO:
                        //scene.ClearMaterialAnimations();
                        //return;
                        foreach (SBHsdMesh m in scene.GetMeshObjects())
                        {
                            m.ClearTextures();
                        }
                        RefreshList();
                    }
                }
            };

            optionPanel      = new GroupBox();
            optionPanel.Text = "Options";
            ApplicationSettings.SkinControl(optionPanel);
            optionPanel.Dock = DockStyle.Top;

            //AutoScroll = true;

            exportTexture         = new SBButton("Export Texture");
            exportTexture.Dock    = DockStyle.Top;
            exportTexture.Visible = false;
            optionPanel.Controls.Add(exportTexture);
            exportTexture.Click += (sender, args) =>
            {
                string filePath;

                if (propertyGrid.SelectedObject is HSD_TOBJ tobj)
                {
                    var filter = "PNG (*.png)|*.png;";

                    //if (tobj.ImageData != null && tobj.ImageData.Format == GXTexFmt.CMP)
                    //    filter = "DDS (*.dds)|*.dds;";

                    if (FileTools.TrySaveFile(out filePath, filter))
                    {
                        //TODO: dds export / import

                        /*if (tobj.ImageData != null && tobj.ImageData.Format == GXTexFmt.CMP)
                         * {
                         *  SBSurface s = new SBSurface();
                         *  s.Width = tobj.ImageData.Width;
                         *  s.Height = tobj.ImageData.Height;
                         *  s.InternalFormat = OpenTK.Graphics.OpenGL.InternalFormat.CompressedRgbaS3tcDxt1Ext;
                         *  s.Arrays.Add(new MipArray() { Mipmaps = new List<byte[]>() { HSDRaw.Tools.TPLConv.ToCMP(tobj.ImageData.ImageData, tobj.ImageData.Width, tobj.ImageData.Height) } });
                         *
                         *  IO_DDS.Export(filePath, s);
                         * }
                         * else*/
                        {
                            FileTools.WriteBitmapFile(filePath, tobj.ImageData.Width, tobj.ImageData.Height, tobj.GetDecodedImageData());
                        }
                    }
                }
            };

            removeTexture         = new SBButton("Remove Texture");
            removeTexture.Dock    = DockStyle.Top;
            removeTexture.Visible = false;
            optionPanel.Controls.Add(removeTexture);
            removeTexture.Click += (sender, args) =>
            {
                if (dobjList.SelectedNode.Tag is HSD_TOBJ tobj)
                {
                    // remove tobj from list
                    var mobj = (HSD_MOBJ)dobjList.SelectedNode.Parent.Tag;

                    HSD_TOBJ prevTexture = null;
                    if (mobj.Textures != null)
                    {
                        foreach (var tex in mobj.Textures.List)
                        {
                            if (tex._s == tobj._s)
                            {
                                if (prevTexture == null)
                                {
                                    mobj.Textures = tex.Next;
                                }
                                else
                                {
                                    prevTexture.Next = tex.Next;
                                }
                                // update texture and flag stuff
                                break;
                            }
                            prevTexture = tex;
                        }
                    }

                    FixMOBJTexIDs(mobj);

                    var root = dobjList.SelectedNode.Parent.Parent;
                    root.Nodes.Clear();
                    root.Nodes.Add(CreateMOBJNode(mobj));
                    scene.RefreshRendering();
                }
            };

            importTexture         = new SBButton("Import Texture");
            importTexture.Dock    = DockStyle.Top;
            importTexture.Visible = false;
            optionPanel.Controls.Add(importTexture);
            importTexture.Click += (sender, args) =>
            {
                // select texture
                HSD_MOBJ   mobj = null;
                SBTreeNode root = null;
                if (dobjList.SelectedNode.Tag is SBHsdMesh mesh)
                {
                    if (mesh.DOBJ.Mobj != null)
                    {
                        mobj = mesh.DOBJ.Mobj;
                        root = (SBTreeNode)dobjList.SelectedNode;
                    }
                }
                if (dobjList.SelectedNode.Tag is HSD_MOBJ m)
                {
                    mobj = m;
                    root = (SBTreeNode)dobjList.SelectedNode.Parent;
                }
                if (dobjList.SelectedNode.Tag is HSD_TOBJ)
                {
                    if (dobjList.SelectedNode.Parent.Tag is HSD_MOBJ mo)
                    {
                        mobj = mo;
                        root = (SBTreeNode)dobjList.SelectedNode.Parent.Parent;
                    }
                }
                if (mobj == null)
                {
                    return;
                }
                string filePath;
                if (FileTools.TryOpenFile(out filePath, "Supported Formats (*.png*.dds)|*.png;*.dds"))
                {
                    var settings = new TOBJImportSettings();
                    // select textue import options
                    using (SBCustomDialog d = new SBCustomDialog(settings))
                    {
                        if (d.ShowDialog() == DialogResult.OK)
                        {
                            // create tobj and attach to selected mobj
                            HSD_TOBJ tobj = new HSD_TOBJ();
                            tobj.MagFilter = GXTexFilter.GX_LINEAR;
                            tobj.HScale    = 1;
                            tobj.WScale    = 1;
                            tobj.WrapS     = GXWrapMode.REPEAT;
                            tobj.WrapT     = GXWrapMode.REPEAT;
                            tobj.SX        = 1;
                            tobj.SY        = 1;
                            tobj.SZ        = 1;

                            if (System.IO.Path.GetExtension(filePath.ToLower()) == ".dds")
                            {
                                var dxtsurface = IO_DDS.Import(filePath);

                                if (dxtsurface.InternalFormat != OpenTK.Graphics.OpenGL.InternalFormat.CompressedRgbaS3tcDxt1Ext)
                                {
                                    throw new NotSupportedException("DDS format " + dxtsurface.InternalFormat.ToString() + " not supported");
                                }

                                tobj.EncodeImageData(dxtsurface.Arrays[0].Mipmaps[0], dxtsurface.Width, dxtsurface.Height, GXTexFmt.CMP, GXTlutFmt.IA8);
                            }
                            else
                            {
                                var bmp = new Bitmap(filePath);

                                var bitmapData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                                var length     = bitmapData.Stride * bitmapData.Height;

                                byte[] bytes = new byte[length];

                                Marshal.Copy(bitmapData.Scan0, bytes, 0, length);
                                bmp.UnlockBits(bitmapData);

                                tobj.EncodeImageData(bytes, bmp.Width, bmp.Height, settings.ImageFormat, settings.PaletteFormat);

                                bmp.Dispose();
                            }

                            if (settings.UseBlending && mobj.PEDesc == null)
                            {
                                mobj.PEDesc = new HSD_PEDesc();
                            }

                            //TODO: set flags for texture types
                            if (settings.TextureType == TOBJTextureType.Diffuse)
                            {
                                mobj.RenderFlags |= RENDER_MODE.DIFFUSE;
                                tobj.Flags       |= TOBJ_FLAGS.LIGHTMAP_DIFFUSE;
                            }
                            if (settings.TextureType == TOBJTextureType.Specular)
                            {
                                mobj.RenderFlags |= RENDER_MODE.SPECULAR;
                                tobj.Flags       |= TOBJ_FLAGS.LIGHTMAP_SPECULAR;
                            }
                            if (settings.TextureType == TOBJTextureType.Bump)
                            {
                                tobj.Flags |= TOBJ_FLAGS.BUMP;
                            }

                            switch (settings.UVType)
                            {
                            case TOBJUVType.Sphere:
                                tobj.Flags |= TOBJ_FLAGS.COORD_REFLECTION;
                                break;

                            case TOBJUVType.TextureCoord:
                                tobj.Flags |= TOBJ_FLAGS.COORD_UV;
                                break;
                            }

                            if (mobj.Textures == null)
                            {
                                mobj.Textures = tobj;
                                tobj.Flags   |= TOBJ_FLAGS.COLORMAP_REPLACE;
                            }
                            else
                            {
                                tobj.Flags |= TOBJ_FLAGS.COLORMAP_BLEND;
                            }
                            propertyGrid.SelectedObject = tobj;

                            FixMOBJTexIDs(mobj);

                            root.Nodes.Clear();
                            root.Nodes.Add(CreateMOBJNode(mobj));
                            scene.RefreshRendering();
                        }
                    }
                }
            };

            propertyPanel      = new GroupBox();
            propertyPanel.Text = "Properties";
            propertyPanel.Dock = DockStyle.Top;
            propertyPanel.Controls.Add(propertyGrid);
            propertyPanel.Height = 300;
            ApplicationSettings.SkinControl(propertyPanel);

            Controls.Add(propertyPanel);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10, BackColor = ApplicationSettings.BGColor2
            });
            Controls.Add(optionPanel);
            Controls.Add(new Splitter()
            {
                Dock = DockStyle.Top, Height = 10, BackColor = ApplicationSettings.BGColor2
            });
            Controls.Add(dobjList);
            Controls.Add(clearTextures);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static SBScene LoadScene(string filePath, SBScene loadedScene)
        {
            DialogResult Result = DialogResult.OK;

            var settings = new IONET.ImportSettings();

            using (SBCustomDialog d = new SBCustomDialog(settings))
                Result = d.ShowDialog();

            if (Result == DialogResult.OK)
            {
                IONET.Core.IOScene ioModel;
                try
                {
                    ioModel = IONET.IOManager.LoadScene(filePath, settings);
                }
                catch (ArgumentNullException e)
                {
                    throw new ArgumentNullException("This error is usually caused by missing textures. Make sure you can correctly preview your model with textures before exporting.\nOriginal Error Msg: \n" + e.Message, e);
                }
                catch (NullReferenceException e)
                {
                    throw new NullReferenceException("This error is usually caused by a not exporting the Skeleton along with the Meshes. \nOriginal Message: \n" + e.Message, e);
                }

                SBScene scene;
                if (loadedScene == null)
                {
                    SBConsole.WriteLine("No scene loaded, defaulted to Smash Ultimate scene");
                    scene = new SBSceneSSBH();

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.NewImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.NewImportSettings.NumatbFile != null && SBSceneSSBH.NewImportSettings.NumatbFile != "")
                        {
                            MATL_Loader.Open(SBSceneSSBH.NewImportSettings.NumatbFile, scene);
                        }

                        if (SBSceneSSBH.NewImportSettings.NusktbFile != null && SBSceneSSBH.NewImportSettings.NusktbFile != "")
                        {
                            ioModel.Models[0].Skeleton = SKEL_Loader.Open(SBSceneSSBH.NewImportSettings.NusktbFile, scene).ToIOSkeleton();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }
                else
                {
                    scene = loadedScene;

                    using (var dialog = new SBCustomDialog(SBSceneSSBH.ImportSettings))
                        Result = dialog.ShowDialog();

                    if (Result == DialogResult.OK)
                    {
                        if (SBSceneSSBH.ImportSettings.UseExistingSkeleton)
                        {
                            ioModel.Models[0].Skeleton = ((SBSkeleton)scene.Skeleton).ToIOSkeleton();
                            //ioModel.ConvertToSkeleton((SBSkeleton)scene.Skeleton);
                            // ionet uses bone names so no need to convert bone mapping indices
                        }
                    }
                    else
                    {
                        MessageBox.Show("Failed to import model");
                        return(null);
                    }
                }

                scene.FromIOModel(ioModel);
                return(scene);
            }
            else
            {
                return(null);
            }
        }