PDA

View Full Version : select visible faces?


Haamu
12-26-2004, 08:56 PM
Can anyone think of any good way to select all the faces that are visible to camera/view. Much like checking ignore backfacing and doing a selection in Epoly, but via script.

Bobo
12-27-2004, 11:09 AM
Can anyone think of any good way to select all the faces that are visible to camera/view. Much like checking ignore backfacing and doing a selection in Epoly, but via script.


--Get the viewport TMatrix, invert to get the equivalent of a camera transformation
theTM = inverse (viewport.getTM())
--Loop through all geometry objects that have EPoly Base Object
for theObj in Geometry where classof theObj.baseobject == Editable_Poly do
(
theFacesToSelect = #{} --ini. a bitArray to collect faces to select
numFaces = polyOp.getNumFaces theObj --get the number of polygons in the EPoly
--loop from 1 to the number of polygons and set the corresponding bit in the bitArray
--to true if the normal of the polygon as seen in camera space has a positive Z,
--and false if it is negative or zero (facing away from the camera)
for f = 1 to numFaces do
theFacesToSelect[f] = (in coordsys theTM polyOp.getFaceNormal theObj f).z > 0
--finally, set the selection in the object
polyOp.setFaceSelection theObj theFacesToSelect
)
--when done with all, redraw the views - if a Poly SO level is selected,
--the selection will be updated in the viewport...
redrawViews()

Haamu
12-27-2004, 01:35 PM
Wonderful, just what I needed :thumbsup:. Thanks.

cutcopypaste
12-27-2004, 09:22 PM
Bobo, (or anyone else of course)

Can you make this script to do :

Select from view (as already done above)
*Invert selection (sub-object-polygons)
*Hide selection (sub-object-polygons)

*perform for all selections in the set. (not by having to do this manually to each individual item)

I just kind of thought that this might be an interesting manner to quickly hide geometry that isn't necessary to be viewed. (wouldn't this speed-up the viewport redraw in heavy scenes ?)

Of course if this is true then you'd probably want a button to un-hide all "hidden" sub-object-polygons with one click as well.

Just a thought.

Bobo
12-27-2004, 09:57 PM
Bobo, (or anyone else of course)

Can you make this script to do :

Select from view (as already done above)
*Invert selection (sub-object-polygons)
*Hide selection (sub-object-polygons)

*perform for all selections in the set. (not by having to do this manually to each individual item)

I just kind of thought that this might be an interesting manner to quickly hide geometry that isn't necessary to be viewed. (wouldn't this speed-up the viewport redraw in heavy scenes ?)

Of course if this is true then you'd probably want a button to un-hide all "hidden" sub-object-polygons with one click as well.

Just a thought.


theTM = inverse (viewport.getTM())
for theObj in Geometry where classof theObj.baseobject == Editable_Poly do
(
theFacesToSelect = #{}
numFaces = polyOp.getNumFaces theObj
for f = 1 to numFaces do
theFacesToSelect[f] = (in coordsys theTM polyOp.getFaceNormal theObj f).z <= 0
polyOp.setFaceSelection theObj theFacesToSelect
theObj.Hide #Face
)
redrawViews()



This is easy, but not really necessary.
The changes:
*Instead of >0, the check does <= 0 for the normals to select the back-faces.
*Then, after setting the face selection, it calls Hide for the selected Faces.

It doesn't make much sense because Max does fast back-face culling in the viewports by default, and the renderer also renders single-sided (skipping just the faces we removed) unless you force 2-sided...

I don't see this as a useful tool, just as an "accademic" example of comparing face normals in camera space. (Max 7 users can also check out the MAXScript FAQ for a very similar example I added in the last update...)

mrapelje
12-31-2004, 06:10 PM
I looked for a tool like this awhile ago for games. We had some really nice gun models for the first person player view, but they were to little to high poly for the platform we were developing for, and we wanted take out all the back faces before export... I ended up doing this manually. With a script we could have done this a lot quicker.

Just one example of how this script could be used.

CGTalk Moderation
01-20-2006, 07:00 AM
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.