# which facets are visible?

 02 February 2009 urika New Member portfolio uri kadushin haifa, Israel which facets are visible? hi all i want to load an obj object, then position a camera somewhere in space . then i want to know which facets of the object (numbered) are visible to the camera, meaning that the normal is toward the camera and the facet is not behind any other facet. i guess that this is done automatically all the time in 3dsmax but can i somehow get the info? thanks in advance p.s this is my first post so i hope i managed to describe my problem correctly... share quote
 02 February 2009 ZeBoxx2 Lord of the posts   Richard Annema Caustic Graphics / SplutterFish Groningen, Netherlands this isn't nearly as easy as you were hoping, I'm gonna guess For faces facing towards/away from the camera it's easy enough. 1. Get the camera's direction (\$.dir) this is a vector. 2. Get the Normal of the face (getFaceNormal i) this, too, is a vector. 3. Use 'dot ' to test whether the face is facing away from (negative value) or towards (positive value) the camera. For faces being occluded or not - welcome to a world of hurt that starts with this thread: http://forums.cgsociety.org/showthr...p?f=98&t=295257 Basically, for each face you would have to check if any of its vertices are in front of all the other faces in the mesh; if a vertex is in front of another face, then some part of the face itself should be in front as well. The 'in front of another face' part is the annoying bit. If all the vertices of the other face are further away from the camera than the vertex you're checking, then the vertex you're checking is in front (similarly, if they're all closer, then the vertex is behind). If one or two of the vertices of the other face are -closer-, however, you'll need to do tricky math. Dare we ask what you're trying to do, just in case there's a simpler solution? share quote
 02 February 2009 SyncViewS IC.Developer   Enrico Gullotti Technical Artist and Programmer United Kingdom Hi Uri and welcome, here is a function to just look for faces orientation, it doesn't consider occlusion, but it's a starting point. It works with Editable Poly and Editable Mesh. ``````-- getFrontFaces accepts Editable Poly and Editable Mesh objects and returns -- a bitArray containing Camera-Facing faces index function getFrontFaces obj = ( -- general threshold local fThresh = 1e-4 -- initialize face index storage local baFrontFaces = #{} -- initialize variables local iNumFaces = 0 local p3FaceCenter = [0,0,0] local p3FaceNormal = [0,0,0] local p3CameraToFaceVect = [0,0,0] local fDotViewAngle = 0.0 -- get current camera e viewport data local p3CameraPos = (inverse(getViewTM())).row4 local p3CameraViewDir = -(inverse(getViewTM())).row3 local bIsPerspective = viewport.IsPerspView() -- if object is an Editable Poly if ((classOf obj) == Editable_Poly) then ( -- get current number of faces in object iNumFaces = polyOp.getNumFaces obj -- cycle through faces for i = 1 to iNumFaces do ( -- get face center and normal vector p3FaceCenter = polyOp.getFaceCenter obj i p3FaceNormal = polyOp.getFaceNormal obj i if (bIsPerspective == true) then -- view is perspective ( -- get vector from camera to face center p3CameraToFaceVect = p3FaceCenter - p3CameraPos -- get dot between vector form camera and face normal fDotViewAngle = dot p3CameraToFaceVect p3FaceNormal ) else -- view is orthographic ( -- get dot between camera view direction and face normal fDotViewAngle = dot p3CameraViewDir p3FaceNormal ) -- if face is not looking backward, collect it if (fDotViewAngle < -fThresh) then ( baFrontFaces[i] = true ) ) ) else if ((classOf obj) == Editable_Mesh) then ( iNumFaces = meshOp.getNumFaces obj for i = 1 to iNumFaces do ( p3FaceCenter = meshOp.getFaceCenter obj i p3FaceNormal = getFaceNormal obj i if (bIsPerspective == true) then ( p3CameraToFaceVect = p3FaceCenter - p3CameraPos fDotViewAngle = dot p3CameraToFaceVect p3FaceNormal ) else ( fDotViewAngle = dot p3CameraViewDir p3FaceNormal ) if (fDotViewAngle < -fThresh) then ( baFrontFaces[i] = true ) ) ) else ( throw "Wrong input in function getFrontFaces()" ) return baFrontFaces )`````` - Enrico __________________ IllusionCatalyst – Instrument set for 3ds Max │ AliquaForma – Personal portfolio in fieri share quote
 02 February 2009 urika New Member portfolio uri kadushin haifa, Israel Quote: Dare we ask what you're trying to do, just in case there's a simpler solution? basically i need to know which faces are visible at a specific camera/object orientation ,and then color the visible faces according to temperature (temperature calculations done in a different program), coloring everything and then viewing through a camera view is NOT sufficient i dont really care if the occlusion is partial (i'll just say it is occluded) while reading some help files i saw "deselectHiddenFaces " can i somehow select all faces ,then remove from selection the hidden ones and get a list of the remaining selected faces? Mesh Face Methods thank you so much for your replies share quote
 02 February 2009 SyncViewS IC.Developer   Enrico Gullotti Technical Artist and Programmer United Kingdom Hi Uri, I just finished to write the whole function. It takes into account face direction and occlusion. It's still a bit messy, not fast, and not commented, but seems to work well enough. I'll try to refine it in the near future. It's too long to post in this thread, you can find it here under "Snippets" -> "Get Front Faces". Mind that you also need the function "getPolyFromMeshFace" under "Editable Poly data from underlying Mesh". I hope it helps. - Enrico __________________ IllusionCatalyst – Instrument set for 3ds Max │ AliquaForma – Personal portfolio in fieri share quote
 02 February 2009 urika New Member portfolio uri kadushin haifa, Israel Thanks!!! Thank you so much share quote
 02 February 2009 urika New Member portfolio uri kadushin haifa, Israel almost perfect i got it to work almost perfectly (including UI ) but i see that the selection is not perfect, there are a few faces that are definitely not occluded and their normals are exactly like their neighbors which dont get selected, any possible reasons ? i converted obj to mesh thanks share quote

 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 vBulletinCopyright ©2000 - 2006, Jelsoft Enterprises Ltd.