30 const bool use_toolflags,
36 size_t vert_size, edge_size, loop_size, face_size;
38 if (use_toolflags ==
true) {
41 loop_size =
sizeof(
BMLoop);
45 vert_size =
sizeof(
BMVert);
46 edge_size =
sizeof(
BMEdge);
47 loop_size =
sizeof(
BMLoop);
48 face_size =
sizeof(
BMFace);
131 BMesh *
bm = MEM_new<BMesh>(__func__);
174 if (is_ldata_free || is_pdata_free) {
226#ifdef USE_BMESH_HOLES
285#ifdef BMOP_UNTAN_MULTIRES_ENABLED
289 bmesh_mdisps_space_set(
bm, MULTIRES_SPACE_TANGENT, MULTIRES_SPACE_ABSOLUTE);
292 bmesh_rationalize_normals(
bm, 0);
300 ListBaseT<BMEditSelection> select_history;
303#ifdef BMOP_UNTAN_MULTIRES_ENABLED
307 bmesh_rationalize_normals(
bm, 1);
308 bmesh_mdisps_space_set(
bm, MULTIRES_SPACE_ABSOLUTE, MULTIRES_SPACE_TANGENT);
310 else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
311 bmesh_rationalize_normals(
bm, 1);
345 if (elem_offset ==
nullptr) {
348 if (htype_needed == 0) {
358 int index = elem_offset ? elem_offset[0] : 0;
374 int index = elem_offset ? elem_offset[1] : 0;
387 (elem_offset && (elem_offset[2] || elem_offset[3])))
395 int index_loop = elem_offset ? elem_offset[2] : 0;
396 int index = elem_offset ? elem_offset[3] : 0;
409 }
while ((l_iter = l_iter->
next) != l_first);
459 BMesh *
bm,
const char *location,
const char *func,
const char *msg_a,
const char *msg_b)
464 const char *type_names[3] = {
"vert",
"edge",
"face"};
469 bool is_any_error =
false;
471 for (i = 0; i < 3; i++) {
474 bool is_error =
false;
490 if ((is_error ==
true) && (is_dirty ==
false)) {
493 "Invalid Index: at %s, %s, %s[%d] invalid index %d, '%s', '%s'\n",
502 else if ((is_error ==
false) && (is_dirty ==
true)) {
508 "Invalid Dirty: at %s, %s (%s), dirty flag was set but all index values are "
509 "correct, '%s', '%s'\n",
521 if (is_any_error == 0) {
522 fprintf(stderr,
"Valid Index Success: at %s, %s, '%s', '%s'\n", location, func, msg_a, msg_b);
568 const char htype_needed =
579 if (htype_needed == 0) {
687 }
while ((l_iter = l_iter->
next) != l_first);
748 if (!(vert_idx || edge_idx || face_idx)) {
757 BMVert **verts_pool, *verts_copy, **vep;
768 void **pyptrs = (cd_vert_pyptr != -1) ?
771 for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--;
776 if (cd_vert_pyptr != -1) {
783 vptr_map = MEM_new<Map<BMVert *, BMVert *>>(__func__);
787 new_idx = vert_idx + totvert - 1;
788 ve = verts_copy + totvert - 1;
789 vep = verts_pool + totvert - 1;
790 for (i = totvert; i--; new_idx--, ve--, vep--) {
791 BMVert *new_vep = verts_pool[*new_idx];
795 "mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);
797 vptr_map->
add(*vep, new_vep);
798 if (cd_vert_pyptr != -1) {
799 void **pyptr =
static_cast<void **
>(
801 *pyptr = pyptrs[*new_idx];
807 MEM_delete(verts_copy);
815 BMEdge **edges_pool, *edges_copy, **edp;
826 void **pyptrs = (cd_edge_pyptr != -1) ?
829 for (i = totedge,
ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--;
833 if (cd_edge_pyptr != -1) {
840 eptr_map = MEM_new<Map<BMEdge *, BMEdge *>>(__func__);
844 new_idx = edge_idx + totedge - 1;
845 ed = edges_copy + totedge - 1;
846 edp = edges_pool + totedge - 1;
847 for (i = totedge; i--; new_idx--,
ed--, edp--) {
848 BMEdge *new_edp = edges_pool[*new_idx];
850 eptr_map->
add(*edp, new_edp);
853 "mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp);
855 if (cd_edge_pyptr != -1) {
856 void **pyptr =
static_cast<void **
>(
858 *pyptr = pyptrs[*new_idx];
864 MEM_delete(edges_copy);
872 BMFace **faces_pool, *faces_copy, **fap;
883 void **pyptrs = (cd_poly_pyptr != -1) ?
886 for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--;
890 if (cd_poly_pyptr != -1) {
897 fptr_map = MEM_new<Map<BMFace *, BMFace *>>(__func__);
901 new_idx = face_idx + totface - 1;
902 fa = faces_copy + totface - 1;
903 fap = faces_pool + totface - 1;
904 for (i = totface; i--; new_idx--, fa--, fap--) {
905 BMFace *new_fap = faces_pool[*new_idx];
907 fptr_map->
add(*fap, new_fap);
908 if (cd_poly_pyptr != -1) {
909 void **pyptr =
static_cast<void **
>(
911 *pyptr = pyptrs[*new_idx];
918 MEM_delete(faces_copy);
938 if (vptr_map || eptr_map) {
950 printf(
"Edge v1_disk_link prev: %p -> %p\n",
951 ed->v1_disk_link.prev,
953 printf(
"Edge v1_disk_link next: %p -> %p\n",
954 ed->v1_disk_link.next,
956 printf(
"Edge v2_disk_link prev: %p -> %p\n",
957 ed->v2_disk_link.prev,
959 printf(
"Edge v2_disk_link next: %p -> %p\n",
960 ed->v2_disk_link.next,
963 ed->v1_disk_link.prev = eptr_map->
lookup(
ed->v1_disk_link.prev);
964 ed->v1_disk_link.next = eptr_map->
lookup(
ed->v1_disk_link.next);
965 ed->v2_disk_link.prev = eptr_map->
lookup(
ed->v2_disk_link.prev);
966 ed->v2_disk_link.next = eptr_map->
lookup(
ed->v2_disk_link.next);
1021 MEM_delete(vptr_map);
1022 MEM_delete(eptr_map);
1023 MEM_delete(fptr_map);
1033 const char remap = (vpool_dst ?
BM_VERT : 0) | (epool_dst ?
BM_EDGE : 0) |
1057 memcpy(v_dst, v_src,
sizeof(
BMVert));
1058 if (use_toolflags) {
1064 vtable_dst[
index] = v_dst;
1075 memcpy(e_dst, e_src,
sizeof(
BMEdge));
1076 if (use_toolflags) {
1082 etable_dst[
index] = e_dst;
1089 int index, index_loop = 0;
1095 memcpy(f_dst, f_src,
sizeof(
BMFace));
1096 if (use_toolflags) {
1103 ftable_dst[
index] = f_dst;
1109 BMLoop *l_iter_src, *l_first_src;
1113 memcpy(l_dst, l_iter_src,
sizeof(
BMLoop));
1114 ltable_dst[index_loop] = l_dst;
1116 }
while ((l_iter_src = l_iter_src->
next) != l_first_src);
1121#define MAP_VERT(ele) vtable_dst[BM_elem_index_get(ele)]
1122#define MAP_EDGE(ele) etable_dst[BM_elem_index_get(ele)]
1123#define MAP_LOOP(ele) ltable_dst[BM_elem_index_get(ele)]
1124#define MAP_FACE(ele) ftable_dst[BM_elem_index_get(ele)]
1126#define REMAP_VERT(ele) \
1128 if (remap & BM_VERT) { \
1129 ele = MAP_VERT(ele); \
1133#define REMAP_EDGE(ele) \
1135 if (remap & BM_EDGE) { \
1136 ele = MAP_EDGE(ele); \
1140#define REMAP_LOOP(ele) \
1142 if (remap & BM_LOOP) { \
1143 ele = MAP_LOOP(ele); \
1147#define REMAP_FACE(ele) \
1149 if (remap & BM_FACE) { \
1150 ele = MAP_FACE(ele); \
1184 BMFace *f = ftable_dst[i];
1188 BMLoop *l_iter, *l_first;
1199 }
while ((l_iter = l_iter->
next) != l_first);
1205 switch (ese.
htype) {
1247 MEM_delete(vtable_dst);
1258 MEM_delete(etable_dst);
1265 MEM_delete(ltable_dst);
1276 MEM_delete(ftable_dst);
1294 bm_mempool_init_ex(&allocsize, use_toolflags, &vpool_dst, &epool_dst,
nullptr, &fpool_dst);
1296 if (use_toolflags ==
false) {
1323 positions[i] =
v->
co;
CustomData interface, see also DNA_customdata_types.h.
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
#define BM_FACE_FIRST_LOOP(p)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_ELEM_INDEX_VALIDATE(_bm, _msg_a, _msg_b)
#define BM_elem_index_get(ele)
#define BM_elem_index_set(ele, index)
#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)
#define BMALLOC_TEMPLATE_FROM_BM(bm)
bool add(const Key &key, const Value &value)
const Value & lookup(const Key &key) const
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BM_mesh_vert_normals_get(BMesh *bm, MutableSpan< float3 > normals)
void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *func, const char *msg_a, const char *msg_b)
void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
BMFace * BM_face_at_index_find(BMesh *bm, const int index)
void BM_mesh_elem_toolflags_ensure(BMesh *bm)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
void BM_mesh_data_free(BMesh *bm)
BMesh Free Mesh Data.
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BM_mesh_vert_coords_apply_with_mat4(BMesh *bm, const Span< float3 > vert_coords, const float4x4 &transform)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void BM_mesh_elem_table_ensure(BMesh *bm, const char htype)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
void BM_mesh_vert_coords_apply(BMesh *bm, const Span< float3 > vert_coords)
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
void BMO_error_clear(BMesh *bm)
BMVert * BM_vert_at_index_find_or_table(BMesh *bm, const int index)
static void bm_mempool_init_ex(const BMAllocTemplate *allocsize, const bool use_toolflags, BLI_mempool **r_vpool, BLI_mempool **r_epool, BLI_mempool **r_lpool, BLI_mempool **r_fpool)
ATTR_WARN_UNUSED_RESULT const BMVert * v
MatBase< float, 4, 4 > float4x4
void BM_mesh_rebuild(BMesh *bm, const BMeshCreateParams *params, BLI_mempool *vpool_dst, BLI_mempool *epool_dst, BLI_mempool *lpool_dst, BLI_mempool *fpool_dst)
BMLoop * BM_loop_at_index_find(BMesh *bm, const int index)
void BM_mesh_select_mode_flush(BMesh *bm)
void BM_mesh_vert_coords_get(const BMesh *bm, MutableSpan< float3 > positions)
const BMAllocTemplate bm_mesh_chunksize_default
BMVert * BM_vert_at_index_find(BMesh *bm, const int index)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
void CustomData_bmesh_free_block(CustomData *data, void **block)
ATTR_WARN_UNUSED_RESULT const BMFlagLayer * oflags
BMEdge * BM_edge_at_index_find(BMesh *bm, const int index)
void CustomData_reset(CustomData *data)
bool CustomData_bmesh_has_free(const CustomData *data)
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
BMFace * BM_face_at_index_find_or_table(BMesh *bm, const int index)
int BM_mesh_elem_count(BMesh *bm, const char htype)
void BM_mesh_clear(BMesh *bm)
BMesh Clear Mesh.
const BMAllocTemplate bm_mesh_allocsize_default
Array< float3 > BM_mesh_vert_coords_alloc(const BMesh *bm)
void BM_mesh_toolflags_set(BMesh *bm, bool use_toolflags)
static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize, const bool use_toolflags)
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr)
void CustomData_free(CustomData *data)
@ BMO_OPTYPE_FLAG_SELECT_FLUSH
@ BMO_OPTYPE_FLAG_INVALIDATE_CLNOR_ALL
@ BMO_OPTYPE_FLAG_SELECT_VALIDATE
@ BMO_OPTYPE_FLAG_NORMALS_CALC
@ BMO_OPTYPE_FLAG_UNTAN_MULTIRES
void * BLI_mempool_calloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
void bmesh_edit_begin(BMesh *, BMOpTypeFlag)
BMesh Begin Edit.
void * BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
void BM_mesh_elem_table_init(BMesh *bm, const char htype)
void BM_mesh_elem_table_free(BMesh *bm, const char htype)
void bmesh_edit_end(BMesh *bm, BMOpTypeFlag type_flag)
BMesh End Edit.
void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4])
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
void BM_mesh_elem_toolflags_clear(BMesh *bm)
void * BLI_mempool_findelem(BLI_mempool *pool, unsigned int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void bpy_bm_generic_invalidate(struct BPy_BMGeneric *)
int BM_iter_as_array(BMesh *bm, const char itype, void *data, void **array, const int len)
Iterator as Array.
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const uint *face_idx)
void BM_mesh_normals_update(BMesh *bm)
BMEdge * BM_edge_at_index_find_or_table(BMesh *bm, const int index)
bool BM_mesh_elem_table_check(BMesh *bm)
struct BMFlagLayer * oflags
struct BMFlagLayer * oflags
struct BMLoop * radial_prev
struct BMLoop * radial_next
struct BMFlagLayer * oflags
struct MLoopNorSpaceArray * lnor_spacearr
BLI_mempool * vtoolflagpool
BLI_mempool * ftoolflagpool
BLI_mempool * etoolflagpool
ListBaseT< BMEditSelection > selected
struct BLI_mempool * pool