# How do I have my obj loaded properly centered at 0,0,0 and scaled?

**URL:** <https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093>\
**Category:** Questions\
**Created:** [May 25, 2021, 5:23am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093 "2021-05-25T05:23:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [May 25, 2021, 5:23am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/1 "2021-05-25T05:23:14Z")

</div>

Hi, guys!

I have been playing with Babylon.js for the last week or so and having so much fun!!

Though, I am having a trouble looking for my object every time I load a different one.

This [example on Babylon PlayGround](https://playground.babylonjs.com/#C1QH9J#2) is somehow at the origin (0, 0, 0) and its scale is beautifully appropriate.

However, when I loaded an object that I downloaded from “[sketchfab.com](http://sketchfab.com),” it is located way up in the Y axis. Of course, I can manually type in values for camera and target position and drag and zoom in/out to find objects that I load every time, but it is just so frustrating.

Here is what I did:

```
var createScene = function () {
  // This creates a basic Babylon Scene object (non-mesh)
  const scene = new BABYLON.Scene(engine);
  var camera = new BABYLON.ArcRotateCamera("camera", 2.372, 1, 0.5, BABYLON.Vector3.Zero(), scene);
  camera.upperRadiusLimit = 0.5;
  camera.lowerRadiusLimit = 0.25;
  camera.minZ = 0.01;
  // Attaches the camera to the canvas
  camera.attachControl(canvas, true);
  
  // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 0, 0), scene);
  
  // Default intensity is 1. Let's dim the light a small amount
  light.intensity = 1;
  light.range = 10;
  
  var assetsManager = new BABYLON.AssetsManager(scene);
  var meshTask = assetsManager.addMeshTask("shoe task", "", "https://assets.babylonjs.com/meshes/", "shoe_variants.glb");
  // var meshTask = assetsManager.addMeshTask("shoe task", "", "./hoodie-v2/source/Hoodie/", "Hoodie.obj");
  meshTask.onSuccess = function (task) {
    task.loadedMeshes[0].position = BABYLON.Vector3.Zero();
  }
  
  assetsManager.onFinish = function (tasks) {
    engine.runRenderLoop(function () {
      scene.render();
    });
  };
  
  assetsManager.load();
  
  showAxis(900);
  
  return scene;
};

```

I tried BABYLON.Vector3.Zero(); so that hopefully, it is centered when I load it, but it is not working. Also, sometimes, the object is way too big.

Is there a way for me to load objects with properly centered with adequately scaled so it is fit right in the canvas?

Thank you so much!! I hope you guys enjoy coding with Babylon!!

Have a wonderful day!!

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [May 25, 2021, 6:07am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/2 "2021-05-25T06:07:45Z")

</div>

hi @DOEHOONLEE there is something about that mesh. I’m turning my computer off now, though. I would try loading it in the scene explorer to learn more what is going on. I can’t see it right now why it’s not working, but this code I’ve used in the past for scaling - maybe it helps a bit (you can also create a transform node and parent that to the meshes without parents, which is what I do):  
[Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#MUPWVF)

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [May 25, 2021, 10:20am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/3 "2021-05-25T10:20:53Z")

</div>

The simplest way for all such models is to open it in some 3D editor like Blender, then set mesh origin as you need (one may add scaling to taste).

---

<div class="post-metadata">

**Author:** ![Faber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/faber/32/15884_2.png) [@Faber](https://forum.babylonjs.com/u/Faber)\
**Post date:** [May 25, 2021, 10:16pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/4 "2021-05-25T22:16:16Z")

</div>

Hello there !

I’ve encountered some similar issues when trying to import .glb files I created with blender.

When you import a file, even if there is only one mesh in it, you’ll get an array of several meshes (called `task.loadedMeshes` in your case). I’m fairly new so I don’t exactly know why, but Babylon wraps your imported mesh as the child of a “\_ _root_ \_” mesh.

There may even be **several imbricated parents** before you find your actual mesh, which is what’s happening in your playground. You can see you got 3 successive parents on your import :

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/b/0/b08b8c76c3c47a5e8a0f9edc300907da90301b0d.jpeg)

And one of them has some transformations you might not want.  
In your playground example for instance :

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/a/1a8850507c0d7af7c9bd8ce17f100559995906dd.jpeg)

I think this structure after import is **an artefact of the way your mesh was created and exported**. I don’t know sketchfab, but I know in Blender I have to pay attention to edit the scale and the position of my mesh in ‘edit’ mode, to alter its geometry, and not in ‘object’ mode. Otherwise, this will create some offset transformations on the \_ _root_ \_ mesh, leading to **unexact scaling** , or **offcentered meshes**.

I tried to put my imports in a **separate async method** , and setting its **scaling** to `new BABYLON.Vector3(1, 1, 1)`, just in case. You can also set its parent to another mesh than the default \_ _root_ \_ object, and then (not before) delete it using `dispose()`.

That worked for me and I then had the same transforms in the Babylon scene as in my Blender software.

[EDIT] - Also this kinda is my first reply to a dev forum so if anything’s not clear or just sounds wrong about what I said, please tell me ! 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 25, 2021, 10:53pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/5 "2021-05-25T22:53:19Z")

</div>

> [@Faber](#):
>
> Also this kinda is my first reply to a dev forum so if anything’s not clear or just sounds wrong about what I said, please tell me

Thanks for that!

---

<div class="post-metadata">

**Author:** ![shaderbytes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shaderbytes/32/174_2.png) [@shaderbytes](https://forum.babylonjs.com/u/shaderbytes)\
**Post date:** [May 25, 2021, 11:17pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/6 "2021-05-25T23:17:10Z")

</div>

i personally remove the root mesh objects of all my loaded .glb files because I hate them as well. We need to do a democratic vote and send the results to Khronos Group because I simply cannot for the life of me even fathom even once good reason my. " \_ _root_ \_" for every mesh … no thanks.

---

<div class="post-metadata">

**Author:** ![JohnK](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/johnk/32/26764_2.png) [@JohnK](https://forum.babylonjs.com/u/JohnK)\
**Post date:** [May 26, 2021, 1:02am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/7 "2021-05-26T01:02:11Z")

</div>

> [@shaderbytes](#):
>
> We need to do a democratic vote and send the results to Khronos Group

Nothing to do with the Khronos Group.

> [@Does a glb have to come in with a \_\_root\_\_ node?](https://forum.babylonjs.com/t/does-a-glb-have-to-come-in-with-a-root-node/11663/2):
>
> We need it because it conveys the right to left hand conversion

---

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [May 26, 2021, 2:51am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/8 "2021-05-26T02:51:04Z")

</div>

That sounds like a very nice and convenient way!! Thanks!! 🙂

---

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [May 26, 2021, 2:56am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/9 "2021-05-26T02:56:02Z")

</div>

Woah~!! What a thorough explanation! Since I am new to Babylon, this seems very confusing for me at this moment though. Let me try your way and I’ll get back to you again. It might take some time xD

Big thank to you!!

---

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [May 26, 2021, 2:59am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/10 "2021-05-26T02:59:19Z")

</div>

Some of the obj files I downloaded from sketchfab did not have _root_ mesh and the arrays length were 1 only ☹ Is this possible?

---

<div class="post-metadata">

**Author:** ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)\
**Post date:** [May 26, 2021, 3:49am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/11 "2021-05-26T03:49:29Z")

</div>

Yes. A single mesh is not uncommon for .obj files 🙂

---

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [May 26, 2021, 6:36am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/12 "2021-05-26T06:36:11Z")

</div>

I see. I guess some free downloadable .obj are sometimes differently structured.

---

<div class="post-metadata">

**Author:** ![Faber](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/faber/32/15884_2.png) [@Faber](https://forum.babylonjs.com/u/Faber)\
**Post date:** [May 26, 2021, 7:48am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/13 "2021-05-26T07:48:12Z")

</div>

> [@DOEHOONLEE](#):
>
> Some of the obj files I downloaded from sketchfab did not have _root_ mesh and the arrays length were 1 only ☹ Is this possible?

I never met this case, but I guess it is possible.  
As JohnK said above, the \_ _root_ \_ apparently has a purpose of handling some Babylon aspect.

> [@Does a glb have to come in with a \_\_root\_\_ node?](https://forum.babylonjs.com/t/does-a-glb-have-to-come-in-with-a-root-node/11663/2):
>
> We need it because it conveys the right to left hand conversion

I suppose in some cases this purpose is not needed (maybe the mesh is already in left hand mode) and thus the \_ _root_ \_ node won’t be necessary. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![shaderbytes](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shaderbytes/32/174_2.png) [@shaderbytes](https://forum.babylonjs.com/u/shaderbytes)\
**Post date:** [May 26, 2021, 12:43pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/14 "2021-05-26T12:43:45Z")

</div>

> [@Does a glb have to come in with a \_\_root\_\_ node?](https://forum.babylonjs.com/t/does-a-glb-have-to-come-in-with-a-root-node/11663/2):
>
> We need it because it conveys the right to left hand conversion

haha , ok i get that , although I hate that as well. When I build a scene in blender and then use babylon I want all my objects transform properties to be the same and same axis system.

If i export y-up … an identity transform becomes -1 xscale and 90deg xRotation . So they are not the same as my scene. So i create a single root node that counters this transform , then i export normal axis from blender and add all imports into that root object.

I also then trash the ` __root__ ` object on import.

So now my babylon scene ( well inside the custom root node ) is the same as blender … same “root” objects names, same hierarchy for each , transform values the same , axis the same. life is now sweet again

I do know this is a horrible hack using a single custom root node but hey, to me , this seems a better solution than adding a ` __root__ ` to every imported object.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [May 26, 2021, 12:49pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/15 "2021-05-26T12:49:46Z")

</div>

> [@Does a glb have to come in with a \_\_root\_\_ node?](https://forum.babylonjs.com/t/does-a-glb-have-to-come-in-with-a-root-node/11663/2):
>
> We need it because it conveys the right to left hand conversion

Approved. I can endorse this request. 😀

---

<div class="post-metadata">

**Author:** ![trusktr](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/trusktr/32/840_2.png) [@trusktr](https://forum.babylonjs.com/u/trusktr)\
**Post date:** [July 28, 2023, 7:35pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/16 "2023-07-28T19:35:31Z")

</div>

Here’s a function to center mesh content in a node:

> [@Mesh not importing in the center of scene](https://forum.babylonjs.com/t/mesh-not-importing-in-the-center-of-scene/10383/5):
>
> Here’s a function to center mesh content in a node: function centerMeshContent(node: TransformNode) { const { min, max } = node.getHierarchyBoundingVectors(); const halfRange = max.subtract(min).scaleInPlace(0.5); const currentCenter = min.add(halfRange); const offset = currentCenter.negate(); traverseNodes(node, (n) =\> { if (n instanceof Mesh) { n.position.addInPlace(offset); // The bounding box is world-…

---

<div class="post-metadata">

**Author:** ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)\
**Post date:** [July 28, 2023, 7:42pm UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/17 "2023-07-28T19:42:56Z")

</div>

If you have an app where you don’t know which object will come in, and in what condition, or even which format it is, you could utilize boundingBox of the object.

Specifically, you would calculate bounding box from every mesh in the scene, and you will find the center point of the object/structure or whatever.

I already explained the process in some of the previous threads with playground example.

> [@Is there an easy way to ensure a model's size and position is displayed consistently across several device form-factors?](https://forum.babylonjs.com/t/is-there-an-easy-way-to-ensure-a-models-size-and-position-is-displayed-consistently-across-several-device-form-factors/16433/13):
>
> Hi. I am just throwing one solution that I usually use. I had several project where I had to deal with huge amount of different object fetched from storage, where I don’t know what’s the model, which format is model etc. This solution doesn’t require updating the position of the camera, as I usually find that not consistent for each possible model. Basically, what I do is I create one box using Babylon, and I set the size of that box to be whichever is the biggest dimension of the mesh inside …

> [@Display model in the center](https://forum.babylonjs.com/t/display-model-in-the-center/32738/32):
>
> Here is the working playground (to be honest, I just copy pasted everything from the existing Playground I posted in the above mentioned thread). The reason why your playground is not working is because you didn’t implement anything that I mentioned in the comment and in the existing playground (fully commented on each step). smiley Basically the logic is, you use the provided method totalBoundingInfo, which basically loops through every mesh in the scene, looks at the boundingBox values a…

Hopefully it helps you out.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [July 29, 2023, 6:31am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/18 "2023-07-29T06:31:19Z")

</div>

I believe that question has been answered (multiple times) and this old thread should have been closed.  
I believe the answer from @nogalo is correct. There are variants of the same but the logic remains and is rather well explained in the linked post (my opinion).  
May be someone from the Team would kindly close this topic. Mark the above as solution? cc @sebavan @carolhmj Thank you,

---

<div class="post-metadata">

**Author:** ![DOEHOONLEE](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/doehoonlee/32/16289_2.png) [@DOEHOONLEE](https://forum.babylonjs.com/u/DOEHOONLEE)\
**Post date:** [August 1, 2023, 3:14am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/19 "2023-08-01T03:14:08Z")

</div>

Thank you all for wonderful solutions!! 🙂

I am not sure if I can close this thread.

---

<div class="post-metadata">

**Author:** ![mawa](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mawa/32/12384_2.png) [@mawa](https://forum.babylonjs.com/u/mawa)\
**Post date:** [August 1, 2023, 8:59am UTC](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093/20 "2023-08-01T08:59:36Z")

</div>

> [@DOEHOONLEE](#):
>
> I am not sure if I can close this thread.

No, you can’t… and neither can I. Only the Team can, so don’t worry about it 😃  
Glad you found a solution to your problem and have a great day 🕶

**Edit:** Oops. My apologies, didn’t realize this was your thread. So you did it. By marking it as a solution.  
All good. Thanks for that 🙏

[Next page](https://forum.babylonjs.com/t/how-do-i-have-my-obj-loaded-properly-centered-at-0-0-0-and-scaled/21093.md?page=2)
