diff --git a/FinModelUtility/Formats/Dat/Dat/src/api/DatModelFileBundle.cs b/FinModelUtility/Formats/Dat/Dat/src/api/DatModelFileBundle.cs index f37922467..063071dd8 100644 --- a/FinModelUtility/Formats/Dat/Dat/src/api/DatModelFileBundle.cs +++ b/FinModelUtility/Formats/Dat/Dat/src/api/DatModelFileBundle.cs @@ -1,5 +1,6 @@ using fin.io; using fin.model.io; +using fin.util.enumerables; namespace dat.api { public class DatModelFileBundle : IModelFileBundle { @@ -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 Files + => this.MainFile.Yield() + .ConcatIfNonnull(this.AnimationDatFile) + .ConcatIfNonnull(this.FighterDatFile); } } \ No newline at end of file diff --git a/FinModelUtility/Formats/Dat/Dat/src/api/DatModelImporter.cs b/FinModelUtility/Formats/Dat/Dat/src/api/DatModelImporter.cs index 7b48da53d..3b36a9a3f 100644 --- a/FinModelUtility/Formats/Dat/Dat/src/api/DatModelImporter.cs +++ b/FinModelUtility/Formats/Dat/Dat/src/api/DatModelImporter.cs @@ -26,14 +26,17 @@ using SixLabors.ImageSharp.PixelFormats; namespace dat.api { + // TODO: Split out this importer based on the game public class DatModelImporter : IModelImporter { public unsafe IModel ImportModel(DatModelFileBundle modelFileBundle) { var primaryDat = modelFileBundle.PrimaryDatFile.ReadNew(Endianness.BigEndian); - var primaryDatSubfile = primaryDat.Subfiles.First(); + var primaryDatSubfile = primaryDat.Subfiles.Single(); var animationDat = modelFileBundle.AnimationDatFile?.ReadNew(Endianness.BigEndian); + var fighterDat = + modelFileBundle.FighterDatFile?.ReadNew(Endianness.BigEndian); var finModel = new ModelImpl(); var finSkin = finModel.Skin; @@ -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; diff --git a/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/games/super_smash_bros_melee/SuperSmashBrosMeleeModelFileGatherer.cs b/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/games/super_smash_bros_melee/SuperSmashBrosMeleeModelFileGatherer.cs index f5eb16cc8..06f913747 100644 --- a/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/games/super_smash_bros_melee/SuperSmashBrosMeleeModelFileGatherer.cs +++ b/FinModelUtility/UniversalAssetTool/UniversalAssetTool/src/games/super_smash_bros_melee/SuperSmashBrosMeleeModelFileGatherer.cs @@ -27,23 +27,24 @@ public class SuperSmashBrosMeleeModelAnnotatedFileGatherer var stageFiles = new LinkedList(); var trophyFiles = new LinkedList(); - var plFilesByName = new Dictionary(); + var plFilesByNameWithoutExtension = + new Dictionary(); 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); } } @@ -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 = @@ -69,12 +79,6 @@ 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)) @@ -82,7 +86,8 @@ public class SuperSmashBrosMeleeModelAnnotatedFileGatherer yield return new DatModelFileBundle { GameName = "super_smash_bros_melee", PrimaryDatFile = modelFile, - AnimationDatFile = animationPlFile, + AnimationDatFile = animationFile, + FighterDatFile = fighterFile, }.Annotate(modelFile); } }