2
2
"name" : "Precise UV Export" ,
3
3
"description" : "Export pixel-perfect UV layouts as images" ,
4
4
"author" : "majik" ,
5
- "version" : (1 , 1 , 1 ),
5
+ "version" : (1 , 2 , 0 ),
6
6
"blender" : (3 , 0 , 0 ),
7
7
"category" : "Import-Export"
8
8
}
@@ -30,6 +30,9 @@ class ExportLayout(bpy.types.Operator):
30
30
31
31
shade_islands : BoolProperty (default = True , name = "Shade Islands" ,
32
32
description = "Shade separate UV islands differently" )
33
+
34
+ show_overlap : BoolProperty (default = True , name = "Show Overlap" ,
35
+ description = "Shade overlapping UV islands differently" )
33
36
34
37
@classmethod
35
38
def poll (cls , context ):
@@ -91,8 +94,7 @@ def draw_line(ax, ay, bx, by):
91
94
92
95
while dist < length :
93
96
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 )
96
98
97
99
if x_dist < y_dist :
98
100
x_dist += x_delta
@@ -114,19 +116,34 @@ def fill_poly(ax, ay, bx, by, cx, cy):
114
116
positive = dist_a > 0 or dist_b > 0 or dist_c > 0
115
117
116
118
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
119
137
120
- def get_colour ():
121
138
if self .shade_islands :
122
- value = 1 - (island_index % 9 ) * 0.05
139
+ value = 1 - (index - 1 ) % 9 * 0.05
123
140
124
141
return value , value , value , 1
125
142
126
143
return 1 , 1 , 1 , 1
127
144
128
145
width , height = self .size
129
- pixels = [0 , 0 , 0 , 0 ] * width * height
146
+ pixels = [0 ] * width * height
130
147
131
148
for triangle in triangles :
132
149
island_index = triangle .pop ()
@@ -146,6 +163,8 @@ def get_colour():
146
163
147
164
fill_poly (* v1 , * v2 , * v3 )
148
165
166
+ pixels = [v for pixel in pixels for v in get_colour (pixel )]
167
+
149
168
try :
150
169
image = bpy .data .images .new ("temp" , width , height , alpha = True )
151
170
image .filepath , image .pixels = path , pixels
0 commit comments