Skip to content

Commit

Permalink
Added an island outline feature
Browse files Browse the repository at this point in the history
  • Loading branch information
majikdev committed Nov 26, 2023
1 parent ff6c152 commit c051c97
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions precise_uv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ExportLayout(bpy.types.Operator):
grid_overlay: BoolProperty(default=True, name='Grid Overlay',
description='Overlay a grid on the exported image')

outline_islands: BoolProperty(default=False, name='Outline Islands',
description='Draw an outline around every island')

@classmethod
def poll(cls, context):
mesh = context.active_object
Expand Down Expand Up @@ -125,18 +128,37 @@ def draw_line(x1, y1, x2, y2):

def get_colour(x, y):
index = indices[y * width + x]
value = 1

if index == -1:
return 0, 0, 0, 0
if index != -1:
value = 1

if self.shade_islands:
value -= (index % 6) * 0.1

if self.grid_overlay and (x + y) % 2 == 1:
value -= 0.04

return value, value, value, 1

if self.outline_islands:
has_l = x > 0
has_r = x < width - 1
has_t = y > 0
has_b = y < height - 1

if self.shade_islands:
value -= (index % 6) * 0.1
neighbours = has_l and indices[y * width + (x - 1)] >= 0
neighbours += has_r and indices[y * width + (x + 1)] >= 0
neighbours += has_t and indices[(y - 1) * width + x] >= 0
neighbours += has_b and indices[(y + 1) * width + x] >= 0
neighbours += has_l and has_t and indices[(y - 1) * width + (x - 1)] >= 0
neighbours += has_r and has_t and indices[(y - 1) * width + (x + 1)] >= 0
neighbours += has_l and has_b and indices[(y + 1) * width + (x - 1)] >= 0
neighbours += has_r and has_b and indices[(y + 1) * width + (x + 1)] >= 0

if self.grid_overlay and (x + y) % 2 == 1:
value -= 0.04
if neighbours > 0:
return 0, 0, 0, 1

return value, value, value, 1
return 0, 0, 0, 0

# Draw triangles to a buffer.

Expand Down

0 comments on commit c051c97

Please sign in to comment.