Skip to content

Commit

Permalink
Created a single base type for 3D assets that will appear in the view…
Browse files Browse the repository at this point in the history
…er when selected.
  • Loading branch information
MeltyPlayer committed Feb 7, 2024
1 parent 91a0191 commit 932e648
Show file tree
Hide file tree
Showing 43 changed files with 174 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using fin.model;
using fin.scene;
using fin.scene;

namespace fin.ui.rendering.gl.scene {
public class SceneRenderer : IRenderable, IDisposable {
public SceneRenderer(IScene scene, ILighting? lighting) {
public SceneRenderer(IScene scene) {
this.AreaRenderers
= scene.Areas
.Select(area => new SceneAreaRenderer(area, lighting))
.Select(area => new SceneAreaRenderer(area, scene.Lighting))
.ToArray();
}

Expand Down
24 changes: 24 additions & 0 deletions FinModelUtility/Fin/Fin/src/importers/ImportersInterfaces.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using fin.io.bundles;

namespace fin.importers {
public interface IImporter<out T, in TFileBundle>
where TFileBundle : IFileBundle {
T Import(TFileBundle fileBundle);
}


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
/// models without running into out of memory exceptions.
/// </summary>
bool UseLowLevelExporter => false;

bool ForceGarbageCollection => false;
}

public interface I3dImporter<out T, in TFileBundle>
: IImporter<T, TFileBundle>
where TFileBundle : I3dFileBundle;
}
21 changes: 5 additions & 16 deletions FinModelUtility/Fin/Fin/src/model/io/ModelIoInterfaces.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
using System.Collections.Generic;
using System.Linq;

using fin.importers;
using fin.io;
using fin.io.bundles;

namespace fin.model.io {
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
/// models without running into out of memory exceptions.
/// </summary>
bool UseLowLevelExporter => false;

bool ForceGarbageCollection => false;
}

public interface IModelFileBundle : I3dFileBundle { }
public interface IModelFileBundle : I3dFileBundle;

public interface IModelPlugin {
string DisplayName { get; }
Expand All @@ -39,9 +28,9 @@ bool SupportsFiles(IEnumerable<IReadOnlySystemFile> files) {
return fileTypes.Where(this.MainFileExtensions.Contains).Count() == 1;
}

IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30);
IModel Import(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30);
}

public interface IModelExporterPlugin : IModelPlugin {
Expand Down
16 changes: 8 additions & 8 deletions FinModelUtility/Fin/Fin/src/model/io/importers/IModelImporter.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System.Threading.Tasks;

namespace fin.model.io.importers {
using fin.importers;

namespace fin.model.io.importers {
public interface IModelImporter<in TModelFileBundle>
where TModelFileBundle : IModelFileBundle {
IModel ImportModel(TModelFileBundle modelFileBundle);
}
: I3dImporter<IModel, TModelFileBundle>
where TModelFileBundle : IModelFileBundle;

public interface IAsyncModelImporter<in TModelFileBundle>
: IModelImporter<TModelFileBundle>
where TModelFileBundle : IModelFileBundle {
IModel IModelImporter<TModelFileBundle>.ImportModel(
IModel IImporter<IModel, TModelFileBundle>.Import(
TModelFileBundle modelFileBundle)
=> this.ImportModelAsync(modelFileBundle).Result;
=> this.ImportAsync(modelFileBundle).Result;

Task<IModel> ImportModelAsync(TModelFileBundle modelFileBundle);
Task<IModel> ImportAsync(TModelFileBundle modelFileBundle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace fin.model.io.importers.assimp {
public class AssimpModelImporter : IModelImporter<AssimpModelFileBundle> {
public unsafe IModel ImportModel(AssimpModelFileBundle modelFileBundle) {
public unsafe IModel Import(AssimpModelFileBundle modelFileBundle) {
var mainFile = modelFileBundle.MainFile;

var finModel = new ModelImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class AssimpModelImporterPlugin : IModelImporterPlugin {

public IReadOnlyList<string> FileExtensions => this.MainFileExtensions;

public IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
public IModel Import(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
var assimpBundle = new AssimpModelFileBundle {
MainFile = files.Single(),
};
outModelFileBundle = assimpBundle;

return new AssimpModelImporter().ImportModel(assimpBundle);
return new AssimpModelImporter().Import(assimpBundle);
}
}
}
16 changes: 10 additions & 6 deletions FinModelUtility/Fin/Fin/src/scene/SceneInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,31 @@
using System.Drawing;

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

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

public interface ISceneImporter<in TSceneFileBundle>
where TSceneFileBundle : ISceneFileBundle {
IScene ImportScene(TSceneFileBundle sceneFileBundle,
out ILighting? lighting);
}
: I3dImporter<IScene, TSceneFileBundle>
where TSceneFileBundle : ISceneFileBundle;


// Scene
/// <summary>
/// A single scene from a game. These can be thought of as the parts of the
/// game that are each separated by a loading screen.
/// </summary>
// TODO: The scene itself shouldn't be tickable, that should be some kind of wrapper over this data
public interface IScene : ITickable, IDisposable {
IReadOnlyList<ISceneArea> Areas { get; }
ISceneArea AddArea();

ILighting? Lighting { get; }
ILighting CreateLighting();

float ViewerScale { get; set; }
}

Expand Down
8 changes: 5 additions & 3 deletions FinModelUtility/Fin/Fin/src/scene/impl/SceneImpl.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

using fin.data;
using fin.math;
using fin.model;
using fin.model.impl;

Expand Down Expand Up @@ -37,6 +34,11 @@ public void Tick() {
}
}


public ILighting? Lighting { get; private set; }
public ILighting CreateLighting() => this.Lighting = new LightingImpl();


private float viewerScale_ = 1;

public float ViewerScale {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static void AssertGolden<TModelBundle>(
var targetDirectory =
hasGoldenExport ? tmpDirectory : outputDirectory.Impl;

var model = modelImporter.ImportModel(modelBundle);
var model = modelImporter.Import(modelBundle);
new AssimpIndirectModelExporter() {
LowLevel = modelBundle.UseLowLevelExporter,
ForceGarbageCollection = modelBundle.ForceGarbageCollection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace cmb.api {
public class CmbModelImporter : IModelImporter<CmbModelFileBundle> {
// TODO: Split these out into separate classes
// TODO: Reading from the file here is gross
public IModel ImportModel(CmbModelFileBundle modelFileBundle) {
public IModel Import(CmbModelFileBundle modelFileBundle) {
var cmbFile = modelFileBundle.CmbFile;
var csabFiles = modelFileBundle.CsabFiles;
var ctxbFiles = modelFileBundle.CtxbFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class CmbModelImporterPlugin : IModelImporterPlugin {
public IReadOnlyList<string> FileExtensions { get; } =
new[] { ".cmb", ".csab", ".ctxb", ".shpa" };

public IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
public IModel Import(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
var filesArray = files.ToArray();
Expand All @@ -45,7 +45,7 @@ public IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
outModelFileBundle = cmbBundle;

var cmbImporter = new CmbModelImporter();
return cmbImporter.ImportModel(cmbBundle);
return cmbImporter.Import(cmbBundle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace dat.api {
// TODO: Split out this importer based on the game
public class DatModelImporter : IModelImporter<DatModelFileBundle> {
public unsafe IModel ImportModel(DatModelFileBundle modelFileBundle) {
public unsafe IModel Import(DatModelFileBundle modelFileBundle) {
var primaryDat =
modelFileBundle.PrimaryDatFile.ReadNew<Dat>(Endianness.BigEndian);
var primaryDatSubfile = primaryDat.Subfiles.Single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GloModelImporter : IModelImporter<GloModelFileBundle> {

private readonly string[] mirrorTextures_ = ["Badg2.bmp"];

public IModel ImportModel(GloModelFileBundle gloModelFileBundle) {
public IModel Import(GloModelFileBundle gloModelFileBundle) {
var gloFile = gloModelFileBundle.GloFile;
var textureDirectories = gloModelFileBundle.TextureDirectories;
var fps = 20;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public string Description
public IReadOnlyList<string> MainFileExtensions => new[] { ".glo" };
public IReadOnlyList<string> FileExtensions => this.MainFileExtensions;

public IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
public IModel Import(IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
var gloFile = files.WithFileType(".glo").Single();
Expand All @@ -26,7 +26,7 @@ public IModel ImportModel(IEnumerable<IReadOnlySystemFile> files,
new GloModelFileBundle(gloFile, new[] { textureDirectory });
outModelFileBundle = gloBundle;

return new GloModelImporter().ImportModel(gloBundle);
return new GloModelImporter().Import(gloBundle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace jsystem.api {
using GxPrimitiveType = BMD.SHP1Section.Batch.Packet.Primitive.GXPrimitive;

public class BmdModelImporter : IModelImporter<BmdModelFileBundle> {
public IModel ImportModel(BmdModelFileBundle modelFileBundle) {
public IModel Import(BmdModelFileBundle modelFileBundle) {
var logger = Logging.Create<BmdModelImporter>();

var bmd = new BMD(modelFileBundle.BmdFile.ReadAllBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public string Description
public IReadOnlyList<string> FileExtensions { get; } =
new[] { ".bca", ".bck", ".bmd", ".bti" };

public IModel ImportModel(
public IModel Import(
IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
Expand All @@ -44,7 +44,7 @@ public IModel ImportModel(
outModelFileBundle = bmdBundle;

var bmdImporter = new BmdModelImporter();
return bmdImporter.ImportModel(bmdBundle);
return bmdImporter.Import(bmdBundle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace level5.api {
public class XcModelImporter : IModelImporter<XcModelFileBundle> {
public IModel ImportModel(XcModelFileBundle modelFileBundle) {
public IModel Import(XcModelFileBundle modelFileBundle) {
var endianness = Endianness.LittleEndian;

var modelXcFile = modelFileBundle.ModelXcFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static GxWrapMode ConvertGcnToGx(TilingMode tilingMode)
_ => GxWrapMode.GX_REPEAT,
};

public IModel ImportModel(ModModelFileBundle modelFileBundle) {
public IModel Import(ModModelFileBundle modelFileBundle) {
var mod =
modelFileBundle.ModFile.ReadNew<Mod>(Endianness.BigEndian);
var anm =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ModModelImporterPlugin : IModelImporterPlugin {
public IReadOnlyList<string> FileExtensions { get; } =
new[] { ".anm", ".mod" };

public IModel ImportModel(
public IModel Import(
IEnumerable<IReadOnlySystemFile> files,
out IModelFileBundle outModelFileBundle,
float frameRate = 30) {
Expand All @@ -36,7 +36,7 @@ public IModel ImportModel(
outModelFileBundle = modBundle;

var modImporter = new ModModelImporter();
return modImporter.ImportModel(modBundle);
return modImporter.Import(modBundle);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
namespace modl.api {
public class BattalionWarsModelImporter
: IModelImporter<IBattalionWarsModelFileBundle> {
public IModel ImportModel(IBattalionWarsModelFileBundle modelFileBundle)
public IModel Import(IBattalionWarsModelFileBundle modelFileBundle)
=> modelFileBundle switch {
ModlModelFileBundle modlFileBundle => new ModlModelImporter()
.ImportModelAsync(modlFileBundle).Result,
OutModelFileBundle outFileBundle => new OutModelImporter().ImportModel(
.ImportAsync(modlFileBundle).Result,
OutModelFileBundle outFileBundle => new OutModelImporter().Import(
outFileBundle),
_ => throw new ArgumentOutOfRangeException(
nameof(modelFileBundle), modelFileBundle, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public class BwSceneFileBundle : IBattalionWarsFileBundle, ISceneFileBundle {
}

public class BwSceneImporter : ISceneImporter<BwSceneFileBundle> {
public IScene ImportScene(BwSceneFileBundle sceneFileBundle,
out ILighting? lighting)
=> new LevelXmlParser().Parse(sceneFileBundle, out lighting);
public IScene Import(BwSceneFileBundle sceneFileBundle)
=> new LevelXmlParser().Parse(sceneFileBundle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace modl.api {
public class ModlModelImporter : IAsyncModelImporter<ModlModelFileBundle> {
public Task<IModel> ImportModelAsync(ModlModelFileBundle modelFileBundle)
public Task<IModel> ImportAsync(ModlModelFileBundle modelFileBundle)
=> this.ImportModelAsync(modelFileBundle.ModlFile,
modelFileBundle.AnimFiles?.ToArray(),
modelFileBundle.GameVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace modl.api {
public class OutModelImporter : IModelImporter<OutModelFileBundle> {
public IModel ImportModel(OutModelFileBundle modelFileBundle)
public IModel Import(OutModelFileBundle modelFileBundle)
=> modelFileBundle.TextureDirectories != null
? this.ImportModel(modelFileBundle.OutFile,
modelFileBundle.TextureDirectories
Expand Down
Loading

0 comments on commit 932e648

Please sign in to comment.