Exemplo n.º 1
0
        /// <summary>
        /// Import TOBJ from PNG file
        /// </summary>
        /// <returns></returns>
        public static HSD_TOBJ ImportTOBJFromFile()
        {
            try
            {
                var TOBJ = new HSD_TOBJ()
                {
                    MagFilter   = GXTexFilter.GX_LINEAR,
                    Flags       = TOBJ_FLAGS.COORD_UV | TOBJ_FLAGS.LIGHTMAP_DIFFUSE | TOBJ_FLAGS.COLORMAP_MODULATE | TOBJ_FLAGS.ALPHAMAP_MODULATE,
                    HScale      = 1,
                    WScale      = 1,
                    WrapS       = GXWrapMode.CLAMP,
                    WrapT       = GXWrapMode.CLAMP,
                    SX          = 1,
                    SY          = 1,
                    SZ          = 1,
                    GXTexGenSrc = 4,
                    Blending    = 1
                };

                var f = Tools.FileIO.OpenFile(ApplicationSettings.ImageFileFilter);
                if (f != null)
                {
                    using (TextureImportDialog settings = new TextureImportDialog())
                    {
                        if (FormatFromString(f, out GXTexFmt fmt, out GXTlutFmt pal))
                        {
                            settings.PaletteFormat = pal;
                            settings.TextureFormat = fmt;
                        }

                        if (settings.ShowDialog() == DialogResult.OK)
                        {
                            using (Bitmap bmp = new Bitmap(f))
                            {
                                settings.ApplySettings(bmp);
                                InjectBitmap(bmp, TOBJ, settings.TextureFormat, settings.PaletteFormat);
                                return(TOBJ);
                            }
                        }
                    }
                }

                return(null);
            } catch (Exception e)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Injects <see cref="Bitmap"/> into <see cref="HSD_TOBJ"/>
        /// </summary>
        /// <param name="tobj"></param>
        /// <param name="img"></param>
        /// <param name="imgFormat"></param>
        /// <param name="palFormat"></param>
        public static void InjectBitmap(string filepath, HSD_TOBJ tobj)
        {
            using (Bitmap bmp = LoadBitmapFromFile(filepath))
            {
                using (TextureImportDialog settings = new TextureImportDialog())
                {
                    if (FormatFromString(filepath, out GXTexFmt fmt, out GXTlutFmt pal))
                    {
                        settings.PaletteFormat = pal;
                        settings.TextureFormat = fmt;
                    }

                    if (settings.ShowDialog() == DialogResult.OK)
                    {
                        settings.ApplySettings(bmp);

                        InjectBitmap(bmp, tobj, settings.TextureFormat, settings.PaletteFormat);
                    }
                }
            }
        }