private void importStripToolStripMenuItem1_Click(object sender, EventArgs e) { if (TEXG == null) { return; } var f = Tools.FileIO.OpenFile(ApplicationSettings.ImageFileFilter); if (f != null) { using (TextureImportDialog td = new TextureImportDialog()) { td.ShowCount = true; if (td.ShowDialog() == DialogResult.OK) { var bmp = new Bitmap(f); HSD_TOBJ[] images = new HSD_TOBJ[td.ImageCount]; for (int i = 0; i < td.ImageCount; i++) { images[i] = new HSD_TOBJ(); var image = bmp.Clone(new Rectangle(bmp.Width / td.ImageCount * i, 0, bmp.Width / td.ImageCount, bmp.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb); TOBJConverter.InjectBitmap(image, images[i], td.TextureFormat, td.PaletteFormat); image.Dispose(); } bmp.Dispose(); TEXG.SetFromTOBJs(images); Node = Node; } } } }
private void ReplaceTexture(object sender, EventArgs e) { var selected = GetSelectedObjects <STGenericTexture>(); if (selected.Count == 0) { return; } OpenDialogCustom ofd = new OpenDialogCustom(); string name = selected[0].Name; foreach (var file in FileManager.GetImportableTextures()) { if (file is IFileFormat) { ofd.AddFilter((IFileFormat)file); } } ofd.MultiSelect = true; var result = ofd.ShowDialog(); if (result == OpenDialogCustom.Result.OK) { TextureImportDialog importer = new TextureImportDialog(); importer.LoadTextures(ofd.GetFiles(), selected[0]); if (importer.ShowDialog() == System.Windows.Forms.DialogResult.OK) { } } }
/// <summary> /// Import TOBJ from PNG file /// </summary> /// <returns></returns> public static HSD_TOBJ ImportTOBJFromFile() { var TOBJ = new HSD_TOBJ() { MagFilter = GXTexFilter.GX_LINEAR, 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("PNG (.png)|*.png"); if (f != null) { using (TextureImportDialog settings = new TextureImportDialog()) { if (settings.ShowDialog() == DialogResult.OK) { InjectBitmap(TOBJ, f, settings.TextureFormat, settings.PaletteFormat); return(TOBJ); } } } return(null); }
/// <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); } }
/// <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); } } } }
private void importFramesToolStripMenuItem_Click(object sender, EventArgs e) { if (TexAnim == null) { return; } var files = Tools.FileIO.OpenFiles(ApplicationSettings.ImageFileFilter); if (files != null) { using (TextureImportDialog td = new TextureImportDialog()) { if (td.ShowDialog() == DialogResult.OK) { var matched = new HashSet <int>(); var tobjs = new List <HSD_TexBuffer>(); var pals = new List <HSD_TlutBuffer>(); foreach (var f in files) { int num = 0; int.TryParse(Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Name, out num); Console.WriteLine(num + " " + Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Groups[0].Value); if (!int.TryParse(Regex.Match(Path.GetFileName(f).ToLower(), @"(?<=.*_)(\d+?)(?=\.)").Groups[0].Value, out num) || matched.Contains(num)) { throw new InvalidDataException(num + " " + Path.GetFileName(f) + " is missing index tag or has duplicate index"); } else { HSD_TOBJ temp = new HSD_TOBJ(); TOBJConverter.InjectBitmap(f, temp, td.TextureFormat, td.PaletteFormat); HSD_TexBuffer buf = new HSD_TexBuffer(); buf.Data = temp.ImageData; tobjs.Add(buf); if (ImageDataFormat.IsPalettedFormat(td.TextureFormat)) { HSD_TlutBuffer palbuf = new HSD_TlutBuffer(); palbuf.Data = temp.TlutData; pals.Add(palbuf); } matched.Add(num); } } // convert tobjs into proper strip var ib = new HSDArrayAccessor <HSD_TexBuffer>(); ib.Array = tobjs.ToArray(); TexAnim.ImageBuffers = ib; if (ImageDataFormat.IsPalettedFormat(td.TextureFormat)) { var tb = new HSDRaw.HSDArrayAccessor <HSD_TlutBuffer>(); tb.Array = pals.ToArray(); TexAnim.TlutBuffers = tb; if (TexAnim?.AnimationObject?.FObjDesc?.List.Count < 2) { TexAnim.AnimationObject.FObjDesc.Next = new HSD_FOBJDesc(); TexAnim.AnimationObject.FObjDesc.Next.FromFOBJ(new HSD_FOBJ() { JointTrackType = JointTrackType.HSD_A_J_SCAX, Buffer = new byte[0] }); } } else { TexAnim.TlutBuffers = null; if (TexAnim?.AnimationObject?.FObjDesc?.List.Count > 1) { TexAnim.AnimationObject.FObjDesc.Next = null; } } Node = Node; } } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonAdd_Click(object sender, EventArgs e) { //if (textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) // return; //var index = textureList.SelectedIndices[0]; var tobjs = GetTOBJs(); HSD_TOBJ tobj; var f = Tools.FileIO.OpenFiles(ApplicationSettings.ImageFileFilter); if (f != null) { GXTexFmt texFormat = GXTexFmt.CMP; GXTlutFmt palFormat = GXTlutFmt.IA8; if (tobjs.Length == 0 || tobjs[0].ImageData == null) { using (TextureImportDialog settings = new TextureImportDialog()) { if (settings.ShowDialog() == DialogResult.OK) { texFormat = settings.TextureFormat; palFormat = settings.PaletteFormat; tobjs = new HSD_TOBJ[f.Length]; int ti = 0; foreach (var fi in f) { tobj = new HSD_TOBJ(); TOBJConverter.InjectBitmap(fi, tobj, texFormat, palFormat); tobjs[ti++] = tobj; } } else { return; } } } else { texFormat = tobjs[0].ImageData.Format; if (tobjs[0].TlutData != null) { palFormat = tobjs[0].TlutData.Format; } foreach (var fi in f) { tobj = new HSD_TOBJ(); TOBJConverter.InjectBitmap(fi, tobj, texFormat, palFormat); /*if (tobj.ImageData.Width != tobjs[0].ImageData.Width || tobj.ImageData.Height != tobjs[0].ImageData.Height) * { * MessageBox.Show($"Error the texture size does not match\n{tobj.ImageData.Width}x{tobj.ImageData.Height} -> {tobjs[0].ImageData.Width}x{tobjs[0].ImageData.Height}"); * return; * }*/ tobjs = InsertAt(tobjs, tobj, tobjs.Length); } } } else { return; } SetTOBJs(tobjs); ReloadTextures(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonReplace_Click(object sender, EventArgs e) { if ((textureList.SelectedIndices == null || textureList.SelectedIndices.Count == 0) && TOBJ == null) { return; } var index = 0; if (TOBJ == null) { index = textureList.SelectedIndices[0]; } var tobjs = GetTOBJs(); var f = Tools.FileIO.OpenFile("PNG (.png)|*.png"); if (f != null) { if (tobjs.Length == 1) { using (TextureImportDialog settings = new TextureImportDialog()) { if (settings.ShowDialog() == DialogResult.OK) { TOBJConverter.InjectBitmap(tobjs[index], f, settings.TextureFormat, settings.PaletteFormat); } else { return; } } } else { var beforeH = tobjs[index].ImageData.Height; var beforeW = tobjs[index].ImageData.Width; var bmp = new Bitmap(f); if (beforeW != bmp.Width || beforeH != bmp.Height) { MessageBox.Show($"Error the texture size does not match\n{beforeW}x{beforeH} -> {bmp.Width}x{bmp.Height}"); return; } bmp.Dispose(); TOBJConverter.InjectBitmap(tobjs[index], f, tobjs[index].ImageData.Format, tobjs[index].TlutData != null ? tobjs[index].TlutData.Format : GXTlutFmt.IA8); } } else { return; } SetTOBJs(tobjs); ReloadTextures(); }