Refer : T81247
With Constrain to Image Bounds selected, UVs will be constrained to the correct/closest UDIM if the image is tiled. UVs will be constrained to the 0-1 UV space if the image is not tiled.
This will override the present behavior of always constraining selected UVs to the 0-1 UV space (UDIM 1001).
Details
- Reviewers
Campbell Barton (campbellbarton) - Group Reviewers
Restricted Project - Maniphest Tasks
- T81247: Move uvs into correct UDIM when "Constrain to image Bounds" is checked
Diff Detail
- Repository
- rB Blender
- Branch
- TEMP-D11202-UPDATE (branched from master)
- Build Status
Buildable 14538 Build 14538: arc lint + arc unit
Event Timeline
After a second glance I realized that a few things are missing :
- Check to constrain UVs to either existing or closest UDIM tile in UV space.
- In the absence of a tiled texture, the UVs should be constrained to 0-1 in the UV space (Original behavior)
- Description for Constrain to Image Bounds should be changed in the Blender manual (If this patch gets accepted)
Updating the patch to support the following :
- In case of a tiled image, if the selected UVs lie on a UDIM tile, then they will be constrained to that UDIM tile.
- In case of a tiled image, if the selected UVs are not present on any UDIM tile, then they will be constrained to the closest UDIM tile.
- If no image is loaded or the image loaded in UV editor is not tiled, then the selected UVs will be constrained to the 0-1 UV space. (Original behavior)
Mostly this seems fine
| source/blender/editors/transform/transform_convert.c | ||
|---|---|---|
| 513 | Even though these are rounded, they can be floats as they're for the most part being used with other floats. I'd also prefer float base_offset[2], with a comment explaining what this does exactly. | |
| 517 | This can be moved into an image utility function that looks up the closest tile, so any other code that needs to do this can re-use it. e.g. /** Return the tile index. */
int BKE_image_find_nearest_tile(Image *image, co[2])
{
..
} | |
| 520 | The scope can be moved inside the loop. | |
| 525 | For comparing distances there is no need for sqrt, this can be dist_sq (common convention for naming distance squared). | |
| 527 | tile_index % 10, tile_index / 10 can be assigned to variables a they're accessed twice. | |
- Made some changes as suggested by @Campbell Barton (campbellbarton)
- Added BKE_image_find_nearest_tile() for reusability. It returns the tile_number for the tile closest to given coordinates
Accepting with only minor changes requested.
| source/blender/blenkernel/intern/image.c | ||
|---|---|---|
| 5530 | Initialize this to -1, then if anything goes wrong it's clear that no tile could be found. While unlikely, a NAN value in co could cause no tiles to match. | |
| source/blender/editors/transform/transform_convert.c | ||
| 520 | t->center_global can be passed in directly. | |
Some further updates
- Check return value for -1.
- Use const variables where possible.
- Re-order checks so distance isn't calculated in the case of an early return.