Exemple #1
0
        public MeleeEffectTable() : base()
        {
            MenuItem AddNewEffect = new MenuItem("Add new Effect");

            AddNewEffect.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is SBM_EffectTable root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        var file = new HSDRaw.HSDRawFile(f);
                        if (file.Roots[0].Data._s.Length == 0x14)
                        {
                            var mod = root.Models;
                            Array.Resize(ref mod, mod.Length + 1);
                            mod[mod.Length - 1] = new SBM_EffectModel()
                            {
                                _s = file.Roots[0].Data._s
                            };
                            root.Models = mod;
                        }
                    }
                }
            };
            MenuItems.Add(AddNewEffect);
        }
Exemple #2
0
        public AnimJointContextMenu() : base()
        {
            MenuItem OpenAsAJ = new MenuItem("Add AOBJ");

            OpenAsAJ.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint anim)
                {
                    anim.AOBJ = new HSD_AOBJ();
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            MenuItems.Add(OpenAsAJ);


            MenuItem addChild = new MenuItem("Add Child");

            MenuItems.Add(addChild);

            MenuItem createJOBJ = new MenuItem("From Scratch");

            createJOBJ.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint root)
                {
                    root.AddChild(new HSD_AnimJoint()
                    {
                    });
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJ);


            MenuItem createJOBJFromFile = new MenuItem("From File");

            createJOBJFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        HSDRaw.HSDRawFile file = new HSDRaw.HSDRawFile(f);

                        var node = file.Roots[0].Data;
                        if (node is HSD_AnimJoint newchild)
                        {
                            root.AddChild(newchild);
                        }
                    }
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJFromFile);
        }
        public TEXGContextMenu() : base()
        {
            MenuItem addFromFile = new MenuItem("Add TEXG From File");

            addFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_TEXGraphicBank root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        var file = new HSDRaw.HSDRawFile(f);
                        var mod  = root.ParticleImages;
                        Array.Resize(ref mod, mod.Length + 1);
                        mod[mod.Length - 1] = new HSD_TexGraphic()
                        {
                            _s = file.Roots[0].Data._s
                        };
                        root.ParticleImages = mod;
                    }
                }
            };
            MenuItems.Add(addFromFile);

            MenuItem scratch = new MenuItem("Add TEXG From Scratch");

            scratch.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_TEXGraphicBank root)
                {
                    var mod = root.ParticleImages;
                    Array.Resize(ref mod, mod.Length + 1);
                    mod[mod.Length - 1] = new HSD_TexGraphic();
                    root.ParticleImages = mod;
                }
            };
            MenuItems.Add(scratch);


            MenuItem export = new MenuItem("Export TXG");

            export.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_TEXGraphicBank root)
                {
                    var f = Tools.FileIO.SaveFile("TEXG (*.txg)|*.txg");

                    if (f != null)
                    {
                        System.IO.File.WriteAllBytes(f, root._s.GetData());
                    }
                }
            };
            MenuItems.Add(export);
        }
        public ParticleContextMenu() : base()
        {
            MenuItem addFromFile = new MenuItem("Add Particle From File");

            addFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_ParticleGroup root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        var file = new HSDRaw.HSDRawFile(f);
                        var mod  = root.Particles;
                        Array.Resize(ref mod, mod.Length + 1);
                        mod[mod.Length - 1] = new HSD_ParticleGenerator()
                        {
                            _s = file.Roots[0].Data._s
                        };
                        root.Particles = mod;
                    }
                }
            };
            MenuItems.Add(addFromFile);

            MenuItem export = new MenuItem("Export PTL");

            export.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_ParticleGroup root)
                {
                    var f = Tools.FileIO.SaveFile("Particle (*.ptl)|*.ptl");

                    if (f != null)
                    {
                        System.IO.File.WriteAllBytes(f, root._s.GetData());
                    }
                }
            };
            MenuItems.Add(export);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_jointMap"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static JointAnimManager LoadJointAnimFromFile(JointMap _jointMap, string filePath = null)
        {
            if (filePath == null)
            {
                filePath = Tools.FileIO.OpenFile(SupportedImportAnimFilter);
            }

            if (filePath != null)
            {
                if (Path.GetExtension(filePath).ToLower().Equals(".chr0"))
                {
                    return(CHR0Converter.LoadCHR0(filePath, _jointMap));
                }
                else
                if (Path.GetExtension(filePath).ToLower().Equals(".anim"))
                {
                    return(ConvMayaAnim.ImportFromMayaAnim(filePath, _jointMap));
                }
                else
                if (Path.GetExtension(filePath).ToLower().Equals(".dat"))
                {
                    var dat = new HSDRaw.HSDRawFile(filePath);

                    if (dat.Roots.Count > 0 && dat.Roots[0].Data is HSD_FigaTree tree)
                    {
                        return(new JointAnimManager(tree));
                    }

                    if (dat.Roots.Count > 0 && dat.Roots[0].Data is HSD_AnimJoint joint)
                    {
                        return(new JointAnimManager(joint));
                    }
                }
            }

            return(null);
        }
        public FighterArticleContextMenu() : base()
        {
            MenuItem addFromFile = new MenuItem("Add Article From File");

            addFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is SBM_ArticlePointer root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        var file = new HSDRaw.HSDRawFile(f);
                        var mod  = root.Articles;
                        Array.Resize(ref mod, mod.Length + 1);
                        mod[mod.Length - 1] = new SBM_Article()
                        {
                            _s = file.Roots[0].Data._s
                        };
                        root.Articles = mod;
                    }
                }
            };
            MenuItems.Add(addFromFile);
        }
Exemple #7
0
        public bool DoIt(string[] args)
        {
            if (args.Length < 3)
            {
                return(false);
            }

            // load file
            var file = new HSDRaw.HSDRawFile(args[1]);
            var node = file["mexSelectChr"];

            if (node == null)
            {
                return(false);
            }

            // parse percentage
            if (!float.TryParse(args[2], out percentage))
            {
                return(false);
            }
            percentage /= 100;


            var mexNode = node.Data as MEX_mexSelectChr;

            if (mexNode != null)
            {
                var textures = mexNode.CSPMatAnim.TextureAnimation.ToTOBJs();

                for (int i = 0; i < textures.Length; i++)
                {
                    ThreadPool.QueueUserWorkItem(Process, textures[i]);
                }

                int toProcess = textures.Length;
                using (ManualResetEvent resetEvent = new ManualResetEvent(false))
                {
                    for (int i = 0; i < textures.Length; i++)
                    {
                        ThreadPool.QueueUserWorkItem(
                            x =>
                        {
                            var texture = (HSD_TOBJ)x;
                            using (var csp = texture.ToBitmap())
                                using (var shrink = ImageTools.ResizeImage(csp, (int)(csp.Width * percentage), (int)(csp.Height * percentage)))
                                {
                                    texture.EncodeImageData(shrink.GetBGRAData(), shrink.Width, shrink.Height, HSDRaw.GX.GXTexFmt.CI8, HSDRaw.GX.GXTlutFmt.RGB5A3);
                                }

                            if (Interlocked.Decrement(ref toProcess) == 0)
                            {
                                resetEvent.Set();
                            }
                        }, textures[i]);
                    }

                    resetEvent.WaitOne();
                }

                mexNode.CSPMatAnim.TextureAnimation.FromTOBJs(textures, false);
            }

            file.TrimData();
            file.Save(args.Length > 3 ? args[3] : args[1]);

            return(true);
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="material"></param>
        /// <returns></returns>
        private HSD_MOBJ GenerateMaterial(IOMaterial material)
        {
            // create blank mobj
            var Mobj = new HSD_MOBJ();

            Mobj.Material = new HSD_Material()
            {
                AMB_A         = 0xFF,
                AMB_R         = 0x7F,
                AMB_G         = 0x7F,
                AMB_B         = 0x7F,
                DiffuseColor  = System.Drawing.Color.White,
                SpecularColor = System.Drawing.Color.White,
                Shininess     = 50,
                Alpha         = 1
            };

            // detect and set flags
            if (Settings.ImportVertexColor)
            {
                Mobj.RenderFlags |= RENDER_MODE.VERTEX;
            }

            if (Settings.EnableDiffuse)
            {
                Mobj.RenderFlags |= RENDER_MODE.DIFFUSE;
            }

            if (Settings.EnableConstant)
            {
                Mobj.RenderFlags |= RENDER_MODE.CONSTANT;
            }

            // Properties
            if (material != null && Settings.ImportMaterialInfo)
            {
                Mobj.Material.Shininess = material.Shininess;
                Mobj.Material.Alpha     = material.Alpha;

                Mobj.Material.AMB_R = (byte)(material.AmbientColor.X * 255);
                Mobj.Material.AMB_G = (byte)(material.AmbientColor.Y * 255);
                Mobj.Material.AMB_B = (byte)(material.AmbientColor.Z * 255);
                Mobj.Material.AMB_A = (byte)(material.AmbientColor.W * 255);

                Mobj.Material.DIF_R = (byte)(material.DiffuseColor.X * 255);
                Mobj.Material.DIF_G = (byte)(material.DiffuseColor.Y * 255);
                Mobj.Material.DIF_B = (byte)(material.DiffuseColor.Z * 255);
                Mobj.Material.DIF_A = (byte)(material.DiffuseColor.W * 255);

                Mobj.Material.SPC_R = (byte)(material.SpecularColor.X * 255);
                Mobj.Material.SPC_G = (byte)(material.SpecularColor.Y * 255);
                Mobj.Material.SPC_B = (byte)(material.SpecularColor.Z * 255);
                Mobj.Material.SPC_A = (byte)(material.SpecularColor.W * 255);
            }

            // Textures
            if (material != null && Settings.ImportTexture)
            {
                if (material.DiffuseMap != null && !string.IsNullOrEmpty(material.DiffuseMap.FilePath))
                {
                    var texturePath = material.DiffuseMap.FilePath;

                    if (texturePath.Contains("file://"))
                    {
                        texturePath = texturePath.Replace("file://", "");
                    }

                    if (File.Exists(Path.Combine(_cache.FolderPath, texturePath)))
                    {
                        texturePath = Path.Combine(_cache.FolderPath, texturePath);
                    }

                    if (File.Exists(material.DiffuseMap.FilePath))
                    {
                        texturePath = material.DiffuseMap.FilePath;
                    }

                    if (File.Exists(texturePath + ".png"))
                    {
                        texturePath = texturePath + ".png";
                    }


                    var mobjPath = Path.Combine(Path.GetDirectoryName(texturePath), Path.GetFileNameWithoutExtension(texturePath)) + ".mobj";

                    if (Settings.ImportMOBJ && File.Exists(mobjPath))
                    {
                        var dat = new HSDRaw.HSDRawFile(mobjPath);
                        Mobj._s = dat.Roots[0].Data._s;
                        return(Mobj);
                    }
                    else
                    /// special mobj loading
                    if (Path.GetExtension(texturePath).ToLower() == ".mobj")
                    {
                        var dat = new HSDRaw.HSDRawFile(texturePath);
                        Mobj._s = dat.Roots[0].Data._s;
                        return(Mobj);
                    }
                    else
                    if (File.Exists(texturePath) && (texturePath.ToLower().EndsWith(".png") || texturePath.ToLower().EndsWith(".bmp")))
                    {
                        Mobj.RenderFlags |= RENDER_MODE.TEX0;

                        var tobj = TOBJConverter.ImportTOBJFromFile(texturePath, Settings.TextureFormat, Settings.PaletteFormat);
                        tobj.Flags = TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COORD_UV | TOBJ_FLAGS.COLORMAP_MODULATE;

                        tobj.GXTexGenSrc = 4;
                        tobj.TexMapID    = GXTexMapID.GX_TEXMAP0;

                        tobj.WrapS = ToGXWrapMode(material.DiffuseMap.WrapS);
                        tobj.WrapT = ToGXWrapMode(material.DiffuseMap.WrapT);

                        if (TOBJConverter.IsTransparent(tobj))
                        {
                            _cache.HasXLU     = true;
                            Mobj.RenderFlags |= RENDER_MODE.XLU;
                            tobj.Flags       |= TOBJ_FLAGS.ALPHAMAP_MODULATE;
                        }

                        Mobj.Textures = tobj;
                    }
                }
            }

            return(Mobj);
        }
        public AnimJointContextMenu() : base()
        {
            MenuItem OpenAsAJ = new MenuItem("Add AOBJ");

            OpenAsAJ.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint anim)
                {
                    anim.AOBJ = new HSD_AOBJ();
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            MenuItems.Add(OpenAsAJ);


            MenuItem addChild = new MenuItem("Add Child");

            MenuItems.Add(addChild);

            MenuItem createJOBJ = new MenuItem("From Scratch");

            createJOBJ.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint root)
                {
                    root.AddChild(new HSD_AnimJoint()
                    {
                    });
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJ);


            MenuItem createJOBJFromFile = new MenuItem("From File");

            createJOBJFromFile.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint root)
                {
                    var f = Tools.FileIO.OpenFile(ApplicationSettings.HSDFileFilter);
                    if (f != null)
                    {
                        HSDRaw.HSDRawFile file = new HSDRaw.HSDRawFile(f);

                        var node = file.Roots[0].Data;
                        if (node is HSD_AnimJoint newchild)
                        {
                            root.AddChild(newchild);
                        }
                    }
                    MainForm.SelectedDataNode.Refresh();
                }
            };
            addChild.MenuItems.Add(createJOBJFromFile);

#if DEBUG
            MenuItem reverse = new MenuItem("Reverse");
            reverse.Click += (sender, args) =>
            {
                if (MainForm.SelectedDataNode.Accessor is HSD_AnimJoint anim)
                {
                    foreach (var n in anim.BreathFirstList)
                    {
                        if (n.AOBJ != null)
                        {
                            foreach (var a in n.AOBJ.FObjDesc.List)
                            {
                                var keys       = a.GetDecodedKeys();
                                var frameCount = keys.Max(e => e.Frame);

                                Console.WriteLine(frameCount);

                                foreach (var k in keys)
                                {
                                    k.Frame = frameCount - k.Frame;
                                }

                                a.SetKeys(keys, a.TrackType);
                            }
                        }
                    }
                }
            };
            MenuItems.Add(reverse);
#endif
        }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="material"></param>
        /// <returns></returns>
        private static HSD_MOBJ GenerateMaterial(ProcessingCache cache, ModelImportSettings settings, Material material)
        {
            var Mobj = new HSD_MOBJ();

            Mobj.Material = new HSD_Material();
            Mobj.Material.AmbientColorRGBA  = 0x7F7F7FFF;
            Mobj.Material.DiffuseColorRGBA  = 0xFFFFFFFF;
            Mobj.Material.SpecularColorRGBA = 0xFFFFFFFF;
            Mobj.Material.Shininess         = 1;
            Mobj.Material.Alpha             = 1;
            Mobj.RenderFlags = RENDER_MODE.ALPHA_COMPAT | RENDER_MODE.DIFFSE_VTX;

            // Properties
            if (settings.ImportMaterialInfo)
            {
                if (material.HasShininess)
                {
                    Mobj.Material.Shininess = material.Shininess;
                }

                if (material.HasColorAmbient)
                {
                    Mobj.Material.AMB_A = ColorFloatToByte(material.ColorAmbient.A);
                    Mobj.Material.AMB_R = ColorFloatToByte(material.ColorAmbient.R);
                    Mobj.Material.AMB_G = ColorFloatToByte(material.ColorAmbient.G);
                    Mobj.Material.AMB_B = ColorFloatToByte(material.ColorAmbient.B);
                }
                if (material.HasColorDiffuse)
                {
                    Mobj.Material.DIF_A = ColorFloatToByte(material.ColorDiffuse.A);
                    Mobj.Material.DIF_R = ColorFloatToByte(material.ColorDiffuse.R);
                    Mobj.Material.DIF_G = ColorFloatToByte(material.ColorDiffuse.G);
                    Mobj.Material.DIF_B = ColorFloatToByte(material.ColorDiffuse.B);
                }
                if (material.HasColorSpecular)
                {
                    Mobj.Material.SPC_A = ColorFloatToByte(material.ColorSpecular.A);
                    Mobj.Material.SPC_R = ColorFloatToByte(material.ColorSpecular.R);
                    Mobj.Material.SPC_G = ColorFloatToByte(material.ColorSpecular.G);
                    Mobj.Material.SPC_B = ColorFloatToByte(material.ColorSpecular.B);
                }
            }

            // Textures
            if (settings.ImportTexture)
            {
                if (material.HasTextureDiffuse)
                {
                    var texturePath = Path.Combine(cache.FolderPath, material.TextureDiffuse.FilePath);

                    if (File.Exists(material.TextureDiffuse.FilePath))
                    {
                        texturePath = material.TextureDiffuse.FilePath;
                    }

                    /// special mobj loading
                    if (Path.GetExtension(texturePath).ToLower() == ".mobj")
                    {
                        var dat = new HSDRaw.HSDRawFile(texturePath);
                        Mobj._s = dat.Roots[0].Data._s;
                        return(Mobj);
                    }
                    else
                    if (File.Exists(texturePath))
                    {
                        Mobj.RenderFlags |= RENDER_MODE.TEX0;

                        var tobj = TOBJConverter.ImportTOBJFromFile(texturePath, settings.TextureFormat, settings.PaletteFormat);
                        tobj.Flags = TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COORD_UV;

                        if (settings.ShadingType == ShadingType.VertexColor || settings.ShadingType == ShadingType.Material)
                        {
                            tobj.Flags |= TOBJ_FLAGS.COLORMAP_MODULATE;
                        }
                        else
                        {
                            tobj.Flags |= TOBJ_FLAGS.COLORMAP_REPLACE;
                        }

                        tobj.GXTexGenSrc = 4;
                        tobj.TexMapID    = GXTexMapID.GX_TEXMAP0;

                        tobj.WrapS = ToGXWrapMode(material.TextureDiffuse.WrapModeU);
                        tobj.WrapT = ToGXWrapMode(material.TextureDiffuse.WrapModeV);

                        Mobj.Textures = tobj;
                    }
                }
            }

            return(Mobj);
        }