From 5c4c0eeebc504abae10d9cf4620f93637f0e5f93 Mon Sep 17 00:00:00 2001 From: MayNL Date: Thu, 7 May 2026 00:47:40 -0400 Subject: [PATCH] Simplified Generate MipMap tool -Now generates just one level via the user given value --- PCK-Studio/Controls/Editor/PckEditor.cs | 57 ++++++++++++------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/PCK-Studio/Controls/Editor/PckEditor.cs b/PCK-Studio/Controls/Editor/PckEditor.cs index 51a90ea9..936f5782 100644 --- a/PCK-Studio/Controls/Editor/PckEditor.cs +++ b/PCK-Studio/Controls/Editor/PckEditor.cs @@ -1698,41 +1698,40 @@ namespace PckStudio.Controls string textureExtension = Path.GetExtension(asset.Filename); using NumericPrompt numericPrompt = new NumericPrompt(0); - numericPrompt.Minimum = 1; - numericPrompt.Maximum = 4; // 5 is the presumed max MipMap level - numericPrompt.ToolTipText = "You can enter the amount of MipMap levels that you would like to generate. " + - "For example: if you enter 2, MipMapLevel1.png and MipMapLevel2.png will be generated"; - numericPrompt.TextLabel.Text = "Levels"; + numericPrompt.Minimum = 2; + numericPrompt.Maximum = 5; // 5 is the presumed max MipMap level + numericPrompt.TextLabel.Text = "Level"; if (numericPrompt.ShowDialog(this) == DialogResult.OK) { - for (int i = 2; i < 2 + numericPrompt.SelectedValueAsInt; i++) + int level = numericPrompt.SelectedValueAsInt; + + string mippedPath = $"{textureDirectory}/{textureName}MipMapLevel{level}{textureExtension}"; + Debug.WriteLine(mippedPath); + if (EditorValue.File.HasAsset(mippedPath, PckAssetType.TextureFile)) + EditorValue.File.RemoveAsset(EditorValue.File.GetAsset(mippedPath, PckAssetType.TextureFile)); + PckAsset mipMappedAsset = new PckAsset(mippedPath, PckAssetType.TextureFile); + + Image originalTexture = asset.GetTexture(); + int newWidth = Math.Max(originalTexture.Width / (int)Math.Pow(2, level - 1), 1); + int newHeight = Math.Max(originalTexture.Height / (int)Math.Pow(2, level - 1), 1); + + Rectangle tileArea = new Rectangle(0, 0, newWidth, newHeight); + Image mippedTexture = new Bitmap(newWidth, newHeight); + using (Graphics gfx = Graphics.FromImage(mippedTexture)) { - string mippedPath = $"{textureDirectory}/{textureName}MipMapLevel{i}{textureExtension}"; - Debug.WriteLine(mippedPath); - if (EditorValue.File.HasAsset(mippedPath, PckAssetType.TextureFile)) - EditorValue.File.RemoveAsset(EditorValue.File.GetAsset(mippedPath, PckAssetType.TextureFile)); - PckAsset mipMappedAsset = new PckAsset(mippedPath, PckAssetType.TextureFile); - - Image originalTexture = asset.GetTexture(); - int newWidth = Math.Max(originalTexture.Width / (int)Math.Pow(2, i - 1), 1); - int newHeight = Math.Max(originalTexture.Height / (int)Math.Pow(2, i - 1), 1); - - Rectangle tileArea = new Rectangle(0, 0, newWidth, newHeight); - Image mippedTexture = new Bitmap(newWidth, newHeight); - using (Graphics gfx = Graphics.FromImage(mippedTexture)) - { - gfx.SmoothingMode = SmoothingMode.None; - gfx.InterpolationMode = InterpolationMode.NearestNeighbor; - gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; - gfx.DrawImage(originalTexture, tileArea); - } - - mipMappedAsset.SetTexture(mippedTexture); - - EditorValue.File.InsertAsset(EditorValue.File.IndexOfAsset(asset) + i - 1, mipMappedAsset); + gfx.SmoothingMode = SmoothingMode.AntiAlias; + gfx.InterpolationMode = InterpolationMode.NearestNeighbor; + gfx.PixelOffsetMode = PixelOffsetMode.HighQuality; + gfx.DrawImage(originalTexture, tileArea); } + + mipMappedAsset.SetTexture(mippedTexture); + + EditorValue.File.InsertAsset(EditorValue.File.IndexOfAsset(asset) + 1, mipMappedAsset); + BuildMainTreeView(); + _wasModified = true; } } }