Skip to content

Commit

Permalink
Automatically fix duplicate anchor mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
Insprill committed Jul 3, 2023
1 parent 1af4bf0 commit cc8c247
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 31 additions & 0 deletions GaugeBundleBuilder/Assets/Scripts/AssetBundleBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static void BuildAssetBundles()
importer.SaveAndReimport();
}

FixAnchor();

AssetBundleBuild build = new AssetBundleBuild {
assetBundleName = ASSET_BUNDLE_NAME,
assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(ASSET_BUNDLE_NAME)
Expand Down Expand Up @@ -97,6 +99,35 @@ private static IEnumerable<KeyValuePair<string, string>> GetMeshPaths()
return File.ReadAllLines(MESH_LIST_PATH)
.Select(s => new KeyValuePair<string, string>(s, $"{MESH_PATH}/{s}"));
}

/// <summary>
/// Finds all meshes with the name "Anchor" and deletes all but the one with the most vertices.
/// This is due to Derail Valley having two meshes named 'Anchor'. One is a pair of anchors, and the other is a single anchor.
/// </summary>
private static void FixAnchor()
{
const string anchor = "Anchor";
Mesh[] anchorMeshes = AssetDatabase.FindAssets(anchor)
.Select(AssetDatabase.GUIDToAssetPath)
.Distinct()
.Where(assetPath => Path.GetFileName(assetPath).StartsWith(anchor))
.Select(AssetDatabase.LoadAssetAtPath<Mesh>)
.OrderByDescending(mesh => mesh.vertices.Length)
.ToArray();

if (anchorMeshes.Length < 2)
{
Debug.LogWarning($"Only found {anchorMeshes.Length} anchor mesh(s)!");
return;
}

for (var i = anchorMeshes.Length - 1; i >= 1; i--)
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(anchorMeshes[i]));

AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(anchorMeshes[0]), anchor);

AssetDatabase.Refresh();
}
}
}
#endif
1 change: 0 additions & 1 deletion GaugeBundleBuilder/Assets/Scripts/MeshDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ private static void RunAssetStudio(string installDirectory)
string assetList = string.Join(",",
File.ReadLines(AssetBundleBuilder.MESH_LIST_PATH).Select(s => Path.ChangeExtension(s, null))
);
Debug.Log(assetList);
ProcessStartInfo startInfo = new ProcessStartInfo {
FileName = "dotnet",
Arguments = $"Assets/Scripts/AssetStudio/AssetStudioModCLI.dll \"{installDirectory}\" -o \"{AssetBundleBuilder.MESH_PATH}\" -t mesh --filter-by-name \"{assetList}\"",
Expand Down

0 comments on commit cc8c247

Please sign in to comment.