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/index.php/t-575182.html ).
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.
- 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.