diff options
author | Jesse Yurkovich <jesse.y@gmail.com> | 2021-12-31 09:06:23 +0300 |
---|---|---|
committer | Jesse Yurkovich <jesse.y@gmail.com> | 2022-01-03 07:48:59 +0300 |
commit | 180b66ae8a1ffc0a1bb7d3993028240b4c7f7246 (patch) | |
tree | cbc9405b97f02826d181829859b12ce82a672def /intern | |
parent | 367fc69dc1c5ebb6e30ef74488a041502ea8a370 (diff) |
UDIM: Support virtual filenames
This implements the design detailed in T92696 to support virtual
filenames for UDIM textures. Currently, the following 2 substitution
tokens are supported:
| Token | Meaning |
| ----- | ---- |
| <UDIM> | 1001 + u-tile + v-tile * 10 |
| <UVTILE> | Equivalent to u<u-tile + 1>_v<v-tile + 1> |
Example for u-tile of 3 and v-tile of 1:
filename.<UDIM>_ver0023.png --> filename.1014_ver0023.png
filename.<UVTILE>_ver0023.png --> filename.u4_v2_ver0023.png
For image loading, the existing workflow is unchanged. A user can select
one or more image files, belonging to one or more UDIM tile sets, and
have Blender load them all as it does today. Now the <UVTILE> format is
"guessed" just as the <UDIM> format was guessed before.
If guessing fails, the user can simply go into the Image Editor and type
the proper substitution in the filename. Once typing is complete,
Blender will reload the files and correctly fill the tiles. This
workflow is new as attempting to fix the guessing in current versions
did not really work, and the user was often stuck with a confusing
situation.
For image saving, the existing workflow is changed slightly. Currently,
when saving, a user has to be sure to type the filename of the first
tile (e.g. filename.1001.png) to save the entire UDIM set. The number
could differ if they start at a different tile etc. This is confusing.
Now, the user should type a filename containing the appropriate
substitution token. By default Blender will fill in a default name using
the <UDIM> token but the user is free to save out images using <UVTILE>
if they wish.
Differential Revision: https://developer.blender.org/D13057
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/blender/shader.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/blender/util.h | 19 | ||||
-rw-r--r-- | intern/cycles/scene/image.cpp | 7 |
3 files changed, 13 insertions, 17 deletions
diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp index 70acfce6891..5604c2989fd 100644 --- a/intern/cycles/blender/shader.cpp +++ b/intern/cycles/blender/shader.cpp @@ -776,7 +776,7 @@ static ShaderNode *add_node(Scene *scene, } else { ustring filename = ustring( - image_user_file_path(b_image_user, b_image, b_scene.frame_current(), true)); + image_user_file_path(b_image_user, b_image, b_scene.frame_current())); image->set_filename(filename); } } @@ -813,7 +813,7 @@ static ShaderNode *add_node(Scene *scene, } else { env->set_filename( - ustring(image_user_file_path(b_image_user, b_image, b_scene.frame_current(), false))); + ustring(image_user_file_path(b_image_user, b_image, b_scene.frame_current()))); } } node = env; diff --git a/intern/cycles/blender/util.h b/intern/cycles/blender/util.h index be36bcdaaa8..6c396d39614 100644 --- a/intern/cycles/blender/util.h +++ b/intern/cycles/blender/util.h @@ -33,7 +33,7 @@ extern "C" { void BKE_image_user_frame_calc(void *ima, void *iuser, int cfra); -void BKE_image_user_file_path(void *iuser, void *ima, char *path); +void BKE_image_user_file_path_ex(void *iuser, void *ima, char *path, bool resolve_udim); unsigned char *BKE_image_get_pixels_for_frame(void *image, int frame, int tile); float *BKE_image_get_float_pixels_for_frame(void *image, int frame, int tile); } @@ -290,25 +290,14 @@ static inline int render_resolution_y(BL::RenderSettings &b_render) return b_render.resolution_y() * b_render.resolution_percentage() / 100; } -static inline string image_user_file_path(BL::ImageUser &iuser, - BL::Image &ima, - int cfra, - bool load_tiled) +static inline string image_user_file_path(BL::ImageUser &iuser, BL::Image &ima, int cfra) { char filepath[1024]; iuser.tile(0); BKE_image_user_frame_calc(ima.ptr.data, iuser.ptr.data, cfra); - BKE_image_user_file_path(iuser.ptr.data, ima.ptr.data, filepath); + BKE_image_user_file_path_ex(iuser.ptr.data, ima.ptr.data, filepath, false); - string filepath_str = string(filepath); - if (load_tiled && ima.source() == BL::Image::source_TILED) { - string udim; - if (!ima.tiles.empty()) { - udim = to_string(ima.tiles[0].number()); - } - string_replace(filepath_str, udim, "<UDIM>"); - } - return filepath_str; + return string(filepath); } static inline int image_user_frame_number(BL::ImageUser &iuser, BL::Image &ima, int cfra) diff --git a/intern/cycles/scene/image.cpp b/intern/cycles/scene/image.cpp index 8bb2d87fd1e..3595ca55a46 100644 --- a/intern/cycles/scene/image.cpp +++ b/intern/cycles/scene/image.cpp @@ -381,8 +381,15 @@ ImageHandle ImageManager::add_image(const string &filename, foreach (int tile, tiles) { string tile_filename = filename; + + /* Since we don't have information about the exact tile format used in this code location, + * just attempt all replacement patterns that Blender supports. */ if (tile != 0) { string_replace(tile_filename, "<UDIM>", string_printf("%04d", tile)); + + int u = ((tile - 1001) % 10); + int v = ((tile - 1001) / 10); + string_replace(tile_filename, "<UVTILE>", string_printf("u%d_v%d", u + 1, v + 1)); } const int slot = add_image_slot(new OIIOImageLoader(tile_filename), params, false); handle.tile_slots.push_back(slot); |