How to fit model to a new bounding box

I currently have a bounding box for a gltf model. I have taken the bounding box and scaled it to a bigger size, what I want to do is to scale the model to the new bounding box, but without scaling the thickness of the walls and other components. So for now lets say i know what walls are exterior, i want to move the walls along the new bounding box, and stretch it so that the exterior walls are still connected. Idk if it makes sense,

to put it simple, i want to scale the house model in x and z direction depending on a new bounding box without affecting the thickness of the walls.

In architectural contexts, you would usually have a representation of the house defined as a bunch of wall segments, that you generate the house geometry from.
You would then scale these segments and regenerate the geometry of house from those segments.

If you only have a gltf to work with, you’re kinda out of luck, except for a specific case where you can move the vertices away from the center, and it won’t break your model.
so for each vertex… if vertex.x< 0 vertex.x -= moveAmount;
else if(vertex.x>0)vertex.x += moveXAmount;
… for y and z as well.

1 Like

is there another method ? i heard ifc is good, how is it better for geometry manipulation and ote

IFC is a architectural model format unrelated to GLTF.
There’s pretty much no option that I can think of to achieve what you want without changing something upstream, and not using gltf.

Here is an oversimplified diagram:

There are file formats that describe the structure of an object and the relations of its elements. Such data are convenient to modify the structure. If the object is a house, these data may contains positions of walls, their thickness, how they join, the material and its strength, etc.

Then, these data are cooked/baked into graphical data, which are convenient to draw (render) the object. During the cooking process a lot of data is lost, as it is not needed for the visualization (e.g. if you have coordinates of wall corners, you do not need to have wall’s dimensions and connections to other walls). GLTF is such format. It is useful to draw the object, but it contains no data to manipulate easily the objects.

Having this said, manipulation must be done at the higher level, when topology data is present. Once these data are cooked into GLTF, your only option is to modify the graphical properties. So, it is still possible to change the structure of an object, but only to some limited degree, as a complete manipulation becomes too difficult (and sometimes impossible).

Here is a comparison: imagine you have ingredients and a receipt for a meal; once you cook it into something suitable for eating (that’s the GLTF), in most cases you cannot change the proportions of ingredients.

Back to your question. If you have a house as GLTF format, and you have no way to get any other data about this house, your options are these:

  • Very hard to implement: analyze the meshes in the GLTF, extract positions, sizes and orientations of walls, rescale the house by rescalings positions and lengths of walls, but keep walls thickness the same, then generate (or update) the meshes
  • Easier to implement, but not universal: if you want to extend the house along X direction (for example); think of imaginary plane crossing the house across its X axis. Then traverse all meshes, get their vertices and move only the vertices that are from the correct side of the invisible plane. Special treatment is needed for walls that reuse the same geometry and walls that are nested in other objects.

The second approach is used in these two demos. The first demo expands a vehicle, the second one does the same with the globe:

https://codepen.io/boytchev/pen/yLQJZdr
https://codepen.io/boytchev/pen/VwVjOre

2 Likes