Add option to dump material assets during model export

This commit is contained in:
VaDiM
2026-06-03 03:01:42 +03:00
parent 4154ce0b82
commit 02a288894d
8 changed files with 114 additions and 34 deletions
+18 -1
View File
@@ -281,7 +281,7 @@ namespace AssetStudioCLI
return true;
}
private static void ExportFbx(IImported convert, string exportPath)
private static void ExportFbx(ModelConverter convert, string exportPath)
{
var fbxSettings = new Fbx.Settings
{
@@ -289,8 +289,25 @@ namespace AssetStudioCLI
ScaleFactor = CLIOptions.o_fbxScaleFactor.Value,
ExportAllUvsAsDiffuseMaps = CLIOptions.f_fbxUvsAsDiffuseMaps.Value,
ExportAnimations = CLIOptions.o_fbxAnimMode.Value != AnimationExportMode.Skip,
DumpMaterials = CLIOptions.f_fbxDumpMaterials.Value,
};
ModelExporter.ExportFbx(exportPath, convert, fbxSettings);
if (!fbxSettings.DumpMaterials || convert.MaterialAssetSet.Count == 0 || !File.Exists(exportPath))
return;
var exportDir = Path.Combine(Path.GetDirectoryName(exportPath), "Materials");
Directory.CreateDirectory(exportDir);
foreach (var mat in convert.MaterialAssetSet)
{
var jsonDoc = mat.ToJsonDoc();
var str = System.Text.Json.JsonSerializer.Serialize(jsonDoc, Object.JsonOptions);
var exportFullPath = Path.Combine(exportDir, $"{mat.m_Name}.json");
if (File.Exists(exportFullPath))
{
exportFullPath = Path.Combine(exportDir, $"{mat.m_Name} #{mat.GetHashCode():x}.json");
}
File.WriteAllText(exportFullPath, str);
}
}
public static bool ExportRawFile(AssetItem item, string exportPath)