hit2501

How can I change the origin point of a imported mesh dynamically in Babylon?

Recommended Posts

Hi, I wonder if this is posible but dynamically in Babylon instead Blender:

 

I can change the size of a mesh with some sliders and .scaling but this only works starting from the origin point. I tried Pivot Point but this seems to work the first time and then the mesh changes location (to pivot point) and the scaling continues working taking the new central point.

Also I can find the coordinates for each vertex but I dont know how to move the origin point to that vertex.

Is there any way to change the origin point to be able to scale starting from that point?  

Thank you.

Share this post


Link to post
Share on other sites

You can set the Pivot Point in BabylonJS with the pivot matrix, but there are two methods, so good to know the difference:

mesh.setPivotMatrix(pivotMatrix)
mesh.setPreTransformMatrix(preTransformMatrix)

Otherwise maybe you can export your model and we can work together on a Playground.  Here I'm just changing scaling and it is making the mesh scale the same as your video with a blender origin:
https://www.babylonjs-playground.com/#AVXVIQ#2

Share this post


Link to post
Share on other sites
12 hours ago, hit2501 said:

I tried Pivot Point but this seems to work the first time and then the mesh changes location (to pivot point) and the scaling continues working taking the new central point.

This behaviour depends on the version of babylon.js you are using see https://doc.babylonjs.com/how_to/pivots#breaking-change

 

Share this post


Link to post
Share on other sites

There is also setPivotPoint.

https://doc.babylonjs.com/how_to/pivots#how-to-set-and-get-a-pivot-point

edit:

Maybe you tried it already.

13 hours ago, hit2501 said:

I tried Pivot Point but this seems to work the first time and then the mesh changes location (to pivot point) and the scaling continues working taking the new central point.

 

Share this post


Link to post
Share on other sites

@hit2501

You can also make the mesh a child of another mesh. The advantage of this is that your pivot point can also be dynamically animated along with the child mesh. But this doesn't work for all scenarios.

DB

Share this post


Link to post
Share on other sites

Yes for sure.  I'm following this thread now, so will get an email when you post.

edit: As JohnK mentioned - my playground demo assumes a version of BabylonJS >= 3.2, so keep that in mind.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.