Notifications
Clear all

[Closed] select visible faces?

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.

5 Replies
1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

--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() 
 

Wonderful, just what I needed . Thanks.

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.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0
 
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…)

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.