Add a function to merge multiple ArrayMeshes together #107838
+210
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I needed the ability to merge multiple ArrayMeshes together into one ArrayMesh in a glTF context, and I searched the APIs of ArrayMesh and SurfaceTool only to find that such a thing does not exist yet. This PR implements it.
This function will be important for godotengine/godot-proposals#4630. This PR does not expose anything in the editor for merging meshes, it just adds the underlying functionality to ArrayMesh. Because godotengine/godot-proposals#4630 exists I don't think I need to open a separate proposal for this, but a full solution to godotengine/godot-proposals#4630 will involve showing stuff in the editor.
This is a highly requested feature. See godotengine/godot-proposals#182, godotengine/godot-proposals#901, godotengine/godot-proposals#7970, godotengine/godot-proposals#12110, https://forum.godotengine.org/t/combining-meshes/55687, https://forum.godotengine.org/t/combine-multiple-meshinstance3d-into-1-meshinstance3d/88140, https://godotforums.org/d/32740-merging-array-meshessubtracting-from-array-meshes-with-csg, https://www.reddit.com/r/godot/comments/nfc22a/how_to_join_3d_meshes_from_code/, and more.
I have tested this PR on a simple mesh, including duplicating surfaces, deduplicating surfaces, negative scale, and positive scale, and at least in my testing it works correctly.