From ed2c38a96db2bd8caffac4a60d9aa513812102b9 Mon Sep 17 00:00:00 2001 From: franMarz Date: Wed, 13 Mar 2024 13:19:09 +0100 Subject: [PATCH] Improve Select Zero Look for consecutively aligned vertices, improves the detection of internal degenerates in a face respect to the former version. Adjusted precision, which now can be adjusted in the Redo panel when no degenerate triangles are found. --- op_select_zero.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/op_select_zero.py b/op_select_zero.py index 9b6bbea..3e1caa2 100644 --- a/op_select_zero.py +++ b/op_select_zero.py @@ -11,7 +11,7 @@ class op(bpy.types.Operator): bl_description = "Select degenerate UVs (zero area UV triangles)" bl_options = {'REGISTER', 'UNDO'} - precision: bpy.props.FloatProperty(name='Precision', default=0.0001, min=0, step=0.00001, precision=8) + precision: bpy.props.FloatProperty(name='Precision', default=0.00005, min=0, step=0.00001, precision=7) @classmethod def poll(cls, context): @@ -40,22 +40,27 @@ def select_zero(self): for obj in utilities_uv.selected_unique_objects_in_mode_with_uv(): bm = bmesh.from_edit_mesh(obj.data) uv_layer = bm.loops.layers.uv.verify() - for l1, l2, l3 in bm.calc_loop_triangles(): - area = mathutils.geometry.area_tri(l1[uv_layer].uv, l2[uv_layer].uv, l3[uv_layer].uv) - tolerance = max((l1[uv_layer].uv - l2[uv_layer].uv).length, (l2[uv_layer].uv - l3[uv_layer].uv).length, (l1[uv_layer].uv - l3[uv_layer].uv).length)**2 * self.precision - if area < tolerance: - if sync: - if not l1.face.select: - counter += 1 - l1.face.select_set(True) - else: - for i in l1.face.loops: - i[uv_layer].select = True + for f in bm.faces: + for l in f.loops: + l1 = l[uv_layer].uv + l2 = l.link_loop_next[uv_layer].uv + l3 = l.link_loop_prev[uv_layer].uv + area = mathutils.geometry.area_tri(l1, l2, l3) + thres = max((l1-l2).length, (l2-l3).length, (l1-l3).length)**2 * self.precision + if area < thres: + if sync: + f.select_set(True) + else: + for i in f.loops: + i[uv_layer].select = True counter += 1 + break + elif len(f.loops) == 3: + break if not counter: self.report({'INFO'}, f'Degenerate triangles not found') - return {'CANCELLED'} + return {'FINISHED'} # Workaround to flush the selected UVs from loops to faces if not sync: