Blender  V3.3
uvedit_ops.c File Reference
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "BLI_array.h"
#include "BLI_kdtree.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mesh_mapping.h"
#include "BKE_node.h"
#include "DEG_depsgraph.h"
#include "ED_image.h"
#include "ED_mesh.h"
#include "ED_node.h"
#include "ED_screen.h"
#include "ED_uvedit.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_message.h"
#include "WM_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "uvedit_intern.h"

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, bNode **r_node, 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 uv_poly_copy_aspect (float uv_orig[][2], float uv[][2], float aspx, float aspy, int len)
 
bool ED_uvedit_minmax_multi (const Scene *scene, Object **objects_edit, uint objects_len, float r_min[2], float r_max[2])
 
bool ED_uvedit_minmax (const Scene *scene, Object *obedit, float r_min[2], float r_max[2])
 
void ED_uvedit_select_all (BMesh *bm)
 
static bool ED_uvedit_median_multi (const Scene *scene, Object **objects_edit, uint objects_len, float co[2])
 
bool ED_uvedit_center_multi (const Scene *scene, Object **objects_edit, uint objects_len, 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)
 
bool ED_uvedit_center_from_pivot (SpaceImage *sima, Scene *scene, ViewLayer *view_layer, float r_center[2], char mode)
 
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_exec (bContext *C, wmOperator *op)
 
static void UV_OT_remove_doubles (wmOperatorType *ot)
 
Weld Near Operator
static int uv_weld_exec (bContext *C, wmOperator *UNUSED(op))
 
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, Object **objects_edit, uint objects_len, 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 UV's 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 *UNUSED(event))
 
static void UV_OT_mark_seam (wmOperatorType *ot)
 
Operator Registration & Keymap
void ED_operatortypes_uvedit (void)
 
void ED_operatormacros_uvedit (void)
 
void ED_keymap_uvedit (wmKeyConfig *keyconf)
 

Hide Operator

#define UV_VERT_SEL_TEST(luv, bool_test)    ((((luv)->flag & MLOOPUV_VERTSEL) == MLOOPUV_VERTSEL) == bool_test)
 
#define UV_EDGE_SEL_TEST(luv, bool_test)    ((((luv)->flag & MLOOPUV_EDGESEL) == MLOOPUV_EDGESEL) == bool_test)
 
static bool bm_face_is_all_uv_sel (BMFace *f, bool select_test, const int cd_loop_uv_offset)
 
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) }
 
typedef enum eUVWeldAlign eUVWeldAlign
 
typedef enum eUVEndPointPrecedence eUVEndPointPrecedence
 
static bool uvedit_uv_align_weld (Scene *scene, BMesh *bm, const eUVWeldAlign tool, const float cent[2])
 
static eUVEndPointPrecedence uvedit_line_update_get_precedence (const MLoopUV *luv)
 
static bool uvedit_line_update_endpoint (const MLoopUV *luv, 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 int cd_loop_uv_offset, 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 (   luv,
  bool_test 
)     ((((luv)->flag & MLOOPUV_EDGESEL) == MLOOPUV_EDGESEL) == bool_test)

Definition at line 1435 of file uvedit_ops.c.

◆ UV_VERT_SEL_TEST

#define UV_VERT_SEL_TEST (   luv,
  bool_test 
)     ((((luv)->flag & MLOOPUV_VERTSEL) == MLOOPUV_VERTSEL) == bool_test)

Definition at line 1432 of file uvedit_ops.c.

Typedef Documentation

◆ eUVEndPointPrecedence

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

◆ eUVWeldAlign

typedef enum eUVWeldAlign eUVWeldAlign

Enumeration Type Documentation

◆ eUVEndPointPrecedence

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

Enumerator
UVEP_INVALID 
UVEP_SELECTED 
UVEP_PINNED 

Definition at line 415 of file uvedit_ops.c.

◆ eUVWeldAlign

Enumerator
UV_STRAIGHTEN 
UV_STRAIGHTEN_X 
UV_STRAIGHTEN_Y 
UV_ALIGN_AUTO 
UV_ALIGN_X 
UV_ALIGN_Y 
UV_WELD 

Definition at line 365 of file uvedit_ops.c.

Function Documentation

◆ bm_face_is_all_uv_sel()

static bool bm_face_is_all_uv_sel ( BMFace f,
bool  select_test,
const int  cd_loop_uv_offset 
)
static

Definition at line 1439 of file uvedit_ops.c.

References BM_ELEM_CD_GET_VOID_P, 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)

Definition at line 2123 of file uvedit_ops.c.

References ED_operator_uvedit(), wmKeyMap::poll, and WM_keymap_ensure().

Referenced by ED_spacetypes_keymap().

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

bool ED_object_get_active_image ( Object ob,
int  mat_nr,
Image **  r_ima,
ImageUser **  r_iuser,
bNode **  r_node,
bNodeTree **  r_ntree 
)

◆ ED_operator_uvmap_mesh()

static int UNUSED_FUNCTION() ED_operator_uvmap_mesh ( bContext C)
static

◆ ED_operatormacros_uvedit()

void ED_operatormacros_uvedit ( void  )

◆ ED_operatortypes_uvedit()

void ED_operatortypes_uvedit ( void  )

◆ ED_uvedit_center_from_pivot()

bool ED_uvedit_center_from_pivot ( SpaceImage sima,
Scene scene,
ViewLayer view_layer,
float  r_center[2],
char  mode 
)

Definition at line 353 of file uvedit_ops.c.

References ED_uvedit_center_from_pivot_ex(), NULL, and scene.

◆ 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,
Object **  objects_edit,
uint  objects_len,
float  cent[2],
char  mode 
)

◆ ED_uvedit_median_multi()

static bool ED_uvedit_median_multi ( const Scene scene,
Object **  objects_edit,
uint  objects_len,
float  co[2] 
)
static

◆ ED_uvedit_minmax()

bool ED_uvedit_minmax ( const Scene scene,
Object obedit,
float  r_min[2],
float  r_max[2] 
)

Definition at line 235 of file uvedit_ops.c.

References ED_uvedit_minmax_multi(), and scene.

◆ ED_uvedit_minmax_multi()

bool ED_uvedit_minmax_multi ( const Scene scene,
Object **  objects_edit,
uint  objects_len,
float  r_min[2],
float  r_max[2] 
)

◆ ED_uvedit_select_all()

void ED_uvedit_select_all ( struct BMesh bm)

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

Definition at line 240 of file uvedit_ops.c.

References bm, BM_ELEM_CD_GET_VOID_P, BM_FACES_OF_MESH, BM_ITER_ELEM, BM_ITER_MESH, BM_LOOPS_OF_FACE, CD_MLOOPUV, CustomData_get_offset(), MLoopUV::flag, l, BMesh::ldata, MLOOPUV_EDGESEL, and MLOOPUV_VERTSEL.

Referenced by ED_uvedit_add_simple_uvs().

◆ ED_uvedit_test()

bool ED_uvedit_test ( Object obedit)

◆ 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 642 of file uvedit_ops.c.

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

Referenced by UV_OT_align().

◆ uv_hide_exec()

static int uv_hide_exec ( bContext C,
wmOperator op 
)
static

◆ uv_mark_seam_exec()

static int uv_mark_seam_exec ( bContext C,
wmOperator op 
)
static

◆ uv_mark_seam_invoke()

static int uv_mark_seam_invoke ( bContext C,
wmOperator op,
const wmEvent UNUSEDevent 
)
static

◆ UV_OT_align()

static void UV_OT_align ( wmOperatorType ot)
static

◆ UV_OT_cursor_set()

static void UV_OT_cursor_set ( wmOperatorType ot)
static

◆ UV_OT_hide()

static void UV_OT_hide ( wmOperatorType ot)
static

◆ UV_OT_mark_seam()

static void UV_OT_mark_seam ( wmOperatorType ot)
static

◆ UV_OT_pin()

static void UV_OT_pin ( wmOperatorType ot)
static

◆ UV_OT_remove_doubles()

static void UV_OT_remove_doubles ( wmOperatorType ot)
static

◆ UV_OT_reveal()

static void UV_OT_reveal ( wmOperatorType ot)
static

◆ UV_OT_seams_from_islands()

static void UV_OT_seams_from_islands ( wmOperatorType ot)
static

◆ UV_OT_snap_cursor()

static void UV_OT_snap_cursor ( wmOperatorType ot)
static

◆ UV_OT_snap_selected()

static void UV_OT_snap_selected ( wmOperatorType ot)
static

◆ UV_OT_weld()

static void UV_OT_weld ( wmOperatorType ot)
static

◆ uv_pin_exec()

static int uv_pin_exec ( bContext C,
wmOperator op 
)
static

◆ uv_poly_copy_aspect()

void uv_poly_copy_aspect ( float  uv_orig[][2],
float  uv[][2],
float  aspx,
float  aspy,
int  len 
)

Definition at line 192 of file uvedit_ops.c.

References len.

◆ uv_remove_doubles_exec()

static int uv_remove_doubles_exec ( bContext C,
wmOperator op 
)
static

◆ uv_remove_doubles_to_selected()

static int uv_remove_doubles_to_selected ( bContext C,
wmOperator op 
)
static

◆ uv_remove_doubles_to_unselected()

static int uv_remove_doubles_to_unselected ( bContext C,
wmOperator op 
)
static

◆ uv_reveal_exec()

static int uv_reveal_exec ( bContext C,
wmOperator op 
)
static

◆ uv_seams_from_islands_exec()

static int uv_seams_from_islands_exec ( bContext C,
wmOperator op 
)
static

◆ uv_set_2d_cursor_exec()

static int uv_set_2d_cursor_exec ( bContext C,
wmOperator op 
)
static

◆ uv_set_2d_cursor_invoke()

static int uv_set_2d_cursor_invoke ( bContext C,
wmOperator op,
const wmEvent event 
)
static

◆ uv_snap_cursor_exec()

static int uv_snap_cursor_exec ( bContext C,
wmOperator op 
)
static

◆ uv_snap_cursor_to_origin()

static void uv_snap_cursor_to_origin ( float  uvco[2])
static

Definition at line 1039 of file uvedit_ops.c.

Referenced by uv_snap_cursor_exec().

◆ uv_snap_cursor_to_pixels()

static void uv_snap_cursor_to_pixels ( SpaceImage sima)
static

◆ uv_snap_cursor_to_selection()

static bool uv_snap_cursor_to_selection ( Scene scene,
Object **  objects_edit,
uint  objects_len,
SpaceImage sima 
)
static

Definition at line 1031 of file uvedit_ops.c.

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

Referenced by uv_snap_cursor_exec().

◆ uv_snap_selection_exec()

static int uv_snap_selection_exec ( bContext C,
wmOperator op 
)
static

◆ uv_snap_to_pixel()

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

Definition at line 1017 of file uvedit_ops.c.

References w().

Referenced by uv_snap_cursor_to_pixels(), and uv_snap_uvs_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()

static bool uv_snap_uvs_to_adjacent_unselected ( Scene scene,
Object obedit 
)
static

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

static void uv_weld_align ( bContext C,
eUVWeldAlign  tool 
)
static

◆ uv_weld_exec()

static int uv_weld_exec ( bContext C,
wmOperator UNUSEDop 
)
static

Definition at line 991 of file uvedit_ops.c.

References C, OPERATOR_FINISHED, UV_WELD, and uv_weld_align().

Referenced by UV_OT_weld().

◆ uvedit_line_update_endpoint()

static bool uvedit_line_update_endpoint ( const MLoopUV luv,
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 434 of file uvedit_ops.c.

References copy_v2_v2(), len_squared_v2v2(), MLoopUV::uv, 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 MLoopUV luv)
static

Definition at line 421 of file uvedit_ops.c.

References MLoopUV::flag, MLOOPUV_PINNED, UVEP_PINNED, and UVEP_SELECTED.

Referenced by uvedit_line_update_endpoint().

◆ uvedit_live_unwrap_update()

void uvedit_live_unwrap_update ( SpaceImage sima,
Scene scene,
Object obedit 
)

◆ uvedit_uv_align_weld()

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

◆ 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 540 of file uvedit_ops.c.

References bm, BM_uv_element_map_create(), BM_uv_element_map_free(), UvElementMap::buf, CD_MLOOPUV, CustomData_get_offset(), UvElementMap::islandIndices, BMesh::ldata, NULL, scene, UvElementMap::totalIslands, UvElementMap::totalUVs, 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 int  cd_loop_uv_offset,
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 468 of file uvedit_ops.c.

References Freestyle::a, BM_ELEM_CD_GET_VOID_P, closest_to_line_segment_v2(), element, l, len, update(), MLoopUV::uv, UV_STRAIGHTEN, UV_STRAIGHTEN_X, UV_STRAIGHTEN_Y, uvedit_line_update_endpoint(), and UVEP_INVALID.

Referenced by uvedit_uv_straighten().