Position of a merged mesh

I have a mesh that I build up of multiple boxes where I change the position of each box so that all boxes together form my desired shape. I then merge all those boxes together using let mergedBoxes = BABYLON.Mesh.MergeMeshes(boxes) where boxes is an array holding all my boxes.
I noticed that the position of mergedBoxes is not in the center of all boxes and also not in the center of any box that was merged.
Here’s a simple PG that reproduces this: https://playground.babylonjs.com/#E0XKDU#1
I have one box at (10, 0, 0) and one box at (10, 0, 10), and after merging their position seems to be (0, 0, 0).
I’m pretty sure this is expected behaviour, but I need the position that is at the center of those boxes because I have an arrow that points to that merged mesh, and it doesn’t point at the right position now.

I thought about taking the positions of all boxes that I merge and averaging out their x,y and z positions so that I have a position for the arrow to point to, but I’d prefer an approach that changes the mergedMesh’s position to what I want

Not entirely sure if this is what you are after. You have to find the average position of all the boxes and use this to apply a pivot matrix.

You can read an explanation here which is an old and out of date set of documentation


Along with this which is the current documentation which explains the breaking change.


Thank you a lot, that’s exactly what I was looking for! Funny enough I was looking through both the doc articles you linked earlier for a different issue, but I didn’t realize I could also use it for this issue.

1 Like