Skip to content

Commit

Permalink
Implemented a grid/checkerboard overlay.
Browse files Browse the repository at this point in the history
  • Loading branch information
majikdev committed Dec 22, 2022
1 parent 0440f10 commit feb3ac3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Convenient for making low-resolution pixelated textures, where the default UV ex

The exported image takes the size of the image in the editor, or 16x16.<br>
Each island in the UV layout is coloured in a different shade of grey.<br>
Pixels, where multiple UV islands overlap, are coloured in black.
Each island also has a checkerboard overlay to make referencing the model easier.<br>
Pixels, where multiple UV islands overlap, can be set to black (not enabled by default).

*These settings can be changed during the exporting process.*
35 changes: 23 additions & 12 deletions precise_uv_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,22 @@ def set_index(x, y):

pixels[offset] = index

def get_colour(index):
def get_colour(position, index):
if index == 0:
return 0, 0, 0, 0

if index == -1:
return 0.1, 0.1, 0.1, 1
return 0.0, 0.0, 0.0, 0.0

if self.shade_islands:
value = 1 - (index - 1) % 9 * 0.05
# White normally, dark grey if overlap.
value = 1.0 if index > 0 else 0.1

return value, value, value, 1

return 1, 1, 1, 1
# Give islands different shades of grey.
if self.shade_islands and index > 0:
value = 1.0 - (index - 1) % 6 * 0.1

# Overlay a grid over the pixels.
if self.grid_overlay and position % 2 == 1:
value -= 0.04

return value, value, value, 1

width, height = self.size
pixels = [0] * width * height
Expand All @@ -167,11 +170,19 @@ def get_colour(index):

fill_poly(*v1, *v2, *v3)

pixels = [v for pixel in pixels for v in get_colour(pixel)]
image_pixels = [0, 0, 0, 0] * width * height

for iy in range(height):
for ix in range(width):
index = iy * width + ix
start = index * 4
end = index * 4 + 4

image_pixels[start:end] = get_colour(ix + iy, pixels[index])

try:
image = bpy.data.images.new("temp", width, height, alpha=True)
image.filepath, image.pixels = path, pixels
image.filepath, image.pixels = path, image_pixels
image.save()

bpy.data.images.remove(image)
Expand Down

0 comments on commit feb3ac3

Please sign in to comment.