Skip to content

Add a function to merge multiple ArrayMeshes together #107838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Jun 22, 2025

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.

@Zylann
Copy link
Contributor

Zylann commented Jun 22, 2025

I found there is SurfaceTool.append_from https://docs.godotengine.org/en/stable/classes/class_surfacetool.html#class-surfacetool-method-append-from which sounds like it's almost that, but only one surface at a time and maybe it has some more stuff it doesn't support

@aaronfranke
Copy link
Member Author

@Zylann I found that too, but it doesn't merge most data, it only merges the vertices.

@Ivorforce
Copy link
Member

Looks like mesh.cpp has no code owner. Is this core or rendering?

@aaronfranke aaronfranke requested review from a team June 22, 2025 10:39
@lawnjelly
Copy link
Member

See also #61568 which is the comprehensive solution in 3.x.

There I put all the merging functionality into merging_tool.h because there's a lot of associated stuff (like making sure meshes are compatible before merging etc).

@aaronfranke
Copy link
Member Author

@lawnjelly I'm not sure this needs to be in another class, it can be done in one function under 200 lines. As for making sure the meshes are compatible, it does this on a per-surface basis during merge by checking the mesh format - it's not exactly trivial, but it's simple enough to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants