mirror of
https://github.com/aelurum/AssetStudio.git
synced 2026-11-15 19:28:48 -05:00
Add option to dump material assets during model export
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -120,6 +120,7 @@ namespace AssetStudioCLI.Options
|
||||
public static Option<float> o_fbxScaleFactor;
|
||||
public static Option<int> o_fbxBoneSize;
|
||||
public static Option<AnimationExportMode> o_fbxAnimMode;
|
||||
public static Option<bool> f_fbxDumpMaterials;
|
||||
public static Option<bool> f_fbxUvsAsDiffuseMaps;
|
||||
//filter
|
||||
public static Option<List<string>> o_filterByName;
|
||||
@@ -417,6 +418,14 @@ namespace AssetStudioCLI.Options
|
||||
optionExample: "Example: \"--fbx-animation skip\"\n",
|
||||
optionHelpGroup: HelpGroups.FBX
|
||||
);
|
||||
f_fbxDumpMaterials = new GroupedOption<bool>
|
||||
(
|
||||
optionDefaultValue: false,
|
||||
optionName: "--fbx-dump-materials",
|
||||
optionDescription: "(Flag) If specified, Studio will dump model-related Material assets along with a model\n",
|
||||
optionExample: "",
|
||||
optionHelpGroup: HelpGroups.FBX
|
||||
);
|
||||
f_fbxUvsAsDiffuseMaps = new GroupedOption<bool>
|
||||
(
|
||||
optionDefaultValue: false,
|
||||
@@ -781,6 +790,17 @@ namespace AssetStudioCLI.Options
|
||||
f_l2dForceBezier.Value = true;
|
||||
flagIndexes.Add(i);
|
||||
break;
|
||||
case "--fbx-dump-mats":
|
||||
case "--fbx-dump-materials":
|
||||
if (o_workMode.Value != WorkMode.SplitObjects)
|
||||
{
|
||||
Console.WriteLine($"{"Error".Color(brightRed)} during parsing [{flag.Color(brightYellow)}] flag. This flag is not suitable for the current working mode [{o_workMode.Value}].\n");
|
||||
ShowOptionDescription(o_workMode);
|
||||
return;
|
||||
}
|
||||
f_fbxDumpMaterials.Value = true;
|
||||
flagIndexes.Add(i);
|
||||
break;
|
||||
case "--fbx-uvs-as-diffuse":
|
||||
if (o_workMode.Value != WorkMode.SplitObjects)
|
||||
{
|
||||
@@ -1601,6 +1621,7 @@ namespace AssetStudioCLI.Options
|
||||
sb.AppendLine($"# FBX Scale Factor: {o_fbxScaleFactor}");
|
||||
sb.AppendLine($"# FBX Bone Size: {o_fbxBoneSize}");
|
||||
sb.AppendLine($"# FBX Animation Mode: {o_fbxAnimMode}");
|
||||
sb.AppendLine($"# FBX Dump Materials: {f_fbxDumpMaterials}");
|
||||
sb.AppendLine($"# FBX UVs as Diffuse Maps: {f_fbxUvsAsDiffuseMaps}");
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user