View Full Version : setFaceNormal?

05 May 2008, 02:17 PM
Any one have any idea of how this work if it works. Funny thing in the help it says that it gets over written when the mesh is updated. What would the point of the function be then?

05 May 2008, 02:28 PM
There's noway in max to set normals and have them not reset some way or the other... The only thing that somehow worked was with the editNormals modifier... you can change normals there and they stick as long as the mesh doesn't deform, then they are reset. I have found no way to change normals and make them stick... max just really sucks at normals...

Some messy code to make all normals in an edit_normals mod look away from a point
Slow on very large meshes... not possible to optimise for realtime... I think...

h = selection[1] -- A geo with an edit normals mod
target = selection[2] -- a point helper or any other object

max modify mode

p = target.pos

select h
hEn = h.Edit_Normals

objTM = h.objecttransform
modTM = getModContextTM h hEn
hPos = objTM.translation
fc = hEn.getNumFaces()

for i in 1 to fc do
fd = hEn.GetFaceDegree i
for ii in 1 to fd do
vId = hEn.getVertexID i ii
nId = hEn.getNormalID i ii

vPos = hEn.GetVertex vId
vDir = normalize ( ( h.pos + vPos ) - p )

hEn.setNormal nId vDir

Maybe of some help,

05 May 2008, 02:43 PM
That is using a modifier again, I can also use the normals modifier to flip them all as that is easier then using edit normals. Whate about rebuilding the mesh with the face vertex creation order reversed?

05 May 2008, 02:50 PM
Yep, that worked, I just reversed the vertex order in the faces and it reversed the normals.

05 May 2008, 03:06 PM
Sorry Johan, I forgot to say thanks for the help and code. Got my head wrapped up in to many things right now to remember common courtesy.

05 May 2008, 03:35 PM
Here is a bit of code, currently doesn't support smoothing groups and I would think mapping coordinates and any other data that is missing. But it does flip the normals.
fn flipNormaps obj=
numV=meshOp.getNumVerts obj.mesh
vertAr=for vert = 1 to numV collect (meshOp.getVert obj.mesh vert)
numF=meshOp.getNumFaces obj.mesh
faceAr=for face = 1 to numF collect (getFace obj.mesh face)

for i = 1 to faceAr.count do
setMesh m verts:vertAr faces:faceAr
update obj.mesh
flipNormaps $

05 May 2008, 03:37 PM
Any one have any idea of how this work if it works. Funny thing in the help it says that it gets over written when the mesh is updated. What would the point of the function be then?

The point is that in Max 2.0, functions were exposed manually (no interfaces yet) and there was always a pair of functions for getting and setting. I assume it was exposed just to have a counterpart to the get method, not to do actually do anything. A Face Normal cannot be changed because it is the normalized cross prodict of two face edges. Vertex Normals in Max are recalculated based on the face normals and smoothing groups. Now when an EditNormals modifier is used, the vertex normals can be marked as explicit and "locked" to survive updates, collapses etc. In fact, I got a mesh from Maya a while ago that was behaving rather strangely until we realised it was imported with the explicit Maya normals locked. We added an EditNormals and restored them so Max would automatically adjust them as usual...
The whole editing of normals was a big wish from the gaming industry (as you might remember) and a sort of an afterthought. Up to around Max 5 it was not possible.

OT: Paul Neale For Max Master (! Go Paul! :)

05 May 2008, 03:41 PM
Thanks for the explanation and the plug Bobo, I bow to the master of all.

05 May 2008, 05:37 PM
Paul, no problem! I put my vote on you, been helping us out for a long time, time for some recognition.

Bobo, I never knew about the make explicit option, this is great news (and I should have RTFineM), should have known it a few months ago... so with that the normals on my script will stick after deforming the mesh.


05 May 2008, 06:29 PM
Thanks for the votes from both of you.

CGTalk Moderation
05 May 2008, 06:29 PM
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.