Blender V5.3
bmo_poke.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12
13#include "bmesh.hh"
14
15#include "intern/bmesh_operators_private.hh" /* own include */
16
17#include "BLI_math_vector_c.hh"
18
19#include "BKE_customdata.hh"
20
21namespace blender {
22
23#define ELE_NEW 1
24
33{
34 const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
35 BMOIter oiter;
36 BMFace *f;
37
38 const float offset = BMO_slot_float_get(op->slots_in, "offset");
39 const bool use_relative_offset = BMO_slot_bool_get(op->slots_in, "use_relative_offset");
40 const int center_mode = BMO_slot_int_get(op->slots_in, "center_mode");
41 void (*bm_face_calc_center_fn)(const BMFace *f, float r_cent[3]);
42
43 switch (center_mode) {
45 bm_face_calc_center_fn = BM_face_calc_center_median_weighted;
46 break;
48 bm_face_calc_center_fn = BM_face_calc_center_bounds;
49 break;
51 bm_face_calc_center_fn = BM_face_calc_center_median;
52 break;
53 default:
54 BLI_assert(0);
55 return;
56 }
57
58 BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) {
59 float f_center[3];
60 BMVert *v_center = nullptr;
61 BMLoop *l_iter, *l_first;
62 /* only interpolate the central loop from the face once,
63 * then copy to all others in the fan */
64 BMLoop *l_center_example;
65
66 /* 1.0 or the average length from the center to the face verts */
67 float offset_fac;
68
69 int i;
70
71 bm_face_calc_center_fn(f, f_center);
72 v_center = BM_vert_create(bm, f_center, nullptr, BM_CREATE_NOP);
74
75 /* handled by BM_loop_interp_from_face */
76 // BM_vert_interp_from_face(bm, v_center, f);
77
78 if (use_relative_offset) {
79 offset_fac = 0.0f;
80 }
81 else {
82 offset_fac = 1.0f;
83 }
84
85 i = 0;
86 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
87 do {
88 BMLoop *l_new;
90 bm, l_iter->v, l_iter->next->v, v_center, nullptr, f, BM_CREATE_NOP);
91 l_new = BM_FACE_FIRST_LOOP(f_new);
92
93 if (i == 0) {
94 l_center_example = l_new->prev;
95 BM_loop_interp_from_face(bm, l_center_example, f, true, false);
96 }
97 else {
98 BM_elem_attrs_copy(bm, l_center_example, l_new->prev);
99 }
100
101 /* Copy Loop Data */
102 BM_elem_attrs_copy(bm, l_iter, l_new);
103 BM_elem_attrs_copy(bm, l_iter->next, l_new->next);
104
106
107 if (cd_loop_mdisp_offset != -1) {
108 float f_new_center[3];
109 BM_face_calc_center_median(f_new, f_new_center);
110 BM_face_interp_multires_ex(bm, f_new, f, f_new_center, f_center, cd_loop_mdisp_offset);
111 }
112
113 if (use_relative_offset) {
114 offset_fac += len_v3v3(f_center, l_iter->v->co);
115 }
116
117 } while ((void)i++, (l_iter = l_iter->next) != l_first);
118
119 if (use_relative_offset) {
120 offset_fac /= float(f->len);
121 }
122 /* else remain at 1.0 */
123
124 copy_v3_v3(v_center->no, f->no);
125 madd_v3_v3fl(v_center->co, v_center->no, offset * offset_fac);
126
127 /* Kill Face */
128 BM_face_kill(bm, f);
129 }
130
133}
134
135} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
#define BM_FACE_FIRST_LOOP(p)
#define BMO_vert_flag_enable(bm, e, oflag)
#define BMO_face_flag_enable(bm, e, oflag)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
#define ELE_NEW
BMesh Iterators.
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
MINLINE void copy_v3_v3(float r[3], const float a[3])
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
BMFace * BM_face_create_quad_tri(BMesh *bm, BMVert *v1, BMVert *v2, BMVert *v3, BMVert *v4, const BMFace *f_example, const eBMCreateFlag create_flag)
Make Quad/Triangle.
@ BM_CREATE_NOP
Definition bmesh_core.hh:34
void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, short oflag)
void bmo_poke_exec(BMesh *bm, BMOperator *op)
Definition bmo_poke.cc:32
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
void BM_face_kill(BMesh *bm, BMFace *f)
void BM_face_interp_multires_ex(BMesh *bm, BMFace *f_dst, const BMFace *f_src, const float f_dst_center[3], const float f_src_center[3], const int cd_loop_mdisp_offset)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
void BM_loop_interp_from_face(BMesh *bm, BMLoop *l_dst, const BMFace *f_src, const bool do_vertex, const bool do_multires)
@ BMOP_POKE_MEDIAN_WEIGHTED
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMLoop * next
struct BMLoop * prev
struct BMVert * v
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]