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

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2005   #1
Why $.min and $.max don't give the expected results in coordsys local ?

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"

Last edited by prettyPixel : 10 October 2005 at 12:17 PM. Reason: add an example
 
Old 10 October 2005   #2
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.
__________________
||||| www.wahooney.net |||||
Head Towards the Light

Learning to use Blender3d
 
Old 10 October 2005   #3
Originally Posted by Wahooney: 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.


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.
 
Old 01 January 2006   #4
Originally Posted by Wahooney: 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.


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
__________________
Frustration free tools to make artists feel like artists again
http://www.75ive.com/tools


 
Old 01 January 2006   #5
Originally Posted by prettyPixel: 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"




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"
 
Old 01 January 2006   #6
Thanks Bobo, this made it clear for me finally!
And it seems that I am not the only one dealing with scripts saturday night
__________________
Frustration free tools to make artists feel like artists again
http://www.75ive.com/tools


 
Old 01 January 2006   #7
Originally Posted by Bobo: 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.


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.
 
Old 01 January 2006   #8
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:34 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.