Skip to content

Commit

Permalink
Fixed a really stupid bug that was breaking the Export As button.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeltyPlayer committed Jan 13, 2024
1 parent e63b6b2 commit 5f638a6
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 68 deletions.
4 changes: 3 additions & 1 deletion FinModelUtility/Fin/Fin/src/model/io/ModelIoInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using fin.io.bundles;

namespace fin.model.io {
public interface IModelFileBundle : IFileBundle {
public interface I3dFileBundle : IFileBundle {
/// <summary>
/// Whether to use a low-level exporter when exporting. This supports
/// less features at the moment, but is required for exporting huge
Expand All @@ -16,6 +16,8 @@ public interface IModelFileBundle : IFileBundle {
bool ForceGarbageCollection => false;
}

public interface IModelFileBundle : I3dFileBundle { }

public interface IModelPlugin {
string DisplayName { get; }
string Description { get; }
Expand Down
4 changes: 2 additions & 2 deletions FinModelUtility/Fin/Fin/src/scene/SceneInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.Drawing;

using fin.animation;
using fin.io.bundles;
using fin.math;
using fin.model;
using fin.model.io;

namespace fin.scene {
public interface ISceneFileBundle : IFileBundle { }
public interface ISceneFileBundle : I3dFileBundle { }

public interface ISceneImporter<in TSceneFileBundle>
where TSceneFileBundle : ISceneFileBundle {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

using uni.api;
using uni.ui.winforms.common.fileTreeView;
using uni.util.bundles;

namespace uni.ui.winforms;

Expand Down Expand Up @@ -360,8 +361,11 @@ private void exportAsToolStripMenuItem_Click(object sender, EventArgs e) {
}

var (fileBundle, _, _) = fileBundleAndScene.Value;
var modelFileBundle =
Asserts.AsA<IAnnotatedFileBundle<IModelFileBundle>>(fileBundle);
if (fileBundle is not I3dFileBundle threeDFileBundle) {
return;
}

// TODO: Merge models in a scene instead!
var model = this.sceneViewerPanel_.FirstSceneModel!.Model;

var allSupportedExportFormats = AssimpUtil.SupportedExportFormats
Expand All @@ -387,7 +391,7 @@ private void exportAsToolStripMenuItem_Click(object sender, EventArgs e) {
var result = saveFileDialog.ShowDialog();
if (result == DialogResult.OK) {
var outputFile = new FinFile(saveFileDialog.FileName);
ExporterUtil.Export(modelFileBundle,
ExporterUtil.Export(threeDFileBundle,
() => model,
outputFile.AssertGetParent(),
new[] { outputFile.FileType },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public static ExporterPromptChoice PromptIfFilesAlreadyExist(
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
return result switch {
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.CANCEL,
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.CANCEL,
};
} else {
var result =
Expand All @@ -105,9 +105,9 @@ public static ExporterPromptChoice PromptIfFilesAlreadyExist(
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
return result switch {
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.SKIP_EXISTING,
DialogResult.Cancel => ExporterPromptChoice.CANCEL,
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.SKIP_EXISTING,
DialogResult.Cancel => ExporterPromptChoice.CANCEL,
};
}
}
Expand All @@ -133,8 +133,8 @@ public static ExporterPromptChoice
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
return result switch {
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.CANCEL,
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.CANCEL,
};
} else {
var existingCount = existingOutputFiles.Count();
Expand All @@ -146,9 +146,9 @@ public static ExporterPromptChoice
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button1);
return result switch {
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.SKIP_EXISTING,
DialogResult.Cancel => ExporterPromptChoice.CANCEL,
DialogResult.Yes => ExporterPromptChoice.OVERWRITE_EXISTING,
DialogResult.No => ExporterPromptChoice.SKIP_EXISTING,
DialogResult.Cancel => ExporterPromptChoice.CANCEL,
};
}
}
Expand Down Expand Up @@ -248,62 +248,61 @@ public static void Export<T>(IAnnotatedFileBundle<T> modelFileBundle,
overwriteExistingFile);
}

public static void Export<T>(IAnnotatedFileBundle<T> modelFileBundle,
public static void Export<T>(IAnnotatedFileBundle<T> threeDFileBundle,
Func<IModel> loaderHandler,
IReadOnlyList<string> extensions,
bool overwriteExistingFile)
where T : IModelFileBundle {
var mainFile = Asserts.CastNonnull(modelFileBundle.FileBundle.MainFile);
where T : I3dFileBundle {
var mainFile = Asserts.CastNonnull(threeDFileBundle.FileBundle.MainFile);

var parentOutputDirectory =
ExtractorUtil
.GetOutputDirectoryForFileBundle(modelFileBundle);
.GetOutputDirectoryForFileBundle(threeDFileBundle);
var outputDirectory = new FinDirectory(
Path.Join(parentOutputDirectory.FullPath,
mainFile.NameWithoutExtension));

Export<T>(modelFileBundle,
Export(threeDFileBundle.TypedFileBundle,
loaderHandler,
outputDirectory,
extensions,
overwriteExistingFile);
}

public static void Export<T>(IAnnotatedFileBundle<T> modelFileBundle,
public static void Export<T>(T threeDFileBundle,
Func<IModel> loaderHandler,
ISystemDirectory outputDirectory,
IReadOnlyList<string> extensions,
bool overwriteExistingFile,
string? overrideName = null)
where T : IModelFileBundle
=> Export(modelFileBundle,
where T : I3dFileBundle
=> Export(threeDFileBundle,
loaderHandler,
outputDirectory,
extensions.Select(AssimpUtil.GetExportFormatFromExtension)
.ToArray(),
overwriteExistingFile,
overrideName);


public static void Export<T>(
IAnnotatedFileBundle<T> annotatedModelFileBundle,
T threeDFileBundle,
Func<IModel> loaderHandler,
ISystemDirectory outputDirectory,
IReadOnlyList<ExportFormatDescription> formats,
bool overwriteExistingFile,
string? overrideName = null)
where T : IModelFileBundle {
var modelFileBundle = annotatedModelFileBundle.TypedFileBundle;
var mainFile = Asserts.CastNonnull(modelFileBundle.MainFile);
where T : I3dFileBundle {
var mainFile = Asserts.CastNonnull(threeDFileBundle.MainFile);
var name = overrideName ?? mainFile.NameWithoutExtension;

if (modelFileBundle.UseLowLevelExporter) {
if (threeDFileBundle.UseLowLevelExporter) {
formats = new[] { AssimpUtil.GetExportFormatFromExtension(".gltf") };
}

if (!overwriteExistingFile && CheckIfModelFileBundleAlreadyExported(
annotatedModelFileBundle,
formats.Select(format => $".{format.FileExtension}"))) {
var targetFiles = formats.Select(format => new FinFile(
Path.Join(outputDirectory.FullPath,
$"{name}.{format.FileExtension}")));
if (!overwriteExistingFile && targetFiles.All(targetFile => targetFile.Exists)) {
MessageUtil.LogAlreadyProcessed(ExporterUtil.logger_, mainFile);
return;
}
Expand All @@ -315,22 +314,19 @@ public static void Export<T>(
var model = loaderHandler();

new AssimpIndirectModelExporter {
LowLevel = modelFileBundle.UseLowLevelExporter,
ForceGarbageCollection = modelFileBundle.ForceGarbageCollection,
LowLevel = threeDFileBundle.UseLowLevelExporter,
ForceGarbageCollection = threeDFileBundle.ForceGarbageCollection,
}.ExportFormats(new ModelExporterParams {
OutputFile = new FinFile(
Path.Join(outputDirectory.FullPath,
name + ".foo")),
Model = model,
Scale = new ScaleSource(
Config.Instance.ExporterSettings
.ExportedModelScaleSource)
.GetScale(model,
annotatedModelFileBundle
.TypedFileBundle)
},
formats,
Config.Instance.ExporterSettings.ExportAllTextures);
OutputFile = new FinFile(
Path.Join(outputDirectory.FullPath,
name + ".foo")),
Model = model,
Scale = new ScaleSource(Config.Instance.ExporterSettings.ExportedModelScaleSource)
.GetScale(model,
threeDFileBundle)
},
formats,
Config.Instance.ExporterSettings.ExportAllTextures);

if (Config.Instance.ThirdPartySettings
.ExportBoneScaleAnimationsSeparately) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static bool HasNotBeenExtractedYet(

public static ISystemDirectory GetOutputDirectoryForFileBundle(
IAnnotatedFileBundle annotatedFileBundle)
=> DirectoryConstants
.OUT_DIRECTORY
.GetOrCreateSubdir(annotatedFileBundle.GameAndLocalPath);
=> new FinFile(Path.Join(
DirectoryConstants.OUT_DIRECTORY.FullPath,
annotatedFileBundle.GameAndLocalPath)).AssertGetParent();
}

static file class ExtractorUtilExtensions {
Expand Down
2 changes: 1 addition & 1 deletion cli/tools/publish_universal_asset_tool.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ cd "FinModelUtility\UniversalAssetTool\UniversalAssetTool.Ui\"
dotnet publish -c Release

echo Copying new universal asset tool...
move "bin\Release\net7.0-windows\win-x86\publish\*" "!universalAssetToolBasePath!"
move "bin\Release\net8.0-windows\win-x86\publish\*" "!universalAssetToolBasePath!"

pause
Binary file modified cli/tools/universal_asset_tool/PenImc_cor3.dll
Binary file not shown.
Binary file modified cli/tools/universal_asset_tool/PresentationNative_cor3.dll
Binary file not shown.
Binary file modified cli/tools/universal_asset_tool/universal_asset_tool.exe
Binary file not shown.
Binary file modified cli/tools/universal_asset_tool/vcruntime140_cor3.dll
Binary file not shown.
Binary file modified cli/tools/universal_asset_tool/wpfgfx_cor3.dll
Binary file not shown.

0 comments on commit 5f638a6

Please sign in to comment.