[Lite] How do you scale a mesh in place?

In Lite, there is Mesh.scaling property. However, rather than scale in place as I assumed, it also changes the position of the mesh that is being scaled.

Also it seems to me that meshes created from a position array differ in how scaling affects them. Example in the playground below shows box1 being scaled in place, box2 being made from the position buffer of box1, but with an offset to each position. box 2 is not scaled, but box3 is scaled and is the same in every way to box 2. However, you can see box3 is not scaling in place like box1.

Playground Reproduction

Isn’t scale always relative to mesh positions data 0,0,0? When you add an offset to mesh vertex data (so the mesh position data is not centered on 0,0,0), then scaling should scale the distance from 0,0,0 as well.

So is there no way to scale a mesh in place, keeping the world position it is currently occupying the same?

Babylon (Heavy?) has setPivotPoint(), but I don’t see the same in Lite.

Yes, you can scale the mesh in place by using a transform node as a pivot.

As HiGreg pointed out, scaling is relative to the mesh’s local origin, not necessarily its geometric center. In your example, adding 2 to every vertex coordinate moves the geometry’s local center to (2, 2, 2), but does not move the local origin. Scaling X by 2 therefore also doubles the geometry’s X offset from that origin. The mesh’s position property itself does not change.

Add createTransformNode and setParent to your imports from @babylonjs/lite.

Then replace your final box3.scaling.set(2, 1, 1) line with the following, before registerScene(scene):

const pivot = createTransformNode("box3-pivot", 2, 2.5, 2);
setParent(box3, pivot);
pivot.scaling.set(2, 1, 1);

Here, (2, 2.5, 2) is the box’s center before scaling: the vertex-data offset (2, 2, 2) plus its position (0, 0.5, 0). setParent preserves the mesh’s current world transform, so parenting does not move the box. Scaling the parent then scales the box around that center, keeping the center fixed. Leave box3.scaling at its default (1, 1, 1) for this replacement.

Alternatively, if you control how the mesh is created, keep its vertices centered around (0, 0, 0) and use position to place it. In your example, create box3 with the original positions array instead of newPositions, then use:

box3.position.set(2, 2.5, 2);
box3.scaling.set(2, 1, 1);

This also keeps the box’s center fixed, without needing a parent node.