Skip to content

Commit

Permalink
Merge pull request KhronosGroup#1117 from scurest/loop-tris
Browse files Browse the repository at this point in the history
Export: use mesh.loop_triangles
  • Loading branch information
julienduroure authored Jul 21, 2020
2 parents 317bc60 + 2adf6ef commit 2710386
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions addons/io_scene_gltf2/blender/exp/gltf2_blender_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#

from mathutils import Vector, Quaternion, Matrix
from mathutils.geometry import tessellate_polygon

from . import gltf2_blender_export_keys
from ...io.com.gltf2_io_debug import print_console
Expand Down Expand Up @@ -232,7 +231,11 @@ def extract_primitives(glTF, blender_mesh, library, blender_object, blender_vert

prims = {}

for blender_polygon in blender_mesh.polygons:
blender_mesh.calc_loop_triangles()

for loop_tri in blender_mesh.loop_triangles:
blender_polygon = blender_mesh.polygons[loop_tri.polygon_index]

material_idx = -1
if use_materials:
material_idx = blender_polygon.material_index
Expand All @@ -257,28 +260,7 @@ def extract_primitives(glTF, blender_mesh, library, blender_object, blender_vert
face_tangent.normalize()
face_bitangent.normalize()

loop_index_list = []

if len(blender_polygon.loop_indices) == 3:
loop_index_list.extend(blender_polygon.loop_indices)
elif len(blender_polygon.loop_indices) > 3:
# Triangulation of polygon. Using internal function, as non-convex polygons could exist.
polyline = []

for loop_index in blender_polygon.loop_indices:
vertex_index = blender_mesh.loops[loop_index].vertex_index
v = blender_mesh.vertices[vertex_index].co
polyline.append(Vector((v[0], v[1], v[2])))

triangles = tessellate_polygon((polyline,))

for triangle in triangles:
for triangle_index in triangle:
loop_index_list.append(blender_polygon.loop_indices[triangle_index])
else:
continue

for loop_index in loop_index_list:
for loop_index in loop_tri.loops:
vertex_index = blender_mesh.loops[loop_index].vertex_index
vertex = blender_mesh.vertices[vertex_index]

Expand Down

0 comments on commit 2710386

Please sign in to comment.