I have a mesh (Mesh-A) with a bounding box of some arbitrary size defined by X,Y,Z scale. In runtime I import another mesh (Mesh-B),which has an overall topology similar to the Mesh-A, but it can have a different default scale. I am looking for an efficient algorithm to rescale the Mesh-B to have the new scale equal to the Mesh-A,which basically means - their bounding boxes are of similar sizes. The naive approach would be to run for... loop, scaling the Mesh-B transform,till its BB has an approximate size equal to that of the Mesh-B's BB. I would like to learn other approaches.
Scaling is linear, so you can do this in one step rather than iteratively. If you have two vector values
sizeB for the sizes of the two meshes’ bounding boxes, the vector value you should scale mesh B by is
sizeA / sizeB. If you want to scale it uniformly, you’ll need to pick a single scalar value; one way to do that would be to average the ratios of each component, i.e.
(sizeA.x / sizeB.x + sizeA.y / sizeB.y + sizeA.z / sizeB.z) / 3.