|
|
// Finds binormal based on three vertices with texture coordinates.
// Fills in dummy values if the triangle has degenerate texture coordinates.
LLVector3 calc_binormal_from_triangle(
const LLVector3& pos0,
const LLVector2& tex0,
const LLVector3& pos1,
const LLVector2& tex1,
const LLVector3& pos2,
const LLVector2& tex2)
{
LLVector3 rx0( pos0.mV[VX], tex0.mV[VX], tex0.mV[VY] );
LLVector3 rx1( pos1.mV[VX], tex1.mV[VX], tex1.mV[VY] );
LLVector3 rx2( pos2.mV[VX], tex2.mV[VX], tex2.mV[VY] );
LLVector3 ry0( pos0.mV[VY], tex0.mV[VX], tex0.mV[VY] );
LLVector3 ry1( pos1.mV[VY], tex1.mV[VX], tex1.mV[VY] );
LLVector3 ry2( pos2.mV[VY], tex2.mV[VX], tex2.mV[VY] );
LLVector3 rz0( pos0.mV[VZ], tex0.mV[VX], tex0.mV[VY] );
LLVector3 rz1( pos1.mV[VZ], tex1.mV[VX], tex1.mV[VY] );
LLVector3 rz2( pos2.mV[VZ], tex2.mV[VX], tex2.mV[VY] );
LLVector3 r0 = (rx0 - rx1) % (rx0 - rx2);
LLVector3 r1 = (ry0 - ry1) % (ry0 - ry2);
LLVector3 r2 = (rz0 - rz1) % (rz0 - rz2);
if( r0.mV[VX] && r1.mV[VX] && r2.mV[VX] )
{
LLVector3 binormal(
-r0.mV[VZ] / r0.mV[VX],
-r1.mV[VZ] / r1.mV[VX],
-r2.mV[VZ] / r2.mV[VX]);
//binormal.normVec();
return binormal;
}
else
{
return LLVector3( 0, 1 , 0 );
}
}
为什么要用纹理UV 去求顶点副法线?什么数学原理? |
|