PDA

View Full Version : Very wierd bug


stuh505
09-05-2005, 08:57 AM
In trying to get the dimensions of the bounding box of an object, I'm getting a very wierd error...

First of all, there doesn't seem to be a function built in to get this. The only way I see is to use getModContextBBoxMin and getModContextBBoxMax, which give the min and max corners of the bounding box given a modifier for context.

So, I must first add a modifier to the object -- any modifier, it doesn't matter which.

Then, for each of the 3 dimensions, I compute the difference between the max and min.

Finally, I delete the modifier.

Here's the strange issue...

If I run the function on an object that ALREADY HAS a modifier attached, it works.

If the object does not have a modifier, I add a modifier....but it doesn't work. If I run it again, it will work the next time though.

Now, perhaps you are thinking that after I add the modifier, there is not enough time for Max to actually setup the modifier before the code that uses it is run? So, I put it in a loop to wait for several seconds inbetween -- same results!??

This has got to be the wierdest bug ever...


function getBoundingBox o =
(
deleteFlag = false

if (o.modifiers.count == 0) do
(
deleteFlag = true
addModifier o (Bend()) --add temp modifier for the calc
)


xdim = ceil (abs(((getModContextBBoxMin o o.modifiers[o.modifiers.count] - getModContextBBoxMax o o.modifiers[o.modifiers.count]) as point3).x))

ydim = ceil (abs(((getModContextBBoxMin o o.modifiers[o.modifiers.count] - getModContextBBoxMax o o.modifiers[o.modifiers.count]) as point3).y))

zdim = ceil (abs(((getModContextBBoxMin o o.modifiers[o.modifiers.count] - getModContextBBoxMax o o.modifiers[o.modifiers.count]) as point3).z))


if (deleteFlag == true) then
deleteModifier o o.modifiers[1]

[ydim, xdim, zdim]

)

j-man
09-06-2005, 12:37 PM
Stuh505

I'm not sure what your bug is but if you want the bounding box of an object it is as simple as:


$.max-$.min


maybe I missed something = >

Josh.

Wahooney
09-06-2005, 12:37 PM
$object.min and $object.max get's the minimum and maximum points of the object's bounding box.

Note that these are the points of an Axis Aligned bounding box and not an Object Aligned bounding box.

Edit: jman beat me to it, sorry for the double post.

stuh505
09-07-2005, 03:28 AM
thanks a lot!

antonv
01-15-2006, 05:46 AM
Hi Stuh, i was searching for some stuff about bounding box and stumbled on a explanation by Bobo on what was happening to you when trying to get modifier's bounding box. Here is the link, look towards the bottom:
http://forums.cgsociety.org/showthread.php?t=305621&highlight=bounding+box

Bobo
01-15-2006, 07:58 AM
In trying to get the dimensions of the bounding box of an object, I'm getting a very wierd error...

First of all, there doesn't seem to be a function built in to get this. The only way I see is to use getModContextBBoxMin and getModContextBBoxMax, which give the min and max corners of the bounding box given a modifier for context.

So, I must first add a modifier to the object -- any modifier, it doesn't matter which.

Then, for each of the 3 dimensions, I compute the difference between the max and min.

Finally, I delete the modifier.

Here's the strange issue...

If I run the function on an object that ALREADY HAS a modifier attached, it works.

If the object does not have a modifier, I add a modifier....but it doesn't work. If I run it again, it will work the next time though.

Now, perhaps you are thinking that after I add the modifier, there is not enough time for Max to actually setup the modifier before the code that uses it is run? So, I put it in a loop to wait for several seconds inbetween -- same results!??

This has got to be the wierdest bug ever...


When you add the modifier and read the data, the modifier stack has not been updated yet and the gizmo of the modifier does not "know" the size of the object.
You have to force an internal refresh of the modifier stack. The simplest and fastest way to do this is to call CLASSOF o before reading the bbox. Since Classof tries to return the class ON TOP of the modifier stack, it triggers an internal reevaluation of the stack where necessary and the gizmo gets its correct size. Then you delete the modifier as usual...

CGTalk Moderation
01-15-2006, 07:58 AM
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.