private void AddObjectDirectory( IModelDirectory <GloModelFileBundle> parentNode, IFileHierarchy gloverFileHierarchy, IFileHierarchyDirectory objectDirectory) { var objectFiles = objectDirectory.FilesWithExtension(".glo"); var gloverSteamDirectory = gloverFileHierarchy.Root; var textureDirectories = gloverSteamDirectory .TryToGetSubdir("data/textures/generic") .Subdirs.ToList(); try { var levelTextureDirectory = gloverSteamDirectory.TryToGetSubdir( objectDirectory.LocalPath.Replace("data\\objects", "data\\textures")); textureDirectories.Add(levelTextureDirectory); textureDirectories.AddRange(levelTextureDirectory.Subdirs); } catch (Exception e) { ; } foreach (var objectFile in objectFiles) { parentNode.AddFileBundle( new GloModelFileBundle(objectFile, textureDirectories)); } }
private void ExtractFromDriverDirectory_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory) { var bmdFiles = directory.FilesWithExtension(".bmd") .ToArray(); var bcxFiles = directory.FilesWithExtensions(".bca", ".bck") .ToArray(); var driverBmdFiles = bmdFiles .Where(file => file.Name.StartsWith("driver")) .ToArray(); var driverBcxFiles = bcxFiles.Where(file => file.Name.StartsWith("b_") || file.Name.StartsWith("c_") || file.Name.StartsWith("all")) .ToArray(); this.ExtractModels_(node, driverBmdFiles, driverBcxFiles); var otherBmdFiles = bmdFiles.Where(file => !driverBmdFiles.Contains(file)) .ToArray(); if (otherBmdFiles.Length > 0) { var otherBcxFiles = bcxFiles.Where(file => !driverBcxFiles.Contains(file)) .ToArray(); this.ExtractModels_(node, otherBmdFiles, otherBcxFiles); } }
public void ExtractModel_( IModelDirectory <CmbModelFileBundle> parentNode, IFileHierarchyDirectory subdir) { var cmbFiles = subdir.FilesWithExtension(".cmb").ToArray(); if (cmbFiles.Length == 0) { return; } var csabFiles = subdir.FilesWithExtension(".csab").ToArray(); var ctxbFiles = subdir.FilesWithExtension(".ctxb").ToArray(); var shpaFiles = subdir.FilesWithExtension(".shpa").ToArray(); try { var bundles = this.separator_.Separate(subdir, cmbFiles, csabFiles); foreach (var bundle in bundles) { parentNode.AddFileBundle(new CmbModelFileBundle( bundle.ModelFile, bundle.AnimationFiles.ToArray(), ctxbFiles, shpaFiles )); } } catch { } }
private void ExtractObjects_(IFileHierarchyDirectory directory) { foreach (var subdir in directory.Subdirs) { this.ExtractObject_(subdir); } }
private void ExtractModelsInDirectoryAutomatically_( IModelDirectory <BmdModelFileBundle> parentNode, IFileHierarchyDirectory directory) { var bmdFiles = directory.FilesWithExtension(".bmd").ToArray(); if (bmdFiles.Length > 0) { var bcxFiles = directory.FilesWithExtensions(".bca", ".bck") .ToList(); var btiFiles = directory.FilesWithExtension(".bti").ToList(); this.ExtractModels_(parentNode, bmdFiles, bcxFiles, btiFiles); } }
public static void LogExtracting <T>( ILogger logger, IFileHierarchyDirectory directory, IReadOnlyList <T> rawModels) { if (rawModels.Count == 1) { LogExtracting(logger, rawModels[0]); } else { logger.LogInformation( $"Extracting models from {directory.LocalPath}"); } }
public static void LogAlreadyProcessed <T>( ILogger logger, IFileHierarchyDirectory directory, IReadOnlyList <T> rawModels) { if (rawModels.Count == 1) { LogAlreadyProcessed(logger, rawModels[0]); } else { logger.LogInformation( $"Already processed models from {directory.LocalPath}"); } }
private void ExtractFromSeparateDriverDirectories_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory, IFileHierarchyDirectory common) { Asserts.Nonnull(common); var bmdFiles = directory.FilesWithExtension(".bmd") .ToArray(); var commonBcxFiles = common.FilesWithExtensions(".bca", ".bck") .ToArray(); var localBcxFiles = directory.FilesWithExtensions(".bca", ".bck") .ToArray(); this.ExtractModels_(node, bmdFiles, commonBcxFiles.Concat(localBcxFiles).ToArray()); }
private void ExtractPrimaryAndSecondaryModels_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory, Func <IFileHierarchyFile, bool> primaryIdentifier ) { var bmdFiles = directory.Files.Where( file => file.Extension == ".bmd") .ToArray(); var bcxFiles = directory .Files.Where( file => file.Extension == ".bck" || file.Extension == ".bca") .ToArray(); this.ExtractPrimaryAndSecondaryModels_(node, primaryIdentifier, bmdFiles, bcxFiles); }
private void ExtractFilesByOrganizing_( IFileHierarchyDirectory directory, IList <IFileHierarchyFile> bmdFiles, IList <IFileHierarchyFile> bckFiles, IOrganizeMethod organizeMethod) { if (organizeMethod is PrefixOrganizeMethod) { bmdFiles.OrderByDescending( file => StringUtil .UpTo(file.NameWithoutExtension, "_") .Length); } var unclaimedBckFiles = new HashSet <IFileHierarchyFile>(bckFiles); var bmdFileToBckFiles = new Dictionary <IFileHierarchyFile, IList <IFileHierarchyFile> >(); foreach (var bmdFile in bmdFiles) { var claimedBckFiles = organizeMethod.GetBcksForBmd(bmdFile, bckFiles); bmdFileToBckFiles[bmdFile] = claimedBckFiles; foreach (var bckFile in claimedBckFiles) { unclaimedBckFiles.Remove(bckFile); } } Asserts.Equal(0, unclaimedBckFiles.Count); foreach (var(bmdFile, claimedBckFiles) in bmdFileToBckFiles) { this.ExtractModels_(directory, new[] { bmdFile }, claimedBckFiles.Select(file => file.Impl) .ToArray()); } }
private void ExtractFromSeparateDirectories_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory, IFileHierarchyDirectory common) { Asserts.Nonnull(common); var bmdFiles = directory.FilesWithExtension(".bmd") .ToArray(); var commonBcxFiles = common.FilesWithExtensions(".bca", ".bck") .ToArray(); var commonBtiFiles = common.FilesWithExtension(".bti") .ToArray(); var localBcxFiles = directory.FilesWithExtensions(".bca", ".bck") .ToArray(); if (bmdFiles.Length == 1) { this.ExtractModels_(node, bmdFiles, commonBcxFiles.Concat(localBcxFiles).ToArray(), commonBtiFiles); return; } try { Asserts.True(localBcxFiles.Length == 0); this.ExtractPrimaryAndSecondaryModels_( node, bmdFile => bmdFile.Name.StartsWith( "default"), bmdFiles, commonBcxFiles); } catch { ; } }
private void ExtractModelsAndAnimationsFromSceneObject_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory) { var bmdFiles = directory.Files.Where( file => file.Extension == ".bmd") .OrderByDescending(file => file.Name.Length) .ToArray(); var allBcxFiles = directory .Files.Where( file => file.Extension == ".bck" || file.Extension == ".bca") .ToArray(); var specialCase = false; if (allBcxFiles.Length == 1 && allBcxFiles[0].Name == "fish_swim.bck" && bmdFiles.All(file => file.Name.StartsWith("fish"))) { specialCase = true; } if (allBcxFiles.Length == 1 && allBcxFiles[0].Name == "butterfly_fly.bck" && bmdFiles.All(file => file.Name.StartsWith("butterfly"))) { specialCase = true; } if (allBcxFiles.All(file => file.Name.StartsWith("popo_")) && bmdFiles.All(file => file.Name.StartsWith("popo"))) { specialCase = true; } // If there is only one model or 0 animations, it's easy to tell which // animations go with which model. if (bmdFiles.Length == 1 || allBcxFiles.Length == 0 || specialCase) { foreach (var bmdFile in bmdFiles) { this.ExtractModels_(node, new[] { bmdFile }, allBcxFiles); } return; } if (directory.Name == "montemcommon" || directory.Name == "montewcommon") { foreach (var bmdFile in bmdFiles) { this.ExtractModels_(node, new[] { bmdFile }); } return; } var unclaimedBcxFiles = allBcxFiles.ToHashSet(); var bmdAndBcxFiles = new Dictionary <IFileHierarchyFile, IFileHierarchyFile[]>(); foreach (var bmdFile in bmdFiles) { var prefix = bmdFile.Name; prefix = prefix.Substring(0, prefix.Length - ".bmd".Length); // Blegh. These special cases are gross. { var modelIndex = prefix.IndexOf("_model"); if (modelIndex != -1) { prefix = prefix.Substring(0, modelIndex); } var bodyIndex = prefix.IndexOf("_body"); if (bodyIndex != -1) { prefix = prefix.Substring(0, bodyIndex); } prefix = prefix.Replace("peach_hair_ponytail", "peach_hair_pony"); prefix = prefix.Replace("eggyoshi_normal", "eggyoshi"); } var claimedBcxFiles = unclaimedBcxFiles .Where(bcxFile => bcxFile.Name.StartsWith(prefix)) .ToArray(); foreach (var claimedBcxFile in claimedBcxFiles) { unclaimedBcxFiles.Remove(claimedBcxFile); } bmdAndBcxFiles[bmdFile] = claimedBcxFiles; } //Asserts.True(unclaimedBcxFiles.Count == 0); foreach (var(bmdFile, bcxFiles) in bmdAndBcxFiles) { this.ExtractModels_(node, new[] { bmdFile }, bcxFiles); } }
private void ExtractModelsAndAnimationsFromSceneObject_( IModelDirectory <BmdModelFileBundle> node, IFileHierarchyDirectory directory) { var bmdFiles = directory.Files.Where( file => file.Extension == ".bmd") .OrderByDescending(file => file.Name.Length) .ToArray(); var allBcxFiles = directory .Files.Where( file => file.Extension == ".bck" || file.Extension == ".bca") .ToArray(); var btiFiles = directory.FilesWithExtension(".bti") .ToArray(); // If there is only one model or 0 animations, it's easy to tell which // animations go with which model. if (bmdFiles.Length == 1 || allBcxFiles.Length == 0) { foreach (var bmdFile in bmdFiles) { this.ExtractModels_(node, new[] { bmdFile }, allBcxFiles, btiFiles); } return; } var unclaimedBcxFiles = allBcxFiles.ToHashSet(); var bmdAndBcxFiles = new Dictionary <IFileHierarchyFile, IFileHierarchyFile[]>(); foreach (var bmdFile in bmdFiles) { var prefix = bmdFile.Name; prefix = prefix.Substring(0, prefix.Length - ".bmd".Length); // Blegh. These special cases are gross. { var modelIndex = prefix.IndexOf("_model"); if (modelIndex != -1) { prefix = prefix.Substring(0, modelIndex); } var babyIndex = prefix.IndexOf("_body"); if (babyIndex != -1) { prefix = prefix.Substring(0, babyIndex); } // TODO: Fix animations shared by piantas } var claimedBcxFiles = unclaimedBcxFiles .Where(bcxFile => bcxFile.Name.StartsWith(prefix)) .ToArray(); foreach (var claimedBcxFile in claimedBcxFiles) { unclaimedBcxFiles.Remove(claimedBcxFile); } bmdAndBcxFiles[bmdFile] = claimedBcxFiles; } Asserts.True(unclaimedBcxFiles.Count == 0); foreach (var(bmdFile, bcxFiles) in bmdAndBcxFiles) { this.ExtractModels_(node, new[] { bmdFile }, bcxFiles, btiFiles); } }
private void ExtractModels_( IFileHierarchyDirectory directory, IReadOnlyList <IFileHierarchyFile> bmdFiles, IReadOnlyList <IFile>?bcxFiles = null, IReadOnlyList <IFile>?btiFiles = null, bool allowMultipleAnimatedModels = false ) { Asserts.True(bmdFiles.Count > 0); var outputDirectory = GameFileHierarchyUtil.GetOutputDirectoryForDirectory(directory); var matches = 0; var existingModelFiles = outputDirectory.GetExistingFiles() .Where(file => file.Extension == ".fbx" || file.Extension == ".glb") .ToArray(); foreach (var bmdFile in bmdFiles) { if (existingModelFiles.Any( existingModelFile => { var existingName = existingModelFile.Name.Substring( 0, existingModelFile.Name.Length - existingModelFile.Extension.Length); var bmdName = bmdFile.Name.Substring(0, bmdFile.Name.Length - ".mod".Length); return(bmdName == existingName || bmdName + "_gltf" == existingName); })) { ++matches; } } if (matches == bmdFiles.Count) { this.logger_.LogInformation( $"Model(s) already processed from {directory.LocalPath}"); return; } bcxFiles ??= new List <IFile>(); btiFiles ??= new List <IFile>(); if (bmdFiles.Count == 1) { MessageUtil.LogExtracting(this.logger_, bmdFiles[0]); } else { MessageUtil.LogExtracting(this.logger_, directory, bmdFiles); } try { /*new ManualBmd2FbxApi().Process(outputDirectory, * bmdFiles.Select(file => file.FullName) * .ToArray(), * bcxFiles.Select(file => file.FullName) * .ToArray(), * btiFiles.Select(file => file.FullName) * .ToArray(), * !allowMultipleAnimatedModels, * 60);*/ } catch (Exception e) { this.logger_.LogError(e.ToString()); } this.logger_.LogInformation(" "); }
private void ExtractObject_(IFileHierarchyDirectory directory) { // TODO: What the heck is the difference between these directories? // Is there any besides the model type within? var bdlSubdir = directory.Subdirs.SingleOrDefault(subdir => subdir.Name == "bdl"); var bdlmSubdir = directory.Subdirs.SingleOrDefault(subdir => subdir.Name == "bdlm"); var bmdSubdir = directory.Subdirs.SingleOrDefault(subdir => subdir.Name == "bmd"); var bmdcSubdir = directory.Subdirs.SingleOrDefault(subdir => subdir.Name == "bmdc"); var bmdmSubdir = directory.Subdirs.SingleOrDefault(subdir => subdir.Name == "bmdm"); var bmdOrBdlFiles = ListUtil.ReadonlyConcat( //bdlSubdir?.FilesWithExtension(".bdl").ToArray(), //bdlmSubdir?.FilesWithExtension(".bdl").ToArray(), bmdSubdir?.FilesWithExtension(".bmd").ToArray(), bmdcSubdir?.FilesWithExtension(".bmd").ToArray(), bmdmSubdir?.FilesWithExtension(".bmd").ToArray()); var bckSubdir = directory.Subdirs.SingleOrDefault( subdir => subdir.Name == "bck" || subdir.Name == "bcks"); var bckFiles = bckSubdir?.FilesWithExtension(".bck").ToList(); if (bmdOrBdlFiles.Count == 1 || (bckFiles == null && bmdOrBdlFiles.Count > 0)) { this.ExtractModels_(directory, bmdOrBdlFiles, bckFiles? .Select(file => file.Impl) .ToArray()); } else if (bmdOrBdlFiles.Count > 0) { IOrganizeMethod organizeMethod; switch (directory.Name) { case "Sh": { organizeMethod = new SuffixOrganizeMethod(1); break; } case "Oq": { organizeMethod = new NameMatchOrganizeMethod(directory.Name); break; } case "Ylesr00": { organizeMethod = new PrefixOrganizeMethod(); break; } default: throw new NotImplementedException(); } this.ExtractFilesByOrganizing_(directory, bmdOrBdlFiles.ToArray(), bckFiles, organizeMethod); } }