# Bitangent and Tangent seams

This topic is 2767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi folks, generated some revolution meshes, and noticed that while my uvs seem to be fine there are seams where there join up:

bitangent

tangent:

The seam along one axis is much more apparent than the other.
There must be a simple way to get rid of these and though I would put it to you guys.

While I could probably calculate these more accurately procedurally, I would like the method to work for loaded geometry too.

here's the code:

var ids:Vector.<uint> = mesh.ids; var vertices:Vector.<Number> = mesh.vertices; var uvs:Vector.<Number> = mesh.uvs; var tangents:Vector.<Number> = new Vector.<Number>(vertices.length); var bitangents:Vector.<Number> = new Vector.<Number>(vertices.length); var numTriangles:int = ids.length; for(var i:int = 0; i < numTriangles; i+=3) { var id1:int = ids; var id2:int = ids[i+1]; var id3:int = ids[i+2]; var p1:Vector3D = new Vector3D(vertices[int(id1 * 3)], vertices[int(id1 * 3 + 1)], vertices[int(id1 * 3 + 2)]); var p2:Vector3D = new Vector3D(vertices[int(id2 * 3)], vertices[int(id2 * 3 + 1)], vertices[int(id2 * 3 + 2)]); var p3:Vector3D = new Vector3D(vertices[int(id3 * 3)], vertices[int(id3 * 3 + 1)], vertices[int(id3 * 3 + 2)]); var uv1:Point = new Point(uvs[int(id1 * 2)], uvs[int(id1 * 2 + 1)]); var uv2:Point = new Point(uvs[int(id2 * 2)], uvs[int(id2 * 2 + 1)]); var uv3:Point = new Point(uvs[int(id3 * 2)], uvs[int(id3 * 2 + 1)]); var edge1:Vector3D = p2.subtract(p1); var edge2:Vector3D = p3.subtract(p1); var edge1uv:Point = uv2.subtract(uv1); var edge2uv:Point = uv3.subtract(uv1); var cp:Number = edge1uv.y * edge2uv.x - edge1uv.x * edge2uv.y; if ( cp != 0 ) { var mul:Number = 1 / cp; var tangent:Vector3D = new Vector3D(); var bitangent:Vector3D = new Vector3D(); tangent.x = (edge2uv.y * edge1.x - edge1uv.y * edge2.x) * mul; tangent.y = (edge2uv.y * edge1.y - edge1uv.y * edge2.y) * mul; tangent.z = (edge2uv.y * edge1.z - edge1uv.y * edge2.z) * mul; bitangent.x = (-edge2uv.x * edge1.x + edge1uv.x * edge2.x) * mul; bitangent.y = (-edge2uv.x * edge1.y + edge1uv.x * edge2.y) * mul; bitangent.z = (-edge2uv.x * edge1.z + edge1uv.x * edge2.z) * mul; tangent.normalize(); bitangent.normalize(); tangents[int(id1 * 3)] = tangent.x; tangents[int(id1 * 3 + 1)] = tangent.y; tangents[int(id1 * 3 + 2)] = tangent.z; tangents[int(id2 * 3)] = tangent.x; tangents[int(id2 * 3 + 1)] = tangent.y; tangents[int(id2 * 3 + 2)] = tangent.z; tangents[int(id3 * 3)] = tangent.x; tangents[int(id3 * 3 + 1)] = tangent.y; tangents[int(id3 * 3 + 2)] = tangent.z; bitangents[int(id1 * 3)] = bitangent.x; bitangents[int(id1 * 3 + 1)] = bitangent.y; bitangents[int(id1 * 3 + 2)] = bitangent.z; bitangents[int(id2 * 3)] = bitangent.x; bitangents[int(id2 * 3 + 1)] = bitangent.y; bitangents[int(id2 * 3 + 2)] = bitangent.z; bitangents[int(id3 * 3)] = bitangent.x; bitangents[int(id3 * 3 + 1)] = bitangent.y; bitangents[int(id3 * 3 + 2)] = bitangent.z; } } mesh.tangents = tangents; mesh.bitangents = bitangents;

hopefully you will know right off the bat what the issue is, thank for your time

edit:
ah, looks like all I need to do is average them as I would the normals? if that's case then boy am I a melon.

##### Share on other sites
solved

smooth as a peach, just had to rewrite an alternative method to generate the shared triangle list (don't use index id, use physical position with slight rounding)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 21
• 21
• 11
• 9