Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created October 3, 2015 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/20752881b72e697bddc5 to your computer and use it in GitHub Desktop.
Save zeffii/20752881b72e697bddc5 to your computer and use it in GitHub Desktop.
find tris and non planar poygons
# This example assumes we have a mesh object selected
import bpy
import bmesh
import mathutils
from mathutils import Vector
tessellate = mathutils.geometry.tessellate_polygon
normal_of = mathutils.geometry.normal
mesh = bpy.context.object.data
for f in mesh.polygons:
if len(f.vertices) == 3:
f.select = True
continue
# 4 or more vertices. let's check coplanarity by
v = [mesh.vertices[i].co for i in f.vertices[:]]
start_normal = Vector()
for idx, pol in enumerate(tessellate([v])):
vectors = [v[i] for i in pol]
if idx == 0:
start_normal = normal_of(vectors)
else:
if (start_normal-normal_of(vectors)).length > 0.002:
f.select = True
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment