CGTalk > Software > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 01-09-2009, 03:57 AM   #1
Gibbz
Game Artist
 
Gibbz's Avatar
portfolio
Bronson Mathews
Game Artist
Australia
 
Join Date: Dec 2002
Posts: 1,090
Send a message via ICQ to Gibbz
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
(http://jgt.akpeters.com/papers/Aken...r01/tribox.html)
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-09-2009 at 05:08 AM.
 
Old 01-09-2009, 05:54 AM   #2
Gibbz
Game Artist
 
Gibbz's Avatar
portfolio
Bronson Mathews
Game Artist
Australia
 
Join Date: Dec 2002
Posts: 1,090
Send a message via ICQ to Gibbz
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-09-2009 at 06:01 AM.
 
Old 01-09-2009, 09:37 AM   #3
SyncViewS
IC.Developer
 
SyncViewS's Avatar
Enrico Gullotti
Technical Artist and Programmer
United Kingdom
 
Join Date: Dec 2004
Posts: 344
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
 
Old 01-10-2009, 03:24 PM   #4
MatanH
Character TD
 
MatanH's Avatar
portfolio
Matan Halberstadt
Head of Rigging dpt.
snowball studios
Tel-Aviv, Israel
 
Join Date: Oct 2002
Posts: 379
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.
 
Old 02-16-2009, 09:51 PM   #5
Floating_Inkpot
Frequenter
Sebrechts Jeff
France
 
Join Date: Oct 2002
Posts: 103
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.
 
Old 02-16-2009, 11:53 PM   #6
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
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 http://forums.cgsociety.org/archive...p/t-575182.html ).

e.g. (completely taken from the help file - this can be optimized for faster processing)
Code:
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:
Code:
$.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.
 
Old 02-16-2009, 11:53 PM   #7
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed 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
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 06:29 AM.


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