There are a great many routines floating around this forum to handle DOT3 vertex colors, but they aren't completely correct. You have to consider the mapping axes of the vertex, or which direction the texture is laid onto the surface. If the normal map is flipped, the results are going to be different.
Since my brushes from 3D World Studio already use mapping axes, I can correctly normal map my static world quite easily. However, triangle meshes are proving to be more difficult, because their mapping axes must be extrapolated from arbitrary texture coordinates. This is where I am having a problem.
The first step would be to go through all the triangles in the mesh and calculate mapping axes for each vertex in the triangle:
Then you have to figure out what direction the U and V vectors point. Anyone have any code to help me complete this?
Once I get the mapping axes, everything else is ready and working.
Since my brushes from 3D World Studio already use mapping axes, I can correctly normal map my static world quite easily. However, triangle meshes are proving to be more difficult, because their mapping axes must be extrapolated from arbitrary texture coordinates. This is where I am having a problem.
The first step would be to go through all the triangles in the mesh and calculate mapping axes for each vertex in the triangle:
Method BuildMappingAxes() For t=0 To indicearray.size()/6-1 a=PeekShort(indicearray,t*6+0) b=PeekShort(indicearray,t*6+2) c=PeekShort(indicearray,t*6+4) Ax#=PeekFloat(vertexarray,a*12+0) Ay#=PeekFloat(vertexarray,a*12+4) Az#=PeekFloat(vertexarray,a*12+8) Bx#=PeekFloat(vertexarray,b*12+0) By#=PeekFloat(vertexarray,b*12+4) Bz#=PeekFloat(vertexarray,b*12+8) Cx#=PeekFloat(vertexarray,c*12+0) Cy#=PeekFloat(vertexarray,c*12+4) Cz#=PeekFloat(vertexarray,c*12+8) Au#=PeekFloat(texcoordarray,a*8+0) Av#=PeekFloat(texcoordarray,a*8+4) Bu#=PeekFloat(texcoordarray,b*8+0) Bv#=PeekFloat(texcoordarray,b*8+4) Cu#=PeekFloat(texcoordarray,c*8+0) Cv#=PeekFloat(texcoordarray,c*8+4) TrianglePlane(ax,ay,az,bx,by,bz,cx,cy,cz) nx#=TFormedX() ny#=TFormedY() nz#=TFormedZ() Next EndMethod
Then you have to figure out what direction the U and V vectors point. Anyone have any code to help me complete this?
Once I get the mapping axes, everything else is ready and working.
