[Closed] how much screen(view) take object in %
I need information about how much of screen(view) size take particular object based on given camera view.
I could estimate it by checking binding box size and distance object from camera but still there is camera lens, fov factor which can distort objects in camera + scene can use different scale size etc. Is there any way to estimate this by taking actual bindingbox from view or any working idea . I’m asking because I work on plugin which fit texture size to it’s actual size in view based on camera movement and screen resolution information to save memory during rendering scene with tons of very heavy textures.
this will return the screen width and height of an object
fn GetScreenWidthAndHieght obj =
(
hXformPointfn = gw.hTransPoint;
maxy = maxx = -99999999.0;
miny = minx = 99999999.0;
msh = snapshotasmesh obj;
numverts = msh.numverts
gw.setTransform(Matrix3 1)
for v = 1 to numverts do
(
spos = hXformPointfn (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;
[maxx - minx + 1,maxy - miny + 1];
)
this will return the a screen space bounding box, faster than above but not as “close”
fn GetNodeScrnBBox nObj =
(
b = nodeGetBoundingBox nObj nObj.transform;
pnts = #();
pnts.count = 8;
pnts[1] = b[1];
pnts[2] = [b[2].x,b[1].y,b[1].z];
pnts[3] = [b[2].x,b[2].y,b[1].z];
pnts[4] = [b[1].x,b[2].y,b[1].z];
pnts[5] = [b[1].x,b[1].y,b[2].z];
pnts[6] = [b[2].x,b[1].y,b[2].z];
pnts[7] = b[2];
pnts[8] = [b[1].x,b[2].y,b[2].z];
smax = [-99999999.0,-99999999.0];
smin = [99999999.0,99999999.0];
gw.setTransform(Matrix3 1);
for p in pnts do
(
tp = gw.wTransPoint (p * nObj.transform);
if tp.x > smax.x then smax.x = tp.x;
if tp.y > smax.y then smax.y = tp.y;
if tp.x < smin.x then smin.x = tp.x;
if tp.y < smin.y then smin.y = tp.y;
)
#(smin,smax)
)