Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Yurkovich <jesse.y@gmail.com>2021-08-18 07:42:28 +0300
committerJesse Yurkovich <jesse.y@gmail.com>2021-08-18 07:44:36 +0300
commit400cb25fc77a4131033f69cf328a31cdcf81edb5 (patch)
treee88d1f14569ddefaa0fe2b75401498fbf84b9af6 /source/blender/editors/space_image
parentf41beca97787d017a437a63cc0da2ce991522dea (diff)
UDIM: Support tile sets that do not start at 1001
Removes the artificial requirement that UDIM tile sets start at 1001. Blender was already capable of handling sparse tile sets (non-contiguous tiles) so the restriction around starting at 1001 was unnecessary in general. This required fixing a few UDIM-related python bugs around manually updating the `tile_number` field on images as well. See the differential for details. No script changes are necessary but they will now work, correctly, in many more cases. Differential Revision: https://developer.blender.org/D11859
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/image_ops.c32
-rw-r--r--source/blender/editors/space_image/image_sequence.c34
2 files changed, 38 insertions, 28 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index 999d2956fef..29c1452b988 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -1289,8 +1289,10 @@ static Image *image_open_single(Main *bmain,
}
if ((range->length > 1) && (ima->source == IMA_SRC_FILE)) {
- if (range->udim_tiles.first && range->offset == 1001) {
+ if (range->udim_tiles.first) {
ima->source = IMA_SRC_TILED;
+ ImageTile *first_tile = ima->tiles.first;
+ first_tile->tile_number = range->offset;
LISTBASE_FOREACH (LinkData *, node, &range->udim_tiles) {
BKE_image_add_tile(ima, POINTER_AS_INT(node->data), NULL);
}
@@ -1806,10 +1808,13 @@ static int image_save_options_init(Main *bmain,
}
/* append UDIM numbering if not present */
- if (ima->source == IMA_SRC_TILED &&
- (BLI_path_sequence_decode(ima->filepath, NULL, NULL, NULL) != 1001)) {
+ if (ima->source == IMA_SRC_TILED) {
+ char udim[6];
+ ImageTile *tile = ima->tiles.first;
+ BLI_snprintf(udim, sizeof(udim), ".%d", tile->tile_number);
+
int len = strlen(opts->filepath);
- STR_CONCAT(opts->filepath, len, ".1001");
+ STR_CONCAT(opts->filepath, len, udim);
}
}
@@ -3868,9 +3873,9 @@ static void tile_fill_init(PointerRNA *ptr, Image *ima, ImageTile *tile)
/* Acquire ibuf to get the default values.
* If the specified tile has no ibuf, try acquiring the main tile instead
- * (unless the specified tile already was the main tile). */
+ * (unless the specified tile already was the first tile). */
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
- if (ibuf == NULL && (tile != NULL) && (tile->tile_number != 1001)) {
+ if (ibuf == NULL && (tile != NULL) && (tile != ima->tiles.first)) {
ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
}
@@ -3932,27 +3937,30 @@ static int tile_add_exec(bContext *C, wmOperator *op)
bool fill_tile = RNA_boolean_get(op->ptr, "fill");
char *label = RNA_string_get_alloc(op->ptr, "label", NULL, 0);
- bool created_tile = false;
+ /* BKE_image_add_tile assumes a pre-sorted list of tiles. */
+ BKE_image_sort_tiles(ima);
+
+ ImageTile *last_tile_created = NULL;
for (int tile_number = start_tile; tile_number <= end_tile; tile_number++) {
ImageTile *tile = BKE_image_add_tile(ima, tile_number, label);
if (tile != NULL) {
- ima->active_tile_index = BLI_findindex(&ima->tiles, tile);
-
if (fill_tile) {
do_fill_tile(op->ptr, ima, tile);
}
- created_tile = true;
+ last_tile_created = tile;
}
}
MEM_freeN(label);
- if (!created_tile) {
+ if (!last_tile_created) {
BKE_report(op->reports, RPT_WARNING, "No UDIM tiles were created");
return OPERATOR_CANCELLED;
}
+ ima->active_tile_index = BLI_findindex(&ima->tiles, last_tile_created);
+
WM_event_add_notifier(C, NC_IMAGE | ND_DRAW, NULL);
return OPERATOR_FINISHED;
}
@@ -4041,7 +4049,7 @@ static bool tile_remove_poll(bContext *C)
{
Image *ima = CTX_data_edit_image(C);
- return (ima != NULL && ima->source == IMA_SRC_TILED && ima->active_tile_index != 0);
+ return (ima != NULL && ima->source == IMA_SRC_TILED && !BLI_listbase_is_single(&ima->tiles));
}
static int tile_remove_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_image/image_sequence.c b/source/blender/editors/space_image/image_sequence.c
index 02546e3e3b3..288b3d94b1d 100644
--- a/source/blender/editors/space_image/image_sequence.c
+++ b/source/blender/editors/space_image/image_sequence.c
@@ -124,7 +124,7 @@ static int image_cmp_frame(const void *a, const void *b)
*
* udim_tiles may get filled even if the result ultimately is false!
*/
-static int image_get_udim(char *filepath, ListBase *udim_tiles)
+static bool image_get_udim(char *filepath, ListBase *udim_tiles, int *udim_start, int *udim_range)
{
char filename[FILE_MAX], dirname[FILE_MAXDIR];
BLI_split_dirfile(filepath, dirname, filename, sizeof(dirname), sizeof(filename));
@@ -133,12 +133,12 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles)
char base_head[FILE_MAX], base_tail[FILE_MAX];
int id = BLI_path_sequence_decode(filename, base_head, base_tail, &digits);
- if (id < 1001 || id >= IMA_UDIM_MAX) {
- return 0;
+ if (id < 1001 || id > IMA_UDIM_MAX) {
+ return false;
}
bool is_udim = true;
- bool has_primary = false;
+ int min_udim = IMA_UDIM_MAX + 1;
int max_udim = 0;
struct direntry *dir;
@@ -155,26 +155,27 @@ static int image_get_udim(char *filepath, ListBase *udim_tiles)
continue;
}
- if (id < 1001 || id >= IMA_UDIM_MAX) {
+ if (id < 1001 || id > IMA_UDIM_MAX) {
is_udim = false;
break;
}
- if (id == 1001) {
- has_primary = true;
- }
BLI_addtail(udim_tiles, BLI_genericNodeN(POINTER_FROM_INT(id)));
+ min_udim = min_ii(min_udim, id);
max_udim = max_ii(max_udim, id);
}
BLI_filelist_free(dir, totfile);
- if (is_udim && has_primary) {
+ if (is_udim && min_udim <= IMA_UDIM_MAX) {
char primary_filename[FILE_MAX];
- BLI_path_sequence_encode(primary_filename, base_head, base_tail, digits, 1001);
+ BLI_path_sequence_encode(primary_filename, base_head, base_tail, digits, min_udim);
BLI_join_dirfile(filepath, FILE_MAX, dirname, primary_filename);
- return max_udim - 1000;
+
+ *udim_start = min_udim;
+ *udim_range = max_udim - min_udim + 1;
+ return true;
}
- return 0;
+ return false;
}
/**
@@ -185,11 +186,12 @@ static void image_detect_frame_range(ImageFrameRange *range, const bool detect_u
{
/* UDIM */
if (detect_udim) {
- int len_udim = image_get_udim(range->filepath, &range->udim_tiles);
+ int udim_start, udim_range;
+ bool result = image_get_udim(range->filepath, &range->udim_tiles, &udim_start, &udim_range);
- if (len_udim > 0) {
- range->offset = 1001;
- range->length = len_udim;
+ if (result) {
+ range->offset = udim_start;
+ range->length = udim_range;
return;
}
}