# Fix t-junction in mesh

I'm currently modifying a mesh using a Python script. I just realised that my mesh have a few t-junctions, which I would like to fix. Is there any way to fix t-junctions in Blender? If so, is it also possible to do this from script?

Clarification: My mesh contains t-junctions where the vertices are disconnected from the opposite face. A script or Blender feature that just 'glues'/connects the vertex would also work fine for me. • see if this helps T-Junction-remover – Chebhou Mar 28 '15 at 15:02
• The script is quite old and doesn't run on the current Blender version. I was hoping to find some off-the-shelf solution that worked out of the box. (If not, I have a few ideas of how to make such script myself) – Mortennobel Mar 28 '15 at 15:34

I came up with the solution below, which seems to work. Generally I just create faces in the holes (the black on the figure above) and finally dissolve degenerate (since the newly introduced faced has the area of zero).

import bpy
import bmesh
from math import radians, degrees, pi, atan2
from mathutils import Vector, Euler

def isEdgesOverlapping(v, e1, e2):
if e1 == e2:
return False
v0 = v.co
v1 = None
v2 = None
if (e1.verts == v):
v1 = e1.verts.co
else:
v1 = e1.verts.co
if (e2.verts == v):
v2 = e2.verts.co
else:
v2 = e2.verts.co
dir1 = (v1 - v0).normalized()
dir2 = (v2 - v0).normalized()
if dir1.cross(dir2) < 0.00001 and dir1.dot(dir2) > 0.5:
return True
return False

def fixTJunctions2(bm):
for e in bm.edges:
e.select = False
for v in bm.verts:
if isEdgesOverlapping(v, e1, e2):
e1.select = True
e2.select = True
return True
return False

def fixTJunctions(obj):
if bpy.context.mode == 'OBJECT':
bpy.ops.object.mode_set(mode='EDIT', toggle=True)
bm = bmesh.from_edit_mesh(obj.data)
for e in bm.edges:
e.select = False
continueLoop = True
count = 0
while continueLoop:
bm.faces.ensure_lookup_table()
bm.edges.ensure_lookup_table()
bm.verts.ensure_lookup_table()
continueLoop = fixTJunctions2(bm)
count = count + 1
if count > 1:
bpy.ops.mesh.dissolve_degenerate()

obj = bpy.context.active_object
fixTJunctions(obj)