WIP: UV Editor Edge Slide #110868

Closed
Melissa-Goon wants to merge 2 commits from Melissa-Goon/blender:gsoc2023-edge-slide into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
First-time contributor

This addresses this request for the addition of an edge slide tool to the UV Editor. This feature would allow users to slide UVs towards adjacent edges, providing more convenient ways to edit UV maps.

Possible future improvements:

  • Support for vert sliding.
  • Integration with existing transform mode.
This addresses [this request](https://blender.community/c/rightclickselect/66dbbc/?sorting=hot) for the addition of an edge slide tool to the UV Editor. This feature would allow users to slide UVs towards adjacent edges, providing more convenient ways to edit UV maps. **Possible future improvements:** - Support for vert sliding. - Integration with existing transform mode.
Campbell Barton requested changes 2023-08-07 06:13:59 +02:00
Campbell Barton left a comment
Owner

This is not a full review, this patch makes BM_vert_step_fan_loop_uv into a public function, then removes the BM_ELEM_TAG check.

That check is needed for UV rip logic. I'd suggest to make a version of BM_vert_step_fan_loop_uv that takes a function which can be used to filter the faces that are stepped over. This way it's possible to reuse the function in both cases.

This is not a full review, this patch makes `BM_vert_step_fan_loop_uv` into a public function, then removes the `BM_ELEM_TAG` check. That check is needed for UV rip logic. I'd suggest to make a version of BM_vert_step_fan_loop_uv that takes a function which can be used to filter the faces that are stepped over. This way it's possible to reuse the function in both cases.
Melissa-Goon force-pushed gsoc2023-edge-slide from 4630b95f86 to 19bcb7462b 2023-08-07 09:20:25 +02:00 Compare
Melissa-Goon requested review from Campbell Barton 2023-08-07 09:31:02 +02:00
Iliya Katushenock added the
Interest
Modeling
Interest
UV Editing
labels 2023-08-07 12:01:49 +02:00
Campbell Barton requested changes 2023-08-08 03:33:06 +02:00
@ -0,0 +49,4 @@
/* -------------------------------------------------------------------- */
/** \name Transform (Edge UV Slide)
* \{ */
typedef struct EdgeSlideUV {

Can be struct EdgeSlideUV { .. }; (this was a C-convention that changed since your project started and code moved to C++).

Also, add doxygen comments before each member, helps readability and clarifies the purpose.

  /** Loops associated with this UV which are being transformed. */
  blender::Vector<BMLoop *> loops;
  /** <unsure of what this comment should be...> */
  BMLoop *side_loop[2];
  /** A pair of target locations in UV space to slide betwen. */
  float sides[2][2];
  /** The original location (never changes), used to re-calculate the slide location. */
  float orig_uv[2];
Can be `struct EdgeSlideUV { .. };` (this was a C-convention that changed since your project started and code moved to C++). Also, add doxygen comments before each member, helps readability and clarifies the purpose. ``` /** Loops associated with this UV which are being transformed. */ blender::Vector<BMLoop *> loops; /** <unsure of what this comment should be...> */ BMLoop *side_loop[2]; /** A pair of target locations in UV space to slide betwen. */ float sides[2][2]; /** The original location (never changes), used to re-calculate the slide location. */ float orig_uv[2]; ```
Melissa-Goon marked this conversation as resolved
@ -0,0 +52,4 @@
typedef struct EdgeSlideUV {
blender::Vector<BMLoop *> loops; /*Loops associated with this uv*/
BMLoop *side_loop[2];
float sides[2][2];

sides is not a very meaningful name, without checking the type is could be an index or represent loops themselves.

Could be slide_uv for e.g.

Also, suggest to use float2 sides[2] which means you can assign them more easily.

    slide_uv[i].sides[0][0] = side0[0];
    slide_uv[i].sides[0][1] = side0[1];

Can then be replaced with:

    slide_uv[i].sides[0] = side0;
`sides` is not a very meaningful name, without checking the type is could be an index or represent loops themselves. Could be `slide_uv` for e.g. Also, suggest to use `float2 sides[2]` which means you can assign them more easily. ``` slide_uv[i].sides[0][0] = side0[0]; slide_uv[i].sides[0][1] = side0[1]; ``` Can then be replaced with: ``` slide_uv[i].sides[0] = side0; ```
Melissa-Goon marked this conversation as resolved
@ -0,0 +63,4 @@
blender::Vector<EdgeSlideUV> *esuvs = static_cast<blender::Vector<EdgeSlideUV> *>(
custom_data->data);
if (esuvs == NULL) {

Note then this is expected to be nullptr (also NULL -> nullptr).

Note then this is expected to be `nullptr` (also NULL -> nullptr).
Melissa-Goon marked this conversation as resolved
@ -0,0 +83,4 @@
int i = 0;
BM_ITER_ELEM (loop_v, &lv_iter, v_orig, BM_LOOPS_OF_VERT) {
if (i == 2) {

Explain why this is needed. It also seems likely that using the first 2 loops would give arbitrary results (as the first 2 may be different depending on the internal ordering of data), this is is not a problem explain why in a comment.

Explain why this is needed. It also seems likely that using the first 2 loops would give arbitrary results (as the first 2 may be different depending on the internal ordering of data), this is is not a problem explain why in a comment.
Melissa-Goon marked this conversation as resolved
@ -0,0 +86,4 @@
if (i == 2) {
break;
}
if (BM_loop_uv_share_vert_check(loop_v, orig_loop, offsets.uv) &&

From reading the body of this code it looks like there is some chance i enters the for loop as 1 then gets set to 2 or 3.. which would cause out of bounds access for esuv.side_loop[i].

If the logic guarantees this is never the case, add assertions this never happens and note why.

From reading the body of this code it looks like there is some chance `i` enters the for loop as `1` then gets set to 2 or 3.. which would cause out of bounds access for `esuv.side_loop[i]`. If the logic guarantees this is never the case, add assertions this never happens and note why.
Melissa-Goon marked this conversation as resolved
@ -0,0 +89,4 @@
if (BM_loop_uv_share_vert_check(loop_v, orig_loop, offsets.uv) &&
(loop_v->f == e->l->f || loop_v->f == e->l->radial_next->f))
{
if (!BM_ELEM_CD_GET_BOOL(loop_v->next, offsets.select_vert) &&

Suggestion: use a for loop to access next/prev members, avoids duplicating code.

for (int dir = 0; dir < 2; dir++) {
  BMLoop *l_other = dir ? l->next : l->prev;
  /* ... snip ... */
}

This avoids code duplication.

Suggestion: use a for loop to access `next/prev` members, avoids duplicating code. ``` for (int dir = 0; dir < 2; dir++) { BMLoop *l_other = dir ? l->next : l->prev; /* ... snip ... */ } ``` This avoids code duplication.
Melissa-Goon marked this conversation as resolved
@ -0,0 +138,4 @@
esuv.side_loop[i] = loop_v->next;
i++;
/*Tag all loops of the side so the same side isn't picked twice*/

Suggestion: use a for loop to access next/prev members, avoids duplicating code. (see other comment).

Suggestion: use a for loop to access `next/prev` members, avoids duplicating code. (see other comment).
Melissa-Goon marked this conversation as resolved
@ -0,0 +333,4 @@
}
}
/*Any vertex w/ 3+ connected selected edges is ignored*/

*picky* All text comments should be C-style, surrounding spaces & be full sentences.

/* Any vertex with 3+ connected selected edges is ignored. */

\*picky\* All text comments should be C-style, surrounding spaces & be full sentences. `/* Any vertex with 3+ connected selected edges is ignored. */`
Melissa-Goon marked this conversation as resolved
@ -0,0 +483,4 @@
blender::Vector<EdgeSlideUV> *slide_edge_loops = static_cast<blender::Vector<EdgeSlideUV> *>(
TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data);
for (int i = 0; i < (*slide_edge_loops).size(); i++) {

Include an explanation for what this loop does (why find the longest edge?).

Include an explanation for what this loop does (why find the longest edge?).
Melissa-Goon marked this conversation as resolved
@ -0,0 +484,4 @@
TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data);
for (int i = 0; i < (*slide_edge_loops).size(); i++) {
float side0_len = len_v2v2((*slide_edge_loops)[i].sides[0], (*slide_edge_loops)[i].orig_uv);

When finding the maximum length, use len_squared_v2v2, avoids an unnecessary sqrtf.

When finding the maximum length, use `len_squared_v2v2`, avoids an unnecessary `sqrtf`.
Melissa-Goon marked this conversation as resolved
@ -0,0 +499,4 @@
if (side_len_max > max_len) {
max_len = side_len_max;
start_uv = (*slide_edge_loops)[i].orig_uv;

(*slide_edge_loops) seems redundant, slide_edge_loops can be used here.

`(*slide_edge_loops)` seems redundant, `slide_edge_loops` can be used here.
Melissa-Goon marked this conversation as resolved
Melissa-Goon force-pushed gsoc2023-edge-slide from 7ef546a2a4 to 34acc9e4f6 2023-08-08 12:11:19 +02:00 Compare
Melissa-Goon requested review from Campbell Barton 2023-08-09 05:05:10 +02:00
Melissa-Goon force-pushed gsoc2023-edge-slide from 34acc9e4f6 to e4b1aa8640 2023-08-09 06:41:53 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from e4b1aa8640 to 50cf368bad 2023-08-09 06:44:25 +02:00 Compare
Campbell Barton reviewed 2023-08-09 06:45:42 +02:00
@ -0,0 +515,4 @@
static void initEdgeUVSlide(TransInfo *t, wmOperator *op)
{
blender::Vector<EdgeSlideUV> *esd;
t->mode = TFM_UV_EDGE_SLIDE;

source/blender/editors/transform/transform_mode_edge_uv_slide.cc:513:1: error: control reaches end of non-void function [-Werror=return-type]

`source/blender/editors/transform/transform_mode_edge_uv_slide.cc:513:1: error: control reaches end of non-void function [-Werror=return-type]`
Melissa-Goon marked this conversation as resolved

A subdivided cube is asserting in a simple test:

BLI_assert failed: source/blender/editors/transform/transform_mode_edge_uv_slide.cc:97, calc_side_loops_from_single_terminating_uv(), at 'i < 2'

Pressing G should transform, pressing G-twice should use edge-slide, see how transform in the 3D view works.

A subdivided cube is asserting in a simple test: ``` BLI_assert failed: source/blender/editors/transform/transform_mode_edge_uv_slide.cc:97, calc_side_loops_from_single_terminating_uv(), at 'i < 2' ``` ---- Pressing G should transform, pressing G-twice should use edge-slide, see how transform in the 3D view works.
Campbell Barton requested changes 2023-08-09 07:01:30 +02:00
@ -0,0 +509,4 @@
if (event->type == MOUSEMOVE) {
calcEdgeSlideCustomPointsUV(t);
return TREDRAW_NOTHING;
}

Missing return.

Missing return.
Melissa-Goon marked this conversation as resolved
Campbell Barton reviewed 2023-08-09 07:02:36 +02:00
@ -0,0 +1,554 @@
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.

2001-2002 NaN shouldn't be copyright holder, use:

/* SPDX-FileCopyrightText: 2023 Blender Foundation
 *
 * SPDX-License-Identifier: GPL-2.0-or-later */
`2001-2002 NaN` shouldn't be copyright holder, use: ``` /* SPDX-FileCopyrightText: 2023 Blender Foundation * * SPDX-License-Identifier: GPL-2.0-or-later */ ```
Melissa-Goon marked this conversation as resolved
Melissa-Goon force-pushed gsoc2023-edge-slide from 50cf368bad to b5c05035d7 2023-08-09 09:02:43 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from b5c05035d7 to 7955fe31f8 2023-08-09 10:12:32 +02:00 Compare
Campbell Barton requested changes 2023-08-09 12:41:44 +02:00
@ -0,0 +75,4 @@
custom_data->data = nullptr;
}
void calc_side_loops_from_single_terminating_uv(BMEdge *edge,

Should be static.

Should be `static`.
Melissa-Goon marked this conversation as resolved
@ -0,0 +121,4 @@
}
}
void calc_side_loops_from_pair(BMLoop *orig_loop, EdgeSlideUV &esuv, BMUVOffsets offsets)

Should be static.

Should be `static`.
Melissa-Goon marked this conversation as resolved
@ -0,0 +156,4 @@
}
}
void flip_and_set_sides(blender::Vector<EdgeSlideUV> &slide_uv, BMUVOffsets offsets)

Should be static.

Should be `static`.
Melissa-Goon marked this conversation as resolved

When sliding an edge on a subdivided cube, one of the end-point vertices isn't sliding.

When sliding an edge on a subdivided cube, one of the end-point vertices isn't sliding.
Melissa-Goon force-pushed gsoc2023-edge-slide from 7955fe31f8 to 4e0376443a 2023-08-11 10:21:37 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from 4e0376443a to 9266ad6d24 2023-08-11 10:29:51 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from 9266ad6d24 to 4664d33772 2023-08-11 10:34:05 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from 4664d33772 to 4f2d0463a9 2023-08-15 04:26:11 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from 058d06aec8 to d1a48b0c04 2023-08-18 04:40:17 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from d1a48b0c04 to db10f55343 2023-08-18 04:43:39 +02:00 Compare
Melissa-Goon requested review from Campbell Barton 2023-08-18 04:45:43 +02:00
Melissa-Goon force-pushed gsoc2023-edge-slide from db10f55343 to a896a42d59 2023-08-18 05:26:30 +02:00 Compare
Campbell Barton requested changes 2023-08-18 06:10:59 +02:00
@ -0,0 +595,4 @@
static void calcEdgeSlideCustomPointsUV(TransInfo *t)
{
float max_len = 0;

use _length suffix, _len is used for integer lengths in quite a few places still.

use `_length` suffix, `_len` is used for integer lengths in quite a few places still.
Melissa-Goon marked this conversation as resolved
@ -0,0 +596,4 @@
static void calcEdgeSlideCustomPointsUV(TransInfo *t)
{
float max_len = 0;
float *start_uv, *end_uv;

In some cases, testing with a single vertex start_uv isn't initialized, causing a crash.

In some cases, testing with a single vertex `start_uv` isn't initialized, causing a crash.
Melissa-Goon marked this conversation as resolved
@ -0,0 +599,4 @@
float *start_uv, *end_uv;
int start_region[2], end_region[2];
blender::Vector<EdgeSlideUV> slide_edge_loops = *(static_cast<blender::Vector<EdgeSlideUV> *>(

This should be a pointer or a reference (by convention pointers are used elsewhere... so that can be used here too).

This should be a pointer or a reference (by convention pointers are used elsewhere... so that can be used here too).
Melissa-Goon marked this conversation as resolved
@ -0,0 +646,4 @@
static void initEdgeUVSlide(TransInfo *t, wmOperator * /*op*/)
{
blender::Vector<EdgeSlideUV> *esd;

Move into nested scope (avoids accidental/uninitialized use).

Move into nested scope (avoids accidental/uninitialized use).
Melissa-Goon marked this conversation as resolved
Melissa-Goon force-pushed gsoc2023-edge-slide from a896a42d59 to c6df8e4264 2023-08-18 06:14:01 +02:00 Compare
Melissa-Goon force-pushed gsoc2023-edge-slide from c6df8e4264 to 9bab4bb17d 2023-08-18 06:28:38 +02:00 Compare

I'm not a big fan of the idea of creating a new mode, which does the same thing as the existing one, but is made to only work on UVs.

The transform code has "convert" files and "mode" files.

The purpose of "convert" is to allow multiple types of elements (Meshes, UVS, Curves) to work in the same "mode".

But Edge Slide (and Vert Slide) are different because they only work for Meshes. Which is bad since in theory it could also work for Curves, Armatures, Grease Pencil...

Creating another mode just for UVs seems to make the situation worse.

The ideal, in my opinion, would be to adapt the existing Edge Slide (and Vert Slide) to work with UVs as well.

But if this is not possible, the PR description must make clear why.

I'm not a big fan of the idea of creating a new mode, which does the same thing as the existing one, but is made to only work on UVs. The transform code has "convert" files and "mode" files. The purpose of "convert" is to allow multiple types of elements (Meshes, UVS, Curves) to work in the same "mode". But Edge Slide (and Vert Slide) are different because they only work for Meshes. Which is bad since in theory it could also work for Curves, Armatures, Grease Pencil... Creating another mode just for UVs seems to make the situation worse. The ideal, in my opinion, would be to adapt the existing Edge Slide (and Vert Slide) to work with UVs as well. But if this is not possible, the PR description must make clear why.

@mano-wii agree. Using a separate mode was more straightforward to begin with (to avoid having to solve integration issues), but eventually they should be merged unless there is a good reason not to.

@mano-wii agree. Using a separate mode was more straightforward to begin with (to avoid having to solve integration issues), but eventually they should be merged unless there is a good reason not to.
Committed in aaadb5005e Also added a note to the release notes: https://projects.blender.org/blender/blender-developer-docs/src/branch/main/docs/release_notes/4.2/modeling.md

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110868
No description provided.