# Reposition mesh based on resizing of floor

**URL:** <https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502>\
**Category:** Questions\
**Created:** [June 8, 2021, 6:11am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502 "2021-06-08T06:11:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohit\_Choudhary1](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mohit\_Choudhary1](https://forum.babylonjs.com/u/Mohit_Choudhary1)\
**Post date:** [June 8, 2021, 6:11am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/1 "2021-06-08T06:11:24Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/7/57b1b9fc64d18fc2584817f7fcca58564c35f85d.png)

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 8, 2021, 8:48am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/2 "2021-06-08T08:48:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 8, 2021, 9:00am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/3 "2021-06-08T09:00:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Mohit\_Choudhary1](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mohit\_Choudhary1](https://forum.babylonjs.com/u/Mohit_Choudhary1)\
**Post date:** [June 8, 2021, 9:40am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/4 "2021-06-08T09:40:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 8, 2021, 10:24am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/5 "2021-06-08T10:24:52Z")

</div>

Then, you have to do something like this pseudocode:

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

---

<div class="post-metadata">

**Author:** ![Mohit\_Choudhary1](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mohit\_Choudhary1](https://forum.babylonjs.com/u/Mohit_Choudhary1)\
**Post date:** [June 8, 2021, 10:38am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/6 "2021-06-08T10:38:37Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [June 8, 2021, 12:54pm UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/7 "2021-06-08T12:54:51Z")

</div>

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)](https://playground.babylonjs.com/#TW801V)

---

<div class="post-metadata">

**Author:** ![Mohit\_Choudhary1](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mohit\_Choudhary1](https://forum.babylonjs.com/u/Mohit_Choudhary1)\
**Post date:** [June 9, 2021, 6:10am UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/8 "2021-06-09T06:10:43Z")

</div>

Thanks @Cedric for giving me solution.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [June 9, 2021, 1:20pm UTC](https://forum.babylonjs.com/t/reposition-mesh-based-on-resizing-of-floor/21502/9 "2021-06-09T13:20:28Z")

</div>

@Cedric you rock !!!
