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:
authorSiddhartha Jejurkar <sidd017>2021-09-29 10:47:32 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-09-29 10:48:35 +0300
commitbf06f76be6316be92a4655a41391e163d2fb1221 (patch)
tree5dac6a12fb65f0897806739d5ef8e00407112041 /source/blender/editors/space_image
parent008ae26712f85475a8a9dc4d031447e12fb05522 (diff)
UV Editor: Grid and snapping improvements
Implements T89789, T89792, custom grid (described as dynamic grid in T78389) and UV grid snapping (T78391) Replaces the default UV editor grid with 2 new types of grid : * Custom grid: Allows the user to create an NxN grid, where the value of N is specified by the user. * Subdividing grid: Subdivides the UV editor grid when the user zooms in the viewport and vice versa when zooming out. UV snapping improvements : * Increment snapping: Increment values for snapping are calculated based on which grid type is being used in the UV editor (subdividing or custom). In general the increment value is equal to the distance between 2 visible grid lines. * Absolute grid snap: New toggle added to increment snapping option in the UV editor, allows UV grid snapping during translation. Reviewed By: campbellbarton Ref D12684
Diffstat (limited to 'source/blender/editors/space_image')
-rw-r--r--source/blender/editors/space_image/image_draw.c60
-rw-r--r--source/blender/editors/space_image/space_image.c2
2 files changed, 62 insertions, 0 deletions
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index d2af26aa1d7..fc04ec1fe02 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -34,6 +34,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_view2d_types.h"
#include "PIL_time.h"
@@ -576,3 +577,62 @@ void draw_image_cache(const bContext *C, ARegion *region)
ED_mask_draw_frames(mask, region, cfra, sfra, efra);
}
}
+
+float ED_space_image_zoom_level(const View2D *v2d, const int grid_dimension)
+{
+ /* UV-space length per pixel */
+ float xzoom = (v2d->cur.xmax - v2d->cur.xmin) / ((float)(v2d->mask.xmax - v2d->mask.xmin));
+ float yzoom = (v2d->cur.ymax - v2d->cur.ymin) / ((float)(v2d->mask.ymax - v2d->mask.ymin));
+
+ /* Zoom_factor for UV/Image editor is calculated based on:
+ * - Default grid size on startup, which is 256x256 pixels
+ * - How blend factor for grid lines is set up in the fragment shader `grid_frag.glsl`. */
+ float zoom_factor;
+ zoom_factor = (xzoom + yzoom) / 2.0f; /* Average for accuracy. */
+ zoom_factor *= 256.0f / (powf(grid_dimension, 2));
+ return zoom_factor;
+}
+
+void ED_space_image_grid_steps(SpaceImage *sima,
+ float grid_steps[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));
+ }
+ }
+ 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)));
+ }
+ }
+}
+
+/**
+ * Calculate the increment snapping value for UV/image editor based on the zoom factor
+ * The code in here (except the offset part) is used in `grid_frag.glsl` (see `grid_res`) for
+ * drawing the grid overlay for the UV/Image editor.
+ */
+float ED_space_image_increment_snap_value(const int grid_dimesnions,
+ const float grid_steps[SI_GRID_STEPS_LEN],
+ const float zoom_factor)
+{
+ /* Small offset on each grid_steps[] so that snapping value doesn't change until grid lines are
+ * significantly visible.
+ * `Offset = 3/4 * (grid_steps[i] - (grid_steps[i] / grid_dimesnsions))`
+ *
+ * Refer `grid_frag.glsl` to find out when grid lines actually start appearing */
+
+ for (int step = 0; step < SI_GRID_STEPS_LEN; step++) {
+ float offset = (3.0f / 4.0f) * (grid_steps[step] - (grid_steps[step] / grid_dimesnions));
+
+ if ((grid_steps[step] - offset) > zoom_factor) {
+ return grid_steps[step];
+ }
+ }
+
+ /* Fallback */
+ return grid_steps[0];
+}
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index de8e4684d45..5adcdacd49d 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -126,6 +126,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;
+
/* tool header */
region = MEM_callocN(sizeof(ARegion), "tool header for image");