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"
42 #include "intern/bmesh_private.h"
44 /* used as an extern, defined in bmesh.h */
45 const BMAllocTemplate bm_mesh_allocsize_default = {512, 1024, 2048, 512};
46 const BMAllocTemplate bm_mesh_chunksize_default = {512, 1024, 2048, 512};
48 static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
50 bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize->totvert,
51 bm_mesh_chunksize_default.totvert, BLI_MEMPOOL_ALLOW_ITER);
52 bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge,
53 bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER);
54 bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop,
55 bm_mesh_chunksize_default.totloop, 0);
56 bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface,
57 bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER);
59 #ifdef USE_BMESH_HOLES
60 bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, 0);
64 void BM_mesh_elem_toolflags_ensure(BMesh *bm)
66 if (bm->vtoolflagpool && bm->etoolflagpool && bm->ftoolflagpool) {
70 bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totvert), 512, 0);
71 bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totedge), 512, 0);
72 bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totface), 512, 0);
74 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
78 BLI_mempool *toolflagpool = bm->vtoolflagpool;
81 BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
82 ele->oflags = BLI_mempool_calloc(toolflagpool);
87 BLI_mempool *toolflagpool = bm->etoolflagpool;
90 BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
91 ele->oflags = BLI_mempool_calloc(toolflagpool);
96 BLI_mempool *toolflagpool = bm->ftoolflagpool;
99 BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
100 ele->oflags = BLI_mempool_calloc(toolflagpool);
109 void BM_mesh_elem_toolflags_clear(BMesh *bm)
111 if (bm->vtoolflagpool) {
112 BLI_mempool_destroy(bm->vtoolflagpool);
113 bm->vtoolflagpool = NULL;
115 if (bm->etoolflagpool) {
116 BLI_mempool_destroy(bm->etoolflagpool);
117 bm->etoolflagpool = NULL;
119 if (bm->ftoolflagpool) {
120 BLI_mempool_destroy(bm->ftoolflagpool);
121 bm->ftoolflagpool = NULL;
126 * \brief BMesh Make Mesh
128 * Allocates a new BMesh structure.
130 * \return The New bmesh
132 * \note ob is needed by multires
134 BMesh *BM_mesh_create(const BMAllocTemplate *allocsize)
136 /* allocate the structure */
137 BMesh *bm = MEM_callocN(sizeof(BMesh), __func__);
139 /* allocate the memory pools for the mesh elements */
140 bm_mempool_init(bm, allocsize);
142 /* allocate one flag pool that we don't get rid of. */
146 CustomData_reset(&bm->vdata);
147 CustomData_reset(&bm->edata);
148 CustomData_reset(&bm->ldata);
149 CustomData_reset(&bm->pdata);
155 * \brief BMesh Free Mesh Data
157 * Frees a BMesh structure.
159 * \note frees mesh, but not actual BMesh struct
161 void BM_mesh_data_free(BMesh *bm)
172 BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
173 CustomData_bmesh_free_block(&(bm->vdata), &(v->head.data));
175 BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
176 CustomData_bmesh_free_block(&(bm->edata), &(e->head.data));
178 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
179 CustomData_bmesh_free_block(&(bm->pdata), &(f->head.data));
180 BM_ITER_ELEM (l, &itersub, f, BM_LOOPS_OF_FACE) {
181 CustomData_bmesh_free_block(&(bm->ldata), &(l->head.data));
185 /* Free custom data pools, This should probably go in CustomData_free? */
186 if (bm->vdata.totlayer) BLI_mempool_destroy(bm->vdata.pool);
187 if (bm->edata.totlayer) BLI_mempool_destroy(bm->edata.pool);
188 if (bm->ldata.totlayer) BLI_mempool_destroy(bm->ldata.pool);
189 if (bm->pdata.totlayer) BLI_mempool_destroy(bm->pdata.pool);
191 /* free custom data */
192 CustomData_free(&bm->vdata, 0);
193 CustomData_free(&bm->edata, 0);
194 CustomData_free(&bm->ldata, 0);
195 CustomData_free(&bm->pdata, 0);
197 /* destroy element pools */
198 BLI_mempool_destroy(bm->vpool);
199 BLI_mempool_destroy(bm->epool);
200 BLI_mempool_destroy(bm->lpool);
201 BLI_mempool_destroy(bm->fpool);
203 /* destroy flag pool */
204 BM_mesh_elem_toolflags_clear(bm);
206 #ifdef USE_BMESH_HOLES
207 BLI_mempool_destroy(bm->looplistpool);
210 BLI_freelistN(&bm->selected);
216 * \brief BMesh Clear Mesh
218 * Clear all data in bm
220 void BM_mesh_clear(BMesh *bm)
223 BM_mesh_data_free(bm);
224 memset(bm, 0, sizeof(BMesh));
226 /* allocate the memory pools for the mesh elements */
227 bm_mempool_init(bm, &bm_mesh_allocsize_default);
232 CustomData_reset(&bm->vdata);
233 CustomData_reset(&bm->edata);
234 CustomData_reset(&bm->ldata);
235 CustomData_reset(&bm->pdata);
239 * \brief BMesh Free Mesh
241 * Frees a BMesh data and its structure.
243 void BM_mesh_free(BMesh *bm)
245 BM_mesh_data_free(bm);
248 /* keep this out of 'BM_mesh_data_free' because we want python
249 * to be able to clear the mesh and maintain access. */
250 bpy_bm_generic_invalidate(bm->py_handle);
251 bm->py_handle = NULL;
258 * \brief BMesh Compute Normals
260 * Updates the normals of a mesh.
262 void BM_mesh_normals_update(BMesh *bm, const bool skip_hidden)
275 /* calculate all face normals */
276 BM_ITER_MESH (f, &faces, bm, BM_FACES_OF_MESH) {
277 if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
280 if (f->head.flag & BM_NONORMCALC)
284 BM_face_normal_update(f);
287 /* Zero out vertex normals */
288 BM_ITER_MESH (v, &verts, bm, BM_VERTS_OF_MESH) {
289 if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
295 /* compute normalized direction vectors for each edge. directions will be
296 * used below for calculating the weights of the face normals on the vertex
299 edgevec = MEM_callocN(sizeof(float) * 3 * bm->totedge, "BM normal computation array");
300 BM_ITER_MESH (e, &edges, bm, BM_EDGES_OF_MESH) {
301 BM_elem_index_set(e, index); /* set_inline */
304 sub_v3_v3v3(edgevec[index], e->v2->co, e->v1->co);
305 normalize_v3(edgevec[index]);
308 /* the edge vector will not be needed when the edge has no radial */
313 bm->elem_index_dirty &= ~BM_EDGE;
315 /* add weighted face normals to vertices */
316 BM_ITER_MESH (f, &faces, bm, BM_FACES_OF_MESH) {
318 if (skip_hidden && BM_elem_flag_test(f, BM_ELEM_HIDDEN))
321 BM_ITER_ELEM (l, &loops, f, BM_LOOPS_OF_FACE) {
322 float *e1diff, *e2diff;
326 /* calculate the dot product of the two edges that
327 * meet at the loop's vertex */
328 e1diff = edgevec[BM_elem_index_get(l->prev->e)];
329 e2diff = edgevec[BM_elem_index_get(l->e)];
330 dotprod = dot_v3v3(e1diff, e2diff);
332 /* edge vectors are calculated from e->v1 to e->v2, so
333 * adjust the dot product if one but not both loops
334 * actually runs from from e->v2 to e->v1 */
335 if ((l->prev->e->v1 == l->prev->v) ^ (l->e->v1 == l->v)) {
339 fac = saacos(-dotprod);
341 /* accumulate weighted face normal into the vertex's normal */
342 madd_v3_v3fl(l->v->no, f->no, fac);
346 /* normalize the accumulated vertex normals */
347 BM_ITER_MESH (v, &verts, bm, BM_VERTS_OF_MESH) {
348 if (skip_hidden && BM_elem_flag_test(v, BM_ELEM_HIDDEN))
351 if (UNLIKELY(normalize_v3(v->no) == 0.0f)) {
352 normalize_v3_v3(v->no, v->co);
359 static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to)
361 /* switch multires data out of tangent space */
362 if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
363 BMEditMesh *em = BMEdit_Create(bm, false);
364 DerivedMesh *dm = CDDM_from_editbmesh(em, true, false);
368 // int i = 0; // UNUSED
370 multires_set_space(dm, ob, from, to);
372 mdisps = CustomData_get_layer(&dm->loopData, CD_MDISPS);
374 BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
377 BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
378 MDisps *lmd = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_MDISPS);
381 printf("%s: warning - 'lmd->disps' == NULL\n", __func__);
384 if (lmd->disps && lmd->totdisp == mdisps->totdisp) {
385 memcpy(lmd->disps, mdisps->disps, sizeof(float) * 3 * lmd->totdisp);
387 else if (mdisps->disps) {
389 MEM_freeN(lmd->disps);
391 lmd->disps = MEM_dupallocN(mdisps->disps);
392 lmd->totdisp = mdisps->totdisp;
393 lmd->level = mdisps->level;
404 /* setting this to NULL prevents BMEdit_Free from freeing it */
412 * \brief BMesh Begin Edit
414 * Functions for setting up a mesh for editing and cleaning up after
415 * the editing operations are done. These are called by the tools/operator
416 * API for each time a tool is executed.
418 void bmesh_edit_begin(BMesh *UNUSED(bm), int UNUSED(type_flag))
420 /* Most operators seem to be using BMO_OP_FLAG_UNTAN_MULTIRES to change the MDisps to
421 * absolute space during mesh edits. With this enabled, changes to the topology
422 * (loop cuts, edge subdivides, etc) are not reflected in the higher levels of
423 * the mesh at all, which doesn't seem right. Turning off completely for now,
424 * until this is shown to be better for certain types of mesh edits. */
425 #ifdef BMOP_UNTAN_MULTIRES_ENABLED
426 /* switch multires data out of tangent space */
427 if ((type_flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
428 bmesh_mdisps_space_set(bm, MULTIRES_SPACE_TANGENT, MULTIRES_SPACE_ABSOLUTE);
430 /* ensure correct normals, if possible */
431 bmesh_rationalize_normals(bm, 0);
432 BM_mesh_normals_update(bm);
438 * \brief BMesh End Edit
440 void bmesh_edit_end(BMesh *bm, int UNUSED(flag))
442 /* BMO_OP_FLAG_UNTAN_MULTIRES disabled for now, see comment above in bmesh_edit_begin. */
443 #ifdef BMOP_UNTAN_MULTIRES_ENABLED
444 /* switch multires data into tangent space */
445 if ((flag & BMO_OP_FLAG_UNTAN_MULTIRES) && CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
446 /* set normals to their previous winding */
447 bmesh_rationalize_normals(bm, 1);
448 bmesh_mdisps_space_set(bm, MULTIRES_SPACE_ABSOLUTE, MULTIRES_SPACE_TANGENT);
450 else if (flag & BMO_OP_FLAG_RATIONALIZE_NORMALS) {
451 bmesh_rationalize_normals(bm, 1);
455 /* compute normals, clear temp flags and flush selections */
456 BM_mesh_normals_update(bm, true);
457 BM_mesh_select_mode_flush(bm);
460 void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag)
463 BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__);
466 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
470 if (hflag & BM_VERT) {
471 if (bm->elem_index_dirty & BM_VERT) {
476 BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, index) {
477 BM_elem_index_set(ele, index); /* set_ok */
479 BLI_assert(index == bm->totvert);
482 // printf("%s: skipping vert index calc!\n", __func__);
489 if (hflag & BM_EDGE) {
490 if (bm->elem_index_dirty & BM_EDGE) {
495 BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, index) {
496 BM_elem_index_set(ele, index); /* set_ok */
498 BLI_assert(index == bm->totedge);
501 // printf("%s: skipping edge index calc!\n", __func__);
508 if (hflag & BM_FACE) {
509 if (bm->elem_index_dirty & BM_FACE) {
514 BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, index) {
515 BM_elem_index_set(ele, index); /* set_ok */
517 BLI_assert(index == bm->totface);
520 // printf("%s: skipping face index calc!\n", __func__);
526 bm->elem_index_dirty &= ~hflag;
531 * Array checking/setting macros
533 * Currently vert/edge/loop/face index data is being abused, in a few areas of the code.
535 * To avoid correcting them afterwards, set 'bm->elem_index_dirty' however its possible
536 * this flag is set incorrectly which could crash blender.
538 * These functions ensure its correct and are called more often in debug mode.
541 void BM_mesh_elem_index_validate(BMesh *bm, const char *location, const char *func,
542 const char *msg_a, const char *msg_b)
544 const char iter_types[3] = {BM_VERTS_OF_MESH,
548 const char flag_types[3] = {BM_VERT, BM_EDGE, BM_FACE};
549 const char *type_names[3] = {"vert", "edge", "face"};
554 bool is_any_error = 0;
556 for (i = 0; i < 3; i++) {
557 const bool is_dirty = (flag_types[i] & bm->elem_index_dirty);
559 bool is_error = false;
563 BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
565 if (BM_elem_index_get(ele) != index) {
566 err_val = BM_elem_index_get(ele);
572 BM_elem_index_set(ele, index); /* set_ok */
576 if ((is_error == true) && (is_dirty == false)) {
579 "Invalid Index: at %s, %s, %s[%d] invalid index %d, '%s', '%s'\n",
580 location, func, type_names[i], err_idx, err_val, msg_a, msg_b);
582 else if ((is_error == false) && (is_dirty == true)) {
584 #if 0 /* mostly annoying */
586 /* dirty may have been incorrectly set */
588 "Invalid Dirty: at %s, %s (%s), dirty flag was set but all index values are correct, '%s', '%s'\n",
589 location, func, type_names[i], msg_a, msg_b);
594 #if 0 /* mostly annoying, even in debug mode */
596 if (is_any_error == 0) {
598 "Valid Index Success: at %s, %s, '%s', '%s'\n",
599 location, func, msg_a, msg_b);
603 (void) is_any_error; /* shut up the compiler */
608 * Return the amount of element of type 'type' in a given bmesh.
610 int BM_mesh_elem_count(BMesh *bm, const char htype)
612 if (htype == BM_VERT) return bm->totvert;
613 else if (htype == BM_EDGE) return bm->totedge;
614 else if (htype == BM_FACE) return bm->totface;
620 * Remaps the vertices, edges and/or faces of the bmesh as indicated by vert/edge/face_idx arrays
621 * (xxx_idx[org_index] = new_index).
623 * A NULL array means no changes.
625 * Note: - Does not mess with indices, just sets elem_index_dirty flag.
626 * - For verts/edges/faces only (as loops must remain "ordered" and "aligned"
627 * on a per-face basis...).
629 * WARNING: Be careful if you keep pointers to affected BM elements, or arrays, when using this func!
631 void BM_mesh_remap(BMesh *bm, int *vert_idx, int *edge_idx, int *face_idx)
633 /* Mapping old to new pointers. */
634 GHash *vptr_map = NULL, *eptr_map = NULL, *fptr_map = NULL;
641 if (!(vert_idx || edge_idx || face_idx))
646 BMVert **verts_pool, *verts_copy, **vep;
647 int i, totvert = bm->totvert;
650 /* Init the old-to-new vert pointers mapping */
651 vptr_map = BLI_ghash_ptr_new("BM_mesh_remap vert pointers mapping");
653 /* Make a copy of all vertices. */
654 verts_pool = MEM_callocN(sizeof(BMVert *) * totvert, "BM_mesh_remap verts pool");
655 BM_iter_as_array(bm, BM_VERTS_OF_MESH, NULL, (void **)verts_pool, totvert);
656 verts_copy = MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy");
657 for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) {
659 /* printf("*vep: %p, verts_pool[%d]: %p\n", *vep, i, verts_pool[i]);*/
662 /* Copy back verts to their new place, and update old2new pointers mapping. */
663 new_idx = vert_idx + totvert - 1;
664 ve = verts_copy + totvert - 1;
665 vep = verts_pool + totvert - 1; /* old, org pointer */
666 for (i = totvert; i--; new_idx--, ve--, vep--) {
667 BMVert *new_vep = verts_pool[*new_idx];
669 /* printf("mapping vert from %d to %d (%p/%p to %p)\n", i, *new_idx, *vep, verts_pool[i], new_vep);*/
670 BLI_ghash_insert(vptr_map, (void *)*vep, (void *)new_vep);
672 bm->elem_index_dirty |= BM_VERT;
674 MEM_freeN(verts_pool);
675 MEM_freeN(verts_copy);
678 /* XXX Code not tested yet (though I don't why it would fail)! */
680 BMEdge **edges_pool, *edges_copy, **edp;
681 int i, totedge = bm->totedge;
684 /* Init the old-to-new vert pointers mapping */
685 eptr_map = BLI_ghash_ptr_new("BM_mesh_remap edge pointers mapping");
687 /* Make a copy of all vertices. */
688 edges_pool = MEM_callocN(sizeof(BMEdge *) * totedge, "BM_mesh_remap edges pool");
689 BM_iter_as_array(bm, BM_EDGES_OF_MESH, NULL, (void **)edges_pool, totedge);
690 edges_copy = MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy");
691 for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) {
695 /* Copy back verts to their new place, and update old2new pointers mapping. */
696 new_idx = edge_idx + totedge - 1;
697 ed = edges_copy + totedge - 1;
698 edp = edges_pool + totedge - 1; /* old, org pointer */
699 for (i = totedge; i--; new_idx--, ed--, edp--) {
700 BMEdge *new_edp = edges_pool[*new_idx];
702 BLI_ghash_insert(eptr_map, (void *)*edp, (void *)new_edp);
703 /* printf("mapping edge from %d to %d (%p/%p to %p)\n", i, *new_idx, *edp, edges_pool[i], new_edp);*/
705 bm->elem_index_dirty |= BM_EDGE;
707 MEM_freeN(edges_pool);
708 MEM_freeN(edges_copy);
711 /* XXX Code not tested yet (though I don't why it would fail)! */
713 BMFace **faces_pool, *faces_copy, **fap;
714 int i, totface = bm->totface;
717 /* Init the old-to-new vert pointers mapping */
718 fptr_map = BLI_ghash_ptr_new("BM_mesh_remap face pointers mapping");
720 /* Make a copy of all vertices. */
721 faces_pool = MEM_callocN(sizeof(BMFace *) * totface, "BM_mesh_remap faces pool");
722 BM_iter_as_array(bm, BM_FACES_OF_MESH, NULL, (void **)faces_pool, totface);
723 faces_copy = MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy");
724 for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) {
728 /* Copy back verts to their new place, and update old2new pointers mapping. */
729 new_idx = face_idx + totface - 1;
730 fa = faces_copy + totface - 1;
731 fap = faces_pool + totface - 1; /* old, org pointer */
732 for (i = totface; i--; new_idx--, fa--, fap--) {
733 BMFace *new_fap = faces_pool[*new_idx];
735 BLI_ghash_insert(fptr_map, (void *)*fap, (void *)new_fap);
738 bm->elem_index_dirty |= BM_FACE;
740 MEM_freeN(faces_pool);
741 MEM_freeN(faces_copy);
744 /* And now, fix all vertices/edges/faces/loops pointers! */
745 /* Verts' pointers, only edge pointers... */
747 BM_ITER_MESH (ve, &iter, bm, BM_VERTS_OF_MESH) {
748 /* printf("Vert e: %p -> %p\n", ve->e, BLI_ghash_lookup(eptr_map, (const void *)ve->e));*/
749 ve->e = BLI_ghash_lookup(eptr_map, (const void *)ve->e);
753 /* Edges' pointers, only vert pointers (as we don't mess with loops!), and - ack! - edge pointers,
754 * as we have to handle disklinks... */
755 if (vptr_map || eptr_map) {
756 BM_ITER_MESH (ed, &iter, bm, BM_EDGES_OF_MESH) {
758 /* printf("Edge v1: %p -> %p\n", ed->v1, BLI_ghash_lookup(vptr_map, (const void *)ed->v1));*/
759 /* printf("Edge v2: %p -> %p\n", ed->v2, BLI_ghash_lookup(vptr_map, (const void *)ed->v2));*/
760 ed->v1 = BLI_ghash_lookup(vptr_map, (const void *)ed->v1);
761 ed->v2 = BLI_ghash_lookup(vptr_map, (const void *)ed->v2);
764 /* printf("Edge v1_disk_link prev: %p -> %p\n", ed->v1_disk_link.prev,*/
765 /* BLI_ghash_lookup(eptr_map, (const void *)ed->v1_disk_link.prev));*/
766 /* printf("Edge v1_disk_link next: %p -> %p\n", ed->v1_disk_link.next,*/
767 /* BLI_ghash_lookup(eptr_map, (const void *)ed->v1_disk_link.next));*/
768 /* printf("Edge v2_disk_link prev: %p -> %p\n", ed->v2_disk_link.prev,*/
769 /* BLI_ghash_lookup(eptr_map, (const void *)ed->v2_disk_link.prev));*/
770 /* printf("Edge v2_disk_link next: %p -> %p\n", ed->v2_disk_link.next,*/
771 /* BLI_ghash_lookup(eptr_map, (const void *)ed->v2_disk_link.next));*/
772 ed->v1_disk_link.prev = BLI_ghash_lookup(eptr_map, (const void *)ed->v1_disk_link.prev);
773 ed->v1_disk_link.next = BLI_ghash_lookup(eptr_map, (const void *)ed->v1_disk_link.next);
774 ed->v2_disk_link.prev = BLI_ghash_lookup(eptr_map, (const void *)ed->v2_disk_link.prev);
775 ed->v2_disk_link.next = BLI_ghash_lookup(eptr_map, (const void *)ed->v2_disk_link.next);
780 /* Faces' pointers (loops, in fact), always needed... */
781 BM_ITER_MESH (fa, &iter, bm, BM_FACES_OF_MESH) {
782 BM_ITER_ELEM (lo, &iterl, fa, BM_LOOPS_OF_FACE) {
784 /* printf("Loop v: %p -> %p\n", lo->v, BLI_ghash_lookup(vptr_map, (const void *)lo->v));*/
785 lo->v = BLI_ghash_lookup(vptr_map, (const void *)lo->v);
788 /* printf("Loop e: %p -> %p\n", lo->e, BLI_ghash_lookup(eptr_map, (const void *)lo->e));*/
789 lo->e = BLI_ghash_lookup(eptr_map, (const void *)lo->e);
792 /* printf("Loop f: %p -> %p\n", lo->f, BLI_ghash_lookup(fptr_map, (const void *)lo->f));*/
793 lo->f = BLI_ghash_lookup(fptr_map, (const void *)lo->f);
799 BLI_ghash_free(vptr_map, NULL, NULL);
801 BLI_ghash_free(eptr_map, NULL, NULL);
803 BLI_ghash_free(fptr_map, NULL, NULL);
806 BMVert *BM_vert_at_index(BMesh *bm, const int index)
808 return BLI_mempool_findelem(bm->vpool, index);
811 BMEdge *BM_edge_at_index(BMesh *bm, const int index)
813 return BLI_mempool_findelem(bm->epool, index);
816 BMFace *BM_face_at_index(BMesh *bm, const int index)
818 return BLI_mempool_findelem(bm->fpool, index);