From a24fc6bbc1ae3c0ee5a26c5b964af219215de692 Mon Sep 17 00:00:00 2001 From: Chris Blackbourn Date: Sun, 18 Sep 2022 17:03:40 +1200 Subject: UV: extend custom grid sizes to set each axis separately For example, allows a custom UV grid size of 4 x 12. TODO: Fix snapping with custom UV grid sizes. Manifest Tasks: T78391 Differential Revision: https://developer.blender.org/D16000 --- source/blender/editors/include/ED_image.h | 3 ++- source/blender/editors/space_image/image_draw.c | 19 ++++++++++--------- source/blender/editors/space_image/space_image.c | 3 ++- source/blender/editors/transform/transform.c | 8 +++++++- 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h index ef75277b1ea..da303f3552b 100644 --- a/source/blender/editors/include/ED_image.h +++ b/source/blender/editors/include/ED_image.h @@ -32,7 +32,8 @@ struct wmWindowManager; float ED_space_image_zoom_level(const struct View2D *v2d, int grid_dimension); void ED_space_image_grid_steps(struct SpaceImage *sima, - float grid_steps[SI_GRID_STEPS_LEN], + float grid_steps_x[SI_GRID_STEPS_LEN], + float grid_steps_y[SI_GRID_STEPS_LEN], int grid_dimension); /** * Calculate the increment snapping value for UV/image editor based on the zoom factor diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 37a6e6dfcb1..8a934396229 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -585,18 +585,19 @@ float ED_space_image_zoom_level(const View2D *v2d, const int grid_dimension) } void ED_space_image_grid_steps(SpaceImage *sima, - float grid_steps[SI_GRID_STEPS_LEN], + float grid_steps_x[SI_GRID_STEPS_LEN], + float grid_steps_y[SI_GRID_STEPS_LEN], const int grid_dimension) { - if (sima->flag & SI_CUSTOM_GRID) { - for (int step = 0; step < SI_GRID_STEPS_LEN; step++) { - grid_steps[step] = powf(1, step) * (1.0f / ((float)sima->custom_grid_subdiv)); + const int flag = sima->flag; + for (int step = 0; step < SI_GRID_STEPS_LEN; step++) { + if (flag & SI_CUSTOM_GRID) { + grid_steps_x[step] = 1.0f / sima->custom_grid_subdiv[0]; + grid_steps_y[step] = 1.0f / sima->custom_grid_subdiv[1]; } - } - else { - for (int step = 0; step < SI_GRID_STEPS_LEN; step++) { - grid_steps[step] = powf(grid_dimension, step) * - (1.0f / (powf(grid_dimension, SI_GRID_STEPS_LEN))); + else { + grid_steps_x[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); + grid_steps_y[step] = powf(grid_dimension, step - SI_GRID_STEPS_LEN); } } } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 096ae4fd328..2b65267644a 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -112,7 +112,8 @@ static SpaceLink *image_create(const ScrArea *UNUSED(area), const Scene *UNUSED( simage->tile_grid_shape[0] = 1; simage->tile_grid_shape[1] = 1; - simage->custom_grid_subdiv = 10; + simage->custom_grid_subdiv[0] = 10; + simage->custom_grid_subdiv[1] = 10; /* header */ region = MEM_callocN(sizeof(ARegion), "header for image"); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index eb46da3579a..95aa48efd84 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1719,11 +1719,17 @@ static void initSnapSpatial(TransInfo *t, float r_snap[2]) int grid_size = SI_GRID_STEPS_LEN; float zoom_factor = ED_space_image_zoom_level(v2d, grid_size); float grid_steps[SI_GRID_STEPS_LEN]; + float grid_steps_y[SI_GRID_STEPS_LEN]; - ED_space_image_grid_steps(sima, grid_steps, grid_size); + ED_space_image_grid_steps(sima, grid_steps, grid_steps_y, grid_size); /* Snapping value based on what type of grid is used (adaptive-subdividing or custom-grid). */ r_snap[0] = ED_space_image_increment_snap_value(grid_size, grid_steps, zoom_factor); r_snap[1] = r_snap[0] / 2.0f; + + /* TODO: Implement snapping for custom grid sizes with `grid_steps[0] != grid_steps_y[0]`. + * r_snap_y[0] = ED_space_image_increment_snap_value(grid_size, grid_steps_y, zoom_factor); + * r_snap_y[1] = r_snap_y[0] / 2.0f; + */ } else if (t->spacetype == SPACE_CLIP) { r_snap[0] = 0.125f; -- cgit v1.2.3