Bladetrick Posted November 21, 2018 Share Posted November 21, 2018 hello! 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. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted November 21, 2018 Share Posted November 21, 2018 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: https://doc.babylonjs.com/how_to/pivots Easy way to test is to rotate one of the meshes and see how it rotates or have a look in the inspector. Quote Link to comment Share on other sites More sharing options...
Raggar Posted November 21, 2018 Share Posted November 21, 2018 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. Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 21, 2018 Author Share Posted November 21, 2018 Both position and getAbsolutePosition() come out with 0, 0, 0 for all meshes Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 21, 2018 Author Share Posted November 21, 2018 this OBJ file was generated with 3DS Max. Another odd thing i noticed is that there are multiples of each mesh. Like there are 5-7 meshes that get generated for steering wheel, for example Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 21, 2018 Share Posted November 21, 2018 It would be great to have a playground as it is almost impossible to help without it on this kind of issues, Thanks Quote Link to comment Share on other sites More sharing options...
Raggar Posted November 21, 2018 Share Posted November 21, 2018 In 3Ds Max, try changing the pivots for all the meshes to "Center to object". You can do this by simply selecting everything at once. Quote Link to comment Share on other sites More sharing options...
eps Posted November 21, 2018 Share Posted November 21, 2018 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? Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 27, 2018 Author Share Posted November 27, 2018 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. Quote Link to comment Share on other sites More sharing options...
Bladetrick Posted November 27, 2018 Author Share Posted November 27, 2018 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. Sebavan 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.