UV Export: add option to export UV tiles #104940

Merged
Damien Picard merged 4 commits from pioverfour/blender-addons:dp_export_uv_udim into main 2023-10-09 22:32:24 +02:00
Showing only changes of commit 688f388cae - Show all commits

View File

@ -60,9 +60,9 @@ class ExportUVLayout(bpy.types.Operator):
('NONE', "None", ('NONE', "None",
"Export only UVs in the [0, 1] range"), "Export only UVs in the [0, 1] range"),
('UDIM', "UDIM", ('UDIM', "UDIM",
"Export tiles in the UDIM notation: 1001 + u-tile + 10*v-tile"), "Export tiles in the UDIM numbering scheme: 1001 + u-tile + 10*v-tile"),
('UV', "UV Tiles", ('UV', "UVTILE",
"Export tiles in the UV notation: u(u-tile + 1)_v(v-tile + 1)"), "Export tiles in the UVTILE numbering scheme: u(u-tile + 1)_v(v-tile + 1)"),
), ),
description="Choose whether to export only the [0, 1 range], or all UV tiles", description="Choose whether to export only the [0, 1 range], or all UV tiles",
default='NONE', default='NONE',
@ -165,7 +165,7 @@ class ExportUVLayout(bpy.types.Operator):
if match: if match:
filename = match.groups()[0] filename = match.groups()[0]
for tile in tiles: for tile in sorted(tiles):
filepath = os.path.join(dirname, filename) filepath = os.path.join(dirname, filename)
if self.export_tiles == 'UDIM': if self.export_tiles == 'UDIM':
filepath += f".{1001 + tile[0] + tile[1] * 10:04}" filepath += f".{1001 + tile[0] + tile[1] * 10:04}"
@ -210,7 +210,16 @@ class ExportUVLayout(bpy.types.Operator):
tiles = set() tiles = set()
for poly in polygon_data: for poly in polygon_data:
for uv in poly[0]: for uv in poly[0]:
tiles.add((floor(uv[0]), floor(uv[1]))) # Ignore UVs at corners - precisely touching the right or upper edge
# of a tile should not load its right/upper neighbor as well.
# From intern/cycles/scene/attribute.cpp
u, v = (uv[0], uv[1])
x, y = (floor(u), floor(v))
if (x > 0 and (u < x + 1e-6)):
x -= 1
if (y > 0 and (v < y + 1e-6)):
y -= 1
tiles.add((x, y))
return tiles return tiles
@staticmethod @staticmethod