103 const int cd_loop_uv_offset)
105 BMLoop *l_other =
nullptr;
107 if (l_iter != l_src) {
113 if (l_other ==
nullptr) {
129 const int cd_loop_uv_offset)
132 BMLoop *l_other =
nullptr;
134 if (l_iter != l_src) {
140 if (l_other ==
nullptr) {
151 if (l_other !=
nullptr) {
152 if (l_other->
v == v_src) {
155 else if (l_other->
next->
v == v_src) {
156 l_other = l_other->
next;
158 else if (l_other->
prev->
v == v_src) {
159 l_other = l_other->
prev;
175 if (
l->
e == e_prev) {
178 else if (
l->
prev->
e == e_prev) {
196 bool is_single_vert =
true;
201 is_single_vert =
false;
206 if (is_single_vert ==
false) {
208 if (
UL(
l)->is_select_vert_single) {
226 const float aspect_y,
227 const int cd_loop_uv_offset,
228 float *r_corner_angle,
240 dir_test[0][1] /= aspect_y;
241 dir_test[2][1] /= aspect_y;
247 sub_v2_v2v2(dir_test[1], dir_test[0], dir_test[2]);
251 std::swap(dir_test[1][0], dir_test[1][1]);
252 dir_test[1][1] *= -1.0f;
255 dir_test[1] *= -1.0f;
258 const float angles[3] = {
265 *r_corner_angle = angles[1];
268 if (angles[0] < angles[2]) {
269 *r_edge_angle = angles[0];
273 *r_edge_angle = angles[2];
305 const float aspect_y,
306 const int cd_loop_uv_offset)
310 rip->
loops = MEM_new<Set<BMLoop *>>(__func__);
315 BMLoop *l_init_edge =
nullptr;
316 float corner_angle_best =
FLT_MAX;
317 float edge_angle_best =
FLT_MAX;
318 int edge_index_best = 0;
323 dir_co[1] /= aspect_y;
328 int uv_fan_count_all = 0;
336 uv_fan_count_all += 1;
343 float corner_angle_test;
344 float edge_angle_test;
353 if ((corner_angle_best ==
FLT_MAX) || (corner_angle_test < corner_angle_best)) {
354 corner_angle_best = corner_angle_test;
359 edge_angle_test =
min_ff(corner_angle_test, edge_angle_test);
361 if ((edge_angle_best ==
FLT_MAX) || (edge_angle_test < edge_angle_best)) {
362 edge_angle_best = edge_angle_test;
363 edge_index_best = edge_index_test;
372 int uv_fan_count_contiguous = 1;
374 for (
int i = 0; i < 2; i += 1) {
375 BMEdge *e_prev = i ? l_init->e : l_init->prev->e;
378 (l_iter !=
nullptr) && (
UL(l_iter)->side == 0))
380 uv_fan_count_contiguous += 1;
386 if (l_iter == l_init) {
392 if (uv_fan_count_contiguous != uv_fan_count_all) {
400 if (uv_fan_count_contiguous <= 2) {
406 BMLoop *l_radial_init = (edge_index_best == -1) ? l_init_edge->
prev : l_init_edge;
407 BMLoop *l_radial_iter = l_radial_init;
410 BMLoop *
l = (l_radial_iter->
v == l_init->v) ? l_radial_iter : l_radial_iter->
next;
415 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_radial_init);
424 MEM_delete(rip->
loops);
463 const float aspect_y,
464 const int cd_loop_uv_offset)
468 float angle_of_side = 0.0f;
471 if (
UL(
l)->in_rip_pairs) {
472 if (
UL(
l)->side == side) {
477 float dir_prev[2], dir_next[2];
480 dir_prev[1] /= aspect_y;
481 dir_next[1] /= aspect_y;
482 const float luv_angle =
angle_v2v2(dir_prev, dir_next);
483 if (isfinite(luv_angle)) [[likely]] {
484 angle_of_side += luv_angle;
490 return angle_of_side;
500 if (
UL(
l)->in_rip_pairs) {
501 if (
UL(
l)->side == side) {
514 const float aspect_y,
515 const int cd_loop_uv_offset)
517 const int side_a =
UL(l_switch)->
side;
518 const int side_b =
UL(l_target)->
side;
526 if (count_a + count_b == 4) {
527 return count_a > count_b;
531 l_switch, side_a, aspect_y, cd_loop_uv_offset);
533 l_target, side_b, aspect_y, cd_loop_uv_offset);
535 UL(l_switch)->
side = side_b;
538 l_switch, side_a, aspect_y, cd_loop_uv_offset);
540 l_target, side_b, aspect_y, cd_loop_uv_offset);
542 UL(l_switch)->
side = side_a;
544 return fabsf(angle_a_before - angle_b_before) >
fabsf(angle_a_after - angle_b_after);
556 const float aspect_y,
557 const int cd_loop_uv_offset)
560 rip->
loops = MEM_new<Set<BMLoop *>>(__func__);
570#define UV_SET_SIDE_AND_REMOVE_FROM_RAIL(loop, side_value) \
572 BLI_assert(UL(loop)->side_was_swapped == false); \
573 BLI_assert(UL(loop)->side != side_value); \
574 if (!UL(loop)->in_stack) { \
575 BLI_SMALLSTACK_PUSH(stack, loop); \
576 UL(loop)->in_stack = true; \
578 if (UL(loop)->in_rip_pairs) { \
579 uv_rip_pairs_remove(rip, loop); \
581 UL(loop)->side = side_value; \
582 UL(loop)->side_was_swapped = true; \
591 int side =
UL(l_step)->
side;
599 if (
UL(l_step)->is_select_edge) {
602 if (l_other !=
nullptr) {
603 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
606 UL(l_other)->
side = !side;
609 if (
UL(l_other)->side == side) {
610 if (
UL(l_other)->side_was_swapped ==
false) {
618 l_other = l_step->
next;
619 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
625 if (
UL(l_other)->side != side) {
626 if ((
UL(l_other)->side_was_swapped ==
false) &&
636 for (
int i = 0; i < 2; i++) {
637 BMLoop *l_radial_first = i ? l_step : l_step->
prev;
638 if (l_radial_first != l_radial_first->
radial_next) {
639 BMEdge *e_radial = l_radial_first->
e;
643 if (!
UL(l_radial_iter)->is_select_edge &&
646 BMLoop *l_other = (l_radial_iter->
v == l_step->
v) ? l_radial_iter :
650 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
656 if (
UL(l_other)->side != side) {
657 if ((
UL(l_other)->side_was_swapped ==
false) &&
659 l_other, l_step, aspect_y, cd_loop_uv_offset))
667 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_radial_first);
672#undef UV_SET_SIDE_AND_REMOVE_FROM_RAIL
679 MEM_delete(rip->
loops);
687 const int cd_loop_uv_offset,
689 float r_dir_side[2][2])
692 int center_total = 0;
693 int side_total[2] = {0, 0};
695 for (
int i = 0; i < 2; i++) {
704 if (!
UL(
l)->is_select_edge) {
714 side_total[side] += 1;
718 for (
int i = 0; i < 2; i++) {
721 mul_v2_fl(r_center, 1.0f / center_total);
724 return side_total[0] && side_total[1];
757 const ULData ul_clear = {0};
759 bool changed =
false;
771 bool is_select_all_any =
false;
798 is_select_all_any =
true;
807 if (
UL(
l)->is_select_vert_single) {
820 if (is_select_all_any) {
826 if (!
UL(
l)->is_select_all) {
841 bool vert_selected =
false;
842 bool edge_selected =
false;
847 if (
UL(
l)->is_select_edge) {
848 edge_selected =
true;
849 if (!
UL(
l)->in_rip_pairs) {
853 float dir_side[2][2];
854 int side_from_cursor = -1;
856 for (
int i = 0; i < 2; i++) {
860 side_from_cursor = (
dot_v2v2(dir_side[0], dir_cursor) -
861 dot_v2v2(dir_side[1], dir_cursor)) < 0.0f;
865 if (ul->
side == side_from_cursor) {
875 else if (
UL(
l)->is_select_vert_single) {
876 vert_selected =
true;
879 const int side_from_cursor = 0;
882 if (ul->
side == side_from_cursor) {
895 if (edge_selected && !changed) {
899 if (vert_selected && !changed) {
942 "Rip is only compatible with sync-select with vertex/edge selection");
947 bool changed_multi =
false;
958 const float aspect_y = aspx / aspy;
961 *bmain, scene, view_layer,
nullptr);
969 for (
Object *obedit : objects) {
971 changed_multi =
true;
978 if (!changed_multi) {
1001 ot->
name =
"Rip UVs";
1002 ot->
description =
"Rip selected vertices or a selected region";
1003 ot->
idname =
"UV_OT_rip";
1023 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
CustomData interface, see also DNA_customdata_types.h.
BLI_LINKSTACK_*** wrapper macros for using a LinkNode to store a stack of pointers,...
#define BLI_SMALLSTACK_DECLARE(var, type)
#define BLI_SMALLSTACK_POP(var)
#define BLI_SMALLSTACK_PUSH(var, data)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
bool contains(const Key &key) const
bool remove(const Key &key)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
MINLINE float min_ff(float a, float b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
bool ED_operator_uvedit(bContext *C)
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
static void bm_loop_calc_uv_angle_from_dir(BMLoop *l, const float dir[2], const float aspect_y, const int cd_loop_uv_offset, float *r_corner_angle, float *r_edge_angle, int *r_edge_index)
void ED_uvedit_get_aspect(Object *obedit, float *r_aspx, float *r_aspy)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
bool uvedit_face_visible_test(const Scene *scene, const BMFace *efa)
MINLINE void mul_v2_fl(float r[2], float f)
void uvedit_select_prepare_custom_data(const Scene *scene, BMesh *bm)
void uvedit_loop_vert_select_set(const ToolSettings *ts, const BMesh *bm, BMLoop *l, const bool select)
void BM_mesh_uvselect_flush_from_loop_verts(BMesh *bm)
static void uv_rip_pairs_remove(UVRipPairs *rip, BMLoop *l)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE float normalize_v2(float n[2])
static void uv_rip_single_free(UVRipSingle *rip)
void UV_OT_rip(wmOperatorType *ot)
static UVRipSingle * uv_rip_single_from_loop(BMLoop *l_init_orig, const float co[2], const float aspect_y, const int cd_loop_uv_offset)
BLI_INLINE bool BM_vert_in_edge(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ViewLayer * CTX_data_view_layer(const bContext *C)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
static BMLoop * bm_vert_step_fan_loop_uv(BMLoop *l, BMEdge **e_step, const int cd_loop_uv_offset)
static void bm_loop_uv_select_single_vert_validate(BMLoop *l_init, const int cd_loop_uv_offset)
VecBase< float, 2 > float2
void uvedit_uv_select_disable(const Scene *scene, BMesh *bm, BMLoop *l)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
MINLINE void add_v2_v2(float r[2], const float a[2])
static UVRipPairs * uv_rip_pairs_from_loop(BMLoop *l_init, const float aspect_y, const int cd_loop_uv_offset)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Object * CTX_data_edit_object(const bContext *C)
bool BKE_reports_contain(ReportList *reports, eReportType level)
static bool uv_rip_pairs_loop_change_sides_test(BMLoop *l_switch, BMLoop *l_target, const float aspect_y, const int cd_loop_uv_offset)
bool BM_edge_uv_share_vert_check(const BMEdge *e, const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
static bool uv_rip_object(Scene *scene, Object *obedit, const float co[2], const float aspect_y, ReportList *reports)
float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset)
bool uvedit_loop_vert_select_get(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
bool ED_uvedit_sync_uvselect_ignore(const ToolSettings *ts)
static bool uv_rip_pairs_calc_center_and_direction(UVRipPairs *rip, const int cd_loop_uv_offset, float r_center[2], float r_dir_side[2][2])
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
void uvedit_loop_edge_select_set(const ToolSettings *ts, const BMesh *bm, BMLoop *l, const bool select)
static BMLoop * bm_loop_find_other_fan_loop_with_visible_face(BMLoop *l_src, BMVert *v_src, const int cd_loop_uv_offset)
bool EDBM_selectmode_set_multi_ex(Scene *scene, Span< Object * > objects, const short selectmode)
SpaceImage * CTX_wm_space_image(const bContext *C)
BLI_INLINE ULData * UL(BMLoop *l)
static int uv_rip_pairs_loop_count_on_side(BMLoop *l_init, uint side, const int cd_loop_uv_offset)
Main * CTX_data_main(const bContext *C)
static wmOperatorStatus uv_rip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static float uv_rip_pairs_calc_uv_angle(BMLoop *l_init, uint side, const float aspect_y, const int cd_loop_uv_offset)
static void uv_rip_pairs_free(UVRipPairs *rip)
static void uv_rip_pairs_add(UVRipPairs *rip, BMLoop *l)
float angle_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, const int cd_loop_uv_offset)
Scene * CTX_data_scene(const bContext *C)
static BMLoop * bm_loop_find_other_radial_loop_with_visible_face(BMLoop *l_src, const int cd_loop_uv_offset)
@ OPTYPE_DEPENDS_ON_CURSOR
static wmOperatorStatus uv_rip_exec(bContext *C, wmOperator *op)
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void uvedit_select_prepare_sync_select(const Scene *scene, BMesh *bm)
void uvedit_select_flush_from_verts(const Scene *scene, BMesh *bm, bool select)
MINLINE void zero_v2(float r[2])
ARegion * CTX_wm_region(const bContext *C)
bool uvedit_loop_edge_select_get(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
struct BMLoop * radial_next
struct ToolSettings * toolsettings
uint is_select_vert_single
bool uv_select_sync_valid
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
#define UV_SET_SIDE_AND_REMOVE_FROM_RAIL(loop, side_value)