Notifications
Clear all
[Closed] How can I calculate the camera-oriented bounding box of an object?
Dec 18, 2019 8:23 am
I am attempting export a sequence of a rotating teapot. Each frame is saved as a JPEG image, and I am trying to write the pixel coordinate 2D bbox (xmin, xmax, ymin, ymax) of the teapot from the camera’s perspective to a corresponding text file.
In the example picture here, I would be looking to output bbox values of [220,1200,200,830] for this frame.
I am comfortable with Python, but (as you can tell), MaxScript is new to me.
Thanks!!

2 Replies
Dec 18, 2019 8:23 am
(
fn GetScreenBounds obj =
(
maxy = maxx = -99999999.0;
miny = minx = 99999999.0;
gw.setTransform(Matrix3 1);
msh = snapshotasmesh obj;
for v = 1 to msh.numverts do
(
spos = gw.hTransPoint (getvert msh v);
if spos.x > maxx then maxx = spos.x;
if spos.x < minx then minx = spos.x;
if spos.y > maxy then maxy = spos.y;
if spos.y < miny then miny = spos.y;
)
delete msh;
[minx,maxx,maxy,miny]
)
b = GetScreenBounds $;
gw.setTransform(Matrix3 1)
rect = (box2 b.x b.w (b.y - b.x) (b.z - b.w));
gw.hrect rect red
eRect = rect
eRect.right += 1
eRect.bottom += 1
gw.enlargeUpdateRect eRect
gw.updateScreen()
)