Issue with alignment

Hello Three js team,

I am facing an issue with the alignment i want to keep my two groups that contain several objects at the same level.

For first group bounding box is

{
“min”: {
“x”: -0.6131823062896729,
“y”: 0.16263456642627708,
“z”: -0.5456463694572449
},
“max”: {
“x”: 0.5927552580833435,
“y”: 0.1752917766571046,
“z”: 0.6603027582168579
}
}

for second group the bounding box is

{
“min”: {
“x”: -0.6131823062896729,
“y”: -1.4661666507917068e-16,
“z”: -0.5456463694572449
},
“max”: {
“x”: 0.5927552580833435,
“y”: 1.211578325349116e-16,
“z”: 0.6603027582168579
}
}

here the only difference i see in the y axis is there any way to bring the group at same level. I mean at same y level. Please i am glad if some one give me a quick help

Thanks
Alex

If group1.position.y = group2.position.y doesn’t do it for you, I assume you have several objects in the group that have various y-axis positions?

In this case, it should be enough if you calculate the difference on the y-axis between the groups (probably best to use bbox.min.y, it will then place them on the same elevation like you’d be placing them on a floor):

// Calculate half-distance between the groups on y-axis (bounding box of group1 - bounding box of group2)
const dy = (groupBox2.min.y - groupBox1.min.y) / 2;

// Move each group halfway towards the other (group1+, group1-)
group1.position.y += dy;
group2.position.y -= dy;

Something like this.

Thank you so much for putting efforts i agree with most of your statement and i am learning three js so i am glad i thought in the same way as you did.


I am using this library so it is giving me terrain and i am converting the terrain in flat terrain by setting the z position in its geometry to 0.

Here the problem is terrain never comes at the actual seen position 0,0,0 so i translate y of each child to -box.max.y to bring the terrain near to scene center but it is little underneath the center

I want for any lat lon the flat and terrain comes at the scene center 0,0,0

Please help me in this

Thanks

Pardon? I don’t really understand what you mean or what the problem is. Can you share a jsfiddle showing what’s the issue, and explain what you tried until this point?

That’s probably a bad idea, if meshes are in groups, translate groups - not each child separately.

const box = new THREE.Box3().setFromObject( terrain );
terrain.translateY(-box.max.y)

here terrain is a group and i think this code translate each child in the group also

I mean whatever location i choose the flat site and terrain site both should come at same place means at center of the scene like overlapping each other

flat-site is at origin (0,0,0) but terrain is not.

I tried to bring them together but unable to :pensive:

Please freely ask if i miss something

Thanks