[Closed] Very wierd bug
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 [size=2]getModContextBBoxMin and getModContextBBoxMax, which give the min and max corners of the bounding box given a modifier for context.[/size]
[size=2][/size]
[size=2]So, I must first add a modifier to the object – any modifier, it doesn’t matter which.[/size]
[size=2][/size]
[size=2]Then, for each of the 3 dimensions, I compute the difference between the max and min.[/size]
[size=2][/size]
[size=2]Finally, I delete the modifier.[/size]
[size=2][/size]
[size=2]Here’s the strange issue…[/size]
[size=2][/size]
[size=2]If I run the function on an object that ALREADY HAS a modifier attached, it works.[/size]
[size=2][/size]
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.
[size=1][size=2]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!??[/size][/size]
[size=1][size=2][/size][/size]
[size=1][size=2]This has got to be the wierdest bug ever…[/size][/size]
[size=1][size=2][/size][/size]
[size=1][size=2]
[/size][/size]
[size=1][size=2]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
[size=2]deleteModifier o o.modifiers[1]
[ydim, xdim, zdim]
)
[/size][/size][/size]
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…
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.
$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.
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