Is it possible to set a mesh object's (0,0) pivot position?

Hi all
I’ve been attempting to create my own simple collision system on Babylon.Js, as well as position things around the world.

I’ve noticed that by default, the (0,0) position on a mesh object from the meshbuilder is in the center point of the object.

This isn’t great, as it means all of my calculations would have to use half of the size of the object every time, it’s not very clean.

I’ve noticed that the setPivotPoint function doesn’t seem to effect this, but does have an effect on scale or rotation (which I’m not too interested in).

Is this possible to do?

Hiya SS, welcome to the forum. What you wish is easily possible. I think your best step… is a little docs search about the ‘pivot’ subject: Babylon.js Documentation

AND, here’s a little BJS playground demo… that switches pivotPoints on a y-rotating box… periodically.

setPivotPoint() has a best friend named setPivotMatrix()… also handy. IT has a new 2nd parameter (true/false) that indicates whether/not the mesh should be re-positioned after the pivotMatrix is changed. Docs tell all about it.

That should get you rolling. I hope this helps.

1 Like

Hi Wingnut
I believe pivot works for this for things like rotation and movement, but isn’t too great for the actual positioning of things.

However I believe I may have missed that boolean value when doing it!
Is it in the docs? postMultiplyPivotMatrix is on the boolean but

I think the best way to explain it with the example you linked is if you replaced the timeout functions with the following:

setTimeout(function(){
    box.setPivotPoint(new BABYLON.Vector3(-2, 0, -2));
    box.position.z = 0;
    box.position.x = 0;
}, 5000)
setTimeout(function(){
    box.setPivotPoint(new BABYLON.Vector3(2, 0, 2));
    box.position.z = 0;
    box.position.x = 0;
}, 10000)
setTimeout(function(){
    box.setPivotPoint(new BABYLON.Vector3(0, 0, 0));
    box.position.z = 0;
    box.position.x = 0;
}, 15000)

// y-spinner
scene.onBeforeRenderObservable.add(function(){
    box.position.z += 0.1;
});

I would have thought that with this, the position the box would be set to would be different places each time, what with the pivot being different. This doesn’t seem to be the case.

Hi @SolidShOok and welcome from me.

Yes it is Set and Use a Pivot - Babylon.js Documentation

You may find this useful for using the false option as it describes what happens when false is used (ie what happened before the breaking change)
https://babylonjsguide.github.io/advanced/Pivots.html#using-a-pivot

1 Like

Thanks so much JohnK, that seems to work perfectly!
It looks like this isn’t a feature of set pivot point, which I was preferring to use because matrixes can be a little intimidating.
I have to get over that eventually lol