Coordinate Scaling (glScale equivalent in Babylonjs)

Folks,

I am looking for a way to scale my drawing in Z-direction. The scale factor would be > 1. The OpenGL equivalent is glScale(1, 1, dScaleFactor) which is to be multiplied with the current modeling matrix in OpenGL. How do I achieve that in Babylonjs?

-Thanks

You can use the scaling property of the mesh:

mesh.scaling.z = 3

So, we have to do it per object? In OpenGL, all we need is one glScale call to be applied to the current modeling matrix of the rendering pipeline.

Yes, I think there’s no other way.

Also, if it’s a one-time operation, you can bake the scale into the vertices of the mesh, by doing something like:

mesh.scaling.z = 3;
mesh.bakeCurrentTransformIntoVertices();

Do this for all your meshes and you are set.

Be careful, however, all scaling / position / rotation currently set on your mesh will be baked into the vertices!

If you want to bake only the z scale, you should do:

mesh.scaling.copyFromFloats(1, 1, 1);
mesh.position.copyFromFloats(0, 0, 0);
mesh.rotation.copyFromFloats(0, 0, 0);
mesh.scaling.z = 3;
mesh.bakeCurrentTransformIntoVertices();
2 Likes

Thanks, will try that.