Blender V5.0
bmesh_mesh.cc File Reference
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "BLI_listbase.h"
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BKE_customdata.hh"
#include "BKE_mesh.hh"
#include "bmesh.hh"

Go to the source code of this file.

Macros

#define MAP_VERT(ele)
#define MAP_EDGE(ele)
#define MAP_LOOP(ele)
#define MAP_FACE(ele)
#define REMAP_VERT(ele)
#define REMAP_EDGE(ele)
#define REMAP_LOOP(ele)
#define REMAP_FACE(ele)

Typedefs

using float3
using float4x4

Functions

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)
static void bm_mempool_init (BMesh *bm, const BMAllocTemplate *allocsize, const bool use_toolflags)
void BM_mesh_elem_toolflags_ensure (BMesh *bm)
void BM_mesh_elem_toolflags_clear (BMesh *bm)
BMeshBM_mesh_create (const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
 BMesh Make Mesh.
void BM_mesh_data_free (BMesh *bm)
 BMesh Free Mesh Data.
void BM_mesh_clear (BMesh *bm)
 BMesh Clear Mesh.
void BM_mesh_free (BMesh *bm)
 BMesh Free Mesh.
void bmesh_edit_begin (BMesh *, BMOpTypeFlag)
 BMesh Begin Edit.
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])
void BM_mesh_elem_index_ensure (BMesh *bm, const char htype)
void BM_mesh_elem_index_validate (BMesh *bm, const char *location, const char *func, const char *msg_a, const char *msg_b)
bool BM_mesh_elem_table_check (BMesh *bm)
void BM_mesh_elem_table_ensure (BMesh *bm, const char htype)
void BM_mesh_elem_table_init (BMesh *bm, const char htype)
void BM_mesh_elem_table_free (BMesh *bm, const char htype)
BMVertBM_vert_at_index_find (BMesh *bm, const int index)
BMEdgeBM_edge_at_index_find (BMesh *bm, const int index)
BMFaceBM_face_at_index_find (BMesh *bm, const int index)
BMLoopBM_loop_at_index_find (BMesh *bm, const int index)
BMVertBM_vert_at_index_find_or_table (BMesh *bm, const int index)
BMEdgeBM_edge_at_index_find_or_table (BMesh *bm, const int index)
BMFaceBM_face_at_index_find_or_table (BMesh *bm, const int index)
int BM_mesh_elem_count (BMesh *bm, const char htype)
void BM_mesh_remap (BMesh *bm, const uint *vert_idx, const uint *edge_idx, const uint *face_idx)
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)
void BM_mesh_toolflags_set (BMesh *bm, bool use_toolflags)
BMesh Coordinate Access
void BM_mesh_vert_coords_get (BMesh *bm, MutableSpan< float3 > positions)
void BM_mesh_vert_normals_get (BMesh *bm, MutableSpan< float3 > normals)
Array< float3BM_mesh_vert_coords_alloc (BMesh *bm)
void BM_mesh_vert_coords_apply (BMesh *bm, const Span< float3 > vert_coords)
void BM_mesh_vert_coords_apply_with_mat4 (BMesh *bm, const Span< float3 > vert_coords, const float4x4 &transform)

Variables

const BMAllocTemplate bm_mesh_allocsize_default = {512, 1024, 2048, 512}
const BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512}

Detailed Description

BM mesh level functions.

Definition in file bmesh_mesh.cc.

Macro Definition Documentation

◆ MAP_EDGE

#define MAP_EDGE ( ele)
Value:
etable_dst[BM_elem_index_get(ele)]
#define BM_elem_index_get(ele)

Referenced by BM_mesh_rebuild().

◆ MAP_FACE

#define MAP_FACE ( ele)
Value:
ftable_dst[BM_elem_index_get(ele)]

Referenced by BM_mesh_rebuild().

◆ MAP_LOOP

#define MAP_LOOP ( ele)
Value:
ltable_dst[BM_elem_index_get(ele)]

◆ MAP_VERT

#define MAP_VERT ( ele)
Value:
vtable_dst[BM_elem_index_get(ele)]

Referenced by BM_mesh_rebuild().

◆ REMAP_EDGE

#define REMAP_EDGE ( ele)
Value:
{ \
if (remap & BM_EDGE) { \
ele = MAP_EDGE(ele); \
} \
} \
((void)0)
#define MAP_EDGE(ele)
#define BM_EDGE

Referenced by BM_mesh_rebuild().

◆ REMAP_FACE

#define REMAP_FACE ( ele)
Value:
{ \
if (remap & BM_FACE) { \
ele = MAP_FACE(ele); \
} \
} \
((void)0)
#define MAP_FACE(ele)
#define BM_FACE

Referenced by BM_mesh_rebuild().

◆ REMAP_LOOP

#define REMAP_LOOP ( ele)
Value:
{ \
if (remap & BM_LOOP) { \
ele = MAP_LOOP(ele); \
} \
} \
((void)0)
@ BM_LOOP
#define MAP_LOOP(ele)

Referenced by BM_mesh_rebuild().

◆ REMAP_VERT

#define REMAP_VERT ( ele)
Value:
{ \
if (remap & BM_VERT) { \
ele = MAP_VERT(ele); \
} \
} \
((void)0)
#define MAP_VERT(ele)
#define BM_VERT

Referenced by BM_mesh_rebuild().

Typedef Documentation

◆ float3

Definition at line 619 of file BLI_math_vector_types.hh.

◆ float4x4

Definition at line 1012 of file BLI_math_matrix_types.hh.

Function Documentation

◆ BM_edge_at_index_find()

BMEdge * BM_edge_at_index_find ( BMesh * bm,
const int index )

◆ BM_edge_at_index_find_or_table()

BMEdge * BM_edge_at_index_find_or_table ( BMesh * bm,
const int index )

◆ BM_face_at_index_find()

BMFace * BM_face_at_index_find ( BMesh * bm,
const int index )

◆ BM_face_at_index_find_or_table()

BMFace * BM_face_at_index_find_or_table ( BMesh * bm,
const int index )

◆ BM_loop_at_index_find()

BMLoop * BM_loop_at_index_find ( BMesh * bm,
const int index )

◆ bm_mempool_init()

void bm_mempool_init ( BMesh * bm,
const BMAllocTemplate * allocsize,
const bool use_toolflags )
static

Definition at line 73 of file bmesh_mesh.cc.

References BLI_mempool_create(), BLI_MEMPOOL_NOP, bm, and bm_mempool_init_ex().

Referenced by BM_mesh_clear(), and BM_mesh_create().

◆ bm_mempool_init_ex()

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 )
static

◆ BM_mesh_clear()

void BM_mesh_clear ( BMesh * bm)

BMesh Clear Mesh.

Clear all data in bm

Definition at line 244 of file bmesh_mesh.cc.

References bm, bm_mempool_init(), bm_mesh_allocsize_default, BM_mesh_data_free(), and CustomData_reset().

Referenced by bpy_bmesh_clear().

◆ BM_mesh_create()

◆ BM_mesh_data_free()

◆ BM_mesh_elem_count()

◆ BM_mesh_elem_index_ensure()

void BM_mesh_elem_index_ensure ( BMesh * bm,
const char htype )

Definition at line 457 of file bmesh_mesh.cc.

References bm, and BM_mesh_elem_index_ensure_ex().

Referenced by blender::bke::armature_deform_editmesh(), BKE_bmbvh_new_ex(), BKE_editmesh_cache_ensure_face_centers(), BKE_editmesh_cache_ensure_face_normals(), BKE_editmesh_cache_ensure_vert_normals(), BKE_editmesh_orco_tangents_calc(), BKE_editmesh_uv_tangents_calc(), BKE_mesh_foreach_mapped_edge(), BKE_mesh_foreach_mapped_loop(), bm_decim_triangulate_begin(), bm_edge_info_average_length_fallback(), BM_lnorspace_invalidate(), BM_lnorspace_rebuild(), BM_loop_normal_editdata_array_init_with_htype(), bm_loop_normal_mark_edges(), bm_loop_normal_mark_faces(), bm_loop_normal_mark_indiv(), bm_loop_normal_mark_verts(), bm_mesh_calc_tessellation__multi_threaded(), BM_mesh_calc_tessellation_with_partial_ex(), BM_mesh_decimate_dissolve_ex(), BM_mesh_edgenet(), bm_mesh_edges_sharp_tag(), BM_mesh_intersect(), BM_mesh_is_valid(), bm_mesh_loops_calc_normals__multi_threaded(), bm_mesh_loops_calc_normals__single_threaded(), bm_mesh_loops_calc_normals_no_autosmooth(), BM_mesh_partial_create_from_verts(), BM_mesh_region_match(), bm_mesh_verts_calc_normals(), BM_uv_element_map_create(), BM_uv_vert_map_create(), bmo_offset_edgeloops_exec(), bmo_smooth_laplacian_vert_exec(), bpy_bmelemseq_index_update(), calc_solidify_normals(), construct_param_handle(), construct_param_handle_subsurfed(), DRW_text_edit_mesh_measure_stats(), ED_mesh_mirrtopo_init(), edbm_face_split_by_edges_exec(), edbm_mod_weighted_strength_exec(), EDBM_preselect_edgering_update_from_edge(), EDBM_preselect_elem_update_from_single(), edbm_select_linked_pick_invoke(), edbm_shortest_path_pick_invoke(), EDBM_unified_findnearest_from_raycast(), EDBM_verts_mirror_cache_begin_ex(), gizmo_preselect_edgering_test_select(), gizmo_preselect_elem_test_select(), knifetool_init_obinfo(), lattice_deform_coords_impl(), loopcut_finish(), math_layer_info_init(), mesh_calc_path_region_elem(), mesh_calc_path_region_elem(), blender::ed::transform::mesh_partial_ensure(), blender::draw::mesh_render_data_create(), solidify_add_thickness(), blender::draw::statvis_calc_intersect(), blender::draw::statvis_calc_thickness(), stitch_process_data(), blender::ed::transform::transform_convert_mesh_islands_calc(), uv_find_nearest_edge(), uv_find_nearest_vert(), uv_select_overlap(), blender::ed::transform::uv_set_connectivity_distance(), uv_shortest_path_pick_invoke(), blender::ed::sculpt_paint::vert_random_access_ensure(), and blender::ed::object::vgroup_smooth_subset().

◆ BM_mesh_elem_index_ensure_ex()

void BM_mesh_elem_index_ensure_ex ( BMesh * bm,
const char htype,
int elem_offset[4] )

◆ BM_mesh_elem_index_validate()

void BM_mesh_elem_index_validate ( BMesh * bm,
const char * location,
const char * func,
const char * msg_a,
const char * msg_b )

Array checking/setting macros.

Currently vert/edge/loop/face index data is being abused, in a few areas of the code.

To avoid correcting them afterwards, set 'bm->elem_index_dirty' however its possible this flag is set incorrectly which could crash blender.

Functions that calls this function may depend on dirty indices on being set.

This is read-only, so it can be used for assertions that don't impact behavior.

Definition at line 462 of file bmesh_mesh.cc.

References bm, BM_EDGE, BM_EDGES_OF_MESH, BM_elem_index_get, BM_FACE, BM_FACES_OF_MESH, BM_ITER_MESH, BM_VERT, BM_VERTS_OF_MESH, and i.

◆ BM_mesh_elem_table_check()

bool BM_mesh_elem_table_check ( BMesh * bm)
See also
BM_mesh_elem_index_validate the same rationale applies to this function.

Definition at line 535 of file bmesh_mesh.cc.

References bm, BM_EDGE, BM_EDGES_OF_MESH, BM_FACE, BM_FACES_OF_MESH, BM_ITER_MESH_INDEX, BM_VERT, BM_VERTS_OF_MESH, and i.

Referenced by BM_mesh_elem_table_ensure(), and EDBM_update().

◆ BM_mesh_elem_table_ensure()

void BM_mesh_elem_table_ensure ( BMesh * bm,
const char htype )

Definition at line 569 of file bmesh_mesh.cc.

References BLI_assert, bm, BM_ALL_NOLOOP, BM_EDGE, BM_EDGES_OF_MESH, BM_FACE, BM_FACES_OF_MESH, BM_iter_as_array(), BM_mesh_elem_table_check(), BM_VERT, BM_VERTS_OF_MESH, MEM_freeN(), and MEM_mallocN().

Referenced by bm_mesh_calc_uv_islands(), BM_mesh_elem_table_init(), BM_mesh_intersect(), BM_mesh_intersect_edges(), BM_mesh_remap(), blender::draw::bmesh_normals_domain(), bmo_recalc_face_normals_exec(), bpy_bmelemseq_ensure_lookup_table(), blender::ed::spreadsheet::calc_mesh_selection_mask(), blender::ed::spreadsheet::calc_mesh_selection_mask_faces(), construct_param_handle_subsurfed(), blender::ed::sculpt_paint::face_set::delete_geometry(), ED_mesh_mirror_spatial_table_begin(), ED_mesh_mirrtopo_init(), ED_transverts_create_from_obedit(), edbm_face_split_by_edges_exec(), EDBM_select_interior_faces(), edbm_select_similar_region_exec(), EDBM_verts_mirror_cache_begin_ex(), blender::draw::edit_select::Instance::edit_mesh_sync(), blender::ed::object::get_vert_def_nr(), give_parvert(), blender::ed::sculpt_paint::expand::init_from_face_set_boundary(), loopcut_init(), math_layer_info_init(), blender::geometry::boolean::mesh_bm_concat(), mesh_foreachScreenEdge(), mesh_foreachScreenEdge_clip_bb_segment(), mesh_foreachScreenFace(), mesh_foreachScreenVert(), blender::draw::mesh_render_data_create(), mesh_symmetry_snap_exec(), multires_unsubdivide_extract_grids(), multires_unsubdivide_prepare_original_bmesh_for_extract(), multires_unsubdivide_single_level(), stitch_init(), blender::ed::transform::transform_convert_mesh_islands_calc(), uv_select_linked_multi(), uv_select_overlap(), blender::ed::sculpt_paint::vert_random_access_ensure(), blender::ed::object::vgroup_parray_mirror_assign(), blender::ed::object::vgroup_parray_mirror_sync(), and blender::ed::object::vgroup_smooth_subset().

◆ BM_mesh_elem_table_free()

void BM_mesh_elem_table_free ( BMesh * bm,
const char htype )

Definition at line 647 of file bmesh_mesh.cc.

References bm, BM_EDGE, BM_FACE, BM_VERT, and MEM_SAFE_FREE.

Referenced by BM_mesh_elem_table_init().

◆ BM_mesh_elem_table_init()

void BM_mesh_elem_table_init ( BMesh * bm,
const char htype )

◆ BM_mesh_elem_toolflags_clear()

void BM_mesh_elem_toolflags_clear ( BMesh * bm)

Definition at line 116 of file bmesh_mesh.cc.

References BLI_mempool_destroy(), and bm.

Referenced by BM_mesh_data_free(), and select_linked_delimit_end().

◆ BM_mesh_elem_toolflags_ensure()

◆ BM_mesh_free()

◆ BM_mesh_rebuild()

void BM_mesh_rebuild ( BMesh * bm,
const BMeshCreateParams * params,
BLI_mempool * vpool,
BLI_mempool * epool,
BLI_mempool * lpool,
BLI_mempool * fpool )

◆ BM_mesh_remap()

void BM_mesh_remap ( BMesh * bm,
const uint * vert_idx,
const uint * edge_idx,
const uint * face_idx )

Remaps the vertices, edges and/or faces of the bmesh as indicated by vert/edge/face_idx arrays (xxx_idx[org_index] = new_index).

A NULL array means no changes.

Note
  • Does not mess with indices, just sets elem_index_dirty flag.
  • For verts/edges/faces only (as loops must remain "ordered" and "aligned" on a per-face basis...).
Warning
Be careful if you keep pointers to affected BM elements, or arrays, when using this func!

Definition at line 740 of file bmesh_mesh.cc.

References BLI_assert, BLI_ghash_free(), BLI_ghash_insert(), BLI_ghash_lookup(), BLI_ghash_ptr_new_ex(), bm, BM_EDGE, BM_EDGES_OF_MESH, BM_ELEM_CD_GET_VOID_P, BM_FACE, BM_FACES_OF_MESH, BM_ITER_ELEM, BM_ITER_MESH, BM_LOOP, BM_LOOPS_OF_FACE, BM_mesh_elem_table_ensure(), BM_VERT, BM_VERTS_OF_MESH, CD_BM_ELEM_PYPTR, CustomData_get_offset(), BMLoop::e, BMVert::e, BMLoop::f, i, LISTBASE_FOREACH, MEM_freeN(), MEM_malloc_arrayN(), BMDiskLink::next, BMDiskLink::prev, printf, BMLoop::v, BMEdge::v1, BMEdge::v1_disk_link, BMEdge::v2, and BMEdge::v2_disk_link.

Referenced by bpy_bmelemseq_sort(), and sort_bmelem_flag().

◆ BM_mesh_toolflags_set()

void BM_mesh_toolflags_set ( BMesh * bm,
bool use_toolflags )

Re-allocates mesh data with/without toolflags.

Definition at line 1291 of file bmesh_mesh.cc.

References BLI_mempool_destroy(), bm, bm_mempool_init_ex(), BM_mesh_rebuild(), BMALLOC_TEMPLATE_FROM_BM, and params.

Referenced by blender::ed::sculpt_paint::symmetrize_exec().

◆ BM_mesh_vert_coords_alloc()

◆ BM_mesh_vert_coords_apply()

void BM_mesh_vert_coords_apply ( BMesh * bm,
const Span< float3 > vert_coords )

Definition at line 1353 of file bmesh_mesh.cc.

References bm, BM_ITER_MESH_INDEX, BM_VERTS_OF_MESH, copy_v3_v3(), i, and v.

Referenced by blender::ed::object::data_xform_restore().

◆ BM_mesh_vert_coords_apply_with_mat4()

void BM_mesh_vert_coords_apply_with_mat4 ( BMesh * bm,
const Span< float3 > vert_coords,
const float4x4 & transform )

◆ BM_mesh_vert_coords_get()

◆ BM_mesh_vert_normals_get()

void BM_mesh_vert_normals_get ( BMesh * bm,
MutableSpan< float3 > normals )

◆ BM_vert_at_index_find()

BMVert * BM_vert_at_index_find ( BMesh * bm,
const int index )

◆ BM_vert_at_index_find_or_table()

BMVert * BM_vert_at_index_find_or_table ( BMesh * bm,
int index )

Use lookup table when available, else use slower find functions.

Note
Try to use BM_mesh_elem_table_ensure instead.

Definition at line 698 of file bmesh_mesh.cc.

References bm, BM_VERT, and BM_vert_at_index_find().

Referenced by EDBM_elem_from_index_any(), edbm_select_id_bm_elem_get(), and EDBM_vert_find_nearest_ex().

◆ bmesh_edit_begin()

void bmesh_edit_begin ( BMesh * bm,
BMOpTypeFlag type_flag )

BMesh Begin Edit.

Functions for setting up a mesh for editing and cleaning up after the editing operations are done. These are called by the tools/operator API for each time a tool is executed.

Definition at line 282 of file bmesh_mesh.cc.

References bm, BM_mesh_normals_update(), BMO_OPTYPE_FLAG_UNTAN_MULTIRES, CD_MDISPS, and CustomData_has_layer().

Referenced by BMO_op_exec(), build_skin(), and blender::ed::transform::mesh_customdatacorrect_init_container_generic().

◆ bmesh_edit_end()

Variable Documentation

◆ bm_mesh_allocsize_default

◆ bm_mesh_chunksize_default

const BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512}

Definition at line 31 of file bmesh_mesh.cc.

Referenced by bm_mempool_init_ex(), and CustomData_bmesh_init_pool().