Reposition mesh based on resizing of floor

Hi all,

I am having one additional requirement like whenever I am resizing the floor using the Bounding box Gizmo so the meshes which was outside the floor should also be repositioned inside the floor.

Anyone please help me out with this requirement.Please find the screenshot as well:

Thanks in advance :slight_smile:

You will need to apply the same resizing to all the objects. I think you can use the onDragObservable observer of the gizmo you use to resize the floor and then apply the scaling to all other objects.

Adding @Cedric as he is the master of gizmos.

As @Evgeni_Popov said, you will need to reposition your meshes based on the new size of the floor. To do add, use the onDragOversable. I guess you don’t want to apply the new scale to the objects, only change their positions?

@Cedric yes I don’t want to apply new scale to objects I just need to change their positions.

Then, you have to do something like this pseudocode:

object.position = (object.position - boundingBoxGizmo.pivotPosition) * boundingBoxGizmo.relativeScale + boundingBoxGizmo.pivotPosition

@Cedric Do you have any playground example related to that?

It will be better understandable by some playground example.Can you please provide playground example?

While doing a PG, I’ve found a simpler solution:

  • Compute object normalized coordinates in the floor bounding box space.
  • Then, compute world coordinates based of new floor world bounding box:

object relative coordinates | Babylon.js Playground (babylonjs.com)

4 Likes

Thanks @Cedric for giving me solution.

1 Like

@Cedric you rock !!!

1 Like