115 const int cd_loop_uv_offset)
119 if (l_iter != l_src) {
124 if (l_other ==
NULL) {
140 const int cd_loop_uv_offset)
145 if (l_iter != l_src) {
150 if (l_other ==
NULL) {
161 if (l_other !=
NULL) {
162 if (l_other->
v == v_src) {
165 else if (l_other->
next->
v == v_src) {
166 l_other = l_other->
next;
168 else if (l_other->
prev->
v == v_src) {
169 l_other = l_other->
prev;
185 if (
l->
e == e_prev) {
188 else if (
l->
prev->
e == e_prev) {
206 bool is_single_vert =
true;
211 is_single_vert =
false;
216 if (is_single_vert ==
false) {
218 if (
UL(
l)->is_select_vert_single) {
236 const float aspect_y,
237 const int cd_loop_uv_offset,
238 float *r_corner_angle,
243 float dir_test[3][2];
250 dir_test[0][1] /= aspect_y;
251 dir_test[2][1] /= aspect_y;
257 sub_v2_v2v2(dir_test[1], dir_test[0], dir_test[2]);
261 SWAP(
float, dir_test[1][0], dir_test[1][1]);
262 dir_test[1][1] *= -1.0f;
268 const float angles[3] = {
275 *r_corner_angle = angles[1];
278 if (angles[0] < angles[2]) {
279 *r_edge_angle = angles[0];
283 *r_edge_angle = angles[2];
315 const float aspect_y,
316 const int cd_loop_uv_offset)
319 const float *co_center =
327 float corner_angle_best = FLT_MAX;
328 float edge_angle_best = FLT_MAX;
329 int edge_index_best = 0;
334 dir_co[1] /= aspect_y;
339 int uv_fan_count_all = 0;
347 uv_fan_count_all += 1;
354 float corner_angle_test;
355 float edge_angle_test;
364 if ((corner_angle_best == FLT_MAX) || (corner_angle_test < corner_angle_best)) {
365 corner_angle_best = corner_angle_test;
370 edge_angle_test =
min_ff(corner_angle_test, edge_angle_test);
372 if ((edge_angle_best == FLT_MAX) || (edge_angle_test < edge_angle_best)) {
373 edge_angle_best = edge_angle_test;
374 edge_index_best = edge_index_test;
383 int uv_fan_count_contiguous = 1;
385 for (
int i = 0; i < 2; i += 1) {
389 (l_iter !=
NULL) && (
UL(l_iter)->side == 0)) {
390 uv_fan_count_contiguous += 1;
396 if (l_iter == l_init) {
402 if (uv_fan_count_contiguous != uv_fan_count_all) {
412 if (uv_fan_count_contiguous <= 2) {
418 BMLoop *l_radial_init = (edge_index_best == -1) ? l_init_edge->
prev : l_init_edge;
419 BMLoop *l_radial_iter = l_radial_init;
422 BMLoop *
l = (l_radial_iter->v == l_init->
v) ? l_radial_iter : l_radial_iter->
next;
427 }
while ((l_radial_iter = l_radial_iter->radial_next) != l_radial_init);
475 const float aspect_y,
476 const int cd_loop_uv_offset)
480 float angle_of_side = 0.0f;
483 if (
UL(
l)->in_rip_pairs) {
484 if (
UL(
l)->side == side) {
489 float dir_prev[2], dir_next[2];
492 dir_prev[1] /= aspect_y;
493 dir_next[1] /= aspect_y;
494 const float luv_angle =
angle_v2v2(dir_prev, dir_next);
496 angle_of_side += luv_angle;
502 return angle_of_side;
512 if (
UL(
l)->in_rip_pairs) {
513 if (
UL(
l)->side == side) {
526 const float aspect_y,
527 const int cd_loop_uv_offset)
529 const int side_a =
UL(l_switch)->
side;
530 const int side_b =
UL(l_target)->
side;
538 if (count_a + count_b == 4) {
539 return count_a > count_b;
543 l_switch, side_a, aspect_y, cd_loop_uv_offset);
545 l_target, side_b, aspect_y, cd_loop_uv_offset);
547 UL(l_switch)->
side = side_b;
550 l_switch, side_a, aspect_y, cd_loop_uv_offset);
552 l_target, side_b, aspect_y, cd_loop_uv_offset);
554 UL(l_switch)->
side = side_a;
556 return fabsf(angle_a_before - angle_b_before) >
fabsf(angle_a_after - angle_b_after);
568 const float aspect_y,
569 const int cd_loop_uv_offset)
582 #define UV_SET_SIDE_AND_REMOVE_FROM_RAIL(loop, side_value) \
584 BLI_assert(UL(loop)->side_was_swapped == false); \
585 BLI_assert(UL(loop)->side != side_value); \
586 if (!UL(loop)->in_stack) { \
587 BLI_SMALLSTACK_PUSH(stack, loop); \
588 UL(loop)->in_stack = true; \
590 if (UL(loop)->in_rip_pairs) { \
591 uv_rip_pairs_remove(rip, loop); \
593 UL(loop)->side = side_value; \
594 UL(loop)->side_was_swapped = true; \
603 int side =
UL(l_step)->
side;
611 if (
UL(l_step)->is_select_edge) {
614 if (l_other !=
NULL) {
615 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
618 UL(l_other)->
side = !side;
621 if (
UL(l_other)->side == side) {
622 if (
UL(l_other)->side_was_swapped ==
false) {
630 l_other = l_step->
next;
631 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
637 if (
UL(l_other)->side != side) {
638 if ((
UL(l_other)->side_was_swapped ==
false) &&
647 for (
int i = 0; i < 2; i++) {
648 BMLoop *l_radial_first = i ? l_step : l_step->
prev;
649 if (l_radial_first != l_radial_first->
radial_next) {
650 BMEdge *e_radial = l_radial_first->
e;
654 if (!
UL(l_radial_iter)->is_select_edge &&
656 BMLoop *l_other = (l_radial_iter->
v == l_step->
v) ? l_radial_iter :
666 if (
UL(l_other)->side != side) {
667 if ((
UL(l_other)->side_was_swapped ==
false) &&
669 l_other, l_step, aspect_y, cd_loop_uv_offset)) {
676 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_radial_first);
681 #undef UV_SET_SIDE_AND_REMOVE_FROM_RAIL
696 const int cd_loop_uv_offset,
698 float r_dir_side[2][2])
701 int center_total = 0;
702 int side_total[2] = {0, 0};
704 for (
int i = 0; i < 2; i++) {
715 if (!
UL(
l)->is_select_edge) {
725 side_total[side] += 1;
729 for (
int i = 0; i < 2; i++) {
732 mul_v2_fl(r_center, 1.0f / center_total);
735 return side_total[0] && side_total[1];
758 const ULData ul_clear = {0};
760 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) {
823 if (!
UL(
l)->is_select_all) {
839 if (
UL(
l)->is_select_edge) {
840 if (!
UL(
l)->in_rip_pairs) {
844 float dir_side[2][2];
845 int side_from_cursor = -1;
847 for (
int i = 0; i < 2; i++) {
851 side_from_cursor = (
dot_v2v2(dir_side[0], dir_cursor) -
852 dot_v2v2(dir_side[1], dir_cursor)) < 0.0f;
858 if (ul->
side == side_from_cursor) {
868 else if (
UL(
l)->is_select_vert_single) {
871 const int side_from_cursor = 0;
876 if (ul->
side == side_from_cursor) {
903 bool changed_multi =
false;
914 const float aspect_y = aspx / aspy;
916 uint objects_len = 0;
920 for (
uint ob_index = 0; ob_index < objects_len; ob_index++) {
921 Object *obedit = objects[ob_index];
924 changed_multi =
true;
932 if (!changed_multi) {
954 ot->
description =
"Rip selected vertices or a selected region";
975 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
struct Scene * CTX_data_scene(const bContext *C)
struct Object * CTX_data_edit_object(const bContext *C)
struct ViewLayer * CTX_data_view_layer(const bContext *C)
struct ARegion * CTX_wm_region(const bContext *C)
struct SpaceImage * CTX_wm_space_image(const bContext *C)
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset(const struct CustomData *data, int type)
#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, v3d, r_len)
void BKE_report(ReportList *reports, ReportType type, const char *message)
#define BLI_assert_unreachable()
unsigned int BLI_gset_len(GSet *gs) ATTR_WARN_UNUSED_RESULT
GSet * BLI_gset_ptr_new(const char *info)
#define GSET_ITER(gs_iter_, gset_)
bool BLI_gset_haskey(GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
BLI_INLINE void * BLI_gsetIterator_getKey(GSetIterator *gsi)
bool BLI_gset_add(GSet *gs, void *key)
bool BLI_gset_remove(GSet *gs, const void *key, GSetKeyFreeFP keyfreefp)
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)
MINLINE float min_ff(float a, float b)
float angle_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void mul_v2_fl(float r[2], float f)
MINLINE void negate_v2(float r[2])
MINLINE void add_v2_v2(float r[2], const float a[2])
MINLINE bool equals_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void zero_v2(float r[2])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v2(float r[2])
void DEG_id_tag_update(struct ID *id, int flag)
Object is a sort of wrapper for general info.
bool ED_operator_uvedit(struct bContext *C)
void ED_uvedit_get_aspect(struct Object *obedit, float *r_aspx, float *r_aspy)
void uvedit_uv_select_disable(const struct Scene *scene, struct BMEditMesh *em, struct BMLoop *l, const int cd_loop_uv_offset)
bool uvedit_face_visible_test(const struct Scene *scene, struct BMFace *efa)
NSNotificationCenter * center
Read Guarded memory(de)allocation.
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
#define BM_ELEM_CD_GET_VOID_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)
ATTR_WARN_UNUSED_RESULT BMesh * bm
BLI_INLINE bool BM_vert_in_edge(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMLoop * l
bool BM_edge_uv_share_vert_check(BMEdge *e, BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset)
bool BM_loop_uv_share_edge_check(BMLoop *l_a, BMLoop *l_b, const int cd_loop_uv_offset)
float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset)
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
struct BMLoop * radial_next
struct BMEditMesh * edit_mesh
uint is_select_vert_single
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
void uvedit_live_unwrap_update(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit)
struct UVRipPairs UVRipPairs
static int uv_rip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static BMLoop * bm_loop_find_other_fan_loop_with_visible_face(BMLoop *l_src, BMVert *v_src, const int cd_loop_uv_offset)
#define UV_SET_SIDE_AND_REMOVE_FROM_RAIL(loop, side_value)
static void bm_loop_uv_select_single_vert_validate(BMLoop *l_init, const int cd_loop_uv_offset)
static void uv_rip_pairs_free(UVRipPairs *rip)
static void uv_rip_single_free(UVRipSingle *rip)
static int uv_rip_exec(bContext *C, wmOperator *op)
static void uv_rip_pairs_remove(UVRipPairs *rip, BMLoop *l)
static void uv_rip_pairs_add(UVRipPairs *rip, BMLoop *l)
static int uv_rip_pairs_loop_count_on_side(BMLoop *l_init, uint side, const int cd_loop_uv_offset)
static bool uv_rip_object(Scene *scene, Object *obedit, const float co[2], const float aspect_y)
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)
static float uv_rip_pairs_calc_uv_angle(BMLoop *l_init, uint side, const float aspect_y, const int cd_loop_uv_offset)
BLI_STATIC_ASSERT(sizeof(ULData)<=sizeof(int), "")
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])
static BMLoop * bm_vert_step_fan_loop_uv(BMLoop *l, BMEdge **e_step, const int cd_loop_uv_offset)
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)
static UVRipPairs * uv_rip_pairs_from_loop(BMLoop *l_init, const float aspect_y, const int cd_loop_uv_offset)
struct UVRipSingle UVRipSingle
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)
static BMLoop * bm_loop_find_other_radial_loop_with_visible_face(BMLoop *l_src, const int cd_loop_uv_offset)
BLI_INLINE ULData * UL(BMLoop *l)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)