Propagate a change in geometry and update position of parent elements

Hi,

I am creating an editing tool where it is possible to rotate and move a group of polygons (buildings) and drag the side of a polygon to change its shape. It is possible to drag all sides of the polygon.

The hierarchy like this: Building (Object3D) with children that we can call sub-buildings (Object3D).

Rotate and move is done on the Building, changing its position and rotation, but the “drag a side” is done on a sub building. I don’t think i can use scale as the actual shape is changing, so I am updating the geometry of the sub building.

After doing this I need to update the position of both the sub building and the building, because I need this do be the centeroid (for rotation purposes). This is where I am struggling. How should I update the positions (considering that a rotation might have been applied to the building already) correctly, making sure the geometry is not moved again when I change positions.

Any help would be greatly appreciates.

Hi,

Say you have computed an offset vector (in local space, i.e. in the building space) to apply to the sub buildings positions. Then, you can convert it to world space, negate it and apply to the building. So the center of the building will have changed effectively by the offset, but the sub buildings won’t move.
To do so:

for each subBuilding {
    subBuilding.position.add( offset );
}
building.localToWorld( offset );
building.position.sub( offset );

Thank you, yombo.

I can’t make your suggestion work in my case, I might be stuck in a wrong thought pattern here…

What I am doing is that I start by changing the coordinates that align with the side being dragged. Then I recalculate the centroid of the changed sub building and add the offset (change in sub building centroid) to the sub building and subtract it from each coordinate in the sub building geometry. So far so good (or so it seems visually at least).

Then I recalculate the building centroid and find the offset of the new and old building centroid, i add this to the building and subtract from the sub buildings.

I think I have to do it recursively like this. Or am I overcomplicating this?

This approach seems to work nicely (but it is heavy I guess) when I don’t apply rotation to the building. When a rotation is applied it does not work anymore. I think I have to take the rotation into account when working with the offsets but I am struggling to see how to do this correctly.

I was able to figure out how to apply that quaternion correctly to the offset vectors. So it works as I want now. It feels like I should not have to think about the rotation when working in the local space of a sub building, so I am probably not doing stuff in an optimal way. Will have to investigate and refactor a bit probably.

Still, if anyone has any thoughts on the overall pattern I am describing then please share your thoughts.

Thanks again, @yombo

1 Like