Can I change Mesh position against another Mesh?

Hello everyone, I am new to babylonjs, I wanted to know if it is possible to do make a mesh can take another mesh as a reference ? :thinking:

For the context I have created a bedroom in glb, and I would like to place furniture there, but I would like this furniture to take the bedroom as a position reference point and not the scene.

thank you in advance :slight_smile: .

Hi and welcome to the Community.
There are a number of possibilities for that. Now, if I understand correctly it seems like all your meshes you want to ‘reference to’ your bedroom actually ‘belong’ to the bedroom, correct? Understand it would form a logical group of bedroom objects. In this case, I recommend using parent, i.e.

bed.parent = bedroom;

Not only will your objects take their position (scaling and rotation) from the ‘bedroom’ parent, they will also attach to it as children of this parent node. Meaning if you want to reposition or rotate your bedroom, all your parented objects of ‘bedroom’ will come along with it. Also, if you want to create a clone of this bedroom to create an identically layouted second bedroom, all you have to do is to clone just the parent (and all child objects will duplicate and follow as instances)

Hope this helps and again, a warm welcome to our Community.
Meanwhile, have a great day :sunglasses:

2 Likes

Welcome, Ben! I use bjs for similar purposes. To supplement what mawa stated:

Read the documentation to familiarize yourself with the difference between bed.parent = bedroom and bed.setParent(bedroom), which has to do with how and and when the transforms (position, scaling and rotation) are applied.

2 Likes