Jump to content

Every mesh imported from blender has the same position


Recommended Posts

We are importing several meshes from blender. Even though they're clearly in different places, the mesh.position for all the meshes is the same,
                    var m = new BABYLON.Matrix();
                    var v = BABYLON.Vector3.TransformCoordinates(mesh.position, m);
Above 4 results are same for every mesh.
It's as if every mesh has it's own origin and it's position is being calculated with respect to that.
What's happening here?

Link to comment
Share on other sites

Also, what could be a possibility, try checking mesh.getPivotMatrix(); if they all have different locations on the pivot matrix that will change its location.


Since the complete matrices chain is: PivotMatrix x Scaling x Rotation x Translation


Just a thought

Link to comment
Share on other sites

In my opinion, BitofGold (love the name) has "a" correct answer, depending on how you have set up your scenes and how you are importing scene elements from Blender. If you are importing a single mesh, it will always import to a position located at the origin by default. And without viewing your Blender files, we have no idea what the issue might be, other than what BitofGold has expressed from their experience. However, if you are importing one scene with multiple meshes, then they should retain their positions in reference to the origin. But exporting individual meshes should not retain their position in relation to the origin by default.


If you wish to maintain an object's position in cartesian space when exported individually, one way to do this is to parent the object to a null or other object's axis located at the origin, then the hierarchy should maintain the offset, and you will be able to manipulate the object's local transforms as normal. I haven't tried this myself, but in all my experience, I would be completely baffled if parenting to any null or other object with an axis, doesn't import the object correctly in it's relationship to it's parent. But again, I haven't personally tried this from Blender, and perhaps this isn't a solution for your needs. Based upon what you've posted, I would recommend merging all objects into a single Blender scene, and they should then maintain their offsets to the origin. However, if this doesn't work, then you can certainly parent them all to a single object such as a null, and again, a hierarchy will almost always maintain all local offsets to their parent, and will also allow you to transform all objects together with a single position change on the parent - if this is something you may want to do in your scene - either for animation, or to avoid setting different positions for lights, cameras, and other elements and proceedures - if you already have objects and elements in a scene and are adding additional objects upon import.



Link to comment
Share on other sites

I cannot find any source code which backs up that the behavior of SceneLoader.ImportMesh processes a mesh's position any differently then SceneLoader.Load / SceneLoader.Append.


SceneLoader.ImportMesh calls plugin.importMesh, passing the array to put the reconstituted meshes in.  SceneLoader.ImportMesh does not do anything the array afterward, except forward it on to the on success callback.


plugin.importMesh calls Mesh.Parse at the very end of the loop it has and never refers to the mesh once parsed.


Mesh.Parse assigns the meshes position with the value from the parsed data coming from the file.  Never touches it again.


I needed to do this checking, since I do not really use .babylon files.   I do not really care, but did not want this thread to get saved un-challenged with something that might not be true.  If this is expected behavior, I cannot prove it.

Link to comment
Share on other sites

Without looking at the .blend files for the models it is quite difficult to tell what is going on - but I suspect it lies with the origins of the models.


In the image below , the are 2 pics of the Blender 3D window. In A, there are three cubes - all have the same origin at position 0,0,0.(the yellow dot inside the little red/white circle.


In B, each cube has its own unique origin (orange dots)  - [3.112,0,-0.8688], [4.112,-1,5.1674] and [-2.82,1,5.1674]. Notice one cube as the origin set at a corner - useful for making simple animated doors.


The exported BJS file for both results in the same 3D display of the cubes.


So I think what you maybe looking at is not the fault of Blender or the BJS exporter, but rather the style of modeling in Blender.



cheers, gryff :)


Link to comment
Share on other sites

  • 2 months later...

Yep, origin to geometry, too (might need to SELECT the geometry).  Works fine. 

Me, personally... I was using the "pivot" settings on a top toolbar... but I think that is for Blender in-editor pivot points.  "Origin" is the term we are looking for (as stated above).  It can be found in object mode... tools tab/panel. 

Position (and other settings) can be "hacked" in the .babylon file if you have an editor that doesn't puke on JSON long-lines.  Gist editor seems to work fine, and if you are driving Windows... use notepad or similar.  (I am a newbie to this stuff, but these are the things that worked for me, recently.)

Link to comment
Share on other sites

  • 3 months later...

Had the same problem in 3dsmax 2013 . Problem was, that meshes' pivots were at the same position on the 3dsmax scene, seems like babylonjs determines mesh's position by the position of it's pivot. Tried selecting the meshes and centering the pivot  to object and re-exporting them, but this didn't solve the problem.

Solution: select and export meshes ( as OBJ file for ex.) and then re-import them, in the import dialog check "Center Pivots" ( top right corner ) , after the meshes have pivots centered, export them with babylonjs exporter.

Hope this helps anyone.

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...