Blender V5.3
bmesh_construct.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <algorithm>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_listbase.hh"
16#include "BLI_math_vector_c.hh"
17
18#include "BKE_attribute.hh"
21#include "BKE_customdata.hh"
22#include "BKE_geometry_set.hh"
23
24#include "DNA_mesh_types.h"
25
26#include "bmesh.hh"
28
29namespace blender {
30
31bool BM_verts_from_edges(BMVert **vert_arr, BMEdge **edge_arr, const int len)
32{
33 int i, i_prev = len - 1;
34 for (i = 0; i < len; i++) {
35 vert_arr[i] = BM_edge_share_vert(edge_arr[i_prev], edge_arr[i]);
36 if (vert_arr[i] == nullptr) {
37 return false;
38 }
39 i_prev = i;
40 }
41 return true;
42}
43
44bool BM_edges_from_verts(BMEdge **edge_arr, BMVert **vert_arr, const int len)
45{
46 int i, i_prev = len - 1;
47 for (i = 0; i < len; i++) {
48 edge_arr[i_prev] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]);
49 if (edge_arr[i_prev] == nullptr) {
50 return false;
51 }
52 i_prev = i;
53 }
54 return true;
55}
56
57void BM_edges_from_verts_ensure(BMesh *bm, BMEdge **edge_arr, BMVert **vert_arr, const int len)
58{
59 int i, i_prev = len - 1;
60 for (i = 0; i < len; i++) {
61 edge_arr[i_prev] = BM_edge_create(
62 bm, vert_arr[i_prev], vert_arr[i], nullptr, BM_CREATE_NO_DOUBLE);
63 i_prev = i;
64 }
65}
66
68 BMVert *v1,
69 BMVert *v2,
70 BMVert *v3,
71 BMVert *v4,
72 const BMFace *f_example,
73 const eBMCreateFlag create_flag)
74{
75 BMVert *vtar[4] = {v1, v2, v3, v4};
76 return BM_face_create_verts(bm, vtar, v4 ? 4 : 3, f_example, create_flag, true);
77}
78
79void BM_face_copy_shared(BMesh *bm, BMFace *f, BMLoopFilterFunc filter_fn, void *user_data)
80{
81 BMLoop *l_first;
82 BMLoop *l_iter;
83
84#ifndef NDEBUG
85 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
86 do {
88 } while ((l_iter = l_iter->next) != l_first);
89#endif
90
91 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
92 do {
93 BMLoop *l_other = l_iter->radial_next;
94
95 if (l_other && l_other != l_iter) {
96 BMLoop *l_src[2];
97 BMLoop *l_dst[2] = {l_iter, l_iter->next};
98 uint j;
99
100 if (l_other->v == l_iter->v) {
101 l_src[0] = l_other;
102 l_src[1] = l_other->next;
103 }
104 else {
105 l_src[0] = l_other->next;
106 l_src[1] = l_other;
107 }
108
109 for (j = 0; j < 2; j++) {
110 BLI_assert(l_dst[j]->v == l_src[j]->v);
111 if (BM_ELEM_API_FLAG_TEST(l_dst[j], _FLAG_OVERLAP) == 0) {
112 if ((filter_fn == nullptr) || filter_fn(l_src[j], user_data)) {
113 CustomData_bmesh_copy_block(bm->ldata, l_src[j]->head.data, &l_dst[j]->head.data);
115 }
116 }
117 }
118 }
119 } while ((l_iter = l_iter->next) != l_first);
120
121 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
122 do {
124 } while ((l_iter = l_iter->next) != l_first);
125}
126
135 BMVert *v2,
136 BMEdge **edges,
137 const int len,
138 BMEdge **edges_sort,
139 BMVert **verts_sort)
140{
141 BMEdge *e_iter, *e_first;
142 BMVert *v_iter;
143 int i;
144
145 /* all flags _must_ be cleared on exit! */
146 for (i = 0; i < len; i++) {
148 BM_ELEM_API_FLAG_ENABLE(edges[i]->v1, _FLAG_MV);
150 }
151
152 /* find first edge */
153 i = 0;
154 v_iter = v1;
155 e_iter = e_first = v1->e;
156 do {
157 if (BM_ELEM_API_FLAG_TEST(e_iter, _FLAG_MF) && (BM_edge_other_vert(e_iter, v_iter) == v2)) {
158 i = 1;
159 break;
160 }
161 } while ((e_iter = bmesh_disk_edge_next(e_iter, v_iter)) != e_first);
162 if (i == 0) {
163 goto error;
164 }
165
166 i = 0;
167 do {
168 /* entering loop will always succeed */
169 if (BM_ELEM_API_FLAG_TEST(e_iter, _FLAG_MF)) {
170 if (BM_ELEM_API_FLAG_TEST(v_iter, _FLAG_MV) == false) [[unlikely]] {
171 /* vert is in loop multiple times */
172 goto error;
173 }
174
176 edges_sort[i] = e_iter;
177
179 verts_sort[i] = v_iter;
180
181 i += 1;
182
183 /* walk onto the next vertex */
184 v_iter = BM_edge_other_vert(e_iter, v_iter);
185 if (i == len) {
186 if (v_iter != verts_sort[0]) [[unlikely]] {
187 goto error;
188 }
189 break;
190 }
191
192 e_first = e_iter;
193 }
194 } while ((e_iter = bmesh_disk_edge_next(e_iter, v_iter)) != e_first);
195
196 if (i == len) {
197 return true;
198 }
199
200error:
201 for (i = 0; i < len; i++) {
203 BM_ELEM_API_FLAG_DISABLE(edges[i]->v1, _FLAG_MV);
205 }
206
207 return false;
208}
209
211 BMVert *v1,
212 BMVert *v2,
213 BMEdge **edges,
214 const int len,
215 const BMFace *f_example,
216 const eBMCreateFlag create_flag)
217{
220
221 BLI_assert(len && v1 && v2 && edges && bm);
222
223 if (bm_edges_sort_winding(v1, v2, edges, len, edges_sort.data(), verts_sort.data())) {
224 return BM_face_create(bm, verts_sort.data(), edges_sort.data(), len, f_example, create_flag);
225 }
226
227 return nullptr;
228}
229
231 BMVert **vert_arr,
232 const int len,
233 const BMFace *f_example,
234 const eBMCreateFlag create_flag,
235 const bool calc_winding,
236 const bool create_edges)
237{
239
240 uint winding[2] = {0, 0};
241 int i, i_prev = len - 1;
242 BMVert *v_winding[2] = {vert_arr[i_prev], vert_arr[0]};
243
244 BLI_assert(len > 2);
245
246 for (i = 0; i < len; i++) {
247 if (create_edges) {
248 edge_arr[i] = BM_edge_create(
249 bm, vert_arr[i_prev], vert_arr[i], nullptr, BM_CREATE_NO_DOUBLE);
250 }
251 else {
252 edge_arr[i] = BM_edge_exists(vert_arr[i_prev], vert_arr[i]);
253 if (edge_arr[i] == nullptr) {
254 return nullptr;
255 }
256 }
257
258 if (calc_winding) {
259 /* the edge may exist already and be attached to a face
260 * in this case we can find the best winding to use for the new face */
261 if (edge_arr[i]->l) {
262 BMVert *test_v1, *test_v2;
263 /* we want to use the reverse winding to the existing order */
264 BM_edge_ordered_verts(edge_arr[i], &test_v2, &test_v1);
265 winding[(vert_arr[i_prev] == test_v2)]++;
266 BLI_assert(ELEM(vert_arr[i_prev], test_v2, test_v1));
267 }
268 }
269
270 i_prev = i;
271 }
272
273 /* --- */
274
275 if (calc_winding) {
276 if (winding[0] < winding[1]) {
277 winding[0] = 1;
278 winding[1] = 0;
279 }
280 else {
281 winding[0] = 0;
282 winding[1] = 1;
283 }
284 }
285 else {
286 winding[0] = 0;
287 winding[1] = 1;
288 }
289
290 /* --- */
291
292 /* create the face */
293 return BM_face_create_ngon(bm,
294 v_winding[winding[0]],
295 v_winding[winding[1]],
296 edge_arr.data(),
297 len,
298 f_example,
299 create_flag);
300}
301
303{
304 using AngleIndex = std::pair<float, int>;
307
308 float nor[3], cent[3];
309 int index_tangent = 0;
310 BM_verts_calc_normal_from_cloud_ex(vert_arr, len, nor, cent, &index_tangent);
311 const float *far = vert_arr[index_tangent]->co;
312
313 /* Now calculate every points angle around the normal (signed). */
314 for (int i = 0; i < len; i++) {
315 vang[i].first = angle_signed_on_axis_v3v3v3_v3(far, cent, vert_arr[i]->co, nor);
316 vang[i].second = i;
317 vert_arr_map[i] = vert_arr[i];
318 }
319
320 /* sort by angle and magic! - we have our ngon */
321 std::ranges::sort(vang,
322 [](const AngleIndex &a, const AngleIndex &b) { return a.first < b.first; });
323
324 /* --- */
325
326 for (int i = 0; i < len; i++) {
327 vert_arr[i] = vert_arr_map[vang[i].second];
328 }
329}
330
331/*************************************************************/
332
333void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
334{
335 BLI_assert(src != dst);
337 constexpr char hflag_mask = BM_ELEM_SELECT;
338 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
339 copy_v3_v3(dst->no, src->no);
340}
341void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMEdge *src, BMEdge *dst)
342{
343 BLI_assert(src != dst);
345 constexpr char hflag_mask = BM_ELEM_SELECT;
346 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
347}
348void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMFace *src, BMFace *dst)
349{
350 BLI_assert(src != dst);
352 constexpr char hflag_mask = BM_ELEM_SELECT | BM_ELEM_SELECT_UV;
353 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
354 copy_v3_v3(dst->no, src->no);
355 dst->mat_nr = src->mat_nr;
356}
357void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMLoop *src, BMLoop *dst)
358{
359 BLI_assert(src != dst);
361 constexpr char hflag_mask = BM_ELEM_SELECT | BM_ELEM_SELECT_UV | BM_ELEM_SELECT_UV_EDGE;
362 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
363}
364
365void BM_elem_attrs_copy(BMesh *bm, const BMVert *src, BMVert *dst)
366{
367 BLI_assert(src != dst);
369 constexpr char hflag_mask = BM_ELEM_SELECT;
370 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
371 copy_v3_v3(dst->no, src->no);
372}
373void BM_elem_attrs_copy(BMesh *bm, const BMEdge *src, BMEdge *dst)
374{
375 BLI_assert(src != dst);
377 constexpr char hflag_mask = BM_ELEM_SELECT;
378 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
379}
380void BM_elem_attrs_copy(BMesh *bm, const BMFace *src, BMFace *dst)
381{
382 BLI_assert(src != dst);
383 constexpr char hflag_mask = BM_ELEM_SELECT | BM_ELEM_SELECT_UV;
385 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
386 copy_v3_v3(dst->no, src->no);
387 dst->mat_nr = src->mat_nr;
388}
389void BM_elem_attrs_copy(BMesh *bm, const BMLoop *src, BMLoop *dst)
390{
391 BLI_assert(src != dst);
392 constexpr char hflag_mask = BM_ELEM_SELECT | BM_ELEM_SELECT_UV | BM_ELEM_SELECT_UV_EDGE;
394 dst->head.hflag = (dst->head.hflag & hflag_mask) | (src->head.hflag & ~hflag_mask);
395}
396
397void BM_elem_select_copy(BMesh *bm_dst, void *ele_dst_v, const void *ele_src_v)
398{
399 BMHeader *ele_dst = static_cast<BMHeader *>(ele_dst_v);
400 const BMHeader *ele_src = static_cast<const BMHeader *>(ele_src_v);
401
402 BLI_assert(ele_src->htype == ele_dst->htype);
403
404 if ((ele_src->hflag & BM_ELEM_SELECT) != (ele_dst->hflag & BM_ELEM_SELECT)) {
406 bm_dst, reinterpret_cast<BMElem *>(ele_dst), (ele_src->hflag & BM_ELEM_SELECT) != 0);
407 }
408}
409
410/* helper function for 'BM_mesh_copy' */
412 const BMCustomDataCopyMap &face_map,
413 const BMCustomDataCopyMap &loop_map,
414 BMVert **vtable,
415 BMEdge **etable,
416 BMFace *f)
417{
421
422 BMFace *f_new;
423 BMLoop *l_iter, *l_first;
424 int j;
425
426 j = 0;
427 l_iter = l_first = BM_FACE_FIRST_LOOP(f);
428 do {
429 loops[j] = l_iter;
430 verts[j] = vtable[BM_elem_index_get(l_iter->v)];
431 edges[j] = etable[BM_elem_index_get(l_iter->e)];
432 j++;
433 } while ((l_iter = l_iter->next) != l_first);
434
435 f_new = BM_face_create(bm_new, verts.data(), edges.data(), f->len, nullptr, BM_CREATE_SKIP_CD);
436
437 if (f_new == nullptr) [[unlikely]] {
438 return nullptr;
439 }
440
441 /* use totface in case adding some faces fails */
442 BM_elem_index_set(f_new, (bm_new->totface - 1)); /* set_inline */
443
444 CustomData_bmesh_copy_block(bm_new->pdata, face_map, f->head.data, &f_new->head.data);
445 copy_v3_v3(f_new->no, f->no);
446 f_new->mat_nr = f->mat_nr;
447 f_new->head.hflag = f->head.hflag; /* Low level! don't do this for normal API use. */
448
449 j = 0;
450 l_iter = l_first = BM_FACE_FIRST_LOOP(f_new);
451 do {
452 CustomData_bmesh_copy_block(bm_new->ldata, loop_map, loops[j]->head.data, &l_iter->head.data);
453 l_iter->head.hflag = loops[j]->head.hflag & ~BM_ELEM_SELECT;
454 j++;
455 } while ((l_iter = l_iter->next) != l_first);
456
457 return f_new;
458}
459
461{
462 switch (domain) {
464 return bm.vdata;
466 return bm.edata;
468 return bm.pdata;
470 return bm.ldata;
471 default:
473 return bm.vdata;
474 }
475}
476
478 const Mesh *me_src_array[],
479 const int me_src_array_len,
480 const BMAllocTemplate *allocsize)
481
482{
483 if (allocsize == nullptr) {
484 allocsize = &bm_mesh_allocsize_default;
485 }
486
488 for (int i = 0; i < me_src_array_len; i++) {
489 const Mesh *me_src = me_src_array[i];
490 for (const bke::Attribute &attr : me_src->attribute_storage.wrap()) {
491 if (BM_attribute_stored_in_bmesh_builtin(attr.name())) {
492 continue;
493 }
494 attribute_info.add(attr.name(), {attr.domain(), attr.data_type()});
495 }
496 }
497
498 for (const int i : attribute_info.names.index_range()) {
499 const StringRef name = attribute_info.names[i];
500 const bke::AttrDomain domain = attribute_info.kinds[i].domain;
502 attribute_info.kinds[i].data_type);
503 CustomData &custom_data = get_bmesh_custom_data(*bm_dst, domain);
504 CustomData_add_layer_named(&custom_data, data_type, CD_SET_DEFAULT, 0, name);
505 }
506
507 for (int i = 0; i < me_src_array_len; i++) {
508 const Mesh *me_src = me_src_array[i];
510 &me_src->vert_data, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0);
512 &me_src->edge_data, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0);
514 &me_src->face_data, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0);
516 &me_src->corner_data, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0);
517 }
518
519 CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT);
520 CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE);
521 CustomData_bmesh_init_pool(&bm_dst->ldata, allocsize->totloop, BM_LOOP);
522 CustomData_bmesh_init_pool(&bm_dst->pdata, allocsize->totface, BM_FACE);
523}
524
526 const Mesh *me_src,
527 const BMAllocTemplate *allocsize)
528{
529 BM_mesh_copy_init_customdata_from_mesh_array(bm_dst, &me_src, 1, allocsize);
530}
531
532void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTemplate *allocsize)
533{
534 if (allocsize == nullptr) {
535 allocsize = &bm_mesh_allocsize_default;
536 }
537
539 &bm_src->vdata, &bm_dst->vdata, CD_MASK_BMESH.vmask, CD_SET_DEFAULT, 0);
541 &bm_src->edata, &bm_dst->edata, CD_MASK_BMESH.emask, CD_SET_DEFAULT, 0);
543 &bm_src->ldata, &bm_dst->ldata, CD_MASK_BMESH.lmask, CD_SET_DEFAULT, 0);
545 &bm_src->pdata, &bm_dst->pdata, CD_MASK_BMESH.pmask, CD_SET_DEFAULT, 0);
546
547 CustomData_bmesh_init_pool(&bm_dst->vdata, allocsize->totvert, BM_VERT);
548 CustomData_bmesh_init_pool(&bm_dst->edata, allocsize->totedge, BM_EDGE);
549 CustomData_bmesh_init_pool(&bm_dst->ldata, allocsize->totloop, BM_LOOP);
550 CustomData_bmesh_init_pool(&bm_dst->pdata, allocsize->totface, BM_FACE);
551}
552
554 BMesh *bm_src,
555 const char htype,
556 const BMAllocTemplate *allocsize)
557{
558 if (allocsize == nullptr) {
559 allocsize = &bm_mesh_allocsize_default;
560 }
561
562 const char htypes[4] = {BM_VERT, BM_EDGE, BM_LOOP, BM_FACE};
563 BLI_assert(((&bm_dst->vdata + 1) == &bm_dst->edata) &&
564 ((&bm_dst->vdata + 2) == &bm_dst->ldata) && ((&bm_dst->vdata + 3) == &bm_dst->pdata));
565
566 BLI_assert(((&allocsize->totvert + 1) == &allocsize->totedge) &&
567 ((&allocsize->totvert + 2) == &allocsize->totloop) &&
568 ((&allocsize->totvert + 3) == &allocsize->totface));
569
570 for (int i = 0; i < 4; i++) {
571 if (!(htypes[i] & htype)) {
572 continue;
573 }
574 CustomData *dst = &bm_dst->vdata + i;
575 CustomData *src = &bm_src->vdata + i;
576 const int size = *(&allocsize->totvert + i);
577
578 for (int l = 0; l < src->totlayer; l++) {
580 dst, eCustomDataType(src->layers[l].type), CD_SET_DEFAULT, 0, src->layers[l].name);
581 /* Needed to keep this a working shape key layer (see also #customdata_merge_internal). */
582 dst->layers[l].uid = src->layers[l].uid;
583 }
584 CustomData_bmesh_init_pool(dst, size, htypes[i]);
585 }
586}
587
589{
590 BMesh *bm_new;
591 BMVert *v, *v_new, **vtable = nullptr;
592 BMEdge *e, *e_new, **etable = nullptr;
593 BMFace *f, *f_new, **ftable = nullptr;
594 BMElem **eletable;
595 BMIter iter;
596 int i;
597 const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_BM(bm_old);
598
599 /* allocate a bmesh */
600 BMeshCreateParams params{};
601 params.use_toolflags = bm_old->use_toolflags;
602 bm_new = BM_mesh_create(&allocsize, &params);
603
604 BM_mesh_copy_init_customdata(bm_new, bm_old, &allocsize);
605
607 bm_new->vdata);
609 bm_new->edata);
611 bm_new->pdata);
613 bm_new->ldata);
614
615 vtable = MEM_new_array_uninitialized<BMVert *>(bm_old->totvert, "BM_mesh_copy vtable");
616 etable = MEM_new_array_uninitialized<BMEdge *>(bm_old->totedge, "BM_mesh_copy etable");
617 ftable = MEM_new_array_uninitialized<BMFace *>(bm_old->totface, "BM_mesh_copy ftable");
618
619 BM_ITER_MESH_INDEX (v, &iter, bm_old, BM_VERTS_OF_MESH, i) {
620 /* copy between meshes so can't use 'example' argument */
621 v_new = BM_vert_create(bm_new, v->co, nullptr, BM_CREATE_SKIP_CD);
622 CustomData_bmesh_copy_block(bm_new->vdata, vert_map, v->head.data, &v_new->head.data);
623 copy_v3_v3(v_new->no, v->no);
624 v_new->head.hflag = v->head.hflag; /* Low level! don't do this for normal API use. */
625 vtable[i] = v_new;
626 BM_elem_index_set(v, i); /* set_inline */
627 BM_elem_index_set(v_new, i); /* set_inline */
628 }
629 bm_old->elem_index_dirty &= ~BM_VERT;
630 bm_new->elem_index_dirty &= ~BM_VERT;
631
632 /* safety check */
633 BLI_assert(i == bm_old->totvert);
634
635 BM_ITER_MESH_INDEX (e, &iter, bm_old, BM_EDGES_OF_MESH, i) {
636 e_new = BM_edge_create(bm_new,
637 vtable[BM_elem_index_get(e->v1)],
638 vtable[BM_elem_index_get(e->v2)],
639 e,
641
642 CustomData_bmesh_copy_block(bm_new->edata, edge_map, e->head.data, &e_new->head.data);
643 e_new->head.hflag = e->head.hflag; /* Low level! don't do this for normal API use. */
644 etable[i] = e_new;
645 BM_elem_index_set(e, i); /* set_inline */
646 BM_elem_index_set(e_new, i); /* set_inline */
647 }
648 bm_old->elem_index_dirty &= ~BM_EDGE;
649 bm_new->elem_index_dirty &= ~BM_EDGE;
650
651 /* safety check */
652 BLI_assert(i == bm_old->totedge);
653
654 BM_ITER_MESH_INDEX (f, &iter, bm_old, BM_FACES_OF_MESH, i) {
655 BM_elem_index_set(f, i); /* set_inline */
656
657 f_new = bm_mesh_copy_new_face(bm_new, face_map, loop_map, vtable, etable, f);
658
659 ftable[i] = f_new;
660
661 if (f == bm_old->act_face) {
662 bm_new->act_face = f_new;
663 }
664 }
665 bm_old->elem_index_dirty &= ~BM_FACE;
666 bm_new->elem_index_dirty &= ~BM_FACE;
667
668 /* Low level! don't do this for normal API use. */
669 bm_new->totvertsel = bm_old->totvertsel;
670 bm_new->totedgesel = bm_old->totedgesel;
671 bm_new->totfacesel = bm_old->totfacesel;
672
673 /* safety check */
674 BLI_assert(i == bm_old->totface);
675
676 /* copy over edit selection history */
677 for (BMEditSelection &ese : bm_old->selected) {
678 BMElem *ele = nullptr;
679
680 switch (ese.htype) {
681 case BM_VERT:
682 eletable = reinterpret_cast<BMElem **>(vtable);
683 break;
684 case BM_EDGE:
685 eletable = reinterpret_cast<BMElem **>(etable);
686 break;
687 case BM_FACE:
688 eletable = reinterpret_cast<BMElem **>(ftable);
689 break;
690 default:
691 eletable = nullptr;
692 break;
693 }
694
695 if (eletable) {
696 ele = eletable[BM_elem_index_get(ese.ele)];
697 if (ele) {
698 BM_select_history_store(bm_new, ele);
699 }
700 }
701 }
702
703 MEM_delete(etable);
704 MEM_delete(vtable);
705 MEM_delete(ftable);
706
707 /* Copy various settings. */
708 bm_new->shapenr = bm_old->shapenr;
709 bm_new->selectmode = bm_old->selectmode;
710
711 return bm_new;
712}
713
714} // namespace blender
CustomData interface, see also DNA_customdata_types.h.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define ELEM(...)
#define BM_ELEM_SELECT_UV_EDGE
#define BM_FACE_FIRST_LOOP(p)
#define BM_elem_index_get(ele)
#define BM_elem_index_set(ele, index)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
#define BM_select_history_store(bm, ele)
#define BMALLOC_TEMPLATE_FROM_BM(bm)
#define BM_ELEM_API_FLAG_DISABLE(element, f)
#define BM_ELEM_API_FLAG_TEST(element, f)
#define BM_ELEM_API_FLAG_ENABLE(element, f)
const T * data() const
Definition BLI_array.hh:323
const T & first() const
Definition BLI_array.hh:292
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::optional< eCustomDataType > attr_type_to_custom_data_type(AttrType attr_type)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMFace * BM_face_create_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool create_edges)
void BM_mesh_copy_init_customdata(BMesh *bm_dst, BMesh *bm_src, const BMAllocTemplate *allocsize)
bool CustomData_merge_layout(const CustomData *source, CustomData *dest, eCustomDataMask mask, eCDAllocType alloctype, int totelem)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static bool bm_edges_sort_winding(BMVert *v1, BMVert *v2, BMEdge **edges, const int len, BMEdge **edges_sort, BMVert **verts_sort)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
ATTR_WARN_UNUSED_RESULT const BMLoop * l
BMCustomDataCopyMap CustomData_bmesh_copy_map_calc(const CustomData &src, const CustomData &dst, eCustomDataMask mask_exclude=0)
BMVert * BM_edge_share_vert(BMEdge *e1, BMEdge *e2)
bool BM_verts_from_edges(BMVert **vert_arr, BMEdge **edge_arr, const int len)
void BM_verts_calc_normal_from_cloud_ex(BMVert **varr, int varr_len, float r_normal[3], float r_center[3], int *r_index_tangent)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void CustomData_bmesh_copy_block(CustomData &data, void *src_block, void **dst_block)
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.
BMFace * BM_face_create(BMesh *bm, BMVert *const *verts, BMEdge *const *edges, const int len, const BMFace *f_example, const eBMCreateFlag create_flag)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
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.
void CustomData_init_layout_from(const CustomData *source, CustomData *dest, eCustomDataMask mask, eCDAllocType alloctype, int totelem)
@ BM_CREATE_NO_DOUBLE
Definition bmesh_core.hh:36
@ BM_CREATE_SKIP_CD
Definition bmesh_core.hh:42
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
BMesh * BM_mesh_copy(BMesh *bm_old)
bool BM_edges_from_verts(BMEdge **edge_arr, BMVert **vert_arr, const int len)
void BM_face_copy_shared(BMesh *bm, BMFace *f, BMLoopFilterFunc filter_fn, void *user_data)
copies face loop data from shared adjacent faces.
void * CustomData_add_layer_named(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem, StringRef name)
void BM_elem_select_set(BMesh *bm, BMElem *ele, const bool select)
void BM_elem_select_copy(BMesh *bm_dst, void *ele_dst_v, const void *ele_src_v)
const CustomData_MeshMasks CD_MASK_BMESH
const BMAllocTemplate bm_mesh_allocsize_default
Definition bmesh_mesh.cc:26
void BM_edge_ordered_verts(const BMEdge *edge, BMVert **r_v1, BMVert **r_v2)
static BMFace * bm_mesh_copy_new_face(BMesh *bm_new, const BMCustomDataCopyMap &face_map, const BMCustomDataCopyMap &loop_map, BMVert **vtable, BMEdge **etable, BMFace *f)
BMFace * BM_face_create_ngon_verts(BMesh *bm, BMVert **vert_arr, const int len, const BMFace *f_example, const eBMCreateFlag create_flag, const bool calc_winding, const bool create_edges)
void BM_verts_sort_radial_plane(BMVert **vert_arr, int len)
void BM_edges_from_verts_ensure(BMesh *bm, BMEdge **edge_arr, BMVert **vert_arr, const int len)
BMEdge * BM_edge_exists(BMVert *v_a, BMVert *v_b)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void BM_mesh_copy_init_customdata_all_layers(BMesh *bm_dst, BMesh *bm_src, const char htype, const BMAllocTemplate *allocsize)
BMFace * BM_face_create_ngon(BMesh *bm, BMVert *v1, BMVert *v2, BMEdge **edges, const int len, const BMFace *f_example, const eBMCreateFlag create_flag)
Make NGon.
void CustomData_bmesh_init_pool(CustomData *data, int totelem, char htype)
BLI_INLINE BMEdge * bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void BM_mesh_copy_init_customdata_from_mesh_array(BMesh *bm_dst, const Mesh *me_src_array[], const int me_src_array_len, const BMAllocTemplate *allocsize)
void BM_elem_attrs_copy(BMesh *bm, const BMCustomDataCopyMap &map, const BMVert *src, BMVert *dst)
bool(*)(const BMLoop *, void *user_data) BMLoopFilterFunc
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
@ BM_ELEM_SELECT_UV
void BM_mesh_copy_init_customdata_from_mesh(BMesh *bm_dst, const Mesh *me_src, const BMAllocTemplate *allocsize)
BMEdge * BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
Main function for creating a new edge.
bool BM_attribute_stored_in_bmesh_builtin(const StringRef name)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static CustomData & get_bmesh_custom_data(BMesh &bm, const bke::AttrDomain domain)
struct BMLoop * next
struct BMEdge * e
struct BMVert * v
struct BMLoop * radial_next
struct BMEdge * e
CustomData pdata
ListBaseT< BMEditSelection > selected
CustomData vdata
CustomData edata
CustomData ldata
BMFace * act_face
struct AttributeStorage attribute_storage
CustomData corner_data
CustomData face_data
CustomData edge_data
CustomData vert_data
void add(const StringRef name, const AttributeDomainAndType &kind)
Vector< AttributeDomainAndType, 16 > kinds