Skip to content

Commit

Permalink
Started setting up reading the main fighter file for Melee characters…
Browse files Browse the repository at this point in the history
…, which will be necessary to split out high/low poly meshes.
  • Loading branch information
MeltyPlayer committed Nov 6, 2023
1 parent cd3b9b2 commit 4151600
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 16 deletions.
9 changes: 9 additions & 0 deletions FinModelUtility/Formats/Dat/Dat/src/api/DatModelFileBundle.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using fin.io;
using fin.model.io;
using fin.util.enumerables;

namespace dat.api {
public class DatModelFileBundle : IModelFileBundle {
Expand All @@ -8,5 +9,13 @@ public class DatModelFileBundle : IModelFileBundle {
public IReadOnlyTreeFile MainFile => this.PrimaryDatFile;
public required IReadOnlyTreeFile PrimaryDatFile { get; init; }
public IReadOnlyTreeFile? AnimationDatFile { get; init; }

// TODO: Split out this fighter file into a Melee-specific Dat bundle
public IReadOnlyTreeFile? FighterDatFile { get; init; }

public IEnumerable<IReadOnlyGenericFile> Files
=> this.MainFile.Yield()
.ConcatIfNonnull(this.AnimationDatFile)
.ConcatIfNonnull(this.FighterDatFile);
}
}
7 changes: 6 additions & 1 deletion FinModelUtility/Formats/Dat/Dat/src/api/DatModelImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@
using SixLabors.ImageSharp.PixelFormats;

namespace dat.api {
// TODO: Split out this importer based on the game
public class DatModelImporter : IModelImporter<DatModelFileBundle> {
public unsafe IModel ImportModel(DatModelFileBundle modelFileBundle) {
var primaryDat =
modelFileBundle.PrimaryDatFile.ReadNew<Dat>(Endianness.BigEndian);
var primaryDatSubfile = primaryDat.Subfiles.First();
var primaryDatSubfile = primaryDat.Subfiles.Single();

var animationDat =
modelFileBundle.AnimationDatFile?.ReadNew<Dat>(Endianness.BigEndian);
var fighterDat =
modelFileBundle.FighterDatFile?.ReadNew<Dat>(Endianness.BigEndian);

var finModel = new ModelImpl();
var finSkin = finModel.Skin;
Expand Down Expand Up @@ -342,6 +345,8 @@ public unsafe IModel ImportModel(DatModelFileBundle modelFileBundle) {
var defaultBoneWeights = boneWeightsByJObj[jObj];
var mObjOffset = dObj.MObjOffset;

// TODO: Use fighter file to choose only high-poly meshes

// Adds polygons
foreach (var pObj in dObj.PObjs) {
var pObjFlags = pObj.Header.Flags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ public class SuperSmashBrosMeleeModelAnnotatedFileGatherer

var stageFiles = new LinkedList<IFileHierarchyFile>();
var trophyFiles = new LinkedList<IFileHierarchyFile>();
var plFilesByName = new Dictionary<string, IFileHierarchyFile>();
var plFilesByNameWithoutExtension =
new Dictionary<string, IFileHierarchyFile>();

foreach (var datFile in fileHierarchy.Root.FilesWithExtension(".dat")) {
var datFileName = datFile.NameWithoutExtension;
var datNameWithoutExtension = datFile.NameWithoutExtension;

if (datFileName.StartsWith(STAGE_PREFIX)) {
if (datNameWithoutExtension.StartsWith(STAGE_PREFIX)) {
stageFiles.AddLast(datFile);
continue;
}

if (datFileName.StartsWith(TROPHY_PREFIX)) {
if (datNameWithoutExtension.StartsWith(TROPHY_PREFIX)) {
trophyFiles.AddLast(datFile);
continue;
}

if (datFileName.StartsWith(CHARACTER_PREFIX)) {
plFilesByName.Add(datFileName, datFile);
if (datNameWithoutExtension.StartsWith(CHARACTER_PREFIX)) {
plFilesByNameWithoutExtension.Add(datNameWithoutExtension, datFile);
}
}

Expand All @@ -55,9 +56,18 @@ public class SuperSmashBrosMeleeModelAnnotatedFileGatherer
}

// TODO: How to optimize this??
foreach (var plNameWithoutExtension in plFilesByName.Keys) {
foreach (var (plNameWithoutExtension, plFile) in
plFilesByNameWithoutExtension) {
if (!plFilesByNameWithoutExtension.TryGetValue(
$"{plNameWithoutExtension}{ANIMATION_SUFFIX}",
out var animationFile)) {
continue;
}

var fighterFile = plFile;

var plFilesStartingWithName =
plFilesByName
plFilesByNameWithoutExtension
.Values
.Where(otherPlFile => {
var otherPlNameWithoutExtension =
Expand All @@ -69,20 +79,15 @@ public class SuperSmashBrosMeleeModelAnnotatedFileGatherer
})
.ToDictionary(file => file.NameWithoutExtension);

if (!plFilesStartingWithName.TryGetValue(
$"{plNameWithoutExtension}{ANIMATION_SUFFIX}",
out var animationPlFile)) {
continue;
}

foreach (var modelFile in
plFilesStartingWithName
.Where(pair => !pair.Key.EndsWith(ANIMATION_SUFFIX))
.Select(pair => pair.Value)) {
yield return new DatModelFileBundle {
GameName = "super_smash_bros_melee",
PrimaryDatFile = modelFile,
AnimationDatFile = animationPlFile,
AnimationDatFile = animationFile,
FighterDatFile = fighterFile,
}.Annotate(modelFile);
}
}
Expand Down

0 comments on commit 4151600

Please sign in to comment.