CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
reply share thread « Previous Thread | Next Thread »  
Thread Tools Search this Thread Display Modes
Old 04-08-2014, 03:58 PM   #1
Gdansk, Poland
Join Date: Aug 2009
Posts: 197
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.
Old 04-08-2014, 04:04 PM   #2
Klvnk's Avatar
United Kingdom
Join Date: Feb 2014
Posts: 715
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) )

Last edited by Klvnk : 04-08-2014 at 04:08 PM.
Old 04-10-2014, 10:26 AM   #3
Gdansk, Poland
Join Date: Aug 2009
Posts: 197
great thanks, that's exactly what I was looking for.Perfect code.
reply share thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:10 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.