heavymetalmonk Posted December 17, 2015 Share Posted December 17, 2015 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, console.log(mesh.position); console.log(mesh.getPositionExpressedInLocalSpace(); console.log(mesh.getAbsolutePosition(); var m = new BABYLON.Matrix(); mesh.getWorldMatrix().invertToRef(m); var v = BABYLON.Vector3.TransformCoordinates(mesh.position, m); console.log(v); 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? Quote Link to comment Share on other sites More sharing options...
MarianG Posted December 17, 2015 Share Posted December 17, 2015 Hi.Try mesh.computeWorldMatrix(true);before to check for position. Quote Link to comment Share on other sites More sharing options...
heavymetalmonk Posted December 17, 2015 Author Share Posted December 17, 2015 hi.It still gives the same position for all the meshes. We're using SceneLoader.ImportMesh to load the meshes as a babylon file. We are trying to rotate individual meshes after the import, but the center of rotation is the same for all the meshes and on investigation their positions are also the same. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 17, 2015 Share Posted December 17, 2015 hey,No code that got you where you are, only diagnostic logs. Try reading .babylon in text editor. Search for: "position":[(including quotes). That will break the problem in 2. If the 3 #'s following each successful search are the same, then the issue is before import, else after. Quote Link to comment Share on other sites More sharing options...
ChrisR Posted December 17, 2015 Share Posted December 17, 2015 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 Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted December 18, 2015 Share Posted December 18, 2015 I think this is correct behaviour - when you import an individual mesh, it is without the position in the scene.I have a complete pack of meshes in a .babylon file, and I need to import them as assets (without position)If you import a full scene, positions are imported too. Quote Link to comment Share on other sites More sharing options...
dbawel Posted December 20, 2015 Share Posted December 20, 2015 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. DB Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 20, 2015 Share Posted December 20, 2015 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 20, 2015 Share Posted December 20, 2015 This is weird! I can confirm there is NO difference between mesh importation and scene loading mesh.position SHOULD be set everytime. Can you share a sample that repro the issue? Quote Link to comment Share on other sites More sharing options...
heavymetalmonk Posted December 21, 2015 Author Share Posted December 21, 2015 Hi,The issue was in the babylon file exported from blender. In order to address this issue we wrote a script to assign local origins to the individual meshes directly in blender. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 21, 2015 Share Posted December 21, 2015 Interesting.. this should not be required... Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 21, 2015 Share Posted December 21, 2015 I think we are going to need a test .blend in order to do anything. I have a QA .blend that Gryff built for me, which lays out a bunch of cubes. The camera has an animation which drives a circuit through them. They are not all exported to 0,0,0. Would by any chance these meshes have skeletons? Quote Link to comment Share on other sites More sharing options...
gryff Posted December 21, 2015 Share Posted December 21, 2015 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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 21, 2015 Share Posted December 21, 2015 If that is the case, you could move the origin using shift-crtl-alt-C. It brings up a menu where one of the options is "Origin to 3D Cursor". Another is "Origin to Center of Mass". Both sound better than having to have a python script. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 22, 2016 Share Posted February 22, 2016 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.) Quote Link to comment Share on other sites More sharing options...
cosmicgirl Posted June 3, 2016 Share Posted June 3, 2016 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. 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.