Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions
uvedit_smart_stitch.c File Reference
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_windowmanager_types.h"
#include "BLI_ghash.h"
#include "BLI_math.h"
#include "BLI_math_vector.h"
#include "BLI_string.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_mesh_mapping.h"
#include "BKE_report.h"
#include "DEG_depsgraph.h"
#include "UI_interface.h"
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_uvedit.h"
#include "GPU_batch.h"
#include "GPU_state.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_prototypes.h"
#include "WM_api.h"
#include "WM_types.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "uvedit_intern.h"

Go to the source code of this file.

Classes

struct  StitchPreviewer
 
struct  IslandStitchData
 
struct  UVVertAverage
 
struct  UvEdge
 
struct  StitchState
 
struct  StitchStateContainer
 
struct  PreviewPosition
 
struct  UvElementID
 
struct  StitchStateInit
 

Macros

#define STITCH_SELECTED   1
 
#define STITCH_STITCHABLE   2
 
#define STITCH_PROCESSED   4
 
#define STITCH_BOUNDARY   8
 
#define STITCH_STITCHABLE_CANDIDATE   16
 
#define STITCH_NO_PREVIEW   -1
 

Typedefs

typedef struct StitchPreviewer StitchPreviewer
 
typedef struct IslandStitchData IslandStitchData
 
typedef struct UVVertAverage UVVertAverage
 
typedef struct UvEdge UvEdge
 
typedef struct StitchState StitchState
 
typedef struct StitchStateContainer StitchStateContainer
 
typedef struct PreviewPosition PreviewPosition
 
typedef struct UvElementID UvElementID
 
typedef struct StitchStateInit StitchStateInit
 

Enumerations

enum  StitchModes { STITCH_VERT , STITCH_EDGE }
 

Functions

static StitchPreviewer * stitch_preview_init (void)
 
static void stitch_preview_delete (StitchPreviewer *stitch_preview)
 
static void stitch_update_header (StitchStateContainer *ssc, bContext *C)
 
static int getNumOfIslandUvs (UvElementMap *elementMap, int island)
 
static void stitch_uv_rotate (const float mat[2][2], const float medianPoint[2], float uv[2], float aspect)
 
static bool stitch_check_uvs_stitchable (UvElement *element, UvElement *element_iter, StitchStateContainer *ssc, StitchState *state)
 
static bool stitch_check_edges_stitchable (UvEdge *edge, UvEdge *edge_iter, StitchStateContainer *ssc, StitchState *state)
 
static bool stitch_check_uvs_state_stitchable (UvElement *element, UvElement *element_iter, StitchStateContainer *ssc, StitchState *state)
 
static bool stitch_check_edges_state_stitchable (UvEdge *edge, UvEdge *edge_iter, StitchStateContainer *ssc, StitchState *state)
 
static void stitch_calculate_island_snapping (StitchState *state, PreviewPosition *preview_position, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final)
 
static void stitch_island_calculate_edge_rotation (UvEdge *edge, StitchStateContainer *ssc, StitchState *state, UVVertAverage *uv_average, const uint *uvfinal_map, IslandStitchData *island_stitch_data)
 
static void stitch_island_calculate_vert_rotation (UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
 
static void state_delete (StitchState *state)
 
static void state_delete_all (StitchStateContainer *ssc)
 
static void stitch_uv_edge_generate_linked_edges (GHash *edge_hash, StitchState *state)
 
static void determine_uv_stitchability (UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
 
static void determine_uv_edge_stitchability (UvEdge *edge, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data)
 
static void stitch_set_face_preview_buffer_position (BMFace *efa, StitchPreviewer *preview, PreviewPosition *preview_position)
 
static void stitch_setup_face_preview_for_uv_group (UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
 
static void stitch_validate_uv_stitchability (UvElement *element, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
 
static void stitch_validate_edge_stitchability (UvEdge *edge, StitchStateContainer *ssc, StitchState *state, IslandStitchData *island_stitch_data, PreviewPosition *preview_position)
 
static void stitch_propagate_uv_final_position (Scene *scene, UvElement *element, int index, PreviewPosition *preview_position, UVVertAverage *final_position, StitchStateContainer *ssc, StitchState *state, const bool final)
 
static int stitch_process_data (StitchStateContainer *ssc, StitchState *state, Scene *scene, int final)
 
static int stitch_process_data_all (StitchStateContainer *ssc, Scene *scene, int final)
 
static uint uv_edge_hash (const void *key)
 
static bool uv_edge_compare (const void *a, const void *b)
 
static void stitch_select_edge (UvEdge *edge, StitchState *state, int always_select)
 
static void stitch_select_uv (UvElement *element, StitchState *state, int always_select)
 
static void stitch_set_selection_mode (StitchState *state, const char from_stitch_mode)
 
static void stitch_switch_selection_mode_all (StitchStateContainer *ssc)
 
static void stitch_calculate_edge_normal (BMEditMesh *em, UvEdge *edge, float *normal, float aspect)
 
static void stitch_draw_vbo (GPUVertBuf *vbo, GPUPrimType prim_type, const float col[4])
 
static void stitch_draw (const bContext *UNUSED(C), ARegion *UNUSED(region), void *arg)
 
static UvEdge * uv_edge_get (BMLoop *l, StitchState *state)
 
static StitchState * stitch_init (bContext *C, wmOperator *op, StitchStateContainer *ssc, Object *obedit, StitchStateInit *state_init)
 
static bool goto_next_island (StitchStateContainer *ssc)
 
static int stitch_init_all (bContext *C, wmOperator *op)
 
static int stitch_invoke (bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 
static void stitch_exit (bContext *C, wmOperator *op, int finished)
 
static void stitch_cancel (bContext *C, wmOperator *op)
 
static int stitch_exec (bContext *C, wmOperator *op)
 
static StitchState * stitch_select (bContext *C, Scene *scene, const wmEvent *event, StitchStateContainer *ssc)
 
static int stitch_modal (bContext *C, wmOperator *op, const wmEvent *event)
 
void UV_OT_stitch (wmOperatorType *ot)
 

Macro Definition Documentation

◆ STITCH_BOUNDARY

#define STITCH_BOUNDARY   8

Definition at line 206 of file uvedit_smart_stitch.c.

◆ STITCH_NO_PREVIEW

#define STITCH_NO_PREVIEW   -1

Definition at line 209 of file uvedit_smart_stitch.c.

◆ STITCH_PROCESSED

#define STITCH_PROCESSED   4

Definition at line 205 of file uvedit_smart_stitch.c.

◆ STITCH_SELECTED

#define STITCH_SELECTED   1

Definition at line 203 of file uvedit_smart_stitch.c.

◆ STITCH_STITCHABLE

#define STITCH_STITCHABLE   2

Definition at line 204 of file uvedit_smart_stitch.c.

◆ STITCH_STITCHABLE_CANDIDATE

#define STITCH_STITCHABLE_CANDIDATE   16

Definition at line 207 of file uvedit_smart_stitch.c.

Typedef Documentation

◆ IslandStitchData

This is a straightforward implementation, count the UVs in the island that will move and take the mean displacement/rotation and apply it to all elements of the island except from the stitchable.

◆ PreviewPosition

◆ StitchPreviewer

◆ StitchState

typedef struct StitchState StitchState

◆ StitchStateContainer

◆ StitchStateInit

StitchState initialization.

◆ UvEdge

typedef struct UvEdge UvEdge

◆ UvElementID

typedef struct UvElementID UvElementID

UvElement identification.

◆ UVVertAverage

typedef struct UVVertAverage UVVertAverage

Enumeration Type Documentation

◆ StitchModes

Enumerator
STITCH_VERT 
STITCH_EDGE 

Definition at line 211 of file uvedit_smart_stitch.c.

Function Documentation

◆ determine_uv_edge_stitchability()

static void determine_uv_edge_stitchability ( UvEdge *  edge,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data 
)
static

◆ determine_uv_stitchability()

static void determine_uv_stitchability ( UvElement *  element,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data 
)
static

◆ getNumOfIslandUvs()

static int getNumOfIslandUvs ( UvElementMap *  elementMap,
int  island 
)
static

◆ goto_next_island()

static bool goto_next_island ( StitchStateContainer *  ssc)
static

◆ state_delete()

static void state_delete ( StitchState *  state)
static

◆ state_delete_all()

static void state_delete_all ( StitchStateContainer *  ssc)
static

◆ stitch_calculate_edge_normal()

static void stitch_calculate_edge_normal ( BMEditMesh *  em,
UvEdge *  edge,
float *  normal,
float  aspect 
)
static

◆ stitch_calculate_island_snapping()

static void stitch_calculate_island_snapping ( StitchState *  state,
PreviewPosition *  preview_position,
StitchPreviewer *  preview,
IslandStitchData *  island_stitch_data,
int  final 
)
static

◆ stitch_cancel()

static void stitch_cancel ( bContext *  C,
wmOperator *  op 
)
static

Definition at line 2500 of file uvedit_smart_stitch.c.

References C, and stitch_exit().

Referenced by stitch_exec(), stitch_modal(), and UV_OT_stitch().

◆ stitch_check_edges_state_stitchable()

static bool stitch_check_edges_state_stitchable ( UvEdge *  edge,
UvEdge *  edge_iter,
StitchStateContainer *  ssc,
StitchState *  state 
)
static

◆ stitch_check_edges_stitchable()

static bool stitch_check_edges_stitchable ( UvEdge *  edge,
UvEdge *  edge_iter,
StitchStateContainer *  ssc,
StitchState *  state 
)
static

◆ stitch_check_uvs_state_stitchable()

static bool stitch_check_uvs_state_stitchable ( UvElement *  element,
UvElement *  element_iter,
StitchStateContainer *  ssc,
StitchState *  state 
)
static

◆ stitch_check_uvs_stitchable()

static bool stitch_check_uvs_stitchable ( UvElement *  element,
UvElement *  element_iter,
StitchStateContainer *  ssc,
StitchState *  state 
)
static

◆ stitch_draw()

static void stitch_draw ( const bContext *  UNUSEDC,
ARegion *  UNUSEDregion,
void *  arg 
)
static

◆ stitch_draw_vbo()

static void stitch_draw_vbo ( GPUVertBuf *  vbo,
GPUPrimType  prim_type,
const float  col[4] 
)
static

◆ stitch_exec()

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

◆ stitch_exit()

static void stitch_exit ( bContext *  C,
wmOperator *  op,
int  finished 
)
static

◆ stitch_init()

static StitchState* stitch_init ( bContext *  C,
wmOperator *  op,
StitchStateContainer *  ssc,
Object *  obedit,
StitchStateInit *  state_init 
)
static

Definition at line 1870 of file uvedit_smart_stitch.c.

References add_v2_v2(), BKE_editmesh_from_object(), BLI_ghash_free(), BLI_ghash_insert(), BLI_ghash_len(), BLI_ghash_lookup(), BLI_ghash_new(), BLI_ghashIterator_getKey(), BMEditMesh::bm, BM_elem_flag_test, BM_ELEM_HIDDEN, BM_ELEM_SELECT, BM_FACE, BM_face_at_index(), BM_FACE_FIRST_LOOP, BM_FACES_OF_MESH, BM_iter_at_index(), BM_ITER_ELEM, BM_ITER_ELEM_INDEX, BM_ITER_MESH, BM_LOOPS_OF_FACE, BM_mesh_elem_table_ensure(), BM_uv_element_get(), BM_uv_element_map_create(), C, CD_MLOOPUV, counter, CTX_data_scene(), CustomData_get_offset(), ED_uvedit_get_aspect(), element, UvEdge::element, UvElementID::elementIndex, UvElementID::faceIndex, UvEdge::first, UvEdge::flag, GHASH_ITER, l, BMesh::ldata, BMFace::len, map, MEM_callocN, MEM_freeN, MEM_mallocN, StitchStateContainer::mode, BMLoop::next, UvEdge::next, normal, normalize_v2(), NULL, wmOperator::ptr, RNA_enum_get(), SCE_SELECT_VERTEX, scene, ToolSettings::selectmode, state, state_delete(), STITCH_BOUNDARY, stitch_calculate_edge_normal(), stitch_process_data(), stitch_select_edge(), stitch_select_uv(), stitch_set_selection_mode(), stitch_uv_edge_generate_linked_edges(), STITCH_VERT, StitchStateInit::to_select, Scene::toolsettings, BMesh::totvert, UvEdge::uv1, UvEdge::uv2, uv_edge_compare(), uv_edge_get(), uv_edge_hash(), ToolSettings::uv_flag, StitchStateInit::uv_selected_count, UV_SYNC_SELECTION, uvedit_edge_select_test(), and uvedit_uv_select_test().

Referenced by stitch_init_all().

◆ stitch_init_all()

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

Definition at line 2225 of file uvedit_smart_stitch.c.

References StitchStateContainer::active_object_index, BKE_report(), BKE_reportf(), BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs, BLI_assert, C, StitchStateContainer::clear_seams, CTX_data_scene(), CTX_data_view_layer(), CTX_wm_region(), CTX_wm_view3d(), wmOperator::customdata, StitchStateContainer::draw_handle, ED_region_draw_cb_activate(), UvElementID::elementIndex, UvElementID::faceIndex, goto_next_island(), StitchStateContainer::limit_dist, MEM_callocN, MEM_freeN, MEM_mallocN, MEM_SAFE_FREE, StitchStateContainer::midpoints, StitchStateContainer::mode, NULL, StitchStateContainer::objects, StitchStateContainer::objects_len, wmOperator::ptr, REGION_DRAW_POST_VIEW, wmOperator::reports, RNA_BEGIN, RNA_boolean_get(), RNA_collection_clear(), RNA_END, RNA_enum_get(), RNA_float_get(), RNA_int_get(), RNA_int_get_array(), RNA_MAX_ARRAY_LENGTH, RNA_struct_property_is_set(), RPT_ERROR, SCE_SELECT_VERTEX, scene, ToolSettings::selectmode, StitchStateContainer::snap_islands, state, state_delete_all(), StitchStateContainer::states, StitchStateContainer::static_island, stitch_draw(), STITCH_EDGE, stitch_init(), stitch_process_data(), stitch_update_header(), STITCH_VERT, StitchStateInit::to_select, Scene::toolsettings, ARegion::type, StitchStateContainer::use_limit, ToolSettings::uv_flag, UV_SELECT_VERTEX, StitchStateInit::uv_selected_count, ToolSettings::uv_selectmode, and UV_SYNC_SELECTION.

Referenced by stitch_exec(), and stitch_invoke().

◆ stitch_invoke()

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

◆ stitch_island_calculate_edge_rotation()

static void stitch_island_calculate_edge_rotation ( UvEdge *  edge,
StitchStateContainer *  ssc,
StitchState *  state,
UVVertAverage *  uv_average,
const uint *  uvfinal_map,
IslandStitchData *  island_stitch_data 
)
static

◆ stitch_island_calculate_vert_rotation()

static void stitch_island_calculate_vert_rotation ( UvElement *  element,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data 
)
static

◆ stitch_modal()

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

◆ stitch_preview_delete()

static void stitch_preview_delete ( StitchPreviewer *  stitch_preview)
static

◆ stitch_preview_init()

static StitchPreviewer* stitch_preview_init ( void  )
static

◆ stitch_process_data()

static int stitch_process_data ( StitchStateContainer *  ssc,
StitchState *  state,
Scene *  scene,
int  final 
)
static

Definition at line 985 of file uvedit_smart_stitch.c.

References StitchStateContainer::active_object_index, add_v2_v2(), BLI_assert, bm, BM_elem_flag_disable, BM_elem_index_get, BM_ELEM_SEAM, BM_FACE, BM_FACE_FIRST_LOOP, BM_FACES_OF_MESH, BM_ITER_ELEM_INDEX, BM_ITER_MESH, BM_LOOPS_OF_FACE, BM_mesh_elem_index_ensure(), BM_uv_element_get(), BM_VERT, CD_MLOOPUV, StitchStateContainer::clear_seams, copy_v2_v2(), UVVertAverage::count, CustomData_bmesh_get(), BMHeader::data, PreviewPosition::data_position, determine_uv_edge_stitchability(), determine_uv_stitchability(), element, UvEdge::element, getNumOfIslandUvs(), BMLoop::head, if(), UvElement::island, UvElement::l, l, BMesh::ldata, BMFace::len, IslandStitchData::medianPoint, MEM_callocN, MEM_freeN, MEM_mallocN, StitchStateContainer::midpoints, StitchStateContainer::mode, UvElement::next, BMLoop::next, UvEdge::next, NULL, IslandStitchData::numOfElements, PreviewPosition::polycount_position, usdtokens::preview(), scene, UvElement::separate, StitchStateContainer::snap_islands, state, StitchStateContainer::states, StitchStateContainer::static_island, STITCH_BOUNDARY, stitch_calculate_island_snapping(), stitch_check_edges_state_stitchable(), stitch_check_uvs_state_stitchable(), STITCH_EDGE, stitch_island_calculate_edge_rotation(), stitch_island_calculate_vert_rotation(), STITCH_NO_PREVIEW, stitch_preview_delete(), stitch_preview_init(), stitch_propagate_uv_final_position(), STITCH_SELECTED, stitch_set_face_preview_buffer_position(), STITCH_STITCHABLE, STITCH_STITCHABLE_CANDIDATE, stitch_validate_edge_stitchability(), stitch_validate_uv_stitchability(), STITCH_VERT, IslandStitchData::stitchableCandidate, BMesh::totface, IslandStitchData::translation, IslandStitchData::use_edge_rotation, UVVertAverage::uv, MLoopUV::uv, UvEdge::uv1, UvEdge::uv2, and BMLoop::v.

Referenced by stitch_init(), stitch_init_all(), stitch_modal(), and stitch_process_data_all().

◆ stitch_process_data_all()

static int stitch_process_data_all ( StitchStateContainer *  ssc,
Scene *  scene,
int  final 
)
static

◆ stitch_propagate_uv_final_position()

static void stitch_propagate_uv_final_position ( Scene *  scene,
UvElement *  element,
int  index,
PreviewPosition *  preview_position,
UVVertAverage *  final_position,
StitchStateContainer *  ssc,
StitchState *  state,
const bool  final 
)
static

◆ stitch_select()

static StitchState* stitch_select ( bContext *  C,
Scene *  scene,
const wmEvent *  event,
StitchStateContainer *  ssc 
)
static

◆ stitch_select_edge()

static void stitch_select_edge ( UvEdge *  edge,
StitchState *  state,
int  always_select 
)
static

◆ stitch_select_uv()

static void stitch_select_uv ( UvElement *  element,
StitchState *  state,
int  always_select 
)
static

◆ stitch_set_face_preview_buffer_position()

static void stitch_set_face_preview_buffer_position ( BMFace *  efa,
StitchPreviewer *  preview,
PreviewPosition *  preview_position 
)
static

◆ stitch_set_selection_mode()

static void stitch_set_selection_mode ( StitchState *  state,
const char  from_stitch_mode 
)
static

◆ stitch_setup_face_preview_for_uv_group()

static void stitch_setup_face_preview_for_uv_group ( UvElement *  element,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data,
PreviewPosition *  preview_position 
)
static

◆ stitch_switch_selection_mode_all()

static void stitch_switch_selection_mode_all ( StitchStateContainer *  ssc)
static

◆ stitch_update_header()

static void stitch_update_header ( StitchStateContainer *  ssc,
bContext *  C 
)
static

◆ stitch_uv_edge_generate_linked_edges()

static void stitch_uv_edge_generate_linked_edges ( GHash *  edge_hash,
StitchState *  state 
)
static

◆ stitch_uv_rotate()

static void stitch_uv_rotate ( const float  mat[2][2],
const float  medianPoint[2],
float  uv[2],
float  aspect 
)
static

Definition at line 300 of file uvedit_smart_stitch.c.

References add_v2_v2v2(), mul_v2_m2v2(), and sub_v2_v2().

Referenced by stitch_calculate_island_snapping().

◆ stitch_validate_edge_stitchability()

static void stitch_validate_edge_stitchability ( UvEdge *  edge,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data,
PreviewPosition *  preview_position 
)
static

◆ stitch_validate_uv_stitchability()

static void stitch_validate_uv_stitchability ( UvElement *  element,
StitchStateContainer *  ssc,
StitchState *  state,
IslandStitchData *  island_stitch_data,
PreviewPosition *  preview_position 
)
static

◆ uv_edge_compare()

static bool uv_edge_compare ( const void *  a,
const void *  b 
)
static

Definition at line 1550 of file uvedit_smart_stitch.c.

References Freestyle::a, usdtokens::b(), UvEdge::uv1, and UvEdge::uv2.

Referenced by stitch_init().

◆ uv_edge_get()

static UvEdge* uv_edge_get ( BMLoop *  l,
StitchState *  state 
)
static

◆ uv_edge_hash()

static uint uv_edge_hash ( const void *  key)
static

Definition at line 1544 of file uvedit_smart_stitch.c.

References BLI_ghashutil_uinthash().

Referenced by stitch_init().

◆ UV_OT_stitch()

void UV_OT_stitch ( wmOperatorType *  ot)