Gwir Posted July 21, 2016 Share Posted July 21, 2016 Is there a way to scale a mesh along global axis instead of its locals? Quote Link to comment Share on other sites More sharing options...
jerome Posted July 21, 2016 Share Posted July 21, 2016 out-of-the-box, not really what do you intend to do ? Quote Link to comment Share on other sites More sharing options...
Gwir Posted July 21, 2016 Author Share Posted July 21, 2016 I need to scale a mesh along scene global axis, even if the mesh is rotated. mesh.scaling attribute is the most obvious way to do it but it scales the mesh along its local axis. Quote Link to comment Share on other sites More sharing options...
dadiaar Posted July 21, 2016 Share Posted July 21, 2016 Yes, there is. Take a look to BABYLON.Mesh.bakeCurrentTransformIntoVertices() This will commit the transform to the vertices and reset position, rotation and scaling. If you don't want to lose that info, you may want to study the code inside that function, make a clone and recover later the transform info... Quote Link to comment Share on other sites More sharing options...
JohnK Posted July 21, 2016 Share Posted July 21, 2016 There is a fairly simple way provided the scaling is to be the same in all three directions x, y and z. For example when the scaling factor is 2 you can apply the scaling factor to the position as well as below var scalingFactor = new BABYLON.Vector3(2, 2, 2); mesh.scaling = scalingFactor; mesh.position.multiplyInPlace(scalingFactor); However as you can see for this playground http://www.babylonjs-playground.com/#UMR7M#70 size scaling still takes place along the local axes. A second method that works for unequal scaling is to use a parent at the origin; set mesh to parent, position and rotate mesh, scale parent to scale mesh along global axes as in this playground http://www.babylonjs-playground.com/#UMR7M#71 you can see the distortion that occurs because the scaling is not the same in all three directions. This has the advantage that with multiple meshes you can assign the same parent and can scale them all in one go. Hope this helps Quote Link to comment Share on other sites More sharing options...
adam Posted July 21, 2016 Share Posted July 21, 2016 Parent your mesh to an empty mesh and then scale the parent. When you have to move the mesh, move the parent. When you have to rotate, rotate the child. http://www.babylonjs-playground.com/#1TOK7G 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.