Jump to content

Scale mesh along global axis


Gwir
 Share

Recommended Posts

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...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...