Notifications
Clear all

[Closed] Select Face by Normal

Simple Script to select top faces.


myFaceNumbers = polyOp.getNumFaces $
MySelectionSet=#() 

for i = 1 to myFaceNumbers do
	( 
	myFace = i
	myNormal = polyOp.getFaceNormal $ myFace
 
	if myNormal == [0,0,1] then 
		(
	    join MySelectionSet #(myFace)
	   Print MySelectionSet
		)
	)		
	
setFaceSelection $ MySelectionSet

3 Replies

It is a better idea to calculate the angle between the desired vector (in your case [0,0,1]) and the face normal and compare to a threshold.

theVector = [0,0,1]
theThreshold = 0.01
theAngle = acos(dot theNormal theVector)
if theAngle <= theThreshold do …

Because Point3 value components are floats, sometimes a normal pointing up might have a floating point imprecision and not be exactly [0,0,1] while still VERY close to it. Also , if you want all normals that are +/- 10 degrees from the reference direction, you can just set theThreshold to 10 and fire away…

Threshold ! :lightbulb

Bobo reads my thoughts. Exactly what I need, thank you.

1 Reply
(@bobo)
Joined: 11 months ago

Posts: 0

Keine Ursache!

Btw, keep in mind that both vectors used in the DOT function should be normalized. Normally, face normals are normalized, but just to be completely sure you can say

theAngle = acos ( dot (normalize theNormal) (normalize theVector) )