binyan Posted July 4, 2014 Share Posted July 4, 2014 Given a vector expressed in global space and a mesh, how can I get the position of this vector within a mesh local space?Or, alternatively, how can I get a parent position within a child local space? Update:Just figured it out... It is simply vector.subtract(Mesh.getAbsolutePosition()), right? Update2:Ok it's not... Because it doesn't take in account the mesh rotation. Quote Link to comment Share on other sites More sharing options...
binyan Posted July 4, 2014 Author Share Posted July 4, 2014 Think I came up with a solution: var m = new BABYLON.Matrix(); mesh.getWorldMatrix().invertToRef(m); var v = BABYLON.Vector3.TransformCoordinates(vector, m);Is that right? What I did is simply an inverse of local->world transformation process. getzel 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 4, 2014 Share Posted July 4, 2014 Absolutely! Quote Link to comment Share on other sites More sharing options...
getzel Posted October 26, 2016 Share Posted October 26, 2016 Hello ! This is very useful for those who want to transform a vector into a mesh's space. But I don't know why you use Matrix.InvertToRef. I understand better this function : var vector = new BABYLON.Vector3(100,0,0); var m = mesh1.getWorldMatrix(); var v = BABYLON.Vector3.TransformCoordinates(vector, m); mesh2.position = v; JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
adam Posted October 27, 2016 Share Posted October 27, 2016 17 hours ago, getzel said: But I don't know why you use Matrix.InvertToRef. Your example seems to be getting the global position given the local coordinates. Binyan was getting the local coordinates given the global coordinates. Quote Link to comment Share on other sites More sharing options...
KamranK Posted June 8, 2018 Share Posted June 8, 2018 this fixed my problem but I do not understand how it worked. How is the inverted matrix able to give back local coordinates 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.