Blender  V3.3
bmo_poke.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
11 #include "BLI_math.h"
12 
13 #include "bmesh.h"
14 
15 #include "intern/bmesh_operators_private.h" /* own include */
16 
17 #include "BKE_customdata.h"
18 
19 #define ELE_NEW 1
20 
29 {
30  const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
31  BMOIter oiter;
32  BMFace *f;
33 
34  const float offset = BMO_slot_float_get(op->slots_in, "offset");
35  const bool use_relative_offset = BMO_slot_bool_get(op->slots_in, "use_relative_offset");
36  const int center_mode = BMO_slot_int_get(op->slots_in, "center_mode");
37  void (*bm_face_calc_center_fn)(const BMFace *f, float r_cent[3]);
38 
39  switch (center_mode) {
41  bm_face_calc_center_fn = BM_face_calc_center_median_weighted;
42  break;
43  case BMOP_POKE_BOUNDS:
44  bm_face_calc_center_fn = BM_face_calc_center_bounds;
45  break;
46  case BMOP_POKE_MEDIAN:
47  bm_face_calc_center_fn = BM_face_calc_center_median;
48  break;
49  default:
50  BLI_assert(0);
51  return;
52  }
53 
54  BMO_ITER (f, &oiter, op->slots_in, "faces", BM_FACE) {
55  BMFace *f_new;
56  float f_center[3], f_center_mean[3];
57  BMVert *v_center = NULL;
58  BMLoop *l_iter, *l_first;
59  /* only interpolate the central loop from the face once,
60  * then copy to all others in the fan */
61  BMLoop *l_center_example;
62 
63  /* 1.0 or the average length from the center to the face verts */
64  float offset_fac;
65 
66  int i;
67 
68  bm_face_calc_center_fn(f, f_center);
69  v_center = BM_vert_create(bm, f_center, NULL, BM_CREATE_NOP);
70  BMO_vert_flag_enable(bm, v_center, ELE_NEW);
71 
72  if (cd_loop_mdisp_offset != -1) {
73  if (center_mode == BMOP_POKE_MEDIAN) {
74  copy_v3_v3(f_center_mean, f_center);
75  }
76  else {
77  BM_face_calc_center_median(f, f_center_mean);
78  }
79  }
80 
81  /* handled by BM_loop_interp_from_face */
82  // BM_vert_interp_from_face(bm, v_center, f);
83 
84  if (use_relative_offset) {
85  offset_fac = 0.0f;
86  }
87  else {
88  offset_fac = 1.0f;
89  }
90 
91  i = 0;
92  l_iter = l_first = BM_FACE_FIRST_LOOP(f);
93  do {
94  BMLoop *l_new;
95 
97  bm, l_iter->v, l_iter->next->v, v_center, NULL, f, BM_CREATE_NOP);
98  l_new = BM_FACE_FIRST_LOOP(f_new);
99 
100  if (i == 0) {
101  l_center_example = l_new->prev;
102  BM_loop_interp_from_face(bm, l_center_example, f, true, false);
103  }
104  else {
105  BM_elem_attrs_copy(bm, bm, l_center_example, l_new->prev);
106  }
107 
108  /* Copy Loop Data */
109  BM_elem_attrs_copy(bm, bm, l_iter, l_new);
110  BM_elem_attrs_copy(bm, bm, l_iter->next, l_new->next);
111 
113 
114  if (cd_loop_mdisp_offset != -1) {
115  float f_new_center[3];
116  BM_face_calc_center_median(f_new, f_new_center);
117  BM_face_interp_multires_ex(bm, f_new, f, f_new_center, f_center, cd_loop_mdisp_offset);
118  }
119 
120  if (use_relative_offset) {
121  offset_fac += len_v3v3(f_center, l_iter->v->co);
122  }
123 
124  } while ((void)i++, (l_iter = l_iter->next) != l_first);
125 
126  if (use_relative_offset) {
127  offset_fac /= (float)f->len;
128  }
129  /* else remain at 1.0 */
130 
131  copy_v3_v3(v_center->no, f->no);
132  madd_v3_v3fl(v_center->co, v_center->no, offset * offset_fac);
133 
134  /* Kill Face */
135  BM_face_kill(bm, f);
136  }
137 
140 }
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset(const struct CustomData *data, int type)
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define BM_FACE_FIRST_LOOP(p)
Definition: bmesh_class.h:622
@ BM_FACE
Definition: bmesh_class.h:386
@ BM_VERT
Definition: bmesh_class.h:383
void BM_elem_attrs_copy(BMesh *bm_src, BMesh *bm_dst, const void *ele_src, void *ele_dst)
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.
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.
Definition: bmesh_core.c:41
void BM_face_kill(BMesh *bm, BMFace *f)
Definition: bmesh_core.c:828
@ BM_CREATE_NOP
Definition: bmesh_core.h:12
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)
Definition: bmesh_interp.c:544
void BM_loop_interp_from_face(BMesh *bm, BMLoop *l_dst, const BMFace *f_src, const bool do_vertex, const bool do_multires)
Definition: bmesh_interp.c:682
ATTR_WARN_UNUSED_RESULT BMesh * bm
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
#define BMO_vert_flag_enable(bm, e, oflag)
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)
#define BMO_face_flag_enable(bm, e, oflag)
#define BMO_ITER(ele, iter, slot_args, slot_name, restrict_flag)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
@ BMOP_POKE_MEDIAN_WEIGHTED
@ BMOP_POKE_BOUNDS
@ BMOP_POKE_MEDIAN
void BM_face_calc_center_bounds(const BMFace *f, float r_cent[3])
void BM_face_calc_center_median(const BMFace *f, float r_cent[3])
void BM_face_calc_center_median_weighted(const BMFace *f, float r_cent[3])
#define ELE_NEW
Definition: bmo_poke.c:19
void bmo_poke_exec(BMesh *bm, BMOperator *op)
Definition: bmo_poke.c:28
SyclQueue void void size_t num_bytes void
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
int len
Definition: bmesh_class.h:267
float no[3]
Definition: bmesh_class.h:271
struct BMVert * v
Definition: bmesh_class.h:153
struct BMLoop * prev
Definition: bmesh_class.h:233
struct BMLoop * next
Definition: bmesh_class.h:233
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
float co[3]
Definition: bmesh_class.h:87
float no[3]
Definition: bmesh_class.h:88
CustomData ldata
Definition: bmesh_class.h:337