Trying to merge BufferGeometries while preserving transformations

Hello!

So I’m trying to take a bunch of objects that are in a loaded gltf scene and merge them together. The objects are scattered around the scene. When traversing the gltf, I push all the meshes into an array, and then try to do this:

if (meshes.length) {
	let mergedGeom = mergeBufferGeometries(meshes.map(m => m.geometry.clone().applyMatrix4(m.matrixWorld)), true);
	let mergedMesh = new THREE.Mesh(mergedGeom, meshMaterial);

	// just some arbitrary coords so that I can see the mesh immediately after loading the test scene
	mergedMesh.position.x = 11.1863;
	mergedMesh.position.y = 0.5;
	mergedMesh.position.z = -15.0943;

	scene.add(mergedMesh);
}

Similarly to how it was advised by Mugen87 here.

Unfortunately, the objects appear to be all in one place. Am I missing something here?

I could imagine that the world matrix is not up-tp-date. Make sure to recompute the world matrices before you perform the merge. If the meshes are part of the scene, it’s sufficient to call scene.updateMatrixWorld() once since it will process the entire scene graph. If the meshes are not added to the scene yet, you have to call this method for each mesh.

Thanks very much, that’s indeed what was missing.