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.
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.
