[Closed] Selection modifyer based on surface normal?
Hi all,
basically I’m looking for a selection modifyer that will select all faces that point up. It doesn’t have to be “perfect” up vector, just anything pointed at the upper hemisphere of the sky rather than the lower hemisphere (I would assume that means that all it has to check for, is that the “z” value of the surface normal vector is above 0?)
The selection has do be dynamic, as the mesh is animated.
Does anyone know if this exists, or if something similar exist, that can be modyfied?
I know, in this forum I’m merely supposed to get help scripting it myself, but alas, despite many intentions I never got around to getting started in Maxscript… so bear with me, I’m looking for a finished or almost-finished solution.
Cheers all, and thanks a billion for any help.
- Jonas
Hi.
This function selects the faces pointing up with some angle variation:
fn selectUpFaces polyObj range = (
-- Array where the faces will be stored
local upFaces = #()
-- Loop through the faces of the object
for f = 1 to (polyOp.getNumFaces polyObj) do (
-- Calculate the angle between the world up vector and the face normal
local acosine = acos (dot [0,0,1] (polyOp.getFaceNormal polyObj f))
-- If the angle is in the specified range...
if acosine <= range do (
-- Append the face to our array of faces
append upFaces f
)
)
-- Select the faces pointing to or desired direction
polyOp.setFaceSelection polyObj upFaces
)
The parameter “range” is the angle variation. So if, for example, it’s equal to 45º, all the faces with normals pointing straight up or an angle between 0º and 45º will be selected. Obviously, if you specify a range of 180º, all faces will be selected.
This function works for poly editable objects.
Hope that helps.
I’ve introduced another variable so now you can specify the start and end values for the angle range.
fn selectUpFaces polyObj start end = (
-- Array where the faces will be stored
local upFaces = #()
-- Loop through the faces of the object
for f = 1 to (polyOp.getNumFaces polyObj) do (
-- Calculate the angle between the world up vector and the face normal
local acosine = acos (dot [0,0,1] (polyOp.getFaceNormal polyObj f))
-- If the angle is in the specified range...
if acosine >= start and acosine <= end do (
-- Append the face to our array of faces
append upFaces f
)
)
-- Select the faces pointing to or desired direction
polyOp.setFaceSelection polyObj upFaces
)
Obviously, this is a function and not a modifier, so probably this is not exactly what you want but anyway it’s the main functionality of what you want.
Greets.