   Problems with tangents
  I made an exporter for Blender that should calculate tangents for a mesh. I based my code on this site.#per facedCo1 = face.verts[1].co - face.verts[0].codCo2 = face.verts[2].co - face.verts[0].codUV1 = face.uv[1] - face.uv[0]dUV2 = face.uv[2] - face.uv[0]r = 1.0 / (dUV1.x * dUV2.y - dUV2.x - dUV1.y)sDir = Blender.Mathutils.Vector ((dUV2.y * dCo1.x - dUV1.y * dCo2.x) * r, (dUV2.y * dCo1.y - dUV1.y * dCo2.y) * r, (dUV2.y * dCo1.z - dUV1.y * dCo2.z) * r)tDir = Blender.Mathutils.Vector ((dUV1.x * dCo2.x - dUV2.x * dCo1.x) * r, (dUV1.x * dCo2.y - dUV2.x * dCo1.y) * r, (dUV1.x * dCo2.z - dUV2.x * dCo1.z) * r)expTan[face.verts[0].index] += sDir;expTan[face.verts[1].index] += sDir;expTan[face.verts[2].index] += sDir;expTanAux[face.verts[0].index] += tDir;expTanAux[face.verts[1].index] += tDir;expTanAux[face.verts[2].index] += tDir;#per vertexn = mesh.verts[expVert].not = expTan[expVert] #in Python variables initialized this way get linkedb = expTanAux[expVert]t = t - n * Blender.Mathutils.DotVecs (n, t)tL = math.sqrt (t.x * t.x + t.y * t.y + t.z * t.z)if Blender.Mathutils.DotVecs (Blender.Mathutils.CrossVecs (n, t), b) < 0:t = -t / tLelse:t = t / tLThe results contain some errors. See for yourself. Any ideas what can be causing this? Blender's math should be okay, because it outputs the correct geometry. I suppose that there is something wrong in the equations. It seems to be having some difficulty calculating tangents that have X component near 0.   
Quote:r = 1.0 / (dUV1.x * dUV2.y - dUV2.x - dUV1.y)I haven't really read enough of the code to know what it's doing, but that quantity looks fishy. Where did you get the formulas? Do you understand the Math? Can you explain what `r' is?Edit: Oh, you posted a link to where you got the code from. Notice how you didn't copy the definition of `r' correctly.   ;  Ok, stupid me. I checked the variables' names so many times I forgot to check the operators. Thanks, alvaro, for pointing that out.SOLVED