private void ImportTexture(string inputFile, Material mat) { byte[] texdata = null; byte[] palette = null; TextureLoadedInfos info = (TextureLoadedInfos)mat.Tag; var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read); var img1 = Image.FromFile(inputFile); var img = new Bitmap(img1); img1.Dispose(); fs.Close(); // Resize image to fit current one if (mat.Image.Size != img.Size) { img = (Bitmap)SM64Lib.Model.Fast3D.TextureManager.ResizeImage(img, mat.Image.Size); } // Convert Image to N64 Texture SM64Lib.N64Graphics.N64Graphics.Convert(ref texdata, ref palette, info.TextureFormat, img); // Write Texture & Palete Data to ROM var rom = rommgr.GetBinaryRom(FileAccess.ReadWrite); rom.Position = info.TextureRomAddress; rom.Write(texdata); if (palette is object) { rom.Position = info.TexturePaletteRomAddress; rom.Write(palette); } rom.Close(); // Set new Image to Material mat.Image = img; // Set new Image to PictureBox var pb = SearchPictureBoxByMaterial(mat); if (pb is object) { pb.Image = img; } // Reload Texture Info ShowTextureInfos(); }
private void LoadTexturesFromCategorie(TextureBlock block) { var controls = new Control[FlowLayoutPanel_Textures.Controls.Count]; FlowLayoutPanel_Textures.Controls.CopyTo(controls, 0); FlowLayoutPanel_Textures.SuspendLayout(); foreach (Control c in controls) { if (c is PictureBox) { Highlighter1.SetHighlightColor(c, eHighlightColor.None); FlowLayoutPanel_Textures.Controls.Remove(c); } } foreach (Material mat in block.Textures) { TextureLoadedInfos info = mat.Tag as TextureLoadedInfos; var pb = new PictureBox() { Image = mat.Image, SizeMode = PictureBoxSizeMode.Zoom, Tag = mat, Size = new Size(70, 70) }; pb.Click += PictureBox_Clicked; pb.MouseEnter += PictureBox_MouseEnter; pb.MouseLeave += PictureBox_MouseLeave; pb.MouseClick += PictureBox_MouseClick; var lbl = new LabelX() { Text = info.Name, Size = new Size(70, 14), Location = new System.Drawing.Point(1, 55), TextAlignment = StringAlignment.Center }; pb.Controls.Add(lbl); lbl.Click += (sender, e) => PictureBox_Clicked(pb, e); lbl.MouseEnter += (sender, e) => PictureBox_MouseEnter(pb, e); lbl.MouseLeave += (sender, e) => PictureBox_MouseLeave(pb, e); lbl.MouseClick += (sender, e) => PictureBox_MouseClick(pb, e); FlowLayoutPanel_Textures.Controls.Add(pb); } FlowLayoutPanel_Textures.ResumeLayout(); }
private void ImportAllTextures(string inputDirecotry, string extensionFilter) { var files = Directory.GetFiles(inputDirecotry); foreach (var tex in CurBlock.Textures) { TextureLoadedInfos info = (TextureLoadedInfos)tex.Tag; string legalizedName = LegalizeFilePath(info.Name); string f = files.FirstOrDefault(n => (Path.GetFileNameWithoutExtension(n) ?? "") == (legalizedName ?? "")); if (!string.IsNullOrEmpty(f) && !info.IsReadOnly) { ImportTexture(f, tex); } TextureReplaced?.Invoke(this, new TextureReplacedEventArgs(CurBlock, CurTexture)); } }