Blender V4.3
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_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_material.h"
#include "BKE_mesh_mapping.hh"
#include "BKE_mesh_types.hh"
#include "BKE_node.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_resources.hh"
#include "UI_view2d.hh"
#include "uvedit_intern.hh"

Go to the source code of this file.

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)
 
Geometric Utilities
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 (BMesh *bm)
 
static bool ED_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 (SpaceImage *sima, Scene *scene, ViewLayer *view_layer, float r_center[2], char mode, bool *r_has_select)
 
Remove Doubles Operator
static int uv_remove_doubles_to_selected (bContext *C, wmOperator *op)
 
static int uv_remove_doubles_to_unselected (bContext *C, wmOperator *op)
 
static int uv_remove_doubles_to_selected_shared_vertex (bContext *C, wmOperator *op)
 
static int uv_remove_doubles_exec (bContext *C, wmOperator *op)
 
static void UV_OT_remove_doubles (wmOperatorType *ot)
 
Weld Near Operator
static int 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 int 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 int uv_snap_selection_exec (bContext *C, wmOperator *op)
 
static void UV_OT_snap_selected (wmOperatorType *ot)
 
Pin UVs Operator
static int uv_pin_exec (bContext *C, wmOperator *op)
 
static void UV_OT_pin (wmOperatorType *ot)
 
Reveal Operator
static int uv_reveal_exec (bContext *C, wmOperator *op)
 
static void UV_OT_reveal (wmOperatorType *ot)
 
Set 2D Cursor Operator
static int uv_set_2d_cursor_exec (bContext *C, wmOperator *op)
 
static int 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 int uv_seams_from_islands_exec (bContext *C, wmOperator *op)
 
static void UV_OT_seams_from_islands (wmOperatorType *ot)
 
Mark Seam Operator
static int uv_mark_seam_exec (bContext *C, wmOperator *op)
 
static int uv_mark_seam_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
static void UV_OT_mark_seam (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(l, bool_test)   (BM_ELEM_CD_GET_BOOL(l, offsets.select_vert) == bool_test)
 
#define UV_EDGE_SEL_TEST(l, bool_test)   (BM_ELEM_CD_GET_BOOL(l, offsets.select_edge) == bool_test)
 
static bool bm_face_is_all_uv_sel (BMFace *f, bool select_test, const BMUVOffsets offsets)
 
static int uv_hide_exec (bContext *C, wmOperator *op)
 
static void UV_OT_hide (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  eUVEndPointPrecedence { UVEP_INVALID = 0 , UVEP_SELECTED = (1 << 0) , UVEP_PINNED = (1 << 1) }
 
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 void uv_weld_align (bContext *C, eUVWeldAlign tool)
 
static int uv_align_exec (bContext *C, wmOperator *op)
 
static void UV_OT_align (wmOperatorType *ot)
 

Macro Definition Documentation

◆ UV_EDGE_SEL_TEST

#define UV_EDGE_SEL_TEST ( l,
bool_test )   (BM_ELEM_CD_GET_BOOL(l, offsets.select_edge) == bool_test)

Definition at line 1373 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 ( l,
bool_test )   (BM_ELEM_CD_GET_BOOL(l, offsets.select_vert) == bool_test)

Definition at line 1371 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 387 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 351 of file uvedit_ops.cc.

Function Documentation

◆ bm_face_is_all_uv_sel()

static bool bm_face_is_all_uv_sel ( BMFace * f,
bool select_test,
const BMUVOffsets offsets )
static

Definition at line 1376 of file uvedit_ops.cc.

References 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()

◆ ED_object_get_active_image()

◆ ED_operator_uvmap_mesh()

static int UNUSED_FUNCTION ED_operator_uvmap_mesh ( bContext * C)
static

◆ ED_operatormacros_uvedit()

◆ ED_operatortypes_uvedit()

◆ ED_uvedit_center_from_pivot_ex()

bool ED_uvedit_center_from_pivot_ex ( 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_median_multi()

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

Definition at line 271 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().

◆ 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 242 of file uvedit_ops.cc.

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

Referenced by ED_uvedit_center_multi().

◆ ED_uvedit_select_all()

void ED_uvedit_select_all ( BMesh * bm)

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

Definition at line 256 of file uvedit_ops.cc.

References bm, BM_ELEM_CD_SET_BOOL, BM_FACES_OF_MESH, BM_ITER_ELEM, BM_ITER_MESH, BM_LOOPS_OF_FACE, BM_uv_map_get_offsets(), l, BMUVOffsets::select_edge, and BMUVOffsets::select_vert.

Referenced by ED_uvedit_add_simple_uvs().

◆ ED_uvedit_test()

bool ED_uvedit_test ( Object * obedit)

◆ ENUM_OPERATORS()

ENUM_OPERATORS ( eUVEndPointPrecedence ,
UVEP_PINNED  )

◆ is_image_texture_node()

static bool is_image_texture_node ( bNode * node)
static

◆ uv_align_exec()

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

Definition at line 585 of file uvedit_ops.cc.

References OPERATOR_FINISHED, wmOperator::ptr, RNA_enum_get(), and uv_weld_align().

Referenced by UV_OT_align().

◆ uv_hide_exec()

◆ uv_mark_seam_exec()

◆ uv_mark_seam_invoke()

◆ UV_OT_align()

◆ UV_OT_cursor_set()

◆ UV_OT_hide()

◆ UV_OT_mark_seam()

◆ UV_OT_pin()

◆ UV_OT_remove_doubles()

◆ UV_OT_reveal()

◆ UV_OT_seams_from_islands()

◆ UV_OT_snap_cursor()

◆ UV_OT_snap_selected()

◆ UV_OT_weld()

◆ 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()

static void uv_snap_cursor_to_origin ( float uvco[2])
static

Definition at line 1022 of file uvedit_ops.cc.

Referenced by uv_snap_cursor_exec().

◆ uv_snap_cursor_to_pixels()

static void uv_snap_cursor_to_pixels ( SpaceImage * sima)
static

Definition at line 1007 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()

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

Definition at line 1015 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()

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

Definition at line 1001 of file uvedit_ops.cc.

References w().

Referenced by uv_snap_cursor_to_pixels().

◆ uv_snap_uvs_offset()

static 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()

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

◆ uv_snap_uvs_to_pixels()

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

◆ uv_weld_align()

◆ uv_weld_exec()

static int uv_weld_exec ( bContext * C,
wmOperator *  )
static

Definition at line 975 of file uvedit_ops.cc.

References OPERATOR_FINISHED, UV_WELD, and uv_weld_align().

Referenced by UV_OT_weld().

◆ uvedit_line_update_endpoint()

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

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 407 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()

static eUVEndPointPrecedence uvedit_line_update_get_precedence ( const bool pinned)
static

Definition at line 394 of file uvedit_ops.cc.

References UVEP_PINNED, and UVEP_SELECTED.

Referenced by uvedit_line_update_endpoint().

◆ uvedit_live_unwrap_update()

◆ uvedit_uv_align_weld()

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

Definition at line 361 of file uvedit_ops.cc.

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

Referenced by uv_weld_align().

◆ uvedit_uv_straighten()

static 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 515 of file uvedit_ops.cc.

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

Referenced by uv_weld_align().

◆ uvedit_uv_straighten_elements()

static 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 442 of file uvedit_ops.cc.

References BM_ELEM_CD_GET_BOOL, BM_ELEM_CD_GET_FLOAT_P, closest_to_line_segment_v2(), 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().