mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Add option to export images in "assetName@hash" name format
- Redesigned spriteHelper & texture2DConverter - Improved speed of texture2D preview a bit
This commit is contained in:
@@ -53,7 +53,7 @@ namespace AssetStudioGUI
|
||||
#endregion
|
||||
|
||||
#region SpriteControl
|
||||
private SpriteMaskMode spriteMaskVisibleMode = SpriteMaskMode.On;
|
||||
private SpriteMaskMode spriteMaskVisibleMode = SpriteMaskMode.Preview;
|
||||
#endregion
|
||||
|
||||
#region TexControl
|
||||
@@ -441,16 +441,16 @@ namespace AssetStudioGUI
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (lastSelectedItem?.Type == ClassIDType.Sprite && !((Sprite)lastSelectedItem.Asset).m_RD.alphaTexture.IsNull)
|
||||
else if (lastSelectedItem?.Type == ClassIDType.Sprite && new SpriteConverter((Sprite)lastSelectedItem.Asset).m_AlphaTexture2D != null)
|
||||
{
|
||||
switch (e.KeyCode)
|
||||
{
|
||||
case Keys.A:
|
||||
spriteMaskVisibleMode = spriteMaskVisibleMode == SpriteMaskMode.On ? SpriteMaskMode.Off : SpriteMaskMode.On;
|
||||
spriteMaskVisibleMode = spriteMaskVisibleMode == SpriteMaskMode.Preview ? SpriteMaskMode.Off : SpriteMaskMode.Preview;
|
||||
need = true;
|
||||
break;
|
||||
case Keys.M:
|
||||
spriteMaskVisibleMode = spriteMaskVisibleMode == SpriteMaskMode.MaskOnly ? SpriteMaskMode.On : SpriteMaskMode.MaskOnly;
|
||||
spriteMaskVisibleMode = spriteMaskVisibleMode == SpriteMaskMode.MaskOnly ? SpriteMaskMode.Preview : SpriteMaskMode.MaskOnly;
|
||||
need = true;
|
||||
break;
|
||||
}
|
||||
@@ -976,15 +976,14 @@ namespace AssetStudioGUI
|
||||
|
||||
private void PreviewTexture2D(AssetItem assetItem, Texture2D m_Texture2D)
|
||||
{
|
||||
if (!m_Texture2D.TryConvertToImage(true, out var image))
|
||||
var bitmap = new DirectBitmap(m_Texture2D, flip: true);
|
||||
if (bitmap.Bitmap == null)
|
||||
{
|
||||
StatusStripUpdate("Unsupported image for preview");
|
||||
bitmap.Dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
var bitmap = new DirectBitmap(image);
|
||||
image.Dispose();
|
||||
|
||||
assetItem.InfoText =
|
||||
$"Width: {m_Texture2D.m_Width}" +
|
||||
$"\nHeight: {m_Texture2D.m_Height}" +
|
||||
@@ -1488,15 +1487,15 @@ namespace AssetStudioGUI
|
||||
|
||||
private void PreviewSprite(AssetItem assetItem, Sprite m_Sprite)
|
||||
{
|
||||
var image = m_Sprite.GetImage(spriteMaskMode: spriteMaskVisibleMode);
|
||||
if (image != null)
|
||||
var converter = new SpriteConverter(m_Sprite);
|
||||
if (converter.TryConvertToImage(out var image, maskMode: spriteMaskVisibleMode))
|
||||
{
|
||||
var bitmap = new DirectBitmap(image);
|
||||
image.Dispose();
|
||||
assetItem.InfoText = $"Width: {bitmap.Width}\nHeight: {bitmap.Height}\n";
|
||||
PreviewTexture(bitmap);
|
||||
|
||||
if (!m_Sprite.m_RD.alphaTexture.IsNull)
|
||||
if (converter.m_AlphaTexture2D != null)
|
||||
{
|
||||
assetItem.InfoText += $"Alpha Mask: {spriteMaskVisibleMode}\n";
|
||||
StatusStripUpdate("'Ctrl'+'A' - Enable/Disable alpha mask usage. 'Ctrl'+'M' - Show alpha mask only.");
|
||||
@@ -1510,9 +1509,11 @@ namespace AssetStudioGUI
|
||||
|
||||
private void PreviewTexture(DirectBitmap bitmap)
|
||||
{
|
||||
previewPanel.Image.Dispose();
|
||||
imageTexture?.Dispose();
|
||||
imageTexture = bitmap;
|
||||
previewPanel.Image = imageTexture.Bitmap;
|
||||
|
||||
if (imageTexture.Width > previewPanel.Width || imageTexture.Height > previewPanel.Height)
|
||||
previewPanel.SizeMode = PictureBoxSizeMode.Zoom;
|
||||
else
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace AssetStudioGUI
|
||||
public ClassIDType Type;
|
||||
public string InfoText;
|
||||
public string UniqueID;
|
||||
public ulong Hash;
|
||||
public GameObjectTreeNode TreeNode;
|
||||
|
||||
public AssetItem(Object asset)
|
||||
@@ -24,6 +25,7 @@ namespace AssetStudioGUI
|
||||
TypeString = Type.ToString();
|
||||
m_PathID = asset.m_PathID;
|
||||
FullSize = asset.byteSize;
|
||||
Hash = 0;
|
||||
}
|
||||
|
||||
public void SetSubItems()
|
||||
|
||||
@@ -20,12 +20,28 @@ namespace AssetStudioGUI
|
||||
m_bitmap = new Bitmap(Width, Height, Stride, PixelFormat.Format32bppArgb, m_handle.AddrOfPinnedObject());
|
||||
}
|
||||
|
||||
public DirectBitmap(Texture2D texture2D, bool flip)
|
||||
{
|
||||
Width = texture2D.m_Width;
|
||||
Height = texture2D.m_Height;
|
||||
var converter = new Texture2DConverter(texture2D);
|
||||
Bits = BigArrayPool<byte>.Shared.Rent(converter.OutputDataSize);
|
||||
if (converter.GetBgra32RawImageData(Bits, flip))
|
||||
{
|
||||
m_handle = GCHandle.Alloc(Bits, GCHandleType.Pinned);
|
||||
m_bitmap = new Bitmap(Width, Height, Stride, PixelFormat.Format32bppArgb, m_handle.AddrOfPinnedObject());
|
||||
}
|
||||
}
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
m_bitmap.Dispose();
|
||||
m_handle.Free();
|
||||
if (m_bitmap != null)
|
||||
{
|
||||
m_bitmap.Dispose();
|
||||
m_handle.Free();
|
||||
}
|
||||
BigArrayPool<byte>.Shared.Return(Bits);
|
||||
}
|
||||
m_bitmap = null;
|
||||
|
||||
Generated
+4
-2
@@ -201,14 +201,16 @@
|
||||
// filenameFormatComboBox
|
||||
//
|
||||
this.filenameFormatComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.filenameFormatComboBox.DropDownWidth = 198;
|
||||
this.filenameFormatComboBox.FormattingEnabled = true;
|
||||
this.filenameFormatComboBox.Items.AddRange(new object[] {
|
||||
"asset name",
|
||||
"asset name@pathID",
|
||||
"pathID"});
|
||||
"pathID",
|
||||
"asset name@hash (images only)"});
|
||||
this.filenameFormatComboBox.Location = new System.Drawing.Point(210, 25);
|
||||
this.filenameFormatComboBox.Name = "filenameFormatComboBox";
|
||||
this.filenameFormatComboBox.Size = new System.Drawing.Size(139, 23);
|
||||
this.filenameFormatComboBox.Size = new System.Drawing.Size(149, 23);
|
||||
this.filenameFormatComboBox.TabIndex = 3;
|
||||
//
|
||||
// exportSpriteWithAlphaMask
|
||||
|
||||
@@ -18,7 +18,10 @@ namespace AssetStudioGUI
|
||||
if (Properties.Settings.Default.convertTexture)
|
||||
{
|
||||
var type = Properties.Settings.Default.convertType;
|
||||
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
|
||||
var converter = new Texture2DConverter(m_Texture2D);
|
||||
if (Properties.Settings.Default.filenameFormat == 3) //asset name@hash
|
||||
item.Hash = converter.GetTextureHash();
|
||||
if (!TryExportFile(exportPath, item, $".{type}", out var exportFullPath))
|
||||
return false;
|
||||
|
||||
if (GUILogger.ShowDebugMessage)
|
||||
@@ -44,9 +47,9 @@ namespace AssetStudioGUI
|
||||
debugLog += sb.ToString();
|
||||
}
|
||||
|
||||
if (!m_Texture2D.TryConvertToImage(flip: true, out var image))
|
||||
if (!converter.TryConvertToBgra32Image(flip: true, out var image))
|
||||
{
|
||||
Logger.Warning($"Failed to convert texture \"{m_Texture2D.m_Name}\" into image");
|
||||
Logger.Warning($"{debugLog}Failed to convert texture \"{m_Texture2D.m_Name}\" into image");
|
||||
return false;
|
||||
}
|
||||
using (image)
|
||||
@@ -73,11 +76,14 @@ namespace AssetStudioGUI
|
||||
{
|
||||
debugLog = "";
|
||||
var type = Properties.Settings.Default.convertType;
|
||||
var spriteMaskMode = Properties.Settings.Default.exportSpriteWithMask ? SpriteMaskMode.Export : SpriteMaskMode.Off;
|
||||
if (!TryExportFile(exportPath, item, "." + type.ToString().ToLower(), out var exportFullPath))
|
||||
var converter = new SpriteConverter((Sprite)item.Asset);
|
||||
if (Properties.Settings.Default.filenameFormat == 3) //asset name@hash
|
||||
item.Hash = converter.GetSpriteHash();
|
||||
if (!TryExportFile(exportPath, item, $".{type}", out var exportFullPath))
|
||||
return false;
|
||||
var image = ((Sprite)item.Asset).GetImage(spriteMaskMode: spriteMaskMode);
|
||||
if (image != null)
|
||||
|
||||
var spriteMaskMode = Properties.Settings.Default.exportSpriteWithMask ? SpriteMaskMode.On : SpriteMaskMode.Off;
|
||||
if (converter.TryConvertToImage(out var image, maskMode: spriteMaskMode))
|
||||
{
|
||||
using (image)
|
||||
{
|
||||
@@ -191,8 +197,12 @@ namespace AssetStudioGUI
|
||||
case 2: //pathID
|
||||
fileName = item.m_PathID.ToString();
|
||||
break;
|
||||
case 3 when item.Hash > 0: //asset name@hash
|
||||
fileName = $"{fileName} @{item.Hash:x}";
|
||||
break;
|
||||
}
|
||||
fullPath = Path.Combine(dir, fileName + extension);
|
||||
extension = extension.ToLower();
|
||||
fullPath = Path.Combine(dir, $"{fileName}{extension}");
|
||||
if (ExportPathDict.TryAdd(fullPath, true))
|
||||
{
|
||||
if (CanWrite(fullPath, dir, canOverwrite))
|
||||
@@ -200,9 +210,9 @@ namespace AssetStudioGUI
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (filenameFormatIndex == 0) //assetName
|
||||
else if (filenameFormatIndex == 0 || (filenameFormatIndex == 3 && item.Hash == 0)) //assetName, asset name@hash
|
||||
{
|
||||
fullPath = Path.Combine(dir, fileName + item.UniqueID + extension);
|
||||
fullPath = Path.Combine(dir, $"{fileName}{item.UniqueID}{extension}");
|
||||
if (CanWrite(fullPath, dir, canOverwrite))
|
||||
{
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user