Delete faces away from camera (culling)

Hi!

I am abit new to maxscript and I am trying to create a script that will loop through the bojects in scene and delete faces that are not facing the camera. I found a script that works to a point but at certain angles the wrong faces gets deleted. The script I use:

 (
	for theMesh in Geometry where not theMesh.isHiddenInVpt and classof theMesh != TargetObject do
	(
		convertToMesh theMesh --convert to EMesh
		theMeshCount = theMesh.numfaces --get the number of faces in the object
		selArray = #() --init. an array to collect faces
		for f = 1 to theMeshCount do --loop through all faces
		(
		  in coordsys (inverse (viewport.GetTM())) theFN = getFaceNormal theMesh f
		  if theFN.z < 0 then append selArray f -- if Z is negative, add to array
		)
		setFaceSelection theMesh selArray --set the face selection in the EMesh
		max modify mode --go to modify mode
		select theMesh --select the mesh
		subObjectLevel = 3 --go to Face SO level
		modPanel.addModToSelection (deleteMesh()) --add a delete mesh, preserving the SO selection
	)
)

I also put a 3dsmax scene on dropbox with a camera001 that shows the problem and a camera002 that works just fine.(saved in 3dsmax 2012):
https://www.dropbox.com/sh/yopvor8kyzl1893/AADOb7_u57ZP7EYmlTub_DyLa?dl=0

Anyone know what I might be missing here or a solution for this?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
borgb's picture

Ok, so I got some help from

Ok, so I got some help from CGtalk forum where someone suggested the use of flags and polyop to get the faces that turn away from camera. This works great from one view, but it seems that something needs to get updated in order for the flags to be set correctly. If I take an editable poly, go to face level, select all faces, deselect faces, go out of subobject level and deselect object, it will report flags correctly in that view. (0 = normal, 8 = away from camera) However, if I change the view it will still report the same flags for the same faces and I have to do the process again.

I have tried doing the same thing only in script but that does not work. the update does not work. redraw views does not seem to help either.. I can ony manage to get the result by doing it manually. What am I missing?

code that I use for checking:

(
	for obj in geometry where not obj.isHiddenInVpt and not isKindOf obj TargetObject do
	(
		for f = 1 to polyop.getNumFaces obj do
		(
			local faceFlag = polyop.getFaceFlags obj f
			print faceFlag
		)
	)
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.