how much screen(view) take object in %

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Search this Thread Display Modes
Old 04 April 2014   #1
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 April 2014   #2
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 April 2014 at 04:08 PM.
 
Old 04 April 2014   #3
great thanks, that's exactly what I was looking for.Perfect code.
 
reply share thread



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
CGSociety
Society of Digital Artists
www.cgsociety.org

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

All times are GMT. The time now is 04:17 PM.


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