Search code examples
javascriptbabylonjs

How to get mesh center in babylonjs?


After double clicking on a mesh I need to find out what is the centre of the mesh regarding to its boundary box

    window.addEventListener("dblclick", function (event) {
        var pickResult = scene.pick(scene.pointerX, scene.pointerY);
        var mesh = pickResult.pickedMesh;
        //var centerPosition = mesh.GetCenter(); <-- what is the center             
    });

Solution

  • Once you have the mesh, you can call mesh.getBoundingInfo

    On a bounding info object you have a bounding box and a bounding sphere. The sphere provides the mesh center in local and world coordinates

    http://doc.babylonjs.com/api/classes/babylon.boundinginfo