Skip to content

Commit 6c19042

Browse files
committed
Added an option to show overlapping UV islands.
1 parent 0124fdb commit 6c19042

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

precise_uv_export.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "Precise UV Export",
33
"description": "Export pixel-perfect UV layouts as images",
44
"author": "majik",
5-
"version": (1, 1, 1),
5+
"version": (1, 2, 0),
66
"blender": (3, 0, 0),
77
"category": "Import-Export"
88
}
@@ -30,6 +30,9 @@ class ExportLayout(bpy.types.Operator):
3030

3131
shade_islands: BoolProperty(default=True, name="Shade Islands",
3232
description="Shade separate UV islands differently")
33+
34+
show_overlap: BoolProperty(default=True, name="Show Overlap",
35+
description="Shade overlapping UV islands differently")
3336

3437
@classmethod
3538
def poll(cls, context):
@@ -91,8 +94,7 @@ def draw_line(ax, ay, bx, by):
9194

9295
while dist < length:
9396
if x_min <= x < x_max and y_min <= y < y_max:
94-
offset = (y * width + x) * 4
95-
pixels[offset:offset + 4] = get_colour()
97+
set_index(x, y)
9698

9799
if x_dist < y_dist:
98100
x_dist += x_delta
@@ -114,19 +116,34 @@ def fill_poly(ax, ay, bx, by, cx, cy):
114116
positive = dist_a > 0 or dist_b > 0 or dist_c > 0
115117

116118
if not (negative and positive):
117-
offset = (y * width + x) * 4
118-
pixels[offset:offset + 4] = get_colour()
119+
set_index(x, y)
120+
121+
def set_index(x, y):
122+
offset = y * width + x
123+
index = island_index + 1
124+
current = pixels[offset]
125+
126+
if self.show_overlap and current != 0 and current != index:
127+
index = -1
128+
129+
pixels[offset] = index
130+
131+
def get_colour(index):
132+
if index == 0:
133+
return 0, 0, 0, 0
134+
135+
if index == -1:
136+
return 0.1, 0.1, 0.1, 1
119137

120-
def get_colour():
121138
if self.shade_islands:
122-
value = 1 - (island_index % 9) * 0.05
139+
value = 1 - (index - 1) % 9 * 0.05
123140

124141
return value, value, value, 1
125142

126143
return 1, 1, 1, 1
127144

128145
width, height = self.size
129-
pixels = [0, 0, 0, 0] * width * height
146+
pixels = [0] * width * height
130147

131148
for triangle in triangles:
132149
island_index = triangle.pop()
@@ -146,6 +163,8 @@ def get_colour():
146163

147164
fill_poly(*v1, *v2, *v3)
148165

166+
pixels = [v for pixel in pixels for v in get_colour(pixel)]
167+
149168
try:
150169
image = bpy.data.images.new("temp", width, height, alpha=True)
151170
image.filepath, image.pixels = path, pixels

0 commit comments

Comments
 (0)