92 return (
ULData *)&
l->head.index;
102 const int cd_loop_uv_offset)
104 BMLoop *l_other =
nullptr;
106 if (l_iter != l_src) {
112 if (l_other ==
nullptr) {
128 const int cd_loop_uv_offset)
131 BMLoop *l_other =
nullptr;
133 if (l_iter != l_src) {
139 if (l_other ==
nullptr) {
150 if (l_other !=
nullptr) {
151 if (l_other->
v == v_src) {
154 else if (l_other->
next->
v == v_src) {
155 l_other = l_other->
next;
157 else if (l_other->
prev->
v == v_src) {
158 l_other = l_other->
prev;
174 if (
l->e == e_prev) {
177 else if (
l->prev->e == e_prev) {
195 bool is_single_vert =
true;
200 is_single_vert =
false;
205 if (is_single_vert ==
false) {
207 if (
UL(
l)->is_select_vert_single) {
225 const float aspect_y,
226 const int cd_loop_uv_offset,
227 float *r_corner_angle,
239 dir_test[0][1] /= aspect_y;
240 dir_test[2][1] /= aspect_y;
246 sub_v2_v2v2(dir_test[1], dir_test[0], dir_test[2]);
250 std::swap(dir_test[1][0], dir_test[1][1]);
251 dir_test[1][1] *= -1.0f;
254 dir_test[1] *= -1.0f;
257 const float angles[3] = {
264 *r_corner_angle = angles[1];
267 if (angles[0] < angles[2]) {
268 *r_edge_angle = angles[0];
272 *r_edge_angle = angles[2];
304 const float aspect_y,
305 const int cd_loop_uv_offset)
314 BMLoop *l_init_edge =
nullptr;
315 float corner_angle_best =
FLT_MAX;
316 float edge_angle_best =
FLT_MAX;
317 int edge_index_best = 0;
322 dir_co[1] /= aspect_y;
327 int uv_fan_count_all = 0;
335 uv_fan_count_all += 1;
342 float corner_angle_test;
343 float edge_angle_test;
352 if ((corner_angle_best ==
FLT_MAX) || (corner_angle_test < corner_angle_best)) {
353 corner_angle_best = corner_angle_test;
358 edge_angle_test =
min_ff(corner_angle_test, edge_angle_test);
360 if ((edge_angle_best ==
FLT_MAX) || (edge_angle_test < edge_angle_best)) {
361 edge_angle_best = edge_angle_test;
362 edge_index_best = edge_index_test;
371 int uv_fan_count_contiguous = 1;
373 for (
int i = 0;
i < 2;
i += 1) {
377 (l_iter !=
nullptr) && (
UL(l_iter)->side == 0))
379 uv_fan_count_contiguous += 1;
385 if (l_iter == l_init) {
391 if (uv_fan_count_contiguous != uv_fan_count_all) {
401 if (uv_fan_count_contiguous <= 2) {
407 BMLoop *l_radial_init = (edge_index_best == -1) ? l_init_edge->
prev : l_init_edge;
408 BMLoop *l_radial_iter = l_radial_init;
411 BMLoop *
l = (l_radial_iter->
v == l_init->
v) ? l_radial_iter : l_radial_iter->
next;
416 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_radial_init);
464 const float aspect_y,
465 const int cd_loop_uv_offset)
469 float angle_of_side = 0.0f;
472 if (
UL(
l)->in_rip_pairs) {
473 if (
UL(
l)->side == side) {
478 float dir_prev[2], dir_next[2];
481 dir_prev[1] /= aspect_y;
482 dir_next[1] /= aspect_y;
483 const float luv_angle =
angle_v2v2(dir_prev, dir_next);
484 if (
LIKELY(isfinite(luv_angle))) {
485 angle_of_side += luv_angle;
491 return angle_of_side;
501 if (
UL(
l)->in_rip_pairs) {
502 if (
UL(
l)->side == side) {
515 const float aspect_y,
516 const int cd_loop_uv_offset)
518 const int side_a =
UL(l_switch)->
side;
519 const int side_b =
UL(l_target)->
side;
527 if (count_a + count_b == 4) {
528 return count_a > count_b;
532 l_switch, side_a, aspect_y, cd_loop_uv_offset);
534 l_target, side_b, aspect_y, cd_loop_uv_offset);
536 UL(l_switch)->
side = side_b;
539 l_switch, side_a, aspect_y, cd_loop_uv_offset);
541 l_target, side_b, aspect_y, cd_loop_uv_offset);
543 UL(l_switch)->
side = side_a;
545 return fabsf(angle_a_before - angle_b_before) >
fabsf(angle_a_after - angle_b_after);
557 const float aspect_y,
558 const int cd_loop_uv_offset)
571#define UV_SET_SIDE_AND_REMOVE_FROM_RAIL(loop, side_value) \
573 BLI_assert(UL(loop)->side_was_swapped == false); \
574 BLI_assert(UL(loop)->side != side_value); \
575 if (!UL(loop)->in_stack) { \
576 BLI_SMALLSTACK_PUSH(stack, loop); \
577 UL(loop)->in_stack = true; \
579 if (UL(loop)->in_rip_pairs) { \
580 uv_rip_pairs_remove(rip, loop); \
582 UL(loop)->side = side_value; \
583 UL(loop)->side_was_swapped = true; \
592 int side =
UL(l_step)->
side;
600 if (
UL(l_step)->is_select_edge) {
603 if (l_other !=
nullptr) {
604 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
607 UL(l_other)->
side = !side;
610 if (
UL(l_other)->side == side) {
611 if (
UL(l_other)->side_was_swapped ==
false) {
619 l_other = l_step->
next;
620 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
626 if (
UL(l_other)->side != side) {
627 if ((
UL(l_other)->side_was_swapped ==
false) &&
637 for (
int i = 0;
i < 2;
i++) {
638 BMLoop *l_radial_first =
i ? l_step : l_step->
prev;
639 if (l_radial_first != l_radial_first->
radial_next) {
640 BMEdge *e_radial = l_radial_first->
e;
644 if (!
UL(l_radial_iter)->is_select_edge &&
647 BMLoop *l_other = (l_radial_iter->
v == l_step->
v) ? l_radial_iter :
651 if (!
UL(l_other)->in_rip_pairs && !
UL(l_other)->in_stack) {
657 if (
UL(l_other)->side != side) {
658 if ((
UL(l_other)->side_was_swapped ==
false) &&
660 l_other, l_step, aspect_y, cd_loop_uv_offset))
668 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_radial_first);
673#undef UV_SET_SIDE_AND_REMOVE_FROM_RAIL
688 const int cd_loop_uv_offset,
690 float r_dir_side[2][2])
693 int center_total = 0;
694 int side_total[2] = {0, 0};
696 for (
int i = 0;
i < 2;
i++) {
707 if (!
UL(
l)->is_select_edge) {
717 side_total[side] += 1;
721 for (
int i = 0;
i < 2;
i++) {
724 mul_v2_fl(r_center, 1.0f / center_total);
727 return side_total[0] && side_total[1];
753 const ULData ul_clear = {0};
755 bool changed =
false;
766 bool is_select_all_any =
false;
793 is_select_all_any =
true;
802 if (
UL(
l)->is_select_vert_single) {
815 if (is_select_all_any) {
818 if (!
UL(
l)->is_select_all) {
837 if (
UL(
l)->is_select_edge) {
838 if (!
UL(
l)->in_rip_pairs) {
842 float dir_side[2][2];
843 int side_from_cursor = -1;
845 for (
int i = 0;
i < 2;
i++) {
849 side_from_cursor = (
dot_v2v2(dir_side[0], dir_cursor) -
850 dot_v2v2(dir_side[1], dir_cursor)) < 0.0f;
856 if (ul->
side == side_from_cursor) {
866 else if (
UL(
l)->is_select_vert_single) {
869 const int side_from_cursor = 0;
874 if (ul->
side == side_from_cursor) {
912 bool changed_multi =
false;
923 const float aspect_y = aspx / aspy;
926 scene, view_layer,
nullptr);
928 for (
Object *obedit : objects) {
930 changed_multi =
true;
937 if (!changed_multi) {
959 ot->description =
"Rip selected vertices or a selected region";
960 ot->idname =
"UV_OT_rip";
980 "Mouse location in normalized coordinates, 0.0 to 1.0 is within the image bounds",
SpaceImage * CTX_wm_space_image(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
CustomData interface, see also DNA_customdata_types.h.
const char * CustomData_get_active_layer_name(const CustomData *data, eCustomDataType type)
blender::Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
void BKE_report(ReportList *reports, eReportType type, const char *message)
#define BLI_assert_unreachable()
#define BLI_STATIC_ASSERT(a, msg)
GSet * BLI_gset_ptr_new(const char *info)
bool BLI_gset_haskey(const GSet *gs, const void *key) ATTR_WARN_UNUSED_RESULT
unsigned int BLI_gset_len(const GSet *gs) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void * BLI_gsetIterator_getKey(GSetIterator *gsi)
#define GSET_ITER(gs_iter_, gset_)
void BLI_gset_free(GSet *gs, GSetKeyFreeFP keyfreefp)
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 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 n[2])
void DEG_id_tag_update(ID *id, unsigned int flags)
Object is a sort of wrapper for general info.
bool ED_operator_uvedit(bContext *C)
void uvedit_deselect_flush(const Scene *scene, BMesh *bm)
void uvedit_uv_select_disable(const Scene *scene, BMesh *bm, BMLoop *l, const BMUVOffsets &offsets)
void ED_uvedit_get_aspect(Object *obedit, float *r_aspx, float *r_aspy)
bool uvedit_face_visible_test(const Scene *scene, const BMFace *efa)
Read Guarded memory(de)allocation.
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
@ OPTYPE_DEPENDS_ON_CURSOR
#define BM_ELEM_CD_GET_BOOL(ele, offset)
#define BM_ELEM_CD_GET_FLOAT_P(ele, offset)
#define BM_ELEM_CD_SET_BOOL(ele, offset, f)
#define BM_elem_flag_set(ele, hflag, val)
#define BM_elem_flag_test(ele, hflag)
void BM_uv_map_attr_edge_select_ensure(BMesh *bm, const StringRef uv_map_name)
void BM_uv_map_attr_vert_select_ensure(BMesh *bm, const StringRef uv_map_name)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
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
BMUVOffsets BM_uv_map_offsets_get(const BMesh *bm)
bool BM_loop_uv_share_edge_check(const BMLoop *l_a, const BMLoop *l_b, 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)
float BM_face_uv_calc_cross(const BMFace *f, const int cd_loop_uv_offset)
void * MEM_callocN(size_t len, const char *str)
void MEM_freeN(void *vmemh)
VecBase< float, 2 > float2
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, 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)
struct BMLoop * radial_next
MeshRuntimeHandle * runtime
struct ToolSettings * toolsettings
uint is_select_vert_single
struct ReportList * reports
void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
static wmOperatorStatus uv_rip_exec(bContext *C, wmOperator *op)
static wmOperatorStatus 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)
BLI_INLINE ULData * UL(BMLoop *l)
static void uv_rip_single_free(UVRipSingle *rip)
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 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 bool uv_rip_object(Scene *scene, Object *obedit, const float co[2], const float aspect_y)
static BMLoop * bm_loop_find_other_radial_loop_with_visible_face(BMLoop *l_src, const int cd_loop_uv_offset)
void UV_OT_rip(wmOperatorType *ot)
static UVRipPairs * uv_rip_pairs_from_loop(BMLoop *l_init, 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)
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 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 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_vert_step_fan_loop_uv(BMLoop *l, BMEdge **e_step, const int cd_loop_uv_offset)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)