stuh505
09-05-2005, 07: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]
)
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]
)
