2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Geoffrey Bantle.
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/bmesh/intern/bmesh_mesh.c
26 * BM mesh level functions.
29 #include "MEM_guardedalloc.h"
31 #include "DNA_listBase.h"
32 #include "DNA_object_types.h"
34 #include "BLI_listbase.h"
36 #include "BLI_utildefines.h"
38 #include "BKE_cdderivedmesh.h"
39 #include "BKE_tessmesh.h"
40 #include "BKE_multires.h"
44 #include "intern/bmesh_private.h"
46 /* used as an extern, defined in bmesh.h */
47 BMAllocTemplate bm_mesh_allocsize_default = {512, 1024, 2048, 512};
48 BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512};
50 static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
52 bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize->totvert, bm_mesh_chunksize_default.totvert, BLI_MEMPOOL_ALLOW_ITER);
53 bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge, bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER);
54 bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop, bm_mesh_chunksize_default.totloop, 0);
55 bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface, bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER);
57 #ifdef USE_BMESH_HOLES
58 bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), allocsize[3], allocsize[3], FALSE, FALSE);
61 /* allocate one flag pool that we don't get rid of. */
62 bm->toolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), 512, 512, 0);
66 * \brief BMesh Make Mesh
68 * Allocates a new BMesh structure.
70 * \return The New bmesh
72 * \note ob is needed by multires
74 BMesh *BM_mesh_create(BMAllocTemplate *allocsize)
76 /* allocate the structure */
77 BMesh *bm = MEM_callocN(sizeof(BMesh), __func__);
79 /* allocate the memory pools for the mesh elements */
80 bm_mempool_init(bm, allocsize);
82 /* allocate one flag pool that we don't get rid of. */
90 * \brief BMesh Free Mesh Data
92 * Frees a BMesh structure.
94 * \note frees mesh, but not actual BMesh struct
96 void BM_mesh_data_free(BMesh *bm)
107 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
108 CustomData_bmesh_free_block(&(bm->vdata), &(v->head.data));
110 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
111 CustomData_bmesh_free_block(&(bm->edata), &(e->head.data));
113 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
114 CustomData_bmesh_free_block(&(bm->pdata), &(f->head.data));
115 BM_ITER_ELEM (l, &itersub, f, BM_LOOPS_OF_FACE) {
116 CustomData_bmesh_free_block(&(bm->ldata), &(l->head.data));
120 /* Free custom data pools, This should probably go in CustomData_free? */
121 if (bm->vdata.totlayer) BLI_mempool_destroy(bm->vdata.pool);
122 if (bm->edata.totlayer) BLI_mempool_destroy(bm->edata.pool);
123 if (bm->ldata.totlayer) BLI_mempool_destroy(bm->ldata.pool);
124 if (bm->pdata.totlayer) BLI_mempool_destroy(bm->pdata.pool);
126 /* free custom data */
127 CustomData_free(&bm->vdata, 0);
128 CustomData_free(&bm->edata, 0);
129 CustomData_free(&bm->ldata, 0);
130 CustomData_free(&bm->pdata, 0);
132 /* destroy element pools */
133 BLI_mempool_destroy(bm->vpool);
134 BLI_mempool_destroy(bm->epool);
135 BLI_mempool_destroy(bm->lpool);
136 BLI_mempool_destroy(bm->fpool);
138 /* destroy flag pool */
139 BLI_mempool_destroy(bm->toolflagpool);
141 #ifdef USE_BMESH_HOLES
142 BLI_mempool_destroy(bm->looplistpool);
145 /* These tables aren't used yet, so it's not strictly necessary
146 * to 'end' them (with 'e' param) but if someone tries to start
147 * using them, having these in place will save a lot of pain */
148 mesh_octree_table(NULL, NULL, NULL, 'e');
149 mesh_mirrtopo_table(NULL, 'e');
151 BLI_freelistN(&bm->selected);
157 * \brief BMesh Clear Mesh
159 * Clear all data in bm
161 void BM_mesh_clear(BMesh *bm)
164 BM_mesh_data_free(bm);
165 memset(bm, 0, sizeof(BMesh));
167 /* allocate the memory pools for the mesh elements */
168 bm_mempool_init(bm, &bm_mesh_allocsize_default);
175 * \brief BMesh Free Mesh
177 * Frees a BMesh data and its structure.
179 void BM_mesh_free(BMesh *bm)
181 BM_mesh_data_free(bm);
184 /* keep this out of 'BM_mesh_data_free' because we wan't python
185 * to be able to clear the mesh and maintain access. */
186 extern void bpy_bm_generic_invalidate(void *self);
188 bpy_bm_generic_invalidate(bm->py_handle);
189 bm->py_handle = NULL;
196 * \brief BMesh Compute Normals
198 * Updates the normals of a mesh.
200 void BM_mesh_normals_update(BMesh *bm, const short skip_hidden)
213 /* calculate all face normals */
214 BM_ITER_MESH (f, &faces, bm, BM_FACES_OF_MESH) {
215 if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
218 if (f->head.flag & BM_NONORMCALC)
222 BM_face_normal_update(f);
225 /* Zero out vertex normals */
226 BM_ITER_MESH (v, &verts, bm, BM_VERTS_OF_MESH) {
227 if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
233 /* compute normalized direction vectors for each edge. directions will be
234 * used below for calculating the weights of the face normals on the vertex
237 edgevec = MEM_callocN(sizeof(float) * 3 * bm->totedge, "BM normal computation array");
238 BM_ITER_MESH (e, &edges, bm, BM_EDGES_OF_MESH) {
239 BM_elem_index_set(e, index); /* set_inline */
242 sub_v3_v3v3(edgevec[index], e->v2->co, e->v1->co);
243 normalize_v3(edgevec[index]);
246 /* the edge vector will not be needed when the edge has no radial */
251 bm->elem_index_dirty &= ~BM_EDGE;
253 /* add weighted face normals to vertices */
254 BM_ITER_MESH (f, &faces, bm, BM_FACES_OF_MESH) {
256 if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
259 BM_ITER_ELEM (l, &loops, f, BM_LOOPS_OF_FACE) {
260 float *e1diff, *e2diff;
264 /* calculate the dot product of the two edges that
265 * meet at the loop's vertex */
266 e1diff = edgevec[BM_elem_index_get(l->prev->e)];
267 e2diff = edgevec[BM_elem_index_get(l->e)];
268 dotprod = dot_v3v3(e1diff, e2diff);
270 /* edge vectors are calculated from e->v1 to e->v2, so
271 * adjust the dot product if one but not both loops
272 * actually runs from from e->v2 to e->v1 */
273 if ((l->prev->e->v1 == l->prev->v) ^ (l->e->v1 == l->v)) {
277 fac = saacos(-dotprod);
279 /* accumulate weighted face normal into the vertex's normal */
280 madd_v3_v3fl(l->v->no, f->no, fac);
284 /* normalize the accumulated vertex normals */
285 BM_ITER_MESH (v, &verts, bm, BM_VERTS_OF_MESH) {
286 if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
289 if (normalize_v3(v->no) == 0.0f) {
290 normalize_v3_v3(v->no, v->co);
298 * This function ensures correct normals for the mesh, but
299 * sets the flag BM_ELEM_TAG in flipped faces, to allow restoration
300 * of original normals.
302 * if undo is 0: calculate right normals
303 * if undo is 1: restore original normals
306 //keep in sycn with utils.c!
308 static void bm_rationalize_normals(BMesh *bm, int undo)
315 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
316 if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
317 BM_face_normal_flip(bm, f);
319 BM_elem_flag_disable(f, BM_ELEM_TAG);
325 BMO_op_initf(bm, &bmop, "righthandfaces faces=%af do_flip=%b", FALSE);
328 bmo_righthandfaces_exec(bm, &bmop);
330 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
331 BM_elem_flag_set(f, BM_ELEM_TAG, BMO_elem_flag_test(bm, f, FACE_FLIP));
335 BMO_op_finish(bm, &bmop);
338 static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to)
340 /* switch multires data out of tangent space */
341 if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
342 BMEditMesh *em = BMEdit_Create(bm, FALSE);
343 DerivedMesh *dm = CDDM_from_BMEditMesh(em, NULL, TRUE, FALSE);
347 // int i = 0; // UNUSED
349 multires_set_space(dm, ob, from, to);
351 mdisps = CustomData_get_layer(&dm->loopData, CD_MDISPS);
353 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
356 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
357 MDisps *lmd = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MDISPS);
360 printf("%s: warning - 'lmd->disps' == NULL\n", __func__);
363 if (lmd->disps && lmd->totdisp == mdisps->totdisp) {
364 memcpy(lmd->disps, mdisps->disps, sizeof(float) * 3 * lmd->totdisp);
366 else if (mdisps->disps) {
368 MEM_freeN(lmd->disps);
370 lmd->disps = MEM_dupallocN(mdisps->disps);
371 lmd->totdisp = mdisps->totdisp;
372 lmd->level = mdisps->level;
383 /* setting this to NULL prevents BMEdit_Free from freeing it */
391 * \brief BMesh Begin Edit
393 * Functions for setting up a mesh for editing and cleaning up after
394 * the editing operations are done. These are called by the tools/operator
395 * API for each time a tool is executed.
397 void bmesh_edit_begin(BMesh *bm, int flag)
401 /* Most operators seem to be using BMO_OP_FLAG_UNTAN_MULTIRES to change the MDisps to
402 * absolute space during mesh edits. With this enabled, changes to the topology
403 * (loop cuts, edge subdivides, etc) are not reflected in the higher levels of
404 * the mesh at all, which doesn't seem right. Turning off completely for now,
405 * until this is shown to be better for certain types of mesh edits. */
406 #if BMOP_UNTAN_MULTIRES_ENABLED
407 /* switch multires data out of tangent space */
408 if ((flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
409 bmesh_mdisps_space_set(bm, MULTIRES_SPACE_TANGENT, MULTIRES_SPACE_ABSOLUTE);
411 /* ensure correct normals, if possible */
412 bmesh_rationalize_normals(bm, 0);
413 BM_mesh_normals_update(bm);
415 else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
416 bmesh_rationalize_normals(bm, 0);
419 if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
420 bm_rationalize_normals(bm, 0);
426 * \brief BMesh End Edit
428 void bmesh_edit_end(BMesh *bm, int flag)
430 /* BMO_OP_FLAG_UNTAN_MULTIRES disabled for now, see comment above in bmesh_edit_begin. */
431 #if BMOP_UNTAN_MULTIRES_ENABLED
432 /* switch multires data into tangent space */
433 if ((flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
434 /* set normals to their previous winding */
435 bmesh_rationalize_normals(bm, 1);
436 bmesh_mdisps_space_set(bm, MULTIRES_SPACE_ABSOLUTE, MULTIRES_SPACE_TANGENT);
438 else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
439 bmesh_rationalize_normals(bm, 1);
442 if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
443 bm_rationalize_normals(bm, 1);
449 /* compute normals, clear temp flags and flush selections */
450 BM_mesh_normals_update(bm, TRUE);
451 BM_mesh_select_mode_flush(bm);
454 void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag)
460 BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__);
463 if (hflag & BM_VERT) {
464 if (bm->elem_index_dirty & BM_VERT) {
466 BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
467 BM_elem_index_set(ele, index); /* set_ok */
470 bm->elem_index_dirty &= ~BM_VERT;
471 BLI_assert(index == bm->totvert);
474 // printf("%s: skipping vert index calc!\n", __func__);
478 if (hflag & BM_EDGE) {
479 if (bm->elem_index_dirty & BM_EDGE) {
481 BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
482 BM_elem_index_set(ele, index); /* set_ok */
485 bm->elem_index_dirty &= ~BM_EDGE;
486 BLI_assert(index == bm->totedge);
489 // printf("%s: skipping edge index calc!\n", __func__);
493 if (hflag & BM_FACE) {
494 if (bm->elem_index_dirty & BM_FACE) {
496 BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
497 BM_elem_index_set(ele, index); /* set_ok */
500 bm->elem_index_dirty &= ~BM_FACE;
501 BLI_assert(index == bm->totface);
504 // printf("%s: skipping face index calc!\n", __func__);
511 * Array checking/setting macros
513 * Currently vert/edge/loop/face index data is being abused, in a few areas of the code.
515 * To avoid correcting them afterwards, set 'bm->elem_index_dirty' however its possible
516 * this flag is set incorrectly which could crash blender.
518 * These functions ensure its correct and are called more often in debug mode.
521 void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *func,
522 const char *msg_a, const char *msg_b)
524 const char iter_types[3] = {BM_VERTS_OF_MESH,
528 const char flag_types[3] = {BM_VERT, BM_EDGE, BM_FACE};
529 const char *type_names[3] = {"vert", "edge", "face"};
534 int is_any_error = 0;
536 for (i = 0; i < 3; i++) {
537 const int is_dirty = (flag_types[i] & bm->elem_index_dirty);
539 int is_error = FALSE;
543 BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
545 if (BM_elem_index_get(ele) != index) {
546 err_val = BM_elem_index_get(ele);
552 BM_elem_index_set(ele, index); /* set_ok */
556 if ((is_error == TRUE) && (is_dirty == FALSE)) {
559 "Invalid Index: at %s, %s, %s[%d] invalid index %d, '%s', '%s'\n",
560 location, func, type_names[i], err_idx, err_val, msg_a, msg_b);
562 else if ((is_error == FALSE) && (is_dirty == TRUE)) {
564 #if 0 /* mostly annoying */
566 /* dirty may have been incorrectly set */
568 "Invalid Dirty: at %s, %s (%s), dirty flag was set but all index values are correct, '%s', '%s'\n",
569 location, func, type_names[i], msg_a, msg_b);
574 #if 0 /* mostly annoying, even in debug mode */
576 if (is_any_error == 0) {
578 "Valid Index Success: at %s, %s, '%s', '%s'\n",
579 location, func, msg_a, msg_b);
583 (void) is_any_error; /* shut up the compiler */
588 * Return the amount of element of type 'type' in a given bmesh.
590 int BM_mesh_elem_count(BMesh *bm, const char htype)
592 if (htype == BM_VERT) return bm->totvert;
593 else if (htype == BM_EDGE) return bm->totedge;
594 else if (htype == BM_FACE) return bm->totface;
600 * Remaps the vertices, edges and/or faces of the bmesh as indicated by vert/edge/face_idx arrays
601 * (xxx_idx[org_index] = new_index).
603 * A NULL array means no changes.
605 * Note: - Does not mess with indices, just sets elem_index_dirty flag.
606 * - For verts/edges/faces only (as loops must remain "ordered" and "aligned"
607 * on a per-face basis...).
609 * WARNING: Be careful if you keep pointers to affected BM elements, or arrays, when using this func!
611 void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx)
613 /* Mapping old to new pointers. */
614 GHash *vptr_map = NULL, *eptr_map = NULL, *fptr_map = NULL;
621 if (!(vert_idx || edge_idx || face_idx))
626 BMVert **verts_pool, *verts_copy, **vep;
627 int i, totvert = bm->totvert;
630 /* Init the old-to-new vert pointers mapping */
631 vptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap vert pointers mapping");
633 /* Make a copy of all vertices. */
634 verts_pool = MEM_callocN(sizeof(BMVert *) * totvert, "BM_mesh_remap verts pool");
635 BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)verts_pool, totvert);
636 verts_copy = MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy");
637 for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) {
639 /* printf("*vep: %p, verts_pool[%d]: %p\n", *vep, i, verts_pool[i]);*/
642 /* Copy back verts to their new place, and update old2new pointers mapping. */
643 new_idx = vert_idx + totvert - 1;
644 ve = verts_copy + totvert - 1;
645 vep = verts_pool + totvert - 1; /* old, org pointer */
646 for (i = totvert; i--; new_idx--, ve--, vep--) {
647 BMVert *new_vep = verts_pool[*new_idx];
649 /* printf("mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);*/
650 BLI_ghash_insert(vptr_map, (void *)*vep, (void *)new_vep);
652 bm->elem_index_dirty |= BM_VERT;
654 MEM_freeN(verts_pool);
655 MEM_freeN(verts_copy);
658 /* XXX Code not tested yet (though I don't why it would fail)! */
660 BMEdge **edges_pool, *edges_copy, **edp;
661 int i, totedge = bm->totedge;
664 /* Init the old-to-new vert pointers mapping */
665 eptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap edge pointers mapping");
667 /* Make a copy of all vertices. */
668 edges_pool = MEM_callocN(sizeof(BMEdge *) * totedge, "BM_mesh_remap edges pool");
669 BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)edges_pool, totedge);
670 edges_copy = MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy");
671 for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) {
675 /* Copy back verts to their new place, and update old2new pointers mapping. */
676 new_idx = edge_idx + totedge - 1;
677 ed = edges_copy + totedge - 1;
678 edp = edges_pool + totedge - 1; /* old, org pointer */
679 for (i = totedge; i--; new_idx--, ed--, edp--) {
680 BMEdge *new_edp = edges_pool[*new_idx];
682 BLI_ghash_insert(eptr_map, (void *)*edp, (void *)new_edp);
685 bm->elem_index_dirty |= BM_EDGE;
687 MEM_freeN(edges_pool);
688 MEM_freeN(edges_copy);
691 /* XXX Code not tested yet (though I don't why it would fail)! */
693 BMFace **faces_pool, *faces_copy, **fap;
694 int i, totface = bm->totface;
697 /* Init the old-to-new vert pointers mapping */
698 fptr_map = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "BM_mesh_remap face pointers mapping");
700 /* Make a copy of all vertices. */
701 faces_pool = MEM_callocN(sizeof(BMFace *) * totface, "BM_mesh_remap faces pool");
702 BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)faces_pool, totface);
703 faces_copy = MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy");
704 for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) {
708 /* Copy back verts to their new place, and update old2new pointers mapping. */
709 new_idx = face_idx + totface - 1;
710 fa = faces_copy + totface - 1;
711 fap = faces_pool + totface - 1; /* old, org pointer */
712 for (i = totface; i--; new_idx--, fa--, fap--) {
713 BMFace *new_fap = faces_pool[*new_idx];
715 BLI_ghash_insert(fptr_map, (void *)*fap, (void *)new_fap);
718 bm->elem_index_dirty |= BM_FACE;
720 MEM_freeN(faces_pool);
721 MEM_freeN(faces_copy);
724 /* And now, fix all vertices/edges/faces/loops pointers! */
725 /* Verts' pointers, only edge pointers... */
727 BM_ITER_MESH (ve, &iter, bm, BM_VERTS_OF_MESH) {
728 /* printf("Vert e: %p -> %p\n", ve->e, BLI_ghash_lookup(eptr_map, (const void*)ve->e));*/
729 ve->e = BLI_ghash_lookup(eptr_map, (const void *)ve->e);
733 /* Edges' pointers, only vert pointers (as we don't mess with loops!)... */
735 BM_ITER_MESH (ed, &iter, bm, BM_EDGES_OF_MESH) {
736 /* printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, (const void*)ed->v1));*/
737 /* printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, (const void*)ed->v2));*/
738 ed->v1 = BLI_ghash_lookup(vptr_map, (const void *)ed->v1);
739 ed->v2 = BLI_ghash_lookup(vptr_map, (const void *)ed->v2);
743 /* Faces' pointers (loops, in fact), always needed... */
744 BM_ITER_MESH (fa, &iter, bm, BM_FACES_OF_MESH) {
745 BM_ITER_ELEM (lo, &iterl, fa, BM_LOOPS_OF_FACE) {
747 /* printf("Loop v: %p -> %p\n", lo->v, BLI_ghash_lookup(vptr_map, (const void*)lo->v));*/
748 lo->v = BLI_ghash_lookup(vptr_map, (const void *)lo->v);
751 /* printf("Loop e: %p -> %p\n", lo->e, BLI_ghash_lookup(eptr_map, (const void*)lo->e));*/
752 lo->e = BLI_ghash_lookup(eptr_map, (const void *)lo->e);
755 /* printf("Loop f: %p -> %p\n", lo->f, BLI_ghash_lookup(fptr_map, (const void*)lo->f));*/
756 lo->f = BLI_ghash_lookup(fptr_map, (const void *)lo->f);
762 BLI_ghash_free(vptr_map, NULL, NULL);
764 BLI_ghash_free(eptr_map, NULL, NULL);
766 BLI_ghash_free(fptr_map, NULL, NULL);
769 BMVert *BM_vert_at_index(BMesh *bm, const int index)
771 return BLI_mempool_findelem(bm->vpool, index);
774 BMEdge *BM_edge_at_index(BMesh *bm, const int index)
776 return BLI_mempool_findelem(bm->epool, index);
779 BMFace *BM_face_at_index(BMesh *bm, const int index)
781 return BLI_mempool_findelem(bm->fpool, index);