title: Center mesh at world origin in Babylon.js
body: <p>I have a set of 3D face scan obj files I need to display, and I am looking to center each mesh in the world origin.</p>
  
  <p>I have an example below with one of the actual meshes, but if you look, I just tweaked some numbers and rotated it to look right:</p>
  
  <pre><code>    mesh.position.x = .1;
      mesh.position.y = .46;
      mesh.position.z = 0;
      mesh.setPivotPoint(mesh.getBoundingInfo().boundingBox.center);
      mesh.rotate(BABYLON.Axis.Y, -(Math.PI / 2), BABYLON.Space.WORLD);
      mesh.rotate(BABYLON.Axis.X, -(Math.PI / 2), BABYLON.Space.WORLD);
  </code></pre>
  
  <p>I enabled the bounding box and that is correct.  </p>
  
  <p><strong>How can I render each one centered on the origin without magic numbers?</strong></p>
  
  <p>Thanks!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var canvas = document.getElementById("renderCanvas"); // Get the canvas element
  var engine = new BABYLON.Engine(canvas, true); 
  
  
  
  var createScene = function () {
      var scene = new BABYLON.Scene(engine);
  
      
      scene.clearColor = new BABYLON.Color3.FromInts(1, 1, 1);
  
  
      //Adding a light
      var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(20, 20, 100), scene);
  
      //Adding an Arc Rotate Camera
      // var camera = new BABYLON.ArcRotateCamera("Camera", 3, 0, .7, BABYLON.Vector3.Zero(), scene);
      var camera = new BABYLON.ArcRotateCamera("Camera", -(Math.PI/2), Math.PI/2, .5, BABYLON.Vector3.Zero(), scene);
  
      // camera.panningAxis = new BABYLON.Vector3(0, 1, 0);
      camera.attachControl(canvas, false);
  
  
  
      BABYLON.SceneLoader.ImportMesh("" , "https://dl.dropboxusercontent.com/s/n4gwsdn9en6pi86/", "test_ms_simple.obj", scene, function (newMeshes) {
          
          camera.target = BABYLON.Vector3.Zero();
          // var mesh = newMeshes[0].getChildMeshes()[0];
          var mesh = newMeshes[0];
          mesh.showBoundingBox = true;
      
          mesh.position.x = .1;
          mesh.position.y = .46;
          mesh.position.z = 0;
          mesh.setPivotPoint(mesh.getBoundingInfo().boundingBox.center);
          mesh.rotate(BABYLON.Axis.Y, -(Math.PI / 2), BABYLON.Space.WORLD);
          mesh.rotate(BABYLON.Axis.X, -(Math.PI / 2), BABYLON.Space.WORLD);
  
          camera.minZ = 0;
          camera.wheelPrecision = 500;
  
      });
  
    
  
  
  
      // Move the light with the camera
      scene.registerBeforeRender(function () {
          light.position = camera.position;
      });
      // showAxis(10);
      return scene;
  }
  
  
  
   
        var scene = createScene(); //Call the createScene function
  
        // Register a render loop to repeatedly render the scene
        engine.runRenderLoop(function () {
                scene.render();
                
        });
  
        // Watch for browser/canvas resize events
        window.addEventListener("resize", function () {
                engine.resize();
        });
  
  
  function showAxis(size) {
      var makeTextPlane = function(text, color, size) {
          var dynamicTexture = new BABYLON.DynamicTexture("DynamicTexture", 50, scene, true);
          dynamicTexture.hasAlpha = true;
          dynamicTexture.drawText(text, 5, 40, "bold 36px Arial", color , "transparent", true);
          var plane = BABYLON.Mesh.CreatePlane("TextPlane", size, scene, true);
          plane.material = new BABYLON.StandardMaterial("TextPlaneMaterial", scene);
          plane.material.backFaceCulling = false;
          plane.material.specularColor = new BABYLON.Color3(0, 0, 0);
          plane.material.diffuseTexture = dynamicTexture;
      return plane;
       };
      var axisX = BABYLON.Mesh.CreateLines("axisX", [ 
        BABYLON.Vector3.Zero(), new BABYLON.Vector3(size, 0, 0), new BABYLON.Vector3(size * 0.95, 0.05 * size, 0), 
        new BABYLON.Vector3(size, 0, 0), new BABYLON.Vector3(size * 0.95, -0.05 * size, 0)
        ], scene);
      axisX.color = new BABYLON.Color3(1, 0, 0);
      var xChar = makeTextPlane("X", "red", size / 10);
      xChar.position = new BABYLON.Vector3(0.9 * size, -0.05 * size, 0);
      var axisY = BABYLON.Mesh.CreateLines("axisY", [
          BABYLON.Vector3.Zero(), new BABYLON.Vector3(0, size, 0), new BABYLON.Vector3( -0.05 * size, size * 0.95, 0), 
          new BABYLON.Vector3(0, size, 0), new BABYLON.Vector3( 0.05 * size, size * 0.95, 0)
          ], scene);
      axisY.color = new BABYLON.Color3(0, 1, 0);
      var yChar = makeTextPlane("Y", "green", size / 10);
      yChar.position = new BABYLON.Vector3(0, 0.9 * size, -0.05 * size);
      var axisZ = BABYLON.Mesh.CreateLines("axisZ", [
          BABYLON.Vector3.Zero(), new BABYLON.Vector3(0, 0, size), new BABYLON.Vector3( 0 , -0.05 * size, size * 0.95),
          new BABYLON.Vector3(0, 0, size), new BABYLON.Vector3( 0, 0.05 * size, size * 0.95)
          ], scene);
      axisZ.color = new BABYLON.Color3(0, 0, 1);
      var zChar = makeTextPlane("Z", "blue", size / 10);
      zChar.position = new BABYLON.Vector3(0, 0.05 * size, 0.9 * size);
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdn.babylonjs.com/babylon.js"&gt;&lt;/script&gt;
  &lt;script src="https://preview.babylonjs.com/loaders/babylon.objFileLoader.min.js"&gt;&lt;/script&gt;
  
  
  &lt;canvas id="renderCanvas" width=350 height=350&gt;</code></pre>
  </div>
  </div>
  </p>