Reposition Mesh Based on Pivot Point

Simple example Babylon.js Playground

I am setting the Pivot on line 21 at (1,1,1) which is the corner of the box.

Then I want to reposition the box based on the pivot (line 22). Meaning that the corner (pivot) of the box will be positioned at (0,0,0).

The pivot does not become the local origin of the mesh? The .position property is not supposed to move the local origin?

Setting the pivot does not change the local origin since babylon 3.2. it mainly changes the center of rotation and scale without changing the position which is still based on the local origin: Set and Use a Pivot - Babylon.js Documentation

I did read the documentation and its not clear how to move the local origin to the pivot.

Should I use
mesh.setPivotMatrix(BABYLON.Matrix.Translation(-x, -y, -z), false);
instead of setPivotPoint()?

The docs make it sound that this should be used only for old project so thats why I hesitate.

I dont need to rotate or scale the mesh.

Also this page probably needs to be changed? Positioning, Rotating, Scaling - Babylon.js Documentation

Let s summon @JohnK who is a king of pivot ?

Here is a link to the pre 3.2 pages on pivots BabylonJS Guide.

Note for examples on page and for all PG examples to be as described the parameter false must be added as a second parameter to all setPivotPoint methods

Will look at the docs page and make changes.

1 Like

Having a bit of trouble with this. :frowning:

I tried 2 solutions, setPivotMatrix with false parameter, and adding a parent.

1) setPivotMatrix

The box dissappears for some reason!

This would be the ideal way to do this because solution 2 creates problems:

2) Adding a parent

Parent = pivot
Child = box
The pivot is positioned on the corner of the box

This breaks the rest of my code when dragging the boxes.

Ideally, when dragging the child, the parent should re-position with it also. But currently, from what I understand, the child is re-positioned relative to the parent, and the parent stays still.

Is it possible to auto-position the parent based on the position of the child? Or the relationship would have to change?


This is because the parameter for matrix.translation is not a vector it is three coordinates

Not entirely sure what you are trying to achieve. This sets the pivot at (1, 1, 1) and setting box position places the pivot at that position.



Basically, I am positioning outwards the squares that represent corners, which the user can interact with. The red squares represent the previous box location, which now I repositioned with the pivot.

In this end it looks like this:

And I just noticed a bug with the reflex angle degrees!