Notifications
Clear all

[Closed] Why $.min and $.max don't give the expected results ?

That does work for a box but not for a teapot.
That is just an example.

How 3dsmax calculates that ?

EDIT:
Here a script that show the problem.

fn addBoundingBox obj =
(
		objMin=in coordsys local obj.min
		objMax=in coordsys local obj.max
		bb=box width:(objMax.x-objMin.x) length:(objMax.y-objMin.y) height:(objMax.z-objMin.z)
		bb.center=obj.center
		bb.rotation=obj.rotation
		bb.xray=true
		return bb
)

obj=teapot()
rotate obj (quat 30 [1,1,0])
bb=addBoundingBox obj
bb.name="bb"
6 Replies
2 Replies
(@bobo)
Joined: 11 months ago

Posts: 0

It actually makes sense. The $.min and $.max values are ALWAYS in world coordinates. What you have to realize is that after transforming your teapot, the $.min and $.max return the WORLD MIN and MAX of a world-aligned bbox enclosing the LOCAL BBOX.

If you would set your display to Bounding Box and compare your result with the local bounding box of the teapot, you will see that the new box’s min and max mark the corners of a world-aligned bounding box that encloses the local box of the teapot.
Or even easier, create two point helpers
point pos:$.min
point pos:$.max
from the teapot and see that the two points define the cornvers of a world-oriented bbox then encloses the local bbox of the teapot.

So you cannot use in coordsys local to turn those world points into local coordinates, because these points are always the corners of a world-aligned bbox and don’t care about the orientation of the object. This means that other than the local bbox that moves, rotates and scales with the node transformations, the world bbox is always aligned to world XYZ axes and would change its length/width/height as the teapot rotates.

Here is the back-transform trick:


 fn addBoundingBox obj =
 (
 	oldTM = obj.transform --store the original transformation
 	obj.transform *= inverse obj.transform  --transform back into identity matrix
 	objMin=obj.min  --grab the bbox - in this special case, local and world boxes are aligned
 	objMax=obj.max 
 	bb=box width:(objMax.x-objMin.x) length:(objMax.y-objMin.y) height:(objMax.z-objMin.z)
 	obj.transform = oldTM  --return back to original transformation
 	bb.transform = obj.transform --set rotation and scale of the bbox to match object
 	bb.center=obj.center  --center bbox
 	bb.xray=true
 	bb
 )
 
 obj=teapot()
 rotate obj (quat 30 [1,1,0])
 bb=addBoundingBox obj
 bb.name="bb"
(@bobo)
Joined: 11 months ago

Posts: 0

picture == 1000 words:

Blue is the world-oriented bbox that $.min and $.max always return. Green is the local bbox we are looking for. This is the front view of the same teapot from the original test script. All other views looks similar, with the blue enclosing the green bbox.

I find it better to back transform the object (set it’s tm to identity) get the bounding box then transform it again (set it’s tm back). Getting the bounding box in local coordinates doesn’t work for all objects, I don’t know why.

2 Replies
(@prettypixel)
Joined: 11 months ago

Posts: 0

Oh I see.
That is strange.
If “coordsys local” does not function locally it would return world coordinates, but here the coordinates seem unspecified. That has no sense.

At least I know that it is not a bad manipulation of my part.
Thanks Wahooney.

(@antonv)
Joined: 11 months ago

Posts: 0

Hi guys, it’s the first time I am working with finding the bounding box of an object and I have a lot of trouble doing it.
Wahooney, I was wondering what did you mean in your post about back transforming the object to it’s identity matrix. How do you do that? Just by taking the offset matrix out of the object?

Thanks,
Anton

Thanks Bobo, this made it clear for me finally!
And it seems that I am not the only one dealing with scripts saturday night