Jump to content

All meshes loaded from an OBJ file have a position of 0,0,0


Recommended Posts


I have an OBJ file that contains a vehicle.  The vehicle has multiple layers to it (left front tire, passenger door, etc), each one loading up as its own mesh.  I am starting to notice that, though the model loads correctly and looks fine, the mesh.positions are all listed as [0,0,0].  When trying to cast a ray from some arbitrary origin vector to the closest mesh, they all shoot to the world's 0,0,0 and, either miss the target completely (no hit) or hit some other mesh that's in the way.

Any thoughts on how to find the real locations of these meshes?

Thank you.

Link to comment
Share on other sites

I would guess something with pivots, if there are multiple meshes at position {0,0,0}.  In which case the real location would be the opposite of the pivot?  Those depend on how your OBJ file is generated:
Easy way to test is to rotate one of the meshes and see how it rotates or have a look in the inspector.

Link to comment
Share on other sites

Does .position and getAbsolutePosition() match?

As Brian pointed out, it might very well be that the pivot points of the meshes are offset from 0,0,0. This can happen in the 3D-modeling software when you export, reset transforms etc. but is useless if you plan on animating the individual models. You can open your model in Blender, or use BabylonJS to change the pivots to the center of the different meshes.

Link to comment
Share on other sites

Have you created the mesh yourself or are you using someone else's file?

I used some Blender files I found recently but then decided to use Sketchup to create a file which then went in to Blender and then had to play with it in Blender and finally export to .babylon format.  I guess you can inspect the mesh structure similar to the way you can do so in Blender?

Link to comment
Share on other sites

I apologize, I didn't give enough information.  Here's situation. 

1. Object is loaded.  This works.

2. I read some data points in from a database and create spheres at those locations.  This works.

3. Determine closest mesh to sphere.  This works.

4. Determine closest point on closest mesh to sphere.  This is where I get the 0,0,0  Doesn't work so the rest don't either

5. Cast ray from sphere to closest point on closest mesh.

The meshes are stationary and will not move, rotate, translate, etc.  The only movement is from the camera. 

Its probably just a matter of me coding this wrong but here's a playground illustrating it:  https://www.babylonjs-playground.com/#TRAIXW#16

In the playground I'm getting them to shoot to the mesh. but it is still hitting the center and not the closest point on the mesh.  So that's one problem.  Still having issues with my models having positions of 0,0,0 though on my project.  Wish I could post those.

Both rays shoot the center of the meshes instead of the closest point.

eps, I inherited the meshes. 

Raggar, I checked and all the pivot points are centered to object, but I guess I don't understand why it matters if there will be no transformations on the meshes.


Thanks all


edit: side note... for some reason the rays are only visible from certain angles so you'll have to rotate.  not sure why that is.


Link to comment
Share on other sites

Ok, forget it all.  I'm dumb.  I'm so new to this still that I was making things overcomplicated and also noticed i was looking at(and using) the wrong set of coordinates.  Yes, the meshes were returning 0,0,0; however, the closest facet i calculated had real values that I can work with.

Thanks all.  Helped a lot to work it through.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...