Skip to content

Commit 67c111d

Browse files
Update export dialogue
1 parent a9dfab2 commit 67c111d

File tree

4 files changed

+65
-44
lines changed

4 files changed

+65
-44
lines changed

Meddle/Meddle.Plugin/Plugin.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ public ExportConfiguration Clone()
206206
UseDeformer = UseDeformer
207207
};
208208
}
209+
210+
public void SetDefaultCloneOptions()
211+
{
212+
RemoveAttributeDisabledSubmeshes = true;
213+
SkipHiddenBgParts = true;
214+
UseDeformer = true;
215+
}
216+
217+
public void Apply(ExportConfiguration other)
218+
{
219+
CacheFileTypes = other.CacheFileTypes;
220+
ExportType = other.ExportType;
221+
// ExportPose = other.ExportPose;
222+
// TextureMode = other.TextureMode;
223+
PoseMode = other.PoseMode;
224+
RemoveAttributeDisabledSubmeshes = other.RemoveAttributeDisabledSubmeshes;
225+
SkipHiddenBgParts = other.SkipHiddenBgParts;
226+
// RootAttachHandling = other.RootAttachHandling;
227+
UseDeformer = other.UseDeformer;
228+
}
209229
}
210230

211231
public event Action? OnConfigurationSaved;

Meddle/Meddle.Plugin/UI/Layout/LayoutWindow.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,13 @@ private void ExportButton(string text, IEnumerable<ParsedInstance> instances)
381381
requestedPopup = true;
382382
var instancesArray = instances.ToArray();
383383
resolverService.ResolveInstances(instancesArray);
384-
drawExportSettingsCallback = () => DrawExportSettings(instancesArray);
384+
var exportConfig = config.ExportConfig.Clone();
385+
exportConfig.SetDefaultCloneOptions();
386+
drawExportSettingsCallback = () => DrawExportSettings(instancesArray, exportConfig);
385387
}
386388
}
387389

388-
private void DrawExportSettings(ParsedInstance[] instances)
390+
private void DrawExportSettings(ParsedInstance[] instances, Configuration.ExportConfiguration exportConfig)
389391
{
390392
if (!exportTask.IsCompleted)
391393
{
@@ -396,25 +398,26 @@ private void DrawExportSettings(ParsedInstance[] instances)
396398
if (!ImGui.BeginPopup("ExportSettingsPopup", ImGuiWindowFlags.AlwaysAutoResize)) return;
397399
try
398400
{
399-
var flags = UiUtil.ExportConfigDrawFlags.None;
400-
if (instances.Length > 1)
401+
var flags = UiUtil.ExportConfigDrawFlags.ShowLayoutOptions;
402+
if (instances.Length == 1 && (instances[0].Type & ParsedInstanceType.Character) != 0)
401403
{
402-
flags |= UiUtil.ExportConfigDrawFlags.HideExportPose;
404+
flags |= UiUtil.ExportConfigDrawFlags.ShowExportPose;
405+
flags |= UiUtil.ExportConfigDrawFlags.ShowSubmeshOptions;
403406
}
404407

405-
if (UiUtil.DrawExportConfig(config.ExportConfig, flags))
408+
if (UiUtil.DrawExportConfig(exportConfig, flags))
406409
{
410+
config.ExportConfig.Apply(exportConfig);
407411
config.Save();
408412
}
409413

410414
if (ImGui.Button("Export"))
411415
{
412-
var configClone = config.ExportConfig.Clone();
413-
configClone.UseDeformer = true;
414-
if (flags.HasFlag(UiUtil.ExportConfigDrawFlags.HideExportPose))
416+
exportConfig.UseDeformer = true;
417+
if (!flags.HasFlag(UiUtil.ExportConfigDrawFlags.ShowExportPose))
415418
{
416-
// Force export pose to true if multiple instances are selected
417-
configClone.PoseMode = SkeletonUtils.PoseMode.Local;
419+
// Force local pose mode if we don't show the pose option
420+
exportConfig.PoseMode = SkeletonUtils.PoseMode.Local;
418421
}
419422

420423
var filteredInstances = new List<ParsedInstance>();
@@ -454,7 +457,7 @@ private void DrawExportSettings(ParsedInstance[] instances)
454457
exportTask = Task.Run(() =>
455458
{
456459
var composer = composerFactory.CreateComposer(path,
457-
configClone,
460+
exportConfig,
458461
cancelToken.Token);
459462
progress = new ExportProgress(filteredInstanceArray.Length, "Instances");
460463
composer.Compose(filteredInstanceArray, progress);

Meddle/Meddle.Plugin/UI/LiveCharacterTab.cs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ private void ExportButton(string text, Func<ParsedCharacterInfo> resolve, string
255255
{
256256
requestedPopup = true;
257257
var parsedCharacterInfo = resolve();
258-
drawExportSettingsCallback = () => DrawExportSettings(parsedCharacterInfo, name);
258+
var configClone = config.ExportConfig.Clone();
259+
configClone.SetDefaultCloneOptions();
260+
drawExportSettingsCallback = () => DrawExportSettings(parsedCharacterInfo, name, configClone);
259261
}
260262
}
261263

@@ -265,11 +267,13 @@ private void ExportMenuItem(string text, Func<ParsedCharacterInfo> resolve, stri
265267
{
266268
requestedPopup = true;
267269
var parsedCharacterInfo = resolve();
268-
drawExportSettingsCallback = () => DrawExportSettings(parsedCharacterInfo, name);
270+
var configClone = config.ExportConfig.Clone();
271+
configClone.SetDefaultCloneOptions();
272+
drawExportSettingsCallback = () => DrawExportSettings(parsedCharacterInfo, name, configClone);
269273
}
270274
}
271275

272-
private void DrawExportSettings(ParsedCharacterInfo characterInfo, string name)
276+
private void DrawExportSettings(ParsedCharacterInfo characterInfo, string name, Configuration.ExportConfiguration exportConfig)
273277
{
274278
if (!exportTask.IsCompleted)
275279
{
@@ -280,27 +284,21 @@ private void DrawExportSettings(ParsedCharacterInfo characterInfo, string name)
280284
if (!ImGui.BeginPopup("ExportSettingsPopup", ImGuiWindowFlags.AlwaysAutoResize)) return;
281285
try
282286
{
283-
var exportFlags = UiUtil.ExportConfigDrawFlags.HideLayoutOptions;
287+
var exportFlags = UiUtil.ExportConfigDrawFlags.ShowExportPose |
288+
UiUtil.ExportConfigDrawFlags.ShowSubmeshOptions;
284289
if (characterInfo.Models.Length == 1)
285290
{
286291
exportFlags |= UiUtil.ExportConfigDrawFlags.ShowUseDeformer;
287292
}
288293

289-
if (UiUtil.DrawExportConfig(config.ExportConfig, exportFlags))
294+
if (UiUtil.DrawExportConfig(exportConfig, exportFlags))
290295
{
296+
config.ExportConfig.Apply(exportConfig);
291297
config.Save();
292298
}
293299

294300
if (ImGui.Button("Export"))
295301
{
296-
var configClone = config.ExportConfig.Clone();
297-
298-
// Force deformer usage if the flag is not set
299-
if (!exportFlags.HasFlag(UiUtil.ExportConfigDrawFlags.ShowUseDeformer))
300-
{
301-
configClone.UseDeformer = true;
302-
}
303-
304302
var defaultName = $"Character-{name}-{DateTime.Now:yyyy-MM-dd-HH-mm-ss}";
305303
cancelToken = new CancellationTokenSource();
306304
fileDialog.SaveFolderDialog("Save Instances", defaultName,
@@ -312,14 +310,14 @@ private void DrawExportSettings(ParsedCharacterInfo characterInfo, string name)
312310
Directory.CreateDirectory(path);
313311
var characterBlob = JsonSerializer.Serialize(characterInfo, MaterialComposer.JsonOptions);
314312
File.WriteAllText(Path.Combine(path, $"{name}_blob.json"), characterBlob);
315-
var composer = composerFactory.CreateCharacterComposer(path, configClone, cancelToken.Token);
313+
var composer = composerFactory.CreateCharacterComposer(path, exportConfig, cancelToken.Token);
316314
var scene = new SceneBuilder();
317315
var characterRoot = new NodeBuilder($"Character-{name}");
318316
scene.AddNode(characterRoot);
319317
progress = new ExportProgress(characterInfo.Models.Length, "Character");
320318
composer.Compose(characterInfo, scene, characterRoot, progress);
321319
var modelRoot = scene.ToGltf2();
322-
ExportUtil.SaveAsType(modelRoot, configClone.ExportType, path, name);
320+
ExportUtil.SaveAsType(modelRoot, exportConfig.ExportType, path, name);
323321
Process.Start("explorer.exe", path);
324322
});
325323
}, config.ExportDirectory);

Meddle/Meddle.Plugin/Utils/UIUtil.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ public static void Text(string text, string? copyValue)
3434
public enum ExportConfigDrawFlags
3535
{
3636
None = 0,
37-
HideExportPose = 1,
38-
HideLayoutOptions = 2,
37+
ShowExportPose = 1,
38+
ShowLayoutOptions = 2,
3939
ShowUseDeformer = 4,
40+
ShowSubmeshOptions = 8,
4041
}
4142

4243
public static bool DrawExportConfig(Configuration.ExportConfiguration exportConfiguration, ExportConfigDrawFlags flags = ExportConfigDrawFlags.None)
@@ -80,7 +81,7 @@ public static bool DrawExportConfig(Configuration.ExportConfiguration exportConf
8081
// ImGui.TextColored(new Vector4(1, 0, 0, 1), "Baking textures is deprecated, use Raw mode with the MeddleTools Blender addon");
8182
// }
8283

83-
if (!flags.HasFlag(ExportConfigDrawFlags.HideExportPose))
84+
if (flags.HasFlag(ExportConfigDrawFlags.ShowExportPose))
8485
{
8586
// var exportPose = exportConfiguration.ExportPose;
8687
// if (ImGui.Checkbox("Export pose", ref exportPose))
@@ -115,10 +116,10 @@ public static bool DrawExportConfig(Configuration.ExportConfiguration exportConf
115116
"This is recommended for most models, but will result in different deformations based on the race associated with the model.");
116117
}
117118

118-
if (!flags.HasFlag(ExportConfigDrawFlags.HideLayoutOptions))
119+
if (flags.HasFlag(ExportConfigDrawFlags.ShowLayoutOptions))
119120
{
120121
var skipHiddenBgParts = exportConfiguration.SkipHiddenBgParts;
121-
if (ImGui.Checkbox("Skip hidden bg parts", ref skipHiddenBgParts))
122+
if (ImGui.Checkbox("Remove hidden background parts", ref skipHiddenBgParts))
122123
{
123124
exportConfiguration.SkipHiddenBgParts = skipHiddenBgParts;
124125
changed = true;
@@ -129,20 +130,19 @@ public static bool DrawExportConfig(Configuration.ExportConfiguration exportConf
129130
"Example: if an arena changes shape throughout an encounter, the export will only include the arena that is currently visible.");
130131
}
131132

132-
var includeAttributeDisabledSubMeshes = !exportConfiguration.RemoveAttributeDisabledSubmeshes;
133-
if (ImGui.Checkbox("Include all optional character features", ref includeAttributeDisabledSubMeshes))
133+
if (flags.HasFlag(ExportConfigDrawFlags.ShowSubmeshOptions))
134134
{
135-
exportConfiguration.RemoveAttributeDisabledSubmeshes = !includeAttributeDisabledSubMeshes;
136-
changed = true;
137-
}
135+
var removeAttributeDisabledSubmeshes = exportConfiguration.RemoveAttributeDisabledSubmeshes;
136+
if (ImGui.Checkbox("Remove unused character features", ref removeAttributeDisabledSubmeshes))
137+
{
138+
exportConfiguration.RemoveAttributeDisabledSubmeshes = removeAttributeDisabledSubmeshes;
139+
changed = true;
140+
}
138141

139-
ImGui.SameLine();
140-
// technical explanation
141-
// In the character creator, there are some features of characters that can be toggled on and off, if this checkbox is toggled to 'Include all submeshes'
142-
// the export will treat is as if all toggles are enabled
143-
HintCircle("Certain character features can be toggled on and off in the character creator, " +
144-
"this option will include all features regardless of the toggles.\n" +
145-
"Keep this disabled if you want to export the character as they appear in-game");
142+
ImGui.SameLine();
143+
HintCircle("Certain character features can be toggled on and off in the character creator,\n" +
144+
"this will make sure the export only includes the features that are currently enabled.");
145+
}
146146

147147
// var rootAttachHandling = exportConfiguration.RootAttachHandling;
148148
// if (EnumExtensions.DrawEnumDropDown("Root Attach Handling", ref rootAttachHandling))

0 commit comments

Comments
 (0)