Bring the Crane in from outer space?

Right, like, Mesh.resizeTo(Vector3 size) method? Yes that could be handy, would make a nice contribution I guess. Shall we file a RFE then? :slight_smile:

We do have a normalizeToUnitCube function on the transformNode IIRC :slight_smile:

1 Like

Yep doing

mesh.normalizeToUnitCube();
mesh.scaling.scaleInPlace(size);

already does what you want.

1 Like

No, it doesn’t. It does only half of it. It doesn’t center the axis.

Here is how the babylon viewer does it:

if (unitSize) {
                meshesToNormalize.forEach((mesh) => {
                    mesh.normalizeToUnitCube(true);
                    mesh.computeWorldMatrix(true);
                });
            }
            if (center) {
                meshesToNormalize.forEach((mesh) => {
                    const boundingInfo = mesh.getHierarchyBoundingVectors(true);
                    const sizeVec = boundingInfo.max.subtract(boundingInfo.min);
                    const halfSizeVec = sizeVec.scale(0.5);
                    const center = boundingInfo.min.add(halfSizeVec);
                    mesh.position = center.scale(-1);

                    mesh.position.y += halfSizeVec.y;

                    // Recompute Info.
                    mesh.computeWorldMatrix(true);
                });
            }

I am not sure the positioning is worse an helper tbh ?

1 Like

Oh, thanks and my apologies :pray:.
Looks like this is exactly the part I was missing. See, I don’t use the viewer.
I knew nothing about getHierarchyBoundingVectors, which seems to be precisly the part I needed. I’m just happy to see that chatGTP also doesn’t know about it… if I account the clumsy solution it has pulled out relying on merging meshes to retrieve the bounding box :grin: I’m gonna try that shortly and meanwhile, have a great day :sunglasses:

OK, I can hereby now confirm that this solution works (and is actually ez once you know about it).
However, from my readings in this forum and the look at the PG examples from the API when searching for ‘getHierarchyBoundingVectors’, it seems to me like I’m not the only small brain :brain: :sweat_smile: knowing the *** of what he’s doing :dizzy_face: :wink: May be the above would deserve a couple of lines in the doc and a small PG (for those not using the viewer). Just a simple suggestion. I mean I’m good now :smiley: so again, thanks a lot for that :hugs:
Meanwhile, have a great sunday :sunglasses: :sunglasses:

Edit: @bigrig Following the above, I quickly added this to your PG. Thus “Bringing the crane in from outer space” without the need of launching a rocket :grin: nor editing or merging!?! the asset (this one’s for you chatGPT) :sweat_smile:

I’m gonna take this opportunity to share my anger about the faen designers posting assets (even for free) not respecting the rules of modelling for dummies course 1.0. The solution above works well for scaling and positioning but there’s this one thing it will never do, and this is ‘rotation’. EZ enough if coming from a right-handed system you can invert the scaling or rotate. BUT THEN, when the faen designer sets the axis neither facing forward nor backward but randomly rotated facing a direction that doesn’t make any sense, then you’re doomed. Nothing left but to edit the fancy thing or work it one by one on import. I mean I won’t shout after the poor guy creating a model as a hobby and posting it for free. But when an institution like the British Museum of Art releases 300 (beautiful) scans of great works of art and artefacts and the fancy designer doesn’t even take 10s. to set the axis correctly, it just makes me mad :grimacing: :unamused: That’s it for this subject I suppose. I said what I had to.
All, have a great day :sunglasses:

2 Likes

I believe the crane has officially been recovered, due to a concerted effort by the babylon community. NASA and all of the global governments thank you.

1 Like