Find faces in camera frustum?

Become a member of the CGSociety

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

Thread Tools Display Modes
  01 January 2009
Find faces in camera frustum?

Im looking to find all the faces that are in a cameras view frustum.

So some pseudo code.

1. get my cameras skewed matrix
2. use the skewed matrix and apply it to a copy of my mesh(s) to skew it
3. run triangle box intersection test on a 1unit cube over the mesh
4. save my list of faces and delete the mesh

And im stuck on point 1, how do i generate a Projection matrix from a camera, i have a near clip plane and a far clip plane.

Last edited by Gibbz : 01 January 2009 at 05:08 AM.
  01 January 2009
ok i think i need to write my own function to multiply matrix4's

Edit, making my own matrix 4 struct, is there a way to customize the way it prints out data so if i got "Print mMatrix4" it will format it the same as a matrix3 would?

Last edited by Gibbz : 01 January 2009 at 06:01 AM.
  01 January 2009
Hi Bronson,
I admit I cannot completely undertand what you're trying to do, but maybe my article Practical Space Mapping for interaction can be of help.

- Enrico
IllusionCatalyst Instrument set for 3ds Max │ AliquaForma Personal portfolio in fieri
  01 January 2009
I don't have time to look for an answer right now, maybe later,
but in the meanwhile I can suggest what seems to me a simpler solution.
If I understood you correctly, you can model a skewed box that covers the area of the camera fov and use volume select modifier on the object to select the faces outside that skewed box and delete them using delete mesh modifier.
  02 February 2009
I am making a similar script to perform Culling and clipping accordly to the camera frustum.
I use "meshop.slice" to create the new vertices at the intersection of the frustum and the objects.
This way i hope i can get an accurate Face Count to simulate geometry budget in a realtime game context directly in 3dsmax.
  02 February 2009
You can just use the 'how to write a vertex renderer' script in the help file as a guide (as per Bobo's reply to a similar question in ).

e.g. (completely taken from the help file - this can be optimized for faster processing)

 fn isPointInFrustrum pointPos = (
 	thePos = pointPos * viewport.getTM()
 	screen_origin = mapScreenToView [0,0] (thePos.z) [renderWidth,renderHeight]
 	end_screen = mapScreenToView [renderWidth,renderHeight] thePos.z [renderWidth,renderHeight]
 	world_size = screen_origin-end_screen
 	x_aspect = renderWidth/(abs world_size.x)
 	y_aspect = renderHeight/(abs world_size.y)
 	screen_coords = point2 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y)))
 	(((screen_coords.x >= 0) AND (screen_coords.x < renderWidth)) AND ((screen_coords.y >= 0) AND (screen_coords.y < renderHeight)))

Select the vertices on the currently selected editable mesh which are within the current Perspective viewport's view frustrum:

 $.selectedVerts = for i = 1 to $.numVerts collect (
 	if (isPointInFrustrum (getVert $ i)) then ( i ) else ( dontcollect )

With that basic function you can easily check if all 3 vertices of an object's face lay within the view frustrum - if they do, then that face is within the view frustrum. If zero vertices are within the view frustrum, it is outside. Otherwise, it's partially inside and partially outside.

Two notes:
- make sure you view the results with 'Show Safe Frames' enabled as otherwise the different viewport aspect from the actual (camera) view aspect may throw you off
- if any face -spans- the view frustrum or larger, it won't be counted. It will still be in view but because all of its -vertices- lay outside of the frustrum, it would be determined to be outside of the view frustrum. Rare in general, maybe not so rare in computer games (/me walks up to a wall) but probably not a huge issue.
Thread Closed 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
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 03:49 PM.

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