Edit Normals Modifier


#1

I was wanting to write a maxscript to recalculate vertex normals based on face size. I figure the best way to go about that is the Edit Normal Modifier. So far I’ve got it to iterate through all the normals in the mesh and set the normal to a random value (just for testing). The next step would be to take the normal selection and find which faces are attached to this normal. I don’t see any method of the Edit Normal modifier to do that. Am I overlooking something…is there a way not explicit in the modifier?


#2

the Edit_Normals modifier has pretty good and almost solid interface. i didn’t have any major problems with it. could you explain the problem? where did you get stuck?


#3

I can’t figure out how to determine what faces belong to a given normal.


#4

collect all normals belong to face by using ConvertFaceSelection, andusing the result search for all faces those contain the specified normal.


#5

Thanks for the tip. Works now, and the result looks really good like I was hoping it would.

However its kind of slow. I’m iterating through the model several times. I’m trying to find ways to optimize it. The main point I think is slowing things down is the j for loop. It basically iterates through the result of the ConvertFaceSelection to see which returned true…is there a faster way to do that?

addModifier $ (Edit_Normals ()) ui:on
	
numNorms = $.Edit_Normals.GetNumNormals() 
numFaces = $.Edit_Normals.GetNumFaces() 

normalArray = #()   --place to store temp info for each normal.

--fill in normalArray with junk data.
for i = 1 to numNorms do
(
	append normalArray [0,0,0]
)

-- iterate through all the faces in the mesh.  find out which normals belond to this face and then add the weighted value of the face normal to value already in normalArray
for i = 1 to numFaces do 
(
	curFace = #{i}
	
	connectedNormals = #{}
	$.Edit_Normals.ConvertFaceSelection curFace connectedNormals --should now have a bit array of normals connected to current face.
	faceNormal = ( in coordsys local polyop.getFaceNormal $ i) * (polyop.getFaceArea $ i) --getweighted normal for current face.
	for j = 1 to connectedNormals.count do
	(
		if connectedNormals[j] == true do
		(
			
			normalArray[j] = normalArray[j]+faceNormal --add current face value to it.
			
		)
	)
	
)

--normalize values in normaArray and apply to mesh.
for i = 1 to numNorms do
(
	$.Edit_Normals.SetNormalExplicit i
	normalArray[i] = normalize normalArray[i]
	in coordsys local $.Edit_Normals.SetNormal i normalArray[i]
)

#6

   for j = 1 to connectedNormals.count do if connectedNormals[j] == true do ...
   

is wrong. it has to be:


   for j in connectedNormals do ...
   

you don’t need to iterate through all count of the bitarray. the count set to number of normals in the modifier. you have to iterate only through the bitarray members.


#7

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.