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",
"Export only UVs in the [0, 1] range"),
('UDIM', "UDIM",
"Export tiles in the UDIM notation: 1001 + u-tile + 10*v-tile"),
('UV', "UV Tiles",
"Export tiles in the UV notation: u(u-tile + 1)_v(v-tile + 1)"),
"Export tiles in the UDIM numbering scheme: 1001 + u-tile + 10*v-tile"),
('UV', "UVTILE",
"Export tiles in the UVTILE numbering scheme: u(u-tile + 1)_v(v-tile + 1)"),
deadpin marked this conversation as resolved Outdated

I wonder if we should be more descriptive here? Maybe call the items "UDIM format" and "UVTILE format" as these are the 2 formats that both Blender and MaterialX supports and their names are somewhat known in the ecosystem [1]. Also because there's another "uvtile format" (lowercase) which is slightly different [2]

[1] https://materialx.org/assets/MaterialX.v1.38.Spec.pdf (Page 18)
[2] https://openimageio.readthedocs.io/en/v2.5.4.0/texturesys.html#udim-texture-atlases

I wonder if we should be more descriptive here? Maybe call the items "UDIM format" and "UVTILE format" as these are the 2 formats that both Blender and MaterialX supports and their names are somewhat known in the ecosystem [1]. Also because there's another "uvtile format" (lowercase) which is slightly different [2] [1] https://materialx.org/assets/MaterialX.v1.38.Spec.pdf (Page 18) [2] https://openimageio.readthedocs.io/en/v2.5.4.0/texturesys.html#udim-texture-atlases

Thanks, I wasn’t aware of that! I agree that “UVTILE” should be used instead of “UV Tiles”, but I’m not sure about adding “Format”, it seems redundant to me for the label. From your link, OIIO seems to call these “numbering schemes”, which is more descriptive than “notation”.
How about:

            ('UDIM', "UDIM",
             "Export tiles in the UDIM numbering scheme: 1001 + u-tile + 10*v-tile"),
            ('UVTILE', "UVTILE",
             "Export tiles in the UVTILE numbering scheme: u(u-tile + 1)_v(v-tile + 1)"),
Thanks, I wasn’t aware of that! I agree that “UVTILE” should be used instead of “UV Tiles”, but I’m not sure about adding “Format”, it seems redundant to me for the label. From your link, OIIO seems to call these “numbering schemes”, which is more descriptive than “notation”. How about: ``` ('UDIM', "UDIM", "Export tiles in the UDIM numbering scheme: 1001 + u-tile + 10*v-tile"), ('UVTILE', "UVTILE", "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",
default='NONE',
@ -165,7 +165,7 @@ class ExportUVLayout(bpy.types.Operator):
if match:
filename = match.groups()[0]
for tile in tiles:
for tile in sorted(tiles):
filepath = os.path.join(dirname, filename)
if self.export_tiles == 'UDIM':
filepath += f".{1001 + tile[0] + tile[1] * 10:04}"
@ -210,7 +210,16 @@ class ExportUVLayout(bpy.types.Operator):
tiles = set()
for poly in polygon_data:
for uv in poly[0]:
tiles.add((floor(uv[0]), floor(uv[1])))
# Ignore UVs at corners - precisely touching the right or upper edge
pioverfour marked this conversation as resolved Outdated

There's a small gotcha here in that UV coords that "touch" the upper edge or the right edge of a tile might be categorized as existing in the tile above or to the right of its "real" tile. I.e. export the default Cube in UDIM layout and you'll get 2 tiles, 1001 and 1011.

You can mimic what's done in Cycles here to lie about such UV coords: https://projects.blender.org/blender/blender/blame/branch/main/intern/cycles/scene/attribute.cpp#L461

There's a small gotcha here in that UV coords that "touch" the upper edge or the right edge of a tile might be categorized as existing in the tile above or to the right of its "real" tile. I.e. export the default Cube in UDIM layout and you'll get 2 tiles, 1001 and 1011. You can mimic what's done in Cycles here to lie about such UV coords: https://projects.blender.org/blender/blender/blame/branch/main/intern/cycles/scene/attribute.cpp#L461

This works well on the cube!

This works well on the cube!
# 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
@staticmethod