MarianG Posted April 14, 2015 Share Posted April 14, 2015 Hi people. I have a new question. It is a noob question, but i searched for the answer, but I didn't find it. If I have a house for example, and all walls are separate objects, and the floor too. The floor world position is (10,0,10). The floor is the parent of walls. Walls world position show me (0,0,0), and walls._absolutePosition show me (10,0,10) for all walls. And the question is )How can I determine the world position of walls?, One should have (20,0,10), other (10,0,20). But I can't determine this values. Should I get position of floor, floor scale, and then take the position of walls?Sorry my bad english Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 14, 2015 Share Posted April 14, 2015 Hi,All questions are good questions!To get the absolute position of an object use its getAbsolutePosition() method. It's deliver the world position of the object. You might need to force a new computation of the world matrix if it didn't work correctly. Quote Link to comment Share on other sites More sharing options...
Temechon Posted April 14, 2015 Share Posted April 14, 2015 Or you can add the parent position to the children position : absolutePosition = parent.position.add(wall.position); Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 14, 2015 Author Share Posted April 14, 2015 Ok. I have this piece of code:.....box.position = new BABYLON.Vector3(10,0,10);for(var i in m){ m[i].position = BABYLON.Vector3.Zero(); m[i].parent = box; m[i].computeWorldMatrix(true); console.log(m[i].getAbsolutePosition()) return vector Zero (0,0,0) for all meshes console.log(m[i]._absolutePosition) return box.position for all meshes console.log(m[i].position) return vector Zero (0,0,0) for all meshes}I have to apply matrix result from computation to meshes world matrix?Or what I'm doing wrong? )A possible cause, is because all meshes have their pivot, is not the same for all?Thanks Quote Link to comment Share on other sites More sharing options...
RaananW Posted April 14, 2015 Share Posted April 14, 2015 Except for the first one, the results are correct. The meshes' positions are all 0,0,0. They're absolute position is the box's position.I find it odd that getAbsolutePosition return a different result than _absolutePosition, as the function is simply a getter to the value (https://github.com/BabylonJS/Babylon.js/blob/master/Babylon/Mesh/babylon.abstractMesh.ts).Want to create a simple demo in the playground so we can debug it together? I have created a quick demo - http://www.babylonjs-playground.com/#19B7X0 , check the console showing the before and after position of all selected meshes, you will notice they all include the box's position. Try computing the world matrix of the box after changing its position, might solve the problem. MarianG 1 Quote Link to comment Share on other sites More sharing options...
MarianG Posted April 15, 2015 Author Share Posted April 15, 2015 Thanks you both.Computing the world matrix of the box after changing its position solve it. I can't explain why Quote Link to comment Share on other sites More sharing options...
npgrosser Posted January 18, 2016 Share Posted January 18, 2016 why do we have to manually force computation of the worldmatrix? Quote You might need to force a new computation of the world matrix if it didn't work correctly. Thats kinda shady... Is there some documentation about it? I wanna know when I have to do it manually and when not. (without trial and error) Update: I just found it. The renderId is responsible. (so once per frame - without additional check for translation) Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted January 18, 2016 Share Posted January 18, 2016 The only reason to force a worldMatrix computation is when you need it before the next frame. World matrices are updated on every render Quote Link to comment Share on other sites More sharing options...
npgrosser Posted January 18, 2016 Share Posted January 18, 2016 5 minutes ago, Deltakosh said: The only reason to force a worldMatrix computation is when you need it before the next frame. World matrices are updated on every render Yep thanks 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.