Blender V5.0
uvedit_ops.cc File Reference
#include <cmath>
#include <cstdlib>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "BLI_bounds.hh"
#include "BLI_kdtree.h"
#include "BLI_math_base.hh"
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_context.hh"
#include "BKE_customdata.hh"
#include "BKE_editmesh.hh"
#include "BKE_layer.hh"
#include "BKE_main_invariants.hh"
#include "BKE_material.hh"
#include "BKE_mesh_mapping.hh"
#include "BKE_mesh_types.hh"
#include "BKE_node.hh"
#include "BKE_node_legacy_types.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "ED_image.hh"
#include "ED_mesh.hh"
#include "ED_node.hh"
#include "ED_screen.hh"
#include "ED_uvedit.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "WM_api.hh"
#include "WM_message.hh"
#include "WM_types.hh"
#include "UI_interface.hh"
#include "UI_interface_layout.hh"
#include "UI_resources.hh"
#include "UI_view2d.hh"
#include "uvedit_intern.hh"

Go to the source code of this file.

Classes

struct  UVAlignIslandBounds

Functions

State Testing
bool ED_uvedit_test (Object *obedit)
static int UNUSED_FUNCTION ED_operator_uvmap_mesh (bContext *C)
Object Active Image
static bool is_image_texture_node (bNode *node)
bool ED_object_get_active_image (Object *ob, int mat_nr, Image **r_ima, ImageUser **r_iuser, const bNode **r_node, const bNodeTree **r_ntree)
void ED_object_assign_active_image (Main *bmain, Object *ob, int mat_nr, Image *ima)
Live Unwrap Utilities
void uvedit_live_unwrap_update (SpaceImage *sima, Scene *scene, Object *obedit)
Remove Doubles Operator
static wmOperatorStatus uv_remove_doubles_to_selected (bContext *C, wmOperator *op)
static wmOperatorStatus uv_remove_doubles_to_unselected (bContext *C, wmOperator *op)
static wmOperatorStatus uv_remove_doubles_to_selected_shared_vertex (bContext *C, wmOperator *op)
static wmOperatorStatus uv_remove_doubles_exec (bContext *C, wmOperator *op)
static void UV_OT_remove_doubles (wmOperatorType *ot)
Weld Near Operator
static wmOperatorStatus uv_weld_exec (bContext *C, wmOperator *)
static void UV_OT_weld (wmOperatorType *ot)
Snap Cursor Operator
static void uv_snap_to_pixel (float uvco[2], float w, float h)
static void uv_snap_cursor_to_pixels (SpaceImage *sima)
static bool uv_snap_cursor_to_selection (Scene *scene, Span< Object * > objects_edit, SpaceImage *sima)
static void uv_snap_cursor_to_origin (float uvco[2])
static wmOperatorStatus uv_snap_cursor_exec (bContext *C, wmOperator *op)
static void UV_OT_snap_cursor (wmOperatorType *ot)
Snap Selection Operator
static bool uv_snap_uvs_to_cursor (Scene *scene, Object *obedit, const float cursor[2])
static bool uv_snap_uvs_offset (Scene *scene, Object *obedit, const float offset[2])
static bool uv_snap_uvs_to_adjacent_unselected (Scene *scene, Object *obedit)
static bool uv_snap_uvs_to_pixels (SpaceImage *sima, Scene *scene, Object *obedit)
static wmOperatorStatus uv_snap_selection_exec (bContext *C, wmOperator *op)
static void UV_OT_snap_selected (wmOperatorType *ot)
Pin UVs Operator
static wmOperatorStatus uv_pin_exec (bContext *C, wmOperator *op)
static void UV_OT_pin (wmOperatorType *ot)
Reveal Operator
static wmOperatorStatus uv_reveal_exec (bContext *C, wmOperator *op)
static void UV_OT_reveal (wmOperatorType *ot)
Set 2D Cursor Operator
static wmOperatorStatus uv_set_2d_cursor_exec (bContext *C, wmOperator *op)
static wmOperatorStatus uv_set_2d_cursor_invoke (bContext *C, wmOperator *op, const wmEvent *event)
static void UV_OT_cursor_set (wmOperatorType *ot)
Seam from UV Islands Operator
static wmOperatorStatus uv_seams_from_islands_exec (bContext *C, wmOperator *op)
static void UV_OT_seams_from_islands (wmOperatorType *ot)
Mark Seam Operator
static wmOperatorStatus uv_mark_seam_exec (bContext *C, wmOperator *op)
static wmOperatorStatus uv_mark_seam_invoke (bContext *C, wmOperator *op, const wmEvent *)
static void UV_OT_mark_seam (wmOperatorType *ot)
static bool uv_copy_mirrored_faces (const Scene *scene, BMesh *bm, int direction, int precision, int *r_double_warn)
static wmOperatorStatus uv_copy_mirrored_faces_exec (bContext *C, wmOperator *op)
void UV_OT_copy_mirrored_faces (wmOperatorType *ot)
Operator Registration & Keymap
void ED_operatortypes_uvedit ()
void ED_operatormacros_uvedit ()
void ED_keymap_uvedit (wmKeyConfig *keyconf)

Hide Operator

#define UV_VERT_SEL_TEST(ts, bm, l, bool_test)
#define UV_EDGE_SEL_TEST(ts, bm, l, bool_test)
static bool bm_face_is_all_uv_sel (const ToolSettings *ts, const BMesh *bm, BMFace *f, bool select_test)
static bool uv_mesh_hide_sync_select (const ToolSettings *ts, Object *ob, BMEditMesh *em, bool swap)
static wmOperatorStatus uv_hide_exec (bContext *C, wmOperator *op)
static void UV_OT_hide (wmOperatorType *ot)

Geometric Utilities

enum class  UVMoveType { Dynamic = 0 , Pixel = 1 , Udim = 2 }
enum class  UVMoveDirection { X = 0 , Y = 1 }
void ED_uvedit_foreach_uv (const Scene *scene, BMesh *bm, const bool skip_invisible, const bool selected, FunctionRef< void(float[2])> user_fn)
void ED_uvedit_foreach_uv_multi (const Scene *scene, const Span< Object * > objects_edit, const bool skip_invisible, const bool skip_nonselected, FunctionRef< void(float[2])> user_fn)
bool ED_uvedit_minmax_multi (const Scene *scene, const Span< Object * > objects_edit, float r_min[2], float r_max[2])
void ED_uvedit_select_all (const ToolSettings *ts, BMesh *bm)
static bool uvedit_median_multi (const Scene *scene, const Span< Object * > objects_edit, float co[2])
bool ED_uvedit_center_multi (const Scene *scene, Span< Object * > objects_edit, float cent[2], char mode)
bool ED_uvedit_center_from_pivot_ex (const SpaceImage *sima, Scene *scene, ViewLayer *view_layer, float r_center[2], char mode, bool *r_has_select)
static wmOperatorStatus uv_move_on_axis_exec (bContext *C, wmOperator *op)
static void UV_OT_move_on_axis (wmOperatorType *ot)

Weld Align Operator

enum  eUVWeldAlign {
  UV_STRAIGHTEN , UV_STRAIGHTEN_X , UV_STRAIGHTEN_Y , UV_ALIGN_AUTO ,
  UV_ALIGN_X , UV_ALIGN_Y , UV_WELD
}
enum class  UVAlignPositionMode { Mean = 0 , Min = 1 , Max = 2 }
enum  eUVEndPointPrecedence { UVEP_INVALID = 0 , UVEP_SELECTED = (1 << 0) , UVEP_PINNED = (1 << 1) }
enum class  UVAlignInitialPosition { BoundingBox = 0 , UVTileGrid = 1 , ActiveUDIM = 2 , Cursor = 3 }
enum class  UVAlignIslandAxis { X = 0 , Y = 1 }
enum class  UVAlignIslandMode { Max = 0 , Min = 1 , Center = 2 , None = 3 }
enum  UVAlignIslandOrder { LargeToSmall = 0 , SmallToLarge = 1 , Fixed = 2 }
static bool uvedit_uv_align_weld (Scene *scene, BMesh *bm, const eUVWeldAlign tool, const float cent[2])
 ENUM_OPERATORS (eUVEndPointPrecedence, UVEP_PINNED)
static eUVEndPointPrecedence uvedit_line_update_get_precedence (const bool pinned)
static bool uvedit_line_update_endpoint (const float *luv, const bool pinned, float uv_a[2], eUVEndPointPrecedence *prec_a, float uv_b[2], eUVEndPointPrecedence *prec_b)
static bool uvedit_uv_straighten_elements (const UvElement *element, const int len, const BMUVOffsets &offsets, const eUVWeldAlign tool)
static bool uvedit_uv_straighten (Scene *scene, BMesh *bm, eUVWeldAlign tool)
static bool uvedit_uv_islands_arrange (const Scene *scene, BMesh *bm, const UVAlignIslandAxis axis, const UVAlignIslandMode align, const UVAlignIslandOrder order, const float margin, float2 &position)
static wmOperatorStatus uv_arrange_islands_exec (bContext *C, wmOperator *op)
static void UV_OT_arrange_islands (wmOperatorType *ot)
static void uv_weld (bContext *C)
static void uv_align (bContext *C, eUVWeldAlign tool, UVAlignPositionMode position_mode)
static wmOperatorStatus uv_align_exec (bContext *C, wmOperator *op)
static bool uv_align_poll_property (const bContext *, wmOperator *op, const PropertyRNA *prop)
static void UV_OT_align (wmOperatorType *ot)

Macro Definition Documentation

◆ UV_EDGE_SEL_TEST

#define UV_EDGE_SEL_TEST ( ts,
bm,
l,
bool_test )
Value:
(uvedit_edge_select_get_no_sync(ts, bm, l) == bool_test)
BMesh * bm
ATTR_WARN_UNUSED_RESULT const BMLoop * l
bool uvedit_edge_select_get_no_sync(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)

Definition at line 1816 of file uvedit_ops.cc.

Referenced by bm_face_is_all_uv_sel(), and uv_hide_exec().

◆ UV_VERT_SEL_TEST

#define UV_VERT_SEL_TEST ( ts,
bm,
l,
bool_test )
Value:
(uvedit_vert_select_get_no_sync(ts, bm, l) == bool_test)
bool uvedit_vert_select_get_no_sync(const ToolSettings *ts, const BMesh *bm, const BMLoop *l)

Definition at line 1813 of file uvedit_ops.cc.

Referenced by uv_hide_exec().

Enumeration Type Documentation

◆ eUVEndPointPrecedence

Bitwise-or together, then choose loop with highest value.

Enumerator
UVEP_INVALID 
UVEP_SELECTED 
UVEP_PINNED 

Definition at line 489 of file uvedit_ops.cc.

◆ eUVWeldAlign

Enumerator
UV_STRAIGHTEN 
UV_STRAIGHTEN_X 
UV_STRAIGHTEN_Y 
UV_ALIGN_AUTO 
UV_ALIGN_X 
UV_ALIGN_Y 
UV_WELD 

Definition at line 448 of file uvedit_ops.cc.

◆ UVAlignInitialPosition

enum class UVAlignInitialPosition
strong
Enumerator
BoundingBox 
UVTileGrid 
ActiveUDIM 
Cursor 

Definition at line 640 of file uvedit_ops.cc.

◆ UVAlignIslandAxis

enum class UVAlignIslandAxis
strong
Enumerator

Definition at line 646 of file uvedit_ops.cc.

◆ UVAlignIslandMode

enum class UVAlignIslandMode
strong
Enumerator
Max 
Min 
Center 
None 

Definition at line 650 of file uvedit_ops.cc.

◆ UVAlignIslandOrder

Enumerator
LargeToSmall 
SmallToLarge 
Fixed 

Definition at line 656 of file uvedit_ops.cc.

◆ UVAlignPositionMode

enum class UVAlignPositionMode
strong
Enumerator
Mean 
Min 
Max 

Definition at line 457 of file uvedit_ops.cc.

◆ UVMoveDirection

enum class UVMoveDirection
strong
Enumerator

Definition at line 352 of file uvedit_ops.cc.

◆ UVMoveType

enum class UVMoveType
strong
Enumerator
Dynamic 
Pixel 
Udim 

Definition at line 347 of file uvedit_ops.cc.

Function Documentation

◆ bm_face_is_all_uv_sel()

bool bm_face_is_all_uv_sel ( const ToolSettings * ts,
const BMesh * bm,
BMFace * f,
bool select_test )
static

Definition at line 1820 of file uvedit_ops.cc.

References bm, BM_FACE_FIRST_LOOP, BMLoop::next, and UV_EDGE_SEL_TEST.

Referenced by uv_hide_exec().

◆ ED_keymap_uvedit()

void ED_keymap_uvedit ( wmKeyConfig * keyconf)

◆ ED_object_assign_active_image()

void ED_object_assign_active_image ( Main * bmain,
Object * ob,
int mat_nr,
Image * ima )

◆ ED_object_get_active_image()

◆ ED_operator_uvmap_mesh()

◆ ED_operatormacros_uvedit()

◆ ED_operatortypes_uvedit()

◆ ED_uvedit_center_from_pivot_ex()

bool ED_uvedit_center_from_pivot_ex ( const SpaceImage * sima,
Scene * scene,
ViewLayer * view_layer,
float r_center[2],
char mode,
bool * r_has_select )

◆ ED_uvedit_center_multi()

bool ED_uvedit_center_multi ( const Scene * scene,
Span< Object * > objects_edit,
float cent[2],
char mode )

◆ ED_uvedit_foreach_uv()

◆ ED_uvedit_foreach_uv_multi()

void ED_uvedit_foreach_uv_multi ( const Scene * scene,
const Span< Object * > objects_edit,
const bool skip_invisible,
const bool skip_nonselected,
FunctionRef< void(float[2])> user_fn )

◆ ED_uvedit_minmax_multi()

bool ED_uvedit_minmax_multi ( const Scene * scene,
const Span< Object * > objects_edit,
float r_min[2],
float r_max[2] )

Definition at line 246 of file uvedit_ops.cc.

References ED_uvedit_foreach_uv_multi(), INIT_MINMAX2, and minmax_v2v2_v2().

Referenced by ED_uvedit_center_multi(), and uv_align().

◆ ED_uvedit_select_all()

void ED_uvedit_select_all ( const ToolSettings * ts,
BMesh * bm )

Be careful when using this, it bypasses all synchronization options.

Definition at line 260 of file uvedit_ops.cc.

References bm, BM_FACES_OF_MESH, BM_ITER_ELEM, BM_ITER_MESH, BM_LOOPS_OF_FACE, l, uvedit_edge_select_set_no_sync(), uvedit_face_select_set_no_sync(), and uvedit_vert_select_set_no_sync().

Referenced by ED_uvedit_add_simple_uvs().

◆ ED_uvedit_test()

bool ED_uvedit_test ( Object * obedit)

◆ ENUM_OPERATORS()

ENUM_OPERATORS ( eUVEndPointPrecedence ,
UVEP_PINNED  )

References UVEP_PINNED.

◆ is_image_texture_node()

bool is_image_texture_node ( bNode * node)
static

◆ uv_align()

◆ uv_align_exec()

wmOperatorStatus uv_align_exec ( bContext * C,
wmOperator * op )
static

Definition at line 1000 of file uvedit_ops.cc.

References C, OPERATOR_FINISHED, wmOperator::ptr, RNA_enum_get(), and uv_align().

Referenced by UV_OT_align().

◆ uv_align_poll_property()

bool uv_align_poll_property ( const bContext * ,
wmOperator * op,
const PropertyRNA * prop )
static

Definition at line 1009 of file uvedit_ops.cc.

References ELEM, wmOperator::ptr, RNA_enum_get(), RNA_property_identifier(), STREQ, UV_ALIGN_X, and UV_ALIGN_Y.

Referenced by UV_OT_align().

◆ uv_arrange_islands_exec()

◆ uv_copy_mirrored_faces()

◆ uv_copy_mirrored_faces_exec()

◆ uv_hide_exec()

◆ uv_mark_seam_exec()

◆ uv_mark_seam_invoke()

◆ uv_mesh_hide_sync_select()

◆ uv_move_on_axis_exec()

◆ UV_OT_align()

◆ UV_OT_arrange_islands()

◆ UV_OT_copy_mirrored_faces()

void UV_OT_copy_mirrored_faces ( wmOperatorType * ot)

◆ UV_OT_cursor_set()

void UV_OT_cursor_set ( wmOperatorType * ot)
static

◆ UV_OT_hide()

void UV_OT_hide ( wmOperatorType * ot)
static

◆ UV_OT_mark_seam()

void UV_OT_mark_seam ( wmOperatorType * ot)
static

◆ UV_OT_move_on_axis()

void UV_OT_move_on_axis ( wmOperatorType * ot)
static

◆ UV_OT_pin()

◆ UV_OT_remove_doubles()

void UV_OT_remove_doubles ( wmOperatorType * ot)
static

◆ UV_OT_reveal()

void UV_OT_reveal ( wmOperatorType * ot)
static

◆ UV_OT_seams_from_islands()

void UV_OT_seams_from_islands ( wmOperatorType * ot)
static

◆ UV_OT_snap_cursor()

void UV_OT_snap_cursor ( wmOperatorType * ot)
static

◆ UV_OT_snap_selected()

void UV_OT_snap_selected ( wmOperatorType * ot)
static

◆ UV_OT_weld()

void UV_OT_weld ( wmOperatorType * ot)
static

Definition at line 1423 of file uvedit_ops.cc.

References ED_operator_uvedit(), OPTYPE_REGISTER, OPTYPE_UNDO, ot, and uv_weld_exec().

Referenced by ED_operatortypes_uvedit().

◆ uv_pin_exec()

◆ uv_remove_doubles_exec()

◆ uv_remove_doubles_to_selected()

◆ uv_remove_doubles_to_selected_shared_vertex()

◆ uv_remove_doubles_to_unselected()

◆ uv_reveal_exec()

◆ uv_seams_from_islands_exec()

◆ uv_set_2d_cursor_exec()

◆ uv_set_2d_cursor_invoke()

◆ uv_snap_cursor_exec()

◆ uv_snap_cursor_to_origin()

void uv_snap_cursor_to_origin ( float uvco[2])
static

Definition at line 1463 of file uvedit_ops.cc.

Referenced by uv_snap_cursor_exec().

◆ uv_snap_cursor_to_pixels()

void uv_snap_cursor_to_pixels ( SpaceImage * sima)
static

Definition at line 1448 of file uvedit_ops.cc.

References SpaceImage::cursor, ED_space_image_get_size(), and uv_snap_to_pixel().

Referenced by uv_snap_cursor_exec().

◆ uv_snap_cursor_to_selection()

bool uv_snap_cursor_to_selection ( Scene * scene,
Span< Object * > objects_edit,
SpaceImage * sima )
static

Definition at line 1456 of file uvedit_ops.cc.

References SpaceImage::around, SpaceImage::cursor, and ED_uvedit_center_multi().

Referenced by uv_snap_cursor_exec().

◆ uv_snap_selection_exec()

◆ uv_snap_to_pixel()

void uv_snap_to_pixel ( float uvco[2],
float w,
float h )
static

Definition at line 1442 of file uvedit_ops.cc.

References roundf, and w().

Referenced by uv_snap_cursor_to_pixels().

◆ uv_snap_uvs_offset()

bool uv_snap_uvs_offset ( Scene * scene,
Object * obedit,
const float offset[2] )
static

◆ uv_snap_uvs_to_adjacent_unselected()

◆ uv_snap_uvs_to_cursor()

bool uv_snap_uvs_to_cursor ( Scene * scene,
Object * obedit,
const float cursor[2] )
static

◆ uv_snap_uvs_to_pixels()

bool uv_snap_uvs_to_pixels ( SpaceImage * sima,
Scene * scene,
Object * obedit )
static

◆ uv_weld()

◆ uv_weld_exec()

wmOperatorStatus uv_weld_exec ( bContext * C,
wmOperator *  )
static

Definition at line 1416 of file uvedit_ops.cc.

References C, OPERATOR_FINISHED, and uv_weld().

Referenced by UV_OT_weld().

◆ uvedit_line_update_endpoint()

bool uvedit_line_update_endpoint ( const float * luv,
const bool pinned,
float uv_a[2],
eUVEndPointPrecedence * prec_a,
float uv_b[2],
eUVEndPointPrecedence * prec_b )
static

Helper to find two endpoints (a and b) which have higher precedence, and are far apart. Note that is only a heuristic and won't always find the best two endpoints.

Definition at line 509 of file uvedit_ops.cc.

References copy_v2_v2(), len_squared_v2v2(), and uvedit_line_update_get_precedence().

Referenced by uvedit_uv_straighten_elements().

◆ uvedit_line_update_get_precedence()

eUVEndPointPrecedence uvedit_line_update_get_precedence ( const bool pinned)
static

Definition at line 496 of file uvedit_ops.cc.

References UVEP_PINNED, and UVEP_SELECTED.

Referenced by uvedit_line_update_endpoint().

◆ uvedit_live_unwrap_update()

◆ uvedit_median_multi()

bool uvedit_median_multi ( const Scene * scene,
const Span< Object * > objects_edit,
float co[2] )
static

Definition at line 275 of file uvedit_ops.cc.

References add_v2_v2(), ED_uvedit_foreach_uv_multi(), mul_v2_fl(), and zero_v2().

Referenced by ED_uvedit_center_multi().

◆ uvedit_uv_align_weld()

bool uvedit_uv_align_weld ( Scene * scene,
BMesh * bm,
const eUVWeldAlign tool,
const float cent[2] )
static

Definition at line 463 of file uvedit_ops.cc.

References bm, ED_uvedit_foreach_uv(), ELEM, UV_ALIGN_X, UV_ALIGN_Y, and UV_WELD.

Referenced by uv_align(), and uv_weld().

◆ uvedit_uv_islands_arrange()

bool uvedit_uv_islands_arrange ( const Scene * scene,
BMesh * bm,
const UVAlignIslandAxis axis,
const UVAlignIslandMode align,
const UVAlignIslandOrder order,
const float margin,
float2 & position )
static

◆ uvedit_uv_straighten()

bool uvedit_uv_straighten ( Scene * scene,
BMesh * bm,
eUVWeldAlign tool )
static

Group selected UVs into islands, then apply uvedit_uv_straighten_elements to each island.

Definition at line 617 of file uvedit_ops.cc.

References bm, BM_uv_element_map_create(), BM_uv_element_map_free(), BM_uv_map_offsets_get(), i, UvElementMap::island_indices, UvElementMap::island_total_uvs, UvElementMap::storage, UvElementMap::total_islands, BMUVOffsets::uv, and uvedit_uv_straighten_elements().

Referenced by uv_align().

◆ uvedit_uv_straighten_elements()

bool uvedit_uv_straighten_elements ( const UvElement * element,
const int len,
const BMUVOffsets & offsets,
const eUVWeldAlign tool )
static

Find two end extreme points to specify a line, then straighten len elements by moving UVs on the X-axis, Y-axis, or the closest point on the line segment.

Definition at line 544 of file uvedit_ops.cc.

References BM_ELEM_CD_GET_BOOL, BM_ELEM_CD_GET_FLOAT_P, closest_to_line_segment_v2(), element, i, l, len, BMUVOffsets::pin, update(), BMUVOffsets::uv, UV_STRAIGHTEN, UV_STRAIGHTEN_X, UV_STRAIGHTEN_Y, uvedit_line_update_endpoint(), and UVEP_INVALID.

Referenced by uvedit_uv_straighten().