pretend for a second i'm not using this "thought experiment" to further my own goals.
that goal is rendering 1000s of copies of an ArrayMesh as fast as possible, and make the process of "painting" them on a surface in Godot as easy as possible.
the following is a function that takes an array of MeshInstance3Ds, puts them in a blender, and spits out an ArrayMesh, optionally offset by a position, with vertex data combined into one surface according to the material set to that surface. i've not taken time to figure out how to correct for rotation yet.
the code you're seeing is gentrified to oblivion, but it's functionally identical to mine. i figured you might appreciate verbose names and comments.

## Takes an array of MeshInstance3D and commits the surface data of each mesh
## resource to a single ArrayMesh. Set "origin_position" as the global position of the MeshInstance3D
## the returned ArrayMesh will be handed to. Deal with rotation calculation later.
func consolidate_mesh_3d_surfaces(mesh_array:Array[MeshInstance3D], origin_position:Vector3 = Vector3.ZERO) -> ArrayMesh:
	# if a surface is encountered that features a material not yet in this array: it will be added
	var previous_surface_materials:Array[Material] = []
	var surface_arrays:Array[Array]
	
	for mesh_index in mesh_array.size():
		var mesh_instance:MeshInstance3D = mesh_array[mesh_index]
		for surface_index in mesh_instance.mesh.get_surface_count():
			var surface_array:Array = mesh_instance.mesh.surface_get_arrays(surface_index)
			# look for this surface of mesh_instance's mesh resource in the previous_surface_array
			# the returned integer, if above -1, will indicate the array inside surface_arrays this 
			# surface_array will be combined with
			var index:int = previous_surface_materials.find(mesh_instance.mesh.surface_get_material(surface_index))
			# offset each vertex position by difference between the mesh_instance position and given "origin_position"
			for vertex_index in surface_array[Mesh.ARRAY_VERTEX].size():
				surface_array[Mesh.ARRAY_VERTEX][vertex_index] += mesh_instance.position - origin_position
			if index > -1:
				# value of index is over -1: it features a surface that's already been seen
				# increment the elements of the index array so they continue referring to the correct
				# vertices after merging with the existing surface array inside surface_arrays
				for index_index in surface_array[Mesh.ARRAY_INDEX].size():
					surface_array[Mesh.ARRAY_INDEX][index_index] += surface_arrays[index][Mesh.ARRAY_VERTEX].size()
				# merge
				surface_arrays[index][Mesh.ARRAY_VERTEX].append_array(surface_array[Mesh.ARRAY_VERTEX])
				surface_arrays[index][Mesh.ARRAY_NORMAL].append_array(surface_array[Mesh.ARRAY_NORMAL])
				surface_arrays[index][Mesh.ARRAY_TANGENT].append_array(surface_array[Mesh.ARRAY_TANGENT])
				surface_arrays[index][Mesh.ARRAY_TEX_UV].append_array(surface_array[Mesh.ARRAY_TEX_UV])
				surface_arrays[index][Mesh.ARRAY_INDEX].append_array(surface_array[Mesh.ARRAY_INDEX])
			else:
				# index was -1, it contains a newly found material resource
				# remember it in previous_surface_materials array
				previous_surface_materials.push_back(mesh_instance.mesh.surface_get_material(surface_index))
				# introduce this surface_array to surface_arrays
				surface_arrays.push_back(surface_array)
	
	# create a new ArrayMesh resource
	var array_mesh:ArrayMesh = ArrayMesh.new()
	# commit each surface array in "surfaces" to "array_mesh"
	for surface_index in surface_arrays.size():
		array_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, surface_arrays[surface_index])
		# set corresponding material to this surface
		array_mesh.surface_set_material(surface_index, previous_surface_materials[surface_index])
	
	# return ArrayMesh resource
	return array_mesh

the plugin functions by blasting a raycast from the camera, then scattering that raycast around the collision point, its target_position pointing directly down, a number of times, and planting a MeshInstance3D at every collision point. when a "commit" button is pressed, those MeshInstance3Ds are put through this function and the resulting ArrayMesh is then applied to whatever MeshInstance3D was specified by the user (me) in a LineEdit before hitting the button.

packrat changed the title to you're invited to think of some ways to optimize this SURFACE CONSOLIDATOR loop .