Page MenuHome

Fix T81247: Constrain selected UVs to correct UDIM
ClosedPublic

Authored by Siddhartha Jejurkar (sidd017) on May 8 2021, 11:18 AM.

Details

Summary

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).

Diff Detail

Repository
rB Blender
Branch
TEMP-D11202-UPDATE (branched from master)
Build Status
Buildable 14538
Build 14538: arc lint + arc unit

Event Timeline

Pratik Borhade (PratikPB2123) retitled this revision from Constrain selected UVs to correct UDIM to Fix T81247: Constrain selected UVs to correct UDIM.May 8 2021, 5:35 PM
Siddhartha Jejurkar (sidd017) planned changes to this revision.EditedMay 9 2021, 4:36 PM

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)
Siddhartha Jejurkar (sidd017) edited the summary of this revision. (Show Details)

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)
Campbell Barton (campbellbarton) requested changes to this revision.May 12 2021, 10:03 AM

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.

This revision now requires changes to proceed.May 12 2021, 10:03 AM
  • 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
source/blender/editors/transform/transform_convert.c
525

Wasn't sure about the convention so I did a quick search on the code-base and used a few instances where dist_sq is declared as reference.

527

Assigned the variable inside BKE_image_find_nearest_tile()

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.

This revision is now accepted and ready to land.May 12 2021, 3:18 PM

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.
  • Avoid floorf the input location each loop iteration
  • Correct check for tile not found case