Skip to content

Commit

Permalink
Fixed an issue with island colouring.
Browse files Browse the repository at this point in the history
  • Loading branch information
majikdev committed Oct 25, 2022
1 parent 3314b0f commit 2d09c28
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions precise_uv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"category": "Import-Export"
}

import bpy, os
import bpy, bpy_extras, os

from bpy.props import StringProperty, BoolProperty, IntVectorProperty
from mathutils.geometry import tessellate_polygon
Expand Down Expand Up @@ -186,44 +186,16 @@ def get_meshes_to_export(context):
def get_mesh_triangles(meshes):
for mesh in meshes:
layer = mesh.uv_layers.active.data
islands = []
islands = bpy_extras.mesh_utils.mesh_linked_uv_islands(mesh)

# TODO: Sometimes there are more islands than there should be?
# TODO: Sometimes the island_index is calculated incorrectly.
# Perhaps a vertex resides in more than one island?

for vertex in layer:
if vertex not in [uv for island in islands for uv in island]:
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.uv.select_all(action="DESELECT")
bpy.ops.object.mode_set(mode="OBJECT")

vertex.select = True

bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.uv.select_linked()
bpy.ops.object.mode_set(mode="OBJECT")

layer = mesh.uv_layers.active.data
island = [uv for uv in layer if uv.select]

if island:
islands.append(island)

bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.uv.select_all(action="DESELECT")
bpy.ops.object.mode_set(mode="OBJECT")

layer = mesh.uv_layers.active.data

for polygon in mesh.polygons:
for index, polygon in enumerate(mesh.polygons):
start = polygon.loop_start
end = start + polygon.loop_total
uvs = tuple(uv.uv for uv in layer[start:end])
island_index = 0

for i, island in enumerate(islands):
if layer[start] in island:
if index in island:
island_index = i

for triangle in tessellate_polygon([uvs]):
Expand Down

0 comments on commit 2d09c28

Please sign in to comment.