Blender V4.3
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 "BLI_utildefines.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)   vtable_dst[BM_elem_index_get(ele)]
 
#define MAP_EDGE(ele)   etable_dst[BM_elem_index_get(ele)]
 
#define MAP_LOOP(ele)   ltable_dst[BM_elem_index_get(ele)]
 
#define MAP_FACE(ele)   ftable_dst[BM_elem_index_get(ele)]
 
#define REMAP_VERT(ele)
 
#define REMAP_EDGE(ele)
 
#define REMAP_LOOP(ele)
 
#define REMAP_FACE(ele)
 

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 float(*vert_coords)[3])
 
void BM_mesh_vert_coords_apply_with_mat4 (BMesh *bm, const float(*vert_coords)[3], const float mat[4][4])
 

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)    etable_dst[BM_elem_index_get(ele)]

Referenced by BM_mesh_rebuild().

◆ MAP_FACE

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

Referenced by BM_mesh_rebuild().

◆ MAP_LOOP

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

◆ MAP_VERT

#define MAP_VERT ( ele)    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().

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

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

◆ bm_mempool_init_ex()

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

◆ BM_mesh_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 456 of file bmesh_mesh.cc.

References bm, and BM_mesh_elem_index_ensure_ex().

Referenced by armature_deform_coords_impl(), BKE_bmbvh_new_ex(), BKE_editmesh_cache_ensure_face_centers(), BKE_editmesh_cache_ensure_face_normals(), BKE_editmesh_cache_ensure_vert_normals(), BKE_editmesh_loop_tangent_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(), bm_loop_normal_mark_indiv(), BM_mesh_calc_path_edge(), 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_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_validate(), 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(), blender::ed::sculpt_paint::filter::calc_sharpen_filter(), blender::ed::sculpt_paint::calc_smooth_translations(), calc_solidify_normals(), blender::ed::sculpt_paint::islands::calc_topology_islands_bmesh(), construct_param_handle(), construct_param_handle_subsurfed(), blender::ed::sculpt_paint::do_smooth_brush(), blender::ed::sculpt_paint::do_smooth_mask_brush(), blender::ed::sculpt_paint::do_surface_smooth_brush(), 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(), blender::ed::sculpt_paint::cloth::ensure_nodes_constraints(), 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(), mesh_partial_ensure(), blender::draw::mesh_render_data_create(), blender::ed::sculpt_paint::mask::sculpt_mask_filter_exec(), SCULPT_stroke_get_location_ex(), SCULPT_vertex_random_access_ensure(), solidify_add_thickness(), blender::draw::statvis_calc_intersect(), blender::draw::statvis_calc_thickness(), stitch_process_data(), transform_convert_mesh_islands_calc(), uv_find_nearest_edge(), uv_find_nearest_vert(), uv_select_overlap(), uv_set_connectivity_distance(), uv_shortest_path_pick_invoke(), and blender::ed::object::vgroup_smooth_subset().

◆ BM_mesh_elem_index_ensure_ex()

◆ 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 461 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 BMesh::elem_index_dirty.

◆ BM_mesh_elem_table_check()

bool BM_mesh_elem_table_check ( BMesh * bm)

◆ BM_mesh_elem_table_ensure()

void BM_mesh_elem_table_ensure ( BMesh * bm,
const char htype )

Definition at line 568 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, BMesh::elem_table_dirty, BMesh::etable, BMesh::etable_tot, BMesh::ftable, BMesh::ftable_tot, MEM_freeN(), MEM_mallocN, BMesh::totedge, BMesh::totface, BMesh::totvert, BMesh::vtable, and BMesh::vtable_tot.

Referenced by blender::ed::spreadsheet::GeometryDataSource::apply_selection_filter(), 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::sculpt_paint::calc_smooth_translations(), construct_param_handle_subsurfed(), blender::ed::sculpt_paint::face_set::delete_geometry(), blender::ed::sculpt_paint::do_smooth_brush(), blender::ed::sculpt_paint::do_smooth_mask_brush(), draw_select_id_edit_mesh(), blender::ed::sculpt_paint::mask::duplicate_mask(), blender::ed::sculpt_paint::hide::duplicate_visibility_bmesh(), 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::ed::sculpt_paint::cloth::ensure_nodes_constraints(), 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(), blender::ed::sculpt_paint::expand::sculpt_expand_invoke(), SCULPT_stroke_get_location_ex(), SCULPT_vertex_random_access_ensure(), stitch_init(), transform_convert_mesh_islands_calc(), blender::nodes::node_geo_triangulate_cc::triangulate_mesh_selection(), uv_select_flush_from_loop_edge_flag(), uv_select_flush_from_tag_face(), uv_select_flush_from_tag_loop(), uv_select_linked_multi(), uv_select_overlap(), blender::ed::object::vgroup_parray_mirror_assign(), blender::ed::object::vgroup_parray_mirror_sync(), blender::ed::object::vgroup_smooth_subset(), and blender::ed::sculpt_paint::expand::write_mask_data().

◆ BM_mesh_elem_table_free()

void BM_mesh_elem_table_free ( BMesh * bm,
const char htype )

Definition at line 646 of file bmesh_mesh.cc.

References bm, BM_EDGE, BM_FACE, BM_VERT, BMesh::etable, BMesh::ftable, MEM_SAFE_FREE, and BMesh::vtable.

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)

◆ BM_mesh_elem_toolflags_ensure()

◆ BM_mesh_free()

◆ BM_mesh_rebuild()

◆ 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 739 of file bmesh_mesh.cc.

References BMesh::act_face, 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, BMesh::edata, BMesh::elem_index_dirty, BMesh::elem_table_dirty, BMesh::etable, BMLoop::f, BMesh::ftable, LISTBASE_FOREACH, MEM_freeN(), MEM_mallocN, BMDiskLink::next, BMesh::pdata, BMDiskLink::prev, printf, BMesh::selected, BMesh::totedge, BMesh::totface, BMesh::totvert, BMLoop::v, BMEdge::v1, BMEdge::v1_disk_link, BMEdge::v2, BMEdge::v2_disk_link, BMesh::vdata, and BMesh::vtable.

Referenced by BM_log_mesh_elems_reorder(), bpy_bmelemseq_sort(), and sort_bmelem_flag().

◆ BM_mesh_toolflags_set()

void BM_mesh_toolflags_set ( BMesh * bm,
bool use_toolflags )

◆ BM_mesh_vert_coords_alloc()

◆ BM_mesh_vert_coords_apply()

void BM_mesh_vert_coords_apply ( BMesh * bm,
const float(*) vert_coords[3] )

◆ BM_mesh_vert_coords_apply_with_mat4()

void BM_mesh_vert_coords_apply_with_mat4 ( BMesh * bm,
const float(*) vert_coords[3],
const float mat[4][4] )

◆ 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 697 of file bmesh_mesh.cc.

References bm, BM_VERT, BM_vert_at_index_find(), BMesh::elem_table_dirty, and BMesh::vtable.

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 281 of file bmesh_mesh.cc.

References bm, BM_mesh_normals_update(), BMO_OPTYPE_FLAG_UNTAN_MULTIRES, CD_MDISPS, CustomData_has_layer(), and BMesh::ldata.

Referenced by BMO_op_exec(), build_skin(), and 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 30 of file bmesh_mesh.cc.

Referenced by bm_mempool_init_ex(), and CustomData_bmesh_init_pool().