PDA

View Full Version : Setting normals


RobGalanakis
03-03-2008, 08:03 PM
For my last game, we had this system for paintovers where we would push out a vert along its normal for paintover clothing, with vertex color controlling how far. This worked well, but now I have some free time and want to make the system more robust, to be able to move the verts more arbitrarily and not just along the normal.

First, I tried to adjust the vert normal based on red and green, with blue controlling 'how far.' This worked, but was way too unwieldy to use effectively.

This gave me the idea to duplicate the mesh, deform it at will, then get a vector that will take the old vert and put it at the new vert. However, the caveat is that, since this is a paintover, I cannot change the mesh data... I need to use the original vertex normal, which means I will need to adjust/bias it based on the vertex colors (baked out into a texture in the game engine). Regardless, I can for now simply adjust the actual geo normal, encoding it into a color I haven't even got to yet.

Here is some pseudo-code:

a = selection[1] --old, with edit normals modifier
b = selection[2] --new

for i in 1 to 500 do ( --range of verts, shorter for speed ATM, eventually entire mesh
oldPos = getVert a i
newPos = getVert b i

subVec = oldPos - newPos --vector from old to new vert
--dist = length subVec

dirVec = normalize subVec --direction from old to new vert
--oldNormal = getNormal a i --normal of old vert

--diffDir = oldNormal - dirVec

--setNormal a dirVec --This doesn't seem to do anything?
a.modifiers[1].setNormal i dirVec --this is broken
)


Basically, setNormal() doesn't seem to work... it doesn't change the vert normal at all.
edit_normal.setNormal DOES do something: it 'removes' the normal in question, doesn't allow me to edit it in the modifier anymore, etc.

Has anyone had any luck or experience with setting normals? Once I get this figured out it should be trivial to convert it into vertex colors to bias the original normal. Since adjusting the actual vert normal isn't part of the final tool/shader, what I'm asking is sort of useless at the end, but I want to make sure what I'm doing actually works before I go ahead and write the rest, and also so I have something very explicit to compare the much less direct vert-color based version.

bleubleu
10-03-2008, 02:42 AM
I know it is a super old thread, but I just want the information to be out there if anyone else needs it.

First, setting the normal using setNormal will not work. Normals for meshes and editable polys are implicitely computed from face normals and smoothing groups.

Second, the edit normal method is the way to go. You were close, the only thing mssing is a call to "SetNormalExplicit" before setting it. Explicit normals means that normal are no longuer computer from smoothing groups, but specified by you. Note that explicit normals are destroyed when collapsing the stack and can behave strangely when combined with other modifiers.

Please check out the documentation at Documentation (http://www.kxcad.net/autodesk/Autodesk_MAXScript_Reference_9/Edit_Normals_Modifier.htm).

Mat

CGTalk Moderation
10-03-2008, 02:42 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.