binyan Posted July 3, 2014 Share Posted July 3, 2014 In this example I set a parent to the ground and then rotate it. I would expect that the absolute position of the ground would change but it doesn't... The weirder thing is that getAbsolutePosition returns always the same vector - the vector it returned first time I called it. For instance in this example the absolute position does change according to the rotation but after I get an absolute position for the first time it doesn't change.Am I missing something? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 4, 2014 Share Posted July 4, 2014 This is because there is no rendering at that time. If you want babylon.js to update this value, you have to force a complete matrix evaluation through ground.computeWorldMatrix(true); Quote Link to comment Share on other sites More sharing options...
binyan Posted July 4, 2014 Author Share Posted July 4, 2014 Thanks, Deltakosh. Checked it out and it works now. Just a little correction - I should force the both world matrices evaluation (the parent's one and the child's one). Otherwise it doesn't work.If I understood well it will be automatically evaluated if this code will run in rendering loop, right? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 4, 2014 Share Posted July 4, 2014 Correct Quote Link to comment Share on other sites More sharing options...
Srisub Posted March 16, 2016 Share Posted March 16, 2016 I ran into the same problem where i am trying to get the absolute position (or more generally, the world matrix components) of a mesh deep down in the hierarchy of a scene *before* any rendering happens. Seems like what i need to do is to go up the hierarchy and do computeWorldMatrix(true) for each mesh in the ancestry as well. Deltakosh, might be worthwhile to consider a scene.computeWorldMatrixForAllMeshes (force) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 16, 2016 Share Posted March 16, 2016 you can just do mesh.computeWorldMatrix(true) and babylon.js will go up the hierarchy for you Quote Link to comment Share on other sites More sharing options...
Srisub Posted March 16, 2016 Share Posted March 16, 2016 Here's some code i wrote to make sure that the world matrix is up-to-date (outside of rendering loop). Both these seem like nice utilities to add to BJS classes. I am new, so passing on code for now.. /* Get a node's parent hierarchy */ getHierarchy: function ( node, includeThis ) { var hierarchy = []; if ( includeThis ) hierarchy.push( node ); var item = node.parent; while ( item ) { hierarchy.push( item ); item = item.parent; } return hierarchy; } , /* Compute world matrix for node and its parent hierarchy */ computeWorldMatrix: function ( node, force, hierarchy ) { if ( hierarchy ) { var nodes = this.getHierarchy( node ); for ( var n=nodes.length-1; n >= 0; n-- ) nodes[n].computeWorldMatrix( force ); } node.computeWorldMatrix( force ); } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 17, 2016 Share Posted March 17, 2016 No need for this. This is already done Quote Link to comment Share on other sites More sharing options...
Srisub Posted March 17, 2016 Share Posted March 17, 2016 Note that i had to do this only because i was trying to get the world matrix of a mesh deep down in hierarchy BEFORE any rendering starts. (Wanted to set the camera position/rotation to that of the "eye" of the avatar). When i didnt do computeWorldMatrix(force) for the hierarchy, it was only returning the local matrix. After i did the above code, it worked. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 17, 2016 Share Posted March 17, 2016 This should not be the case do you mind sharing the bug in the playground? Quote Link to comment Share on other sites More sharing options...
Numa Posted April 5, 2016 Share Posted April 5, 2016 Has this bug been fixed? I'm getting some strange results when swapping parents/children around in a big hierarchy. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2016 Share Posted April 5, 2016 As far as I'm concerned no one provided a repro case so far Quote Link to comment Share on other sites More sharing options...
mirco Posted March 21, 2017 Share Posted March 21, 2017 Hi, sorry for bumping up this old thread, but I think its not finished yet. I have the same problem like Srisub. It occurs when I use computeWorldMatrix(true) inside the createScene function ( not in the runRenderLoop ). The result of the computeWorldMatrix looks wrong ( expect {X:3 Y:1 Z:0}, but get {X:1 Y:0 Z:0} ) If I use the code from Srisub it works. Here is a Playground where I can reproduce the problem. http://www.babylonjs-playground.com/index.html#1HMKOS#3 @Deltakosh maybe you can have a look on it Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 21, 2017 Share Posted March 21, 2017 @adam found the issue It should be fixed now (clear your cache and run your PG again) Quote Link to comment Share on other sites More sharing options...
mirco Posted March 22, 2017 Share Posted March 22, 2017 thank you, works fine 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.