mirror of
https://github.com/aelurum/AssetStudio.git
synced 2025-05-27 22:00:23 -04:00
[CLI] Add --filter-by-name support for fbx export mode
This commit is contained in:
parent
19c4835ea3
commit
c3f99216b6
@ -878,7 +878,15 @@ namespace AssetStudioCLI.Options
|
|||||||
sb.AppendLine($"# Log Level: {o_logLevel}");
|
sb.AppendLine($"# Log Level: {o_logLevel}");
|
||||||
sb.AppendLine($"# Log Output: {o_logOutput}");
|
sb.AppendLine($"# Log Output: {o_logOutput}");
|
||||||
sb.AppendLine($"# Export Asset List: {o_exportAssetList}");
|
sb.AppendLine($"# Export Asset List: {o_exportAssetList}");
|
||||||
|
if (o_workMode.Value == WorkMode.SplitObjects)
|
||||||
|
{
|
||||||
|
sb.AppendLine($"# Export Image Format: {o_imageFormat}");
|
||||||
|
sb.AppendLine($"# Filter by Name(s): \"{string.Join("\", \"", o_filterByName.Value)}\"");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sb.AppendLine($"# Assebmly Path: \"{o_assemblyPath}\"");
|
sb.AppendLine($"# Assebmly Path: \"{o_assemblyPath}\"");
|
||||||
|
}
|
||||||
sb.AppendLine($"# Unity Version: \"{o_unityVersion}\"");
|
sb.AppendLine($"# Unity Version: \"{o_unityVersion}\"");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -35,9 +35,9 @@ namespace AssetStudioCLI
|
|||||||
if (Studio.LoadAssets())
|
if (Studio.LoadAssets())
|
||||||
{
|
{
|
||||||
Studio.ParseAssets();
|
Studio.ParseAssets();
|
||||||
if (CLIOptions.filterBy != FilterBy.None && CLIOptions.o_workMode.Value != WorkMode.ExportLive2D)
|
if (CLIOptions.filterBy != FilterBy.None)
|
||||||
{
|
{
|
||||||
Studio.FilterAssets();
|
Studio.Filter();
|
||||||
}
|
}
|
||||||
if (CLIOptions.o_exportAssetList.Value != ExportListType.None)
|
if (CLIOptions.o_exportAssetList.Value != ExportListType.None)
|
||||||
{
|
{
|
||||||
|
@ -309,7 +309,20 @@ namespace AssetStudioCLI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void FilterAssets()
|
public static void Filter()
|
||||||
|
{
|
||||||
|
switch (CLIOptions.o_workMode.Value)
|
||||||
|
{
|
||||||
|
case WorkMode.ExportLive2D:
|
||||||
|
case WorkMode.SplitObjects:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
FilterAssets();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FilterAssets()
|
||||||
{
|
{
|
||||||
var assetsCount = parsedAssetsList.Count;
|
var assetsCount = parsedAssetsList.Count;
|
||||||
var filteredAssets = new List<AssetItem>();
|
var filteredAssets = new List<AssetItem>();
|
||||||
@ -317,14 +330,14 @@ namespace AssetStudioCLI
|
|||||||
switch(CLIOptions.filterBy)
|
switch(CLIOptions.filterBy)
|
||||||
{
|
{
|
||||||
case FilterBy.Name:
|
case FilterBy.Name:
|
||||||
filteredAssets = parsedAssetsList.FindAll(x => CLIOptions.o_filterByName.Value.Any(y => x.Text.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0));
|
filteredAssets = parsedAssetsList.FindAll(x => CLIOptions.o_filterByName.Value.Any(y => x.Text.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0));
|
||||||
Logger.Info(
|
Logger.Info(
|
||||||
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
||||||
$"that contain {$"\"{string.Join("\", \"", CLIOptions.o_filterByName.Value)}\"".Color(Ansi.BrightYellow)} in their Names."
|
$"that contain {$"\"{string.Join("\", \"", CLIOptions.o_filterByName.Value)}\"".Color(Ansi.BrightYellow)} in their Names."
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FilterBy.Container:
|
case FilterBy.Container:
|
||||||
filteredAssets = parsedAssetsList.FindAll(x => CLIOptions.o_filterByContainer.Value.Any(y => x.Container.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0));
|
filteredAssets = parsedAssetsList.FindAll(x => CLIOptions.o_filterByContainer.Value.Any(y => x.Container.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0));
|
||||||
Logger.Info(
|
Logger.Info(
|
||||||
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
||||||
$"that contain {$"\"{string.Join("\", \"", CLIOptions.o_filterByContainer.Value)}\"".Color(Ansi.BrightYellow)} in their Containers."
|
$"that contain {$"\"{string.Join("\", \"", CLIOptions.o_filterByContainer.Value)}\"".Color(Ansi.BrightYellow)} in their Containers."
|
||||||
@ -339,8 +352,8 @@ namespace AssetStudioCLI
|
|||||||
break;
|
break;
|
||||||
case FilterBy.NameOrContainer:
|
case FilterBy.NameOrContainer:
|
||||||
filteredAssets = parsedAssetsList.FindAll(x =>
|
filteredAssets = parsedAssetsList.FindAll(x =>
|
||||||
CLIOptions.o_filterByText.Value.Any(y => x.Text.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0) ||
|
CLIOptions.o_filterByText.Value.Any(y => x.Text.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0) ||
|
||||||
CLIOptions.o_filterByText.Value.Any(y => x.Container.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0)
|
CLIOptions.o_filterByText.Value.Any(y => x.Container.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||||
);
|
);
|
||||||
Logger.Info(
|
Logger.Info(
|
||||||
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
||||||
@ -349,8 +362,8 @@ namespace AssetStudioCLI
|
|||||||
break;
|
break;
|
||||||
case FilterBy.NameAndContainer:
|
case FilterBy.NameAndContainer:
|
||||||
filteredAssets = parsedAssetsList.FindAll(x =>
|
filteredAssets = parsedAssetsList.FindAll(x =>
|
||||||
CLIOptions.o_filterByName.Value.Any(y => x.Text.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0) &&
|
CLIOptions.o_filterByName.Value.Any(y => x.Text.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0) &&
|
||||||
CLIOptions.o_filterByContainer.Value.Any(y => x.Container.ToString().IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0)
|
CLIOptions.o_filterByContainer.Value.Any(y => x.Container.IndexOf(y, StringComparison.OrdinalIgnoreCase) >= 0)
|
||||||
);
|
);
|
||||||
Logger.Info(
|
Logger.Info(
|
||||||
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
$"Found [{filteredAssets.Count}/{assetsCount}] asset(s) " +
|
||||||
@ -497,14 +510,25 @@ namespace AssetStudioCLI
|
|||||||
public static void ExportSplitObjects()
|
public static void ExportSplitObjects()
|
||||||
{
|
{
|
||||||
var savePath = CLIOptions.o_outputFolder.Value;
|
var savePath = CLIOptions.o_outputFolder.Value;
|
||||||
var count = gameObjectTree.Sum(x => x.nodes.Count);
|
var searchList = CLIOptions.o_filterByName.Value;
|
||||||
|
var isFiltered = CLIOptions.filterBy == FilterBy.Name;
|
||||||
|
|
||||||
|
var exportableObjects = new List<GameObjectNode>();
|
||||||
var exportedCount = 0;
|
var exportedCount = 0;
|
||||||
int k = 0;
|
var k = 0;
|
||||||
|
|
||||||
|
Logger.Info($"Searching for objects to export..");
|
||||||
Progress.Reset();
|
Progress.Reset();
|
||||||
|
var count = gameObjectTree.Sum(x => x.nodes.Count);
|
||||||
foreach (var node in gameObjectTree)
|
foreach (var node in gameObjectTree)
|
||||||
{
|
{
|
||||||
foreach (GameObjectNode j in node.nodes)
|
foreach (GameObjectNode j in node.nodes)
|
||||||
{
|
{
|
||||||
|
if (isFiltered)
|
||||||
|
{
|
||||||
|
if (!searchList.Any(searchText => j.gameObject.m_Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) >= 0))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
var gameObjects = new List<GameObject>();
|
var gameObjects = new List<GameObject>();
|
||||||
CollectNode(j, gameObjects);
|
CollectNode(j, gameObjects);
|
||||||
|
|
||||||
@ -513,8 +537,26 @@ namespace AssetStudioCLI
|
|||||||
Progress.Report(++k, count);
|
Progress.Report(++k, count);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
exportableObjects.Add(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gameObjectTree.Clear();
|
||||||
|
var exportableCount = exportableObjects.Count;
|
||||||
|
var log = $"Found {exportableCount} exportable object(s) ";
|
||||||
|
if (isFiltered)
|
||||||
|
{
|
||||||
|
log += $"that contain {$"\"{string.Join("\", \"", CLIOptions.o_filterByName.Value)}\"".Color(Ansi.BrightYellow)} in their Names";
|
||||||
|
}
|
||||||
|
Logger.Info(log);
|
||||||
|
if (exportableCount > 0)
|
||||||
|
{
|
||||||
|
Progress.Reset();
|
||||||
|
k = 0;
|
||||||
|
|
||||||
var filename = FixFileName(j.gameObject.m_Name);
|
foreach (var gameObjectNode in exportableObjects)
|
||||||
|
{
|
||||||
|
var gameObject = gameObjectNode.gameObject;
|
||||||
|
var filename = FixFileName(gameObject.m_Name);
|
||||||
var targetPath = $"{savePath}{filename}{Path.DirectorySeparatorChar}";
|
var targetPath = $"{savePath}{filename}{Path.DirectorySeparatorChar}";
|
||||||
//重名文件处理
|
//重名文件处理
|
||||||
for (int i = 1; ; i++)
|
for (int i = 1; ; i++)
|
||||||
@ -531,23 +573,23 @@ namespace AssetStudioCLI
|
|||||||
Directory.CreateDirectory(targetPath);
|
Directory.CreateDirectory(targetPath);
|
||||||
//导出FBX
|
//导出FBX
|
||||||
Logger.Info($"Exporting {filename}.fbx");
|
Logger.Info($"Exporting {filename}.fbx");
|
||||||
|
Progress.Report(k, exportableCount);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ExportGameObject(j.gameObject, targetPath);
|
ExportGameObject(gameObject, targetPath);
|
||||||
Logger.Debug($"{j.gameObject.type} \"{filename}\" saved to \"{targetPath}\"");
|
Logger.Debug($"{gameObject.type} \"{filename}\" saved to \"{targetPath}\"");
|
||||||
exportedCount++;
|
exportedCount++;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Error($"Export GameObject:{j.gameObject.m_Name} error", ex);
|
Logger.Error($"Export GameObject:{gameObject.m_Name} error", ex);
|
||||||
}
|
}
|
||||||
|
k++;
|
||||||
Progress.Report(++k, count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var status = exportedCount > 0
|
var status = exportedCount > 0
|
||||||
? $"Finished exporting [{exportedCount}/{gameObjectTree.Count}] object(s) to \"{CLIOptions.o_outputFolder.Value.Color(Ansi.BrightCyan)}\""
|
? $"Finished exporting [{exportedCount}/{exportableCount}] object(s) to \"{CLIOptions.o_outputFolder.Value.Color(Ansi.BrightCyan)}\""
|
||||||
: "Nothing exported.";
|
: "Nothing exported";
|
||||||
Logger.Default.Log(LoggerEvent.Info, status, ignoreLevel: true);
|
Logger.Default.Log(LoggerEvent.Info, status, ignoreLevel: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user