UV Export: add option to export UV tiles #104940
@ -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)"),
|
||||||
deadpin marked this conversation as resolved
Outdated
|
|||||||
),
|
),
|
||||||
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
|
||||||
pioverfour marked this conversation as resolved
Outdated
Jesse Yurkovich
commented
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
Damien Picard
commented
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
|
return tiles
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user
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: