Gwir Posted August 4, 2016 Share Posted August 4, 2016 I need to scale a mesh along global axis. The mesh.scaling attribute refers to mesh local axis so it's useless to me. I managed to scale the mesh through the direct manipulation of the worldMatrix, but when i rotate the mesh the worldMatrix is reset to its original values and scaling and position data is lost. I also tried to call the bakeCurrentTransformIntoVertices() function after scaling the mesh, but the mesh loses its position and gets other unwanted behaviours. I'd like to avoid the trick of parenting the mesh and scale the parent instead of the mesh. Is there a way to scale a mesh along a global axis? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted August 4, 2016 Share Posted August 4, 2016 I would say: - Convert your global axis to local axis - Scale accordingly Pseudo-code: var globalAxisScale = new BABYLON.Vector3(0.5, 2.0, 1.0); var inverted = BABYLON.Matrix.Invert(mesh.getWorldMatrix()); var localAxisScale = BABYLO.Vector3.TransformNormal(globalAxisScale, inverted); Quote Link to comment Share on other sites More sharing options...
adam Posted August 4, 2016 Share Posted August 4, 2016 Either I'm doing it wrong, or that isn't going to work. http://www.babylonjs-playground.com/#TF2KO#0 Quote Link to comment Share on other sites More sharing options...
Gwir Posted August 5, 2016 Author Share Posted August 5, 2016 Still a scaling along the mesh local axis. I need it to be along the global one, even if it cause the "stretching" of the mesh. Quote Link to comment Share on other sites More sharing options...
adam Posted August 5, 2016 Share Posted August 5, 2016 I created a worldSpaceScale function in this PG: http://www.babylonjs-playground.com/#TF2KO#3 It's modifying the positions of the vertices, so you have to make the mesh updatable. Here is another version that resets the rotation: http://www.babylonjs-playground.com/#TF2KO#7 Quote Link to comment Share on other sites More sharing options...
Gwir Posted August 8, 2016 Author Share Posted August 8, 2016 Thank you very much, it works. What happens if the scaling needs to be on the camera axis? Quote Link to comment Share on other sites More sharing options...
adam Posted August 8, 2016 Share Posted August 8, 2016 31 minutes ago, Gwir said: What happens if the scaling needs to be on the camera axis? Like this? http://www.babylonjs-playground.com/#TF2KO#9 Gwir 1 Quote Link to comment Share on other sites More sharing options...
Gwir Posted August 8, 2016 Author Share Posted August 8, 2016 Exactly, thank you very much! 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.