View Full Version : Select Face by Normal
blenderman0815 12-19-2007, 07:01 PM 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
|
|
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...
blenderman0815
12-21-2007, 08:24 AM
Threshold ! :lightbulb
Bobo reads my thoughts. Exactly what I need, thank you.
Threshold ! :lightbulb
Bobo reads my thoughts. Exactly what I need, thank you.
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) )
CGTalk Moderation
12-21-2007, 08:29 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.