Some refactor

This commit is contained in:
VaDiM
2026-09-10 02:03:15 +03:00
parent da0b6fc918
commit dd83e43673
9 changed files with 50 additions and 54 deletions
+3 -3
View File
@@ -1188,7 +1188,7 @@ namespace AssetStudioCLI
} }
var baseDestPath = Path.Combine(CLIOptions.o_outputFolder.Value, "Live2DOutput"); var baseDestPath = Path.Combine(CLIOptions.o_outputFolder.Value, "Live2DOutput");
var modelGroupOption = CLIOptions.o_l2dGroupOption.Value; var modelGroupOption = CLIOptions.o_l2dGroupOption.Value;
var l2dOptions = new Live2DOptions() var extractorOptions = new Live2DExtractorOptions()
{ {
MotionMode = CLIOptions.o_l2dMotionMode.Value, MotionMode = CLIOptions.o_l2dMotionMode.Value,
ForceBezier = CLIOptions.f_l2dForceBezier.Value, ForceBezier = CLIOptions.f_l2dForceBezier.Value,
@@ -1218,7 +1218,7 @@ namespace AssetStudioCLI
Logger.Info($"[{modelCounter + 1}/{totalModelCount}] Exporting Live2D from: \"{srcContainer.Color(Ansi.BrightCyan)}\"..."); Logger.Info($"[{modelCounter + 1}/{totalModelCount}] Exporting Live2D from: \"{srcContainer.Color(Ansi.BrightCyan)}\"...");
try try
{ {
var cubismExtractor = new Live2DExtractor(assetGroupKvp.Value, cubismModel, l2dOptions); var cubismExtractor = new Live2DExtractor(assetGroupKvp.Value, cubismModel, extractorOptions);
var fileName = string.IsNullOrEmpty(mocMono.assetsFile.originalPath) var fileName = string.IsNullOrEmpty(mocMono.assetsFile.originalPath)
? Path.GetFileNameWithoutExtension(mocMono.assetsFile.fileName) ? Path.GetFileNameWithoutExtension(mocMono.assetsFile.fileName)
: Path.GetFileNameWithoutExtension(mocMono.assetsFile.originalPath); : Path.GetFileNameWithoutExtension(mocMono.assetsFile.originalPath);
@@ -1237,7 +1237,7 @@ namespace AssetStudioCLI
modelPath = modelName; modelPath = modelName;
break; break;
default: //ContainerPath default: //ContainerPath
var container = l2dOptions.SearchByFilename && cubismModel != null var container = extractorOptions.SearchByFilename && cubismModel != null
? cubismModel.Container ? cubismModel.Container
: srcContainer; : srcContainer;
container = container == mocMono.assetsFile.fullName container = container == mocMono.assetsFile.fullName
+1 -16
View File
@@ -158,7 +158,6 @@ namespace AssetStudioGUI
assetsManager.Options.CustomCachePath = GetCachePath(); assetsManager.Options.CustomCachePath = GetCachePath();
assetsManager.Options.MeshPreProcessing = Properties.Settings.Default.meshPreProcessing; assetsManager.Options.MeshPreProcessing = Properties.Settings.Default.meshPreProcessing;
assetsManager.Options.GameSpecific.UnityVersionChanged += OnUnityVersionChanged; assetsManager.Options.GameSpecific.UnityVersionChanged += OnUnityVersionChanged;
FbxInitOrLoadOptions(Properties.Settings.Default.fbxSettings);
FMODinit(); FMODinit();
listSearchFilterMode.SelectedIndex = 0; listSearchFilterMode.SelectedIndex = 0;
@@ -584,7 +583,7 @@ namespace AssetStudioGUI
private void showExpOpt_Click(object sender, EventArgs e) private void showExpOpt_Click(object sender, EventArgs e)
{ {
var exportOpt = new ExportOptions(); var exportOpt = new ExportOptionsForm();
exportOpt.ShowDialog(this); exportOpt.ShowDialog(this);
} }
@@ -2741,20 +2740,6 @@ namespace AssetStudioGUI
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
private static void FbxInitOrLoadOptions(string base64String)
{
if (string.IsNullOrEmpty(base64String))
{
Studio.FbxSettings = new Fbx.Settings();
Properties.Settings.Default.fbxSettings = Studio.FbxSettings.ToBase64();
Properties.Settings.Default.Save();
}
else
{
Studio.FbxSettings = Fbx.Settings.FromBase64(base64String);
}
}
private void moreGameOptionsToolStripMenuItem_Click(object sender, EventArgs e) private void moreGameOptionsToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (gameOptionsForm == null || gameOptionsForm.IsDisposed) if (gameOptionsForm == null || gameOptionsForm.IsDisposed)
@@ -1,6 +1,6 @@
namespace AssetStudioGUI namespace AssetStudioGUI
{ {
partial class ExportOptions partial class ExportOptionsForm
{ {
/// <summary> /// <summary>
/// Required designer variable. /// Required designer variable.
@@ -907,7 +907,7 @@
this.Cancel.UseVisualStyleBackColor = false; this.Cancel.UseVisualStyleBackColor = false;
this.Cancel.Click += new System.EventHandler(this.Cancel_Click); this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
// //
// ExportOptions // ExportOptionsForm
// //
this.AcceptButton = this.OKbutton; this.AcceptButton = this.OKbutton;
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -924,7 +924,7 @@
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MinimizeBox = false; this.MinimizeBox = false;
this.Name = "ExportOptions"; this.Name = "ExportOptionsForm";
this.ShowIcon = false; this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Export options"; this.Text = "Export options";
@@ -6,11 +6,11 @@ using System.Windows.Forms;
namespace AssetStudioGUI namespace AssetStudioGUI
{ {
public partial class ExportOptions : Form public partial class ExportOptionsForm : Form
{ {
private static Dictionary<int, int> uvBindings; private static Dictionary<int, int> uvBindings;
public ExportOptions() public ExportOptionsForm()
{ {
InitializeComponent(); InitializeComponent();
assetGroupOptions.SelectedIndex = Properties.Settings.Default.assetGroupOption; assetGroupOptions.SelectedIndex = Properties.Settings.Default.assetGroupOption;
@@ -38,7 +38,7 @@ namespace AssetStudioGUI
((RadioButton)l2dMotionExportMethodPanel.Controls.Cast<Control>().First(x => x.AccessibleName == defaultMotionMode)).Checked = true; ((RadioButton)l2dMotionExportMethodPanel.Controls.Cast<Control>().First(x => x.AccessibleName == defaultMotionMode)).Checked = true;
l2dForceBezierCheckBox.Checked = Properties.Settings.Default.l2dForceBezier; l2dForceBezierCheckBox.Checked = Properties.Settings.Default.l2dForceBezier;
SetFromFbxSettings(Studio.FbxSettings); SetFromFbxSettings(Exporter.FbxSettings);
} }
private void OKbutton_Click(object sender, EventArgs e) private void OKbutton_Click(object sender, EventArgs e)
@@ -64,19 +64,19 @@ namespace AssetStudioGUI
Properties.Settings.Default.l2dMotionMode = (CubismLive2DExtractor.Live2DMotionMode)Enum.Parse(typeof(CubismLive2DExtractor.Live2DMotionMode), checkedMotionMode.AccessibleName); Properties.Settings.Default.l2dMotionMode = (CubismLive2DExtractor.Live2DMotionMode)Enum.Parse(typeof(CubismLive2DExtractor.Live2DMotionMode), checkedMotionMode.AccessibleName);
Properties.Settings.Default.l2dForceBezier = l2dForceBezierCheckBox.Checked; Properties.Settings.Default.l2dForceBezier = l2dForceBezierCheckBox.Checked;
Studio.FbxSettings.EulerFilter = eulerFilter.Checked; Exporter.FbxSettings.EulerFilter = eulerFilter.Checked;
Studio.FbxSettings.FilterPrecision = (float)filterPrecision.Value; Exporter.FbxSettings.FilterPrecision = (float)filterPrecision.Value;
Studio.FbxSettings.ExportAllNodes = exportAllNodes.Checked; Exporter.FbxSettings.ExportAllNodes = exportAllNodes.Checked;
Studio.FbxSettings.ExportSkins = exportSkins.Checked; Exporter.FbxSettings.ExportSkins = exportSkins.Checked;
Studio.FbxSettings.ExportAnimations = exportAnimations.Checked; Exporter.FbxSettings.ExportAnimations = exportAnimations.Checked;
Studio.FbxSettings.ExportBlendShape = exportBlendShape.Checked; Exporter.FbxSettings.ExportBlendShape = exportBlendShape.Checked;
Studio.FbxSettings.DumpMaterials = dumpMaterialsCheckBox.Checked; Exporter.FbxSettings.DumpMaterials = dumpMaterialsCheckBox.Checked;
Studio.FbxSettings.CastToBone = castToBone.Checked; Exporter.FbxSettings.CastToBone = castToBone.Checked;
Studio.FbxSettings.ExportAllUvsAsDiffuseMaps = exportAllUvsAsDiffuseMaps.Checked; Exporter.FbxSettings.ExportAllUvsAsDiffuseMaps = exportAllUvsAsDiffuseMaps.Checked;
Studio.FbxSettings.BoneSize = (int)boneSize.Value; Exporter.FbxSettings.BoneSize = (int)boneSize.Value;
Studio.FbxSettings.ScaleFactor = (float)scaleFactor.Value; Exporter.FbxSettings.ScaleFactor = (float)scaleFactor.Value;
Studio.FbxSettings.FbxVersionIndex = fbxVersion.SelectedIndex; Exporter.FbxSettings.FbxVersionIndex = fbxVersion.SelectedIndex;
Studio.FbxSettings.FbxFormat = fbxFormat.SelectedIndex; Exporter.FbxSettings.FbxFormat = fbxFormat.SelectedIndex;
for (var i = 0; i < uvIndicesCheckedListBox.Items.Count; i++) for (var i = 0; i < uvIndicesCheckedListBox.Items.Count; i++)
{ {
var isChecked = uvIndicesCheckedListBox.GetItemChecked(i); var isChecked = uvIndicesCheckedListBox.GetItemChecked(i);
@@ -84,8 +84,8 @@ namespace AssetStudioGUI
if ((isChecked && type < 0) || (!isChecked && type > 0)) if ((isChecked && type < 0) || (!isChecked && type > 0))
uvBindings[i] *= -1; uvBindings[i] *= -1;
} }
Studio.FbxSettings.UvBindings = uvBindings; Exporter.FbxSettings.UvBindings = uvBindings;
Properties.Settings.Default.fbxSettings = Studio.FbxSettings.ToBase64(); Properties.Settings.Default.fbxSettings = Exporter.FbxSettings.ToBase64();
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
+17 -5
View File
@@ -9,12 +9,24 @@ namespace AssetStudioGUI
{ {
internal static class Exporter internal static class Exporter
{ {
internal static readonly Fbx.Settings FbxSettings;
private static readonly HashSet<string> ExportPathHashSet = new HashSet<string>(System.StringComparer.OrdinalIgnoreCase); private static readonly HashSet<string> ExportPathHashSet = new HashSet<string>(System.StringComparer.OrdinalIgnoreCase);
private static readonly HashSet<char> InvalidChars = new HashSet<char>(Path.GetInvalidFileNameChars()); private static readonly HashSet<char> InvalidChars = new HashSet<char>(Path.GetInvalidFileNameChars());
static Exporter() static Exporter()
{ {
InvalidChars.UnionWith(new[] { '"', '<', '>', '|', ':', '*', '?', '\\', '/' }); InvalidChars.UnionWith(new[] { '"', '<', '>', '|', ':', '*', '?', '\\', '/' });
if (string.IsNullOrEmpty(Properties.Settings.Default.fbxSettings))
{
FbxSettings = new Fbx.Settings();
Properties.Settings.Default.fbxSettings = FbxSettings.ToBase64();
Properties.Settings.Default.Save();
}
else
{
FbxSettings = Fbx.Settings.FromBase64(Properties.Settings.Default.fbxSettings);
}
} }
private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath, string mode = "Export") private static bool TryExportFile(string dir, AssetItem item, string extension, out string fullPath, string mode = "Export")
@@ -245,7 +257,7 @@ namespace AssetStudioGUI
{ {
exportFullPath = SafeFilePath(exportPath, item.Text + item.UniqueID, item.Text + ".fbx"); exportFullPath = SafeFilePath(exportPath, item.Text + item.UniqueID, item.Text + ".fbx");
} }
if (!Studio.FbxSettings.ExportAnimations) if (!FbxSettings.ExportAnimations)
animationList = new List<AssetItem>(); animationList = new List<AssetItem>();
var m_Animator = (Animator)item.Asset; var m_Animator = (Animator)item.Asset;
var convert = animationList != null var convert = animationList != null
@@ -257,8 +269,8 @@ namespace AssetStudioGUI
private static void ExportFbx(ModelConverter convert, string exportPath) private static void ExportFbx(ModelConverter convert, string exportPath)
{ {
ModelExporter.ExportFbx(exportPath, convert, Studio.FbxSettings); ModelExporter.ExportFbx(exportPath, convert, FbxSettings);
if (!Studio.FbxSettings.DumpMaterials || convert.MaterialAssetSet.Count == 0 || !File.Exists(exportPath)) if (!FbxSettings.DumpMaterials || convert.MaterialAssetSet.Count == 0 || !File.Exists(exportPath))
return; return;
var exportDir = Path.Combine(Path.GetDirectoryName(exportPath), "Materials"); var exportDir = Path.Combine(Path.GetDirectoryName(exportPath), "Materials");
@@ -399,7 +411,7 @@ namespace AssetStudioGUI
public static void ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null) public static void ExportGameObject(GameObject gameObject, string exportPath, List<AssetItem> animationList = null)
{ {
if (!Studio.FbxSettings.ExportAnimations) if (!FbxSettings.ExportAnimations)
animationList = new List<AssetItem>(); animationList = new List<AssetItem>();
var convert = animationList != null var convert = animationList != null
? new ModelConverter(gameObject, Properties.Settings.Default.convertType, animationList.Select(x => (AnimationClip)x.Asset).ToList()) ? new ModelConverter(gameObject, Properties.Settings.Default.convertType, animationList.Select(x => (AnimationClip)x.Asset).ToList())
@@ -411,7 +423,7 @@ namespace AssetStudioGUI
public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null) public static void ExportGameObjectMerge(List<GameObject> gameObject, string exportPath, List<AssetItem> animationList = null)
{ {
var rootName = Path.GetFileNameWithoutExtension(exportPath); var rootName = Path.GetFileNameWithoutExtension(exportPath);
if (!Studio.FbxSettings.ExportAnimations) if (!FbxSettings.ExportAnimations)
animationList = new List<AssetItem>(); animationList = new List<AssetItem>();
var convert = animationList != null var convert = animationList != null
? new ModelConverter(rootName, gameObject, Properties.Settings.Default.convertType, animationList.Select(x => (AnimationClip)x.Asset).ToList()) ? new ModelConverter(rootName, gameObject, Properties.Settings.Default.convertType, animationList.Select(x => (AnimationClip)x.Asset).ToList())
+5 -6
View File
@@ -88,7 +88,6 @@ namespace AssetStudioGUI
public static List<AssetItem> visibleAssets = new List<AssetItem>(); public static List<AssetItem> visibleAssets = new List<AssetItem>();
public static L2DAssetsManager l2dAssetsManager = new L2DAssetsManager(); public static L2DAssetsManager l2dAssetsManager = new L2DAssetsManager();
internal static Action<string> StatusStripUpdate = x => { }; internal static Action<string> StatusStripUpdate = x => { };
internal static Fbx.Settings FbxSettings;
public static int ExtractFolder(string path, string savePath) public static int ExtractFolder(string path, string savePath)
{ {
@@ -1161,7 +1160,7 @@ namespace AssetStudioGUI
{ {
var baseDestPath = Path.Combine(exportPath, "Live2DOutput"); var baseDestPath = Path.Combine(exportPath, "Live2DOutput");
var modelGroupOption = Properties.Settings.Default.l2dModelGroupOption; var modelGroupOption = Properties.Settings.Default.l2dModelGroupOption;
var l2dOptions = new Live2DOptions() var extractorOptions = new Live2DExtractorOptions
{ {
SelectedClipMotions = selClipMotions, SelectedClipMotions = selClipMotions,
SelectedFadeMotions = selFadeMotions, SelectedFadeMotions = selFadeMotions,
@@ -1171,9 +1170,9 @@ namespace AssetStudioGUI
SearchByFilename = Properties.Settings.Default.l2dAssetSearchByFilename, SearchByFilename = Properties.Settings.Default.l2dAssetSearchByFilename,
}; };
if (selClipMotions != null) if (selClipMotions != null)
l2dOptions.MotionMode = Live2DMotionMode.AnimationClipV2; extractorOptions.MotionMode = Live2DMotionMode.AnimationClipV2;
else if (selFadeMotions != null || selFadeLst != null) else if (selFadeMotions != null || selFadeLst != null)
l2dOptions.MotionMode = Live2DMotionMode.MonoBehaviour; extractorOptions.MotionMode = Live2DMotionMode.MonoBehaviour;
ThreadPool.QueueUserWorkItem(state => ThreadPool.QueueUserWorkItem(state =>
{ {
@@ -1197,7 +1196,7 @@ namespace AssetStudioGUI
Logger.Info($"[{modelCounter + 1}/{totalModelCount}] Exporting Live2D from: \"{srcContainer}\"..."); Logger.Info($"[{modelCounter + 1}/{totalModelCount}] Exporting Live2D from: \"{srcContainer}\"...");
try try
{ {
var cubismExtractor = new Live2DExtractor(assetGroupKvp.Value, cubismModel, l2dOptions); var cubismExtractor = new Live2DExtractor(assetGroupKvp.Value, cubismModel, extractorOptions);
var fileName = string.IsNullOrEmpty(mocMono.assetsFile.originalPath) var fileName = string.IsNullOrEmpty(mocMono.assetsFile.originalPath)
? Path.GetFileNameWithoutExtension(mocMono.assetsFile.fileName) ? Path.GetFileNameWithoutExtension(mocMono.assetsFile.fileName)
: Path.GetFileNameWithoutExtension(mocMono.assetsFile.originalPath); : Path.GetFileNameWithoutExtension(mocMono.assetsFile.originalPath);
@@ -1216,7 +1215,7 @@ namespace AssetStudioGUI
modelPath = modelName; modelPath = modelName;
break; break;
default: //ContainerPath default: //ContainerPath
var container = l2dOptions.SearchByFilename && cubismModel != null var container = extractorOptions.SearchByFilename && cubismModel != null
? cubismModel.Container ? cubismModel.Container
: srcContainer; : srcContainer;
container = container == mocMono.assetsFile.fullName container = container == mocMono.assetsFile.fullName
@@ -26,7 +26,7 @@ namespace CubismLive2DExtractor
{ {
public static AssemblyLoader Assembly { get; set; } public static AssemblyLoader Assembly { get; set; }
private CubismModel Model { get; set; } private CubismModel Model { get; set; }
private Live2DOptions Options { get; } private Live2DExtractorOptions Options { get; }
private List<MonoBehaviour> FadeMotions { get; set; } private List<MonoBehaviour> FadeMotions { get; set; }
private List<AnimationClip> AnimationClips { get; set; } private List<AnimationClip> AnimationClips { get; set; }
private List<MonoBehaviour> Expressions { get; set; } private List<MonoBehaviour> Expressions { get; set; }
@@ -42,7 +42,7 @@ namespace CubismLive2DExtractor
private HashSet<string> EyeBlinkParameters { get; set; } private HashSet<string> EyeBlinkParameters { get; set; }
private HashSet<string> LipSyncParameters { get; set; } private HashSet<string> LipSyncParameters { get; set; }
public Live2DExtractor(List<Object> modelAssetsList, CubismModel model, Live2DOptions l2dOptions) public Live2DExtractor(List<Object> modelAssetsList, CubismModel model, Live2DExtractorOptions l2dOptions)
{ {
Options = l2dOptions; Options = l2dOptions;
Expressions = new List<MonoBehaviour>(); Expressions = new List<MonoBehaviour>();
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace CubismLive2DExtractor namespace CubismLive2DExtractor
{ {
public sealed class Live2DOptions public sealed class Live2DExtractorOptions
{ {
public List<AnimationClip> SelectedClipMotions { get; set; } public List<AnimationClip> SelectedClipMotions { get; set; }
public List<MonoBehaviour> SelectedFadeMotions { get; set; } public List<MonoBehaviour> SelectedFadeMotions { get; set; }