46#define USE_NET_ISLAND_CONNECT
145 int (*test_fn)(
BMFace *,
void *);
146 bool use_separate_all =
false;
147 bool use_separate_cut =
false;
156 const bool exact =
false;
172 switch (separate_mode) {
174 use_separate_all =
true;
177 if (use_self ==
false) {
178 use_separate_cut =
true;
183 use_separate_all =
true;
195 for (
Object *obedit : objects) {
203 int nshapes = use_self ? 1 : 2;
205 bm, em->
looptris, test_fn,
nullptr, nshapes, use_self, use_separate_all,
false,
true);
222 if (use_separate_cut) {
235 if (isect_len == objects.
size()) {
252 row = &layout.
row(
false);
256 row = &layout.
row(
false);
268 {
ISECT_SEL,
"SELECT", 0,
"Self Intersect",
"Self intersect selected faces"},
272 "Selected/Unselected",
273 "Intersect selected with unselected faces"},
274 {0,
nullptr, 0,
nullptr,
nullptr},
283 "Cut into geometry keeping each side separate (Selected/Unselected only)"},
285 {0,
nullptr, 0,
nullptr,
nullptr},
293 "Simple solver with good performance, without support for overlapping geometry"},
298 "Slower solver with the best results for coplanar faces"},
299 {0,
nullptr, 0,
nullptr,
nullptr},
303 ot->
name =
"Intersect (Knife)";
304 ot->
description =
"Cut an intersection into faces";
305 ot->
idname =
"MESH_OT_intersect";
317 ot->
srna,
"threshold", 0.000001f, 0.0, 0.01,
"Merge Threshold",
"", 0.0, 0.001);
320 isect_intersect_solver_items,
323 "Which Intersect solver to use");
349 const bool use_exact =
false;
352 int (*test_fn)(
BMFace *,
void *);
362 for (
Object *obedit : objects) {
371 bm, em->
looptris, test_fn,
nullptr, 2, use_self,
true,
false, boolean_operation);
395 if (isect_len == objects.
size()) {
431 {0,
nullptr, 0,
nullptr,
nullptr},
436 {
ISECT_SOLVER_EXACT,
"EXACT", 0,
"Exact",
"Exact solver, slower, handles more cases"},
437 {0,
nullptr, 0,
nullptr,
nullptr},
441 ot->
name =
"Intersect (Boolean)";
442 ot->
description =
"Cut solid geometry from selected to unselected";
443 ot->
idname =
"MESH_OT_intersect_boolean";
453 isect_boolean_operation_items,
456 "Which boolean operation to apply");
461 "Use with difference intersection to swap which side is kept");
463 ot->
srna,
"use_self",
false,
"Self Intersection",
"Do self-union or self-intersection");
465 ot->
srna,
"threshold", 0.000001f, 0.0, 0.01,
"Merge Threshold",
"", 0.0, 0.001);
468 isect_boolean_solver_items,
471 "Which Boolean solver to use");
516 }
while ((l_iter = l_iter->
next) != l_first);
530 edge_net_temp_buf->
append(e_next);
542 edge_net_temp_buf->
clear();
544 for (
BMFace *face : face_arr) {
560 if (l_iter->
f != f_ignore) {
565 }
while ((l_iter = l_iter->
radial_next) != e_radial->
l);
570#ifdef USE_NET_ISLAND_CONNECT
584 ls_base->list =
nullptr;
585 ls_base->list_len = 0;
590 ls->
next = ls_base->list;
593 ls_base->list_len += 1;
599 *(
static_cast<BMEdge **
>(
const_cast<void *
>(e_a_v))));
601 *(
static_cast<BMEdge **
>(
const_cast<void *
>(e_b_v))));
617 int edge_arr_len = 0;
620 edge_arr[edge_arr_len++] =
static_cast<BMEdge *
>(e_link->
link);
621 e_link = e_link->
next;
625 uint edge_arr_holes_len;
634 &edge_arr_holes_len))
636 edge_arr_len = edge_arr_holes_len;
637 edge_arr = edge_arr_holes;
643 for (
int i = e_link_len; i < edge_arr_len; i++) {
647 if (e_link_len != edge_arr_len) {
651 for (
int i = e_link_len; i < edge_arr_len; i++) {
659 "Doubled face detected at " AT ". Resulting mesh may be corrupt.");
692 const int ftable_len,
693 float r_v_pivot_co[3],
694 float *r_v_pivot_fac)
697 bool found_other_self =
false;
698 int found_other_face = 0;
706 if (f_b_index == f_a_index) {
708 found_other_self =
true;
710 else if (f_b_index != -1) {
716 BMFace *f_b = ftable[f_b_index];
726 BMEdge *e_split =
nullptr;
730 if ((found_other_self ==
false) || found_other_face) {
737 float v_pivot_co_test[3];
739 CLAMP(v_pivot_fac, 0.0f, 1.0f);
743 if ((dist_test_sq < dist_best_sq) || (e_split ==
nullptr)) {
753 else if (found_other_face) {
758 int other_face_shared = 0;
759 if (l_radial_iter != l_iter) {
764 }
while ((l_radial_iter = l_radial_iter->
radial_next) != l_iter);
766 if (other_face_shared != found_other_face) {
773 dist_best_sq = dist_test_sq;
775 *r_v_pivot_fac = v_pivot_fac;
778 }
while ((l_iter = l_iter->
next) != l_first);
808 for (
Object *obedit : objects) {
874 if (loop_stack_len == 0) {
877 else if (loop_stack_len == 1) {
898 if (dot_test < dot_best) {
932#ifdef USE_NET_ISLAND_CONNECT
946 EDBM_update(id_cast<Mesh *>(obedit->data), ¶ms);
948#ifdef USE_NET_ISLAND_CONNECT
988 for (
const auto &item : face_edge_map.
items()) {
996 for (
int j = 0; j < 2; j++) {
1001 float v_pivot_co[3];
1022 }
while ((e_link = e_link->
next));
1029 for (
const auto &item : face_edge_map.
items()) {
1034 bm, f, e_ls_base->list, e_ls_base->list_len, mem_arena_edgenet);
1048 EDBM_update(id_cast<Mesh *>(obedit->data), ¶ms);
1062 ot->
name =
"Weld Edges into Faces";
1063 ot->
description =
"Weld loose edges into faces (splitting them into new faces)";
1064 ot->
idname =
"MESH_OT_face_split_by_edges";
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)
#define BLI_SMALLSTACK_POP_EX(var_src, var_dst)
#define BLI_SMALLSTACK_IS_EMPTY(var)
#define BLI_SMALLSTACK_SWAP(var_a, var_b)
#define BLI_MEMARENA_STD_BUFSIZE
Object is a sort of wrapper for general info.
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
#define BM_elem_cb_check_hflag_enabled_simple(type, hflag_p)
#define BM_DISK_EDGE_NEXT(e, v)
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_elem_flag_disable(ele, hflag)
#define BM_elem_index_set(ele, index)
#define BM_elem_flag_test(ele, hflag)
#define BM_elem_flag_enable(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
ItemIterator items() const &
void append(const T &value)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static int bm_face_isect_pair(BMFace *f, void *)
void BKE_bmbvh_free(BMBVHTree *tree)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
float line_point_factor_v3(const float p[3], const float l1[3], const float l2[3])
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int RNA_enum_get(PointerRNA *ptr, const char *name)
void EDBM_selectmode_flush(BMesh *bm, short selectmode)
MemArena * BLI_memarena_new(size_t bufsize, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(2) ATTR_MALLOC
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
static void edbm_intersect_boolean_ui(bContext *, wmOperator *op)
static bool bm_vert_in_faces_radial(BMVert *v, BMEdge *e_radial, BMFace *f_ignore)
bool BLI_stack_is_empty(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct BMFace * BKE_bmbvh_find_face_closest(const BMBVHTree *tree, const float co[3], float dist_max)
void BLI_stack_free(BLI_Stack *stack) ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMLoop * l
static void bm_face_split_by_edges_island_connect(BMesh *bm, BMFace *f, LinkNode *e_link, const int e_link_len, MemArena *mem_arena_edgenet)
bool BM_mesh_boolean(BMesh *, Span< std::array< BMLoop *, 3 > > looptris, int(*test_fn)(BMFace *, void *), void *, const int, const bool, const bool, const bool, const int)
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
static void edbm_intersect_select(Mesh *mesh, bool do_select)
void MESH_OT_intersect(wmOperatorType *ot)
void EDBM_update(Mesh *mesh, const EDBMUpdate_Params *params)
void BLI_stack_pop(BLI_Stack *stack, void *dst) ATTR_NONNULL()
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BM_mesh_select_mode_flush(BMesh *bm)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ViewLayer * CTX_data_view_layer(const bContext *C)
BMBVHTree * BKE_bmbvh_new(struct BMesh *bm, Span< std::array< BMLoop *, 3 > > looptris, int flag, const float3 *cos_cage, bool cos_cage_free)
BMFace * BM_faces_join(BMesh *bm, BMFace **faces, int totface, const bool do_del, BMFace **r_double)
Join Connected Faces.
static void ghash_insert_face_edge_link(Map< BMFace *, LinkBase * > &gh, BMFace *f_key, BMEdge *e_val, MemArena *mem_arena)
bool ED_operator_editmesh(bContext *C)
float angle_signed_on_axis_v3v3v3_v3(const float v1[3], const float v2[3], const float v3[3], const float axis[3]) ATTR_WARN_UNUSED_RESULT
static wmOperatorStatus edbm_intersect_boolean_exec(bContext *C, wmOperator *op)
void BKE_report(ReportList *reports, eReportType type, const char *message)
bool BM_mesh_intersect(BMesh *bm, const Span< std::array< BMLoop *, 3 > > looptris, int(*test_fn)(BMFace *f, void *user_data), void *user_data, const bool use_self, const bool use_separate, const bool use_dissolve, const bool use_island_connect, const bool use_partial_connect, const bool use_edge_tag, const int boolean_mode, const float eps)
bool BM_mesh_boolean_knife(BMesh *, Span< std::array< BMLoop *, 3 > > looptris, int(*test_fn)(BMFace *, void *), void *, const int, const bool, const bool, const bool, const bool)
void BLI_memarena_clear(MemArena *ma) ATTR_NONNULL(1)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
bool BM_vert_in_face(BMVert *v, BMFace *f)
@ BMESH_ISECT_BOOLEAN_DIFFERENCE
@ BMESH_ISECT_BOOLEAN_UNION
@ BMESH_ISECT_BOOLEAN_ISECT
void BM_mesh_separate_faces(BMesh *bm, BMFaceFilterFunc filter_fn, void *user_data)
bool BM_vert_splice(BMesh *bm, BMVert *v_dst, BMVert *v_src)
Splice Vert.
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
bool BM_edge_face_pair(BMEdge *e, BMFace **r_fa, BMFace **r_fb)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
static BMEdge * bm_face_split_edge_find(BMEdge *e_a, BMFace *f_a, BMVert *v_pivot, BMFace **ftable, const int ftable_len, float r_v_pivot_co[3], float *r_v_pivot_fac)
static void bm_face_split_by_edges(BMesh *bm, BMFace *f, const char hflag, Vector< BMEdge *, 128 > *edge_net_temp_buf)
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
void * BLI_memarena_alloc(MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
MINLINE float normalize_v3(float n[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
float BM_edge_calc_length_squared(const BMEdge *e)
BMVert * BM_edge_split(BMesh *bm, BMEdge *e, BMVert *v, BMEdge **r_e, float fac)
Edge Split.
Main * CTX_data_main(const bContext *C)
void MESH_OT_face_split_by_edges(wmOperatorType *ot)
static int bm_face_isect_self(BMFace *f, void *)
bool BM_face_split_edgenet_connect_islands(BMesh *bm, BMFace *f, BMEdge **edge_net_init, const uint edge_net_init_len, bool use_partial_connect, MemArena *mem_arena, BMEdge ***r_edge_net_new, uint *r_edge_net_new_len)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
bool BM_face_split_edgenet(BMesh *bm, BMFace *f, BMEdge **edge_net, const int edge_net_len, Vector< BMFace * > *r_face_arr)
int BM_face_share_vert_count(BMFace *f_a, BMFace *f_b)
void BLI_stack_push(BLI_Stack *stack, const void *src) ATTR_NONNULL()
bool EDBM_uvselect_clear(BMesh *bm)
static int bm_face_isect_pair_swap(BMFace *f, void *)
Scene * CTX_data_scene(const bContext *C)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
static wmOperatorStatus edbm_face_split_by_edges_exec(bContext *C, wmOperator *)
static wmOperatorStatus edbm_intersect_exec(bContext *C, wmOperator *op)
static int bm_edge_sort_length_cb(const void *e_a_v, const void *e_b_v)
BLI_Stack * BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float RNA_float_get(PointerRNA *ptr, const char *name)
View3D * CTX_wm_view3d(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static void edbm_intersect_ui(bContext *, wmOperator *op)
void BLI_memarena_free(MemArena *ma) ATTR_NONNULL(1)
void MESH_OT_intersect_boolean(wmOperatorType *ot)
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
Array< std::array< BMLoop *, 3 > > looptris
struct BMLoop * radial_next
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(*) ui(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports