Blender  V3.3
bmesh_mesh_convert.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
72 #include "DNA_key_types.h"
73 #include "DNA_mesh_types.h"
74 #include "DNA_meshdata_types.h"
75 #include "DNA_modifier_types.h"
76 #include "DNA_object_types.h"
77 
78 #include "MEM_guardedalloc.h"
79 
80 #include "BLI_alloca.h"
81 #include "BLI_array.hh"
82 #include "BLI_index_range.hh"
83 #include "BLI_listbase.h"
84 #include "BLI_math_vector.h"
85 #include "BLI_span.hh"
86 
87 #include "BKE_customdata.h"
88 #include "BKE_mesh.h"
89 #include "BKE_mesh_runtime.h"
90 #include "BKE_multires.h"
91 
92 #include "BKE_key.h"
93 #include "BKE_main.h"
94 
95 #include "DEG_depsgraph_query.h"
96 
97 #include "bmesh.h"
98 #include "intern/bmesh_private.h" /* For element checking. */
99 
100 #include "CLG_log.h"
101 
102 static CLG_LogRef LOG = {"bmesh.mesh.convert"};
103 
104 using blender::Array;
105 using blender::IndexRange;
106 using blender::Span;
107 
108 void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
109 {
110  const char cd_flag_all = BM_mesh_cd_flag_from_bmesh(bm) | cd_flag;
111  BM_mesh_cd_flag_apply(bm, cd_flag_all);
112  if (mesh) {
113  mesh->cd_flag = cd_flag_all;
114  }
115 }
116 
117 void BM_mesh_cd_flag_apply(BMesh *bm, const char cd_flag)
118 {
119  /* CustomData_bmesh_init_pool() must run first */
120  BLI_assert(bm->vdata.totlayer == 0 || bm->vdata.pool != nullptr);
121  BLI_assert(bm->edata.totlayer == 0 || bm->edata.pool != nullptr);
122  BLI_assert(bm->pdata.totlayer == 0 || bm->pdata.pool != nullptr);
123 
124  if (cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
127  }
128  }
129  else {
132  }
133  }
134 
135  if (cd_flag & ME_CDFLAG_VERT_CREASE) {
138  }
139  }
140  else {
143  }
144  }
145 
146  if (cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
149  }
150  }
151  else {
154  }
155  }
156 
157  if (cd_flag & ME_CDFLAG_EDGE_CREASE) {
160  }
161  }
162  else {
165  }
166  }
167 }
168 
170 {
171  char cd_flag = 0;
173  cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
174  }
176  cd_flag |= ME_CDFLAG_VERT_CREASE;
177  }
179  cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
180  }
182  cd_flag |= ME_CDFLAG_EDGE_CREASE;
183  }
184  return cd_flag;
185 }
186 
187 /* Static function for alloc (duplicate in modifiers_bmesh.c) */
189  Span<MLoop> loops,
190  Span<BMVert *> vtable,
191  Span<BMEdge *> etable)
192 {
195 
196  for (const int i : loops.index_range()) {
197  verts[i] = vtable[loops[i].v];
198  edges[i] = etable[loops[i].e];
199  }
200 
201  return BM_face_create(&bm, verts.data(), edges.data(), loops.size(), nullptr, BM_CREATE_SKIP_CD);
202 }
203 
204 void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params)
205 {
206  const bool is_new = !(bm->totvert || (bm->vdata.totlayer || bm->edata.totlayer ||
207  bm->pdata.totlayer || bm->ldata.totlayer));
208  KeyBlock *actkey;
209  float(*keyco)[3] = nullptr;
211  CustomData_MeshMasks_update(&mask, &params->cd_mask_extra);
212 
213  if (!me || !me->totvert) {
214  if (me && is_new) { /* No verts? still copy custom-data layout. */
215  CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_DEFAULT, 0);
216  CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_DEFAULT, 0);
217  CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_DEFAULT, 0);
218  CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_DEFAULT, 0);
219 
224  }
225  return; /* Sanity check. */
226  }
227 
228  const float(*vert_normals)[3] = nullptr;
229  if (params->calc_vert_normal) {
230  vert_normals = BKE_mesh_vertex_normals_ensure(me);
231  }
232 
233  if (is_new) {
234  CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, 0);
235  CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_CALLOC, 0);
236  CustomData_copy(&me->ldata, &bm->ldata, mask.lmask, CD_CALLOC, 0);
237  CustomData_copy(&me->pdata, &bm->pdata, mask.pmask, CD_CALLOC, 0);
238  }
239  else {
244  }
245 
246  /* -------------------------------------------------------------------- */
247  /* Shape Key */
248  int tot_shape_keys = 0;
249  if (me->key != nullptr && DEG_is_original_id(&me->id)) {
250  /* Evaluated meshes can be topologically inconsistent with their shape keys.
251  * Shape keys are also already integrated into the state of the evaluated
252  * mesh, so considering them here would kind of apply them twice. */
253  tot_shape_keys = BLI_listbase_count(&me->key->block);
254 
255  /* Original meshes must never contain a shape-key custom-data layers.
256  *
257  * This may happen if and object's mesh data is accidentally
258  * set to the output from the modifier stack, causing it to be an "original" ID,
259  * even though the data isn't fully compatible (hence this assert).
260  *
261  * This results in:
262  * - The newly created #BMesh having twice the number of custom-data layers.
263  * - When converting the #BMesh back to a regular mesh,
264  * At least one of the extra shape-key blocks will be created in #Mesh.key
265  * depending on the value of #CustomDataLayer.uid.
266  *
267  * We could support mixing both kinds of data if there is a compelling use-case for it.
268  * At the moment it's simplest to assume all original meshes use the key-block and meshes
269  * that are evaluated (through the modifier stack for example) use custom-data layers.
270  */
272  }
273  if (is_new == false) {
274  tot_shape_keys = min_ii(tot_shape_keys, CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY));
275  }
276  const float(**shape_key_table)[3] = tot_shape_keys ? (const float(**)[3])BLI_array_alloca(
277  shape_key_table, tot_shape_keys) :
278  nullptr;
279 
280  if ((params->active_shapekey != 0) && tot_shape_keys > 0) {
281  actkey = static_cast<KeyBlock *>(BLI_findlink(&me->key->block, params->active_shapekey - 1));
282  }
283  else {
284  actkey = nullptr;
285  }
286 
287  if (is_new) {
288  if (tot_shape_keys || params->add_key_index) {
290  }
291  }
292 
293  if (tot_shape_keys) {
294  if (is_new) {
295  /* Check if we need to generate unique ids for the shape-keys.
296  * This also exists in the file reading code, but is here for a sanity check. */
297  if (!me->key->uidgen) {
298  fprintf(stderr,
299  "%s had to generate shape key uid's in a situation we shouldn't need to! "
300  "(bmesh internal error)\n",
301  __func__);
302 
303  me->key->uidgen = 1;
304  LISTBASE_FOREACH (KeyBlock *, block, &me->key->block) {
305  block->uid = me->key->uidgen++;
306  }
307  }
308  }
309 
310  if (actkey && actkey->totelem == me->totvert) {
311  keyco = params->use_shapekey ? static_cast<float(*)[3]>(actkey->data) : nullptr;
312  if (is_new) {
313  bm->shapenr = params->active_shapekey;
314  }
315  }
316 
317  int i;
318  KeyBlock *block;
319  for (i = 0, block = static_cast<KeyBlock *>(me->key->block.first); i < tot_shape_keys;
320  block = block->next, i++) {
321  if (is_new) {
322  CustomData_add_layer_named(&bm->vdata, CD_SHAPEKEY, CD_ASSIGN, nullptr, 0, block->name);
324  bm->vdata.layers[j].uid = block->uid;
325  }
326  shape_key_table[i] = static_cast<const float(*)[3]>(block->data);
327  }
328  }
329 
330  if (is_new) {
335  }
337 
338  /* Only copy these values over if the source mesh is flagged to be using them.
339  * Even if `bm` has these layers, they may have been added from another mesh, when `!is_new`. */
340  const int cd_vert_bweight_offset = (me->cd_flag & ME_CDFLAG_VERT_BWEIGHT) ?
342  -1;
343  const int cd_edge_bweight_offset = (me->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) ?
345  -1;
346  const int cd_edge_crease_offset = (me->cd_flag & ME_CDFLAG_EDGE_CREASE) ?
348  -1;
349  const int cd_shape_key_offset = tot_shape_keys ? CustomData_get_offset(&bm->vdata, CD_SHAPEKEY) :
350  -1;
351  const int cd_shape_keyindex_offset = is_new && (tot_shape_keys || params->add_key_index) ?
353  -1;
354 
355  Span<MVert> mvert{me->mvert, me->totvert};
356  Array<BMVert *> vtable(me->totvert);
357  for (const int i : mvert.index_range()) {
358  BMVert *v = vtable[i] = BM_vert_create(
359  bm, keyco ? keyco[i] : mvert[i].co, nullptr, BM_CREATE_SKIP_CD);
360  BM_elem_index_set(v, i); /* set_ok */
361 
362  /* Transfer flag. */
363  v->head.hflag = BM_vert_flag_from_mflag(mvert[i].flag & ~SELECT);
364 
365  /* This is necessary for selection counts to work properly. */
366  if (mvert[i].flag & SELECT) {
367  BM_vert_select_set(bm, v, true);
368  }
369 
370  if (vert_normals) {
371  copy_v3_v3(v->no, vert_normals[i]);
372  }
373 
374  /* Copy Custom Data */
375  CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data, true);
376 
377  if (cd_vert_bweight_offset != -1) {
378  BM_ELEM_CD_SET_FLOAT(v, cd_vert_bweight_offset, (float)mvert[i].bweight / 255.0f);
379  }
380 
381  /* Set shape key original index. */
382  if (cd_shape_keyindex_offset != -1) {
383  BM_ELEM_CD_SET_INT(v, cd_shape_keyindex_offset, i);
384  }
385 
386  /* Set shape-key data. */
387  if (tot_shape_keys) {
388  float(*co_dst)[3] = (float(*)[3])BM_ELEM_CD_GET_VOID_P(v, cd_shape_key_offset);
389  for (int j = 0; j < tot_shape_keys; j++, co_dst++) {
390  copy_v3_v3(*co_dst, shape_key_table[j][i]);
391  }
392  }
393  }
394  if (is_new) {
395  bm->elem_index_dirty &= ~BM_VERT; /* Added in order, clear dirty flag. */
396  }
397 
398  Span<MEdge> medge{me->medge, me->totedge};
399  Array<BMEdge *> etable(me->totedge);
400  for (const int i : medge.index_range()) {
401  BMEdge *e = etable[i] = BM_edge_create(
402  bm, vtable[medge[i].v1], vtable[medge[i].v2], nullptr, BM_CREATE_SKIP_CD);
403  BM_elem_index_set(e, i); /* set_ok */
404 
405  /* Transfer flags. */
406  e->head.hflag = BM_edge_flag_from_mflag(medge[i].flag & ~SELECT);
407 
408  /* This is necessary for selection counts to work properly. */
409  if (medge[i].flag & SELECT) {
410  BM_edge_select_set(bm, e, true);
411  }
412 
413  /* Copy Custom Data */
414  CustomData_to_bmesh_block(&me->edata, &bm->edata, i, &e->head.data, true);
415 
416  if (cd_edge_bweight_offset != -1) {
417  BM_ELEM_CD_SET_FLOAT(e, cd_edge_bweight_offset, (float)medge[i].bweight / 255.0f);
418  }
419  if (cd_edge_crease_offset != -1) {
420  BM_ELEM_CD_SET_FLOAT(e, cd_edge_crease_offset, (float)medge[i].crease / 255.0f);
421  }
422  }
423  if (is_new) {
424  bm->elem_index_dirty &= ~BM_EDGE; /* Added in order, clear dirty flag. */
425  }
426 
427  Span<MPoly> mpoly{me->mpoly, me->totpoly};
428  Span<MLoop> mloop{me->mloop, me->totloop};
429 
430  /* Only needed for selection. */
431 
432  Array<BMFace *> ftable;
433  if (me->mselect && me->totselect != 0) {
434  ftable.reinitialize(me->totpoly);
435  }
436 
437  int totloops = 0;
438  for (const int i : mpoly.index_range()) {
440  *bm, mloop.slice(mpoly[i].loopstart, mpoly[i].totloop), vtable, etable);
441  if (!ftable.is_empty()) {
442  ftable[i] = f;
443  }
444 
445  if (UNLIKELY(f == nullptr)) {
446  printf(
447  "%s: Warning! Bad face in mesh"
448  " \"%s\" at index %d!, skipping\n",
449  __func__,
450  me->id.name + 2,
451  i);
452  continue;
453  }
454 
455  /* Don't use 'i' since we may have skipped the face. */
456  BM_elem_index_set(f, bm->totface - 1); /* set_ok */
457 
458  /* Transfer flag. */
459  f->head.hflag = BM_face_flag_from_mflag(mpoly[i].flag & ~ME_FACE_SEL);
460 
461  /* This is necessary for selection counts to work properly. */
462  if (mpoly[i].flag & ME_FACE_SEL) {
463  BM_face_select_set(bm, f, true);
464  }
465 
466  f->mat_nr = mpoly[i].mat_nr;
467  if (i == me->act_face) {
468  bm->act_face = f;
469  }
470 
471  int j = mpoly[i].loopstart;
472  BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
473  BMLoop *l_iter = l_first;
474  do {
475  /* Don't use 'j' since we may have skipped some faces, hence some loops. */
476  BM_elem_index_set(l_iter, totloops++); /* set_ok */
477 
478  /* Save index of corresponding #MLoop. */
479  CustomData_to_bmesh_block(&me->ldata, &bm->ldata, j++, &l_iter->head.data, true);
480  } while ((l_iter = l_iter->next) != l_first);
481 
482  /* Copy Custom Data */
483  CustomData_to_bmesh_block(&me->pdata, &bm->pdata, i, &f->head.data, true);
484 
485  if (params->calc_face_normal) {
487  }
488  }
489  if (is_new) {
490  bm->elem_index_dirty &= ~(BM_FACE | BM_LOOP); /* Added in order, clear dirty flag. */
491  }
492 
493  /* -------------------------------------------------------------------- */
494  /* MSelect clears the array elements (to avoid adding multiple times).
495  *
496  * Take care to keep this last and not use (v/e/ftable) after this.
497  */
498 
499  if (me->mselect && me->totselect != 0) {
500  for (const int i : IndexRange(me->totselect)) {
501  const MSelect &msel = me->mselect[i];
502 
503  BMElem **ele_p;
504  switch (msel.type) {
505  case ME_VSEL:
506  ele_p = (BMElem **)&vtable[msel.index];
507  break;
508  case ME_ESEL:
509  ele_p = (BMElem **)&etable[msel.index];
510  break;
511  case ME_FSEL:
512  ele_p = (BMElem **)&ftable[msel.index];
513  break;
514  default:
515  continue;
516  }
517 
518  if (*ele_p != nullptr) {
520  *ele_p = nullptr;
521  }
522  }
523  }
524  else {
526  }
527 }
528 
532 static BMVert **bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
533 {
534  const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX);
535  BMVert **vertMap = nullptr;
536  BMVert *eve;
537  int i = 0;
538  BMIter iter;
539 
540  /* Caller needs to ensure this. */
541  BLI_assert(ototvert > 0);
542 
543  vertMap = static_cast<BMVert **>(MEM_callocN(sizeof(*vertMap) * ototvert, "vertMap"));
544  if (cd_shape_keyindex_offset != -1) {
545  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
546  const int keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset);
547  if ((keyi != ORIGINDEX_NONE) && (keyi < ototvert) &&
548  /* Not fool-proof, but chances are if we have many verts with the same index,
549  * we will want to use the first one,
550  * since the second is more likely to be a duplicate. */
551  (vertMap[keyi] == nullptr)) {
552  vertMap[keyi] = eve;
553  }
554  }
555  }
556  else {
557  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
558  if (i < ototvert) {
559  vertMap[i] = eve;
560  }
561  else {
562  break;
563  }
564  }
565  }
566 
567  return vertMap;
568 }
569 
570 /* -------------------------------------------------------------------- */
656 {
657  int i;
658  int j = 0;
659 
660  for (i = 0; i < bm->vdata.totlayer; i++) {
661  if (bm->vdata.layers[i].type == CD_SHAPEKEY) {
662  if (currkey->uid == bm->vdata.layers[i].uid) {
663  return j;
664  }
665  j++;
666  }
667  }
668  return -1;
669 }
670 
683 static void bm_to_mesh_shape(BMesh *bm,
684  Key *key,
685  MVert *mvert,
686  const bool active_shapekey_to_mvert)
687 {
688  KeyBlock *actkey = static_cast<KeyBlock *>(BLI_findlink(&key->block, bm->shapenr - 1));
689 
690  /* It's unlikely this ever remains false, check for correctness. */
691  bool actkey_has_layer = false;
692 
693  /* Go through and find any shape-key custom-data layers
694  * that might not have corresponding KeyBlocks, and add them if necessary. */
695  for (int i = 0; i < bm->vdata.totlayer; i++) {
696  if (bm->vdata.layers[i].type != CD_SHAPEKEY) {
697  continue;
698  }
699 
700  KeyBlock *currkey;
701  for (currkey = (KeyBlock *)key->block.first; currkey; currkey = currkey->next) {
702  if (currkey->uid == bm->vdata.layers[i].uid) {
703  break;
704  }
705  }
706 
707  if (currkey) {
708  if (currkey == actkey) {
709  actkey_has_layer = true;
710  }
711  }
712  else {
713  currkey = BKE_keyblock_add(key, bm->vdata.layers[i].name);
714  currkey->uid = bm->vdata.layers[i].uid;
715  }
716  }
717 
718  const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX);
719  BMIter iter;
720  BMVert *eve;
721  float(*ofs)[3] = nullptr;
722 
723  /* Editing the basis key updates others. */
724  if ((key->type == KEY_RELATIVE) &&
725  /* The shape-key coordinates used from entering edit-mode are used. */
726  (actkey_has_layer == true) &&
727  /* Original key-indices are only used to check the vertex existed when entering edit-mode. */
728  (cd_shape_keyindex_offset != -1) &&
729  /* Offsets are only needed if the current shape is a basis for others. */
730  BKE_keyblock_is_basis(key, bm->shapenr - 1)) {
731 
732  BLI_assert(actkey != nullptr); /* Assured by `actkey_has_layer` check. */
733  const int actkey_uuid = bm_to_mesh_shape_layer_index_from_kb(bm, actkey);
734 
735  /* Since `actkey_has_layer == true`, this must never fail. */
736  BLI_assert(actkey_uuid != -1);
737 
738  const int cd_shape_offset = CustomData_get_n_offset(&bm->vdata, CD_SHAPEKEY, actkey_uuid);
739 
740  ofs = static_cast<float(*)[3]>(MEM_mallocN(sizeof(float[3]) * bm->totvert, __func__));
741  int i;
742  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
743  const int keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset);
744  /* Check the vertex existed when entering edit-mode (otherwise don't apply an offset). */
745  if (keyi != ORIGINDEX_NONE) {
746  float *co_orig = (float *)BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset);
747  /* Could use 'eve->co' or the destination #MVert.co, they're the same at this point. */
748  sub_v3_v3v3(ofs[i], eve->co, co_orig);
749  }
750  else {
751  /* If there are new vertices in the mesh, we can't propagate the offset
752  * because it will only work for the existing vertices and not the new
753  * ones, creating a mess when doing e.g. subdivide + translate. */
754  MEM_freeN(ofs);
755  ofs = nullptr;
756  break;
757  }
758  }
759  }
760 
761  /* Without this, the real mesh coordinates (uneditable) as soon as you create the Basis shape.
762  * while users might not notice since the shape-key is applied in the viewport,
763  * exporters for example may still use the underlying coordinates, see: T30771 & T96135.
764  *
765  * Needed when editing any shape that isn't the (`key->refkey`), the vertices in `me->mvert`
766  * currently have vertex coordinates set from the current-shape (initialized from #BMVert.co).
767  * In this case it's important to overwrite these coordinates with the basis-keys coordinates. */
768  bool update_vertex_coords_from_refkey = false;
769  int cd_shape_offset_refkey = -1;
770  if (active_shapekey_to_mvert == false) {
771  if ((actkey != key->refkey) && (cd_shape_keyindex_offset != -1)) {
772  const int refkey_uuid = bm_to_mesh_shape_layer_index_from_kb(bm, key->refkey);
773  if (refkey_uuid != -1) {
774  cd_shape_offset_refkey = CustomData_get_n_offset(&bm->vdata, CD_SHAPEKEY, refkey_uuid);
775  if (cd_shape_offset_refkey != -1) {
776  update_vertex_coords_from_refkey = true;
777  }
778  }
779  }
780  }
781 
782  LISTBASE_FOREACH (KeyBlock *, currkey, &key->block) {
783  int keyi;
784  float(*currkey_data)[3];
785 
786  const int currkey_uuid = bm_to_mesh_shape_layer_index_from_kb(bm, currkey);
787  const int cd_shape_offset = (currkey_uuid == -1) ?
788  -1 :
789  CustomData_get_n_offset(&bm->vdata, CD_SHAPEKEY, currkey_uuid);
790 
791  /* Common case, the layer data is available, use it where possible. */
792  if (cd_shape_offset != -1) {
793  const bool apply_offset = (ofs != nullptr) && (currkey != actkey) &&
794  (bm->shapenr - 1 == currkey->relative);
795 
796  if (currkey->data && (currkey->totelem == bm->totvert)) {
797  /* Use memory in-place. */
798  }
799  else {
800  currkey->data = MEM_reallocN(currkey->data, key->elemsize * bm->totvert);
801  currkey->totelem = bm->totvert;
802  }
803  currkey_data = (float(*)[3])currkey->data;
804 
805  int i;
806  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
807  float *co_orig = (float *)BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset);
808 
809  if (currkey == actkey) {
810  copy_v3_v3(currkey_data[i], eve->co);
811 
812  if (update_vertex_coords_from_refkey) {
813  BLI_assert(actkey != key->refkey);
814  keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset);
815  if (keyi != ORIGINDEX_NONE) {
816  float *co_refkey = (float *)BM_ELEM_CD_GET_VOID_P(eve, cd_shape_offset_refkey);
817  copy_v3_v3(mvert[i].co, co_refkey);
818  }
819  }
820  }
821  else {
822  copy_v3_v3(currkey_data[i], co_orig);
823  }
824 
825  /* Propagate edited basis offsets to other shapes. */
826  if (apply_offset) {
827  add_v3_v3(currkey_data[i], ofs[i]);
828  }
829 
830  /* Apply back new coordinates shape-keys that have offset into #BMesh.
831  * Otherwise, in case we call again #BM_mesh_bm_to_me on same #BMesh,
832  * we'll apply diff from previous call to #BM_mesh_bm_to_me,
833  * to shape-key values from original creation of the #BMesh. See T50524. */
834  copy_v3_v3(co_orig, currkey_data[i]);
835  }
836  }
837  else {
838  /* No original layer data, use fallback information. */
839  if (currkey->data && (cd_shape_keyindex_offset != -1)) {
840  CLOG_WARN(&LOG,
841  "Found shape-key but no CD_SHAPEKEY layers to read from, "
842  "using existing shake-key data where possible");
843  }
844  else {
845  CLOG_WARN(&LOG,
846  "Found shape-key but no CD_SHAPEKEY layers to read from, "
847  "using basis shape-key data");
848  }
849 
850  currkey_data = static_cast<float(*)[3]>(
851  MEM_mallocN(key->elemsize * bm->totvert, "currkey->data"));
852 
853  int i;
854  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
855 
856  if ((currkey->data != nullptr) && (cd_shape_keyindex_offset != -1) &&
857  ((keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset)) != ORIGINDEX_NONE) &&
858  (keyi < currkey->totelem)) {
859  /* Reconstruct keys via vertices original key indices.
860  * WARNING(@campbellbarton): `currkey->data` is known to be unreliable as the edit-mesh
861  * coordinates may be flushed back to the shape-key when exporting or rendering.
862  * This is a last resort! If this branch is running as part of regular usage
863  * it can be considered a bug. */
864  const float(*oldkey)[3] = static_cast<const float(*)[3]>(currkey->data);
865  copy_v3_v3(currkey_data[i], oldkey[keyi]);
866  }
867  else {
868  /* Fail! fill in with dummy value. */
869  copy_v3_v3(currkey_data[i], eve->co);
870  }
871  }
872 
873  currkey->totelem = bm->totvert;
874  if (currkey->data) {
875  MEM_freeN(currkey->data);
876  }
877  currkey->data = currkey_data;
878  }
879  }
880 
881  if (ofs) {
882  MEM_freeN(ofs);
883  }
884 }
885 
889 {
890  /* This is a cheap way to set the edge draw, its not precise and will
891  * pick the first 2 faces an edge uses.
892  * The dot comparison is a little arbitrary, but set so that a 5 subdivisions
893  * ico-sphere won't vanish but 6 subdivisions will (as with pre-bmesh Blender). */
894 
895  if (/* (med->flag & ME_EDGEDRAW) && */ /* Assume to be true. */
896  (e->l && (e->l != e->l->radial_next)) &&
897  (dot_v3v3(e->l->f->no, e->l->radial_next->f->no) > 0.9995f)) {
898  med->flag &= ~ME_EDGEDRAW;
899  }
900  else {
901  med->flag |= ME_EDGEDRAW;
902  }
903 }
904 
905 void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
906 {
907  MEdge *med;
908  BMVert *v, *eve;
909  BMEdge *e;
910  BMFace *f;
911  BMIter iter;
912  int i, j;
913 
914  const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
915  const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
916  const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
917  const int cd_shape_keyindex_offset = CustomData_get_offset(&bm->vdata, CD_SHAPE_KEYINDEX);
918 
919  const int ototvert = me->totvert;
920 
921  /* Free custom data. */
922  CustomData_free(&me->vdata, me->totvert);
923  CustomData_free(&me->edata, me->totedge);
924  CustomData_free(&me->fdata, me->totface);
925  CustomData_free(&me->ldata, me->totloop);
926  CustomData_free(&me->pdata, me->totpoly);
927 
928  /* Add new custom data. */
929  me->totvert = bm->totvert;
930  me->totedge = bm->totedge;
931  me->totloop = bm->totloop;
932  me->totpoly = bm->totface;
933  /* Will be overwritten with a valid value if 'dotess' is set, otherwise we
934  * end up with 'me->totface' and `me->mface == nullptr` which can crash T28625. */
935  me->totface = 0;
936  me->act_face = -1;
937 
938  {
940  CustomData_MeshMasks_update(&mask, &params->cd_mask_extra);
941  CustomData_copy(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert);
942  CustomData_copy(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge);
943  CustomData_copy(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop);
944  CustomData_copy(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly);
945  }
946 
947  MVert *mvert = bm->totvert ? (MVert *)MEM_callocN(sizeof(MVert) * bm->totvert, "bm_to_me.vert") :
948  nullptr;
949  MEdge *medge = bm->totedge ? (MEdge *)MEM_callocN(sizeof(MEdge) * bm->totedge, "bm_to_me.edge") :
950  nullptr;
951  MLoop *mloop = bm->totloop ? (MLoop *)MEM_callocN(sizeof(MLoop) * bm->totloop, "bm_to_me.loop") :
952  nullptr;
953  MPoly *mpoly = bm->totface ? (MPoly *)MEM_callocN(sizeof(MPoly) * bm->totface, "bm_to_me.poly") :
954  nullptr;
955 
960 
961  /* Clear normals on the mesh completely, since the original vertex and polygon count might be
962  * different than the BMesh's. */
964 
966 
967  /* This is called again, 'dotess' arg is used there. */
969 
970  i = 0;
971  BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
972  copy_v3_v3(mvert->co, v->co);
973 
974  mvert->flag = BM_vert_flag_to_mflag(v);
975 
976  BM_elem_index_set(v, i); /* set_inline */
977 
978  /* Copy over custom-data. */
980 
981  if (cd_vert_bweight_offset != -1) {
982  mvert->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(v, cd_vert_bweight_offset);
983  }
984 
985  i++;
986  mvert++;
987 
989  }
991 
992  med = medge;
993  i = 0;
994  BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
995  med->v1 = BM_elem_index_get(e->v1);
996  med->v2 = BM_elem_index_get(e->v2);
997 
998  med->flag = BM_edge_flag_to_mflag(e);
999 
1000  BM_elem_index_set(e, i); /* set_inline */
1001 
1002  /* Copy over custom-data. */
1004 
1006 
1007  if (cd_edge_crease_offset != -1) {
1008  med->crease = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_crease_offset);
1009  }
1010  if (cd_edge_bweight_offset != -1) {
1011  med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_bweight_offset);
1012  }
1013 
1014  i++;
1015  med++;
1017  }
1019 
1020  i = 0;
1021  j = 0;
1022  BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
1023  BMLoop *l_iter, *l_first;
1024  mpoly->loopstart = j;
1025  mpoly->totloop = f->len;
1026  mpoly->mat_nr = f->mat_nr;
1027  mpoly->flag = BM_face_flag_to_mflag(f);
1028 
1029  l_iter = l_first = BM_FACE_FIRST_LOOP(f);
1030  do {
1031  mloop->e = BM_elem_index_get(l_iter->e);
1032  mloop->v = BM_elem_index_get(l_iter->v);
1033 
1034  /* Copy over custom-data. */
1035  CustomData_from_bmesh_block(&bm->ldata, &me->ldata, l_iter->head.data, j);
1036 
1037  j++;
1038  mloop++;
1039  BM_CHECK_ELEMENT(l_iter);
1040  BM_CHECK_ELEMENT(l_iter->e);
1041  BM_CHECK_ELEMENT(l_iter->v);
1042  } while ((l_iter = l_iter->next) != l_first);
1043 
1044  if (f == bm->act_face) {
1045  me->act_face = i;
1046  }
1047 
1048  /* Copy over custom-data. */
1050 
1051  i++;
1052  mpoly++;
1053  BM_CHECK_ELEMENT(f);
1054  }
1055 
1056  /* Patch hook indices and vertex parents. */
1057  if (params->calc_object_remap && (ototvert > 0)) {
1058  BLI_assert(bmain != nullptr);
1059  BMVert **vertMap = nullptr;
1060 
1061  LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
1062  if ((ob->parent) && (ob->parent->data == me) && ELEM(ob->partype, PARVERT1, PARVERT3)) {
1063 
1064  if (vertMap == nullptr) {
1065  vertMap = bm_to_mesh_vertex_map(bm, ototvert);
1066  }
1067 
1068  if (ob->par1 < ototvert) {
1069  eve = vertMap[ob->par1];
1070  if (eve) {
1071  ob->par1 = BM_elem_index_get(eve);
1072  }
1073  }
1074  if (ob->par2 < ototvert) {
1075  eve = vertMap[ob->par2];
1076  if (eve) {
1077  ob->par2 = BM_elem_index_get(eve);
1078  }
1079  }
1080  if (ob->par3 < ototvert) {
1081  eve = vertMap[ob->par3];
1082  if (eve) {
1083  ob->par3 = BM_elem_index_get(eve);
1084  }
1085  }
1086  }
1087  if (ob->data == me) {
1088  LISTBASE_FOREACH (ModifierData *, md, &ob->modifiers) {
1089  if (md->type == eModifierType_Hook) {
1090  HookModifierData *hmd = (HookModifierData *)md;
1091 
1092  if (vertMap == nullptr) {
1093  vertMap = bm_to_mesh_vertex_map(bm, ototvert);
1094  }
1095 
1096  for (i = j = 0; i < hmd->indexar_num; i++) {
1097  if (hmd->indexar[i] < ototvert) {
1098  eve = vertMap[hmd->indexar[i]];
1099 
1100  if (eve) {
1101  hmd->indexar[j++] = BM_elem_index_get(eve);
1102  }
1103  }
1104  else {
1105  j++;
1106  }
1107  }
1108 
1109  hmd->indexar_num = j;
1110  }
1111  }
1112  }
1113  }
1114 
1115  if (vertMap) {
1116  MEM_freeN(vertMap);
1117  }
1118  }
1119 
1121 
1122  {
1124 
1125  MEM_SAFE_FREE(me->mselect);
1126  if (me->totselect != 0) {
1127  me->mselect = static_cast<MSelect *>(
1128  MEM_mallocN(sizeof(MSelect) * me->totselect, "Mesh selection history"));
1129  }
1130 
1131  LISTBASE_FOREACH_INDEX (BMEditSelection *, selected, &bm->selected, i) {
1132  if (selected->htype == BM_VERT) {
1133  me->mselect[i].type = ME_VSEL;
1134  }
1135  else if (selected->htype == BM_EDGE) {
1136  me->mselect[i].type = ME_ESEL;
1137  }
1138  else if (selected->htype == BM_FACE) {
1139  me->mselect[i].type = ME_FSEL;
1140  }
1141 
1142  me->mselect[i].index = BM_elem_index_get(selected->ele);
1143  }
1144  }
1145 
1146  if (me->key) {
1147  bm_to_mesh_shape(bm, me->key, me->mvert, params->active_shapekey_to_mvert);
1148  }
1149 
1150  /* Run this even when shape keys aren't used since it may be used for hooks or vertex parents. */
1151  if (params->update_shapekey_indices) {
1152  /* We have written a new shape key, if this mesh is _not_ going to be freed,
1153  * update the shape key indices to match the newly updated. */
1154  if (cd_shape_keyindex_offset != -1) {
1155  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
1156  BM_ELEM_CD_SET_INT(eve, cd_shape_keyindex_offset, i);
1157  }
1158  }
1159  }
1160 
1161  /* Topology could be changed, ensure #CD_MDISPS are ok. */
1163 
1164  /* To be removed as soon as COW is enabled by default. */
1166 }
1167 
1169 {
1170  /* Must be an empty mesh. */
1171  BLI_assert(me->totvert == 0);
1172  BLI_assert(cd_mask_extra == nullptr || (cd_mask_extra->vmask & CD_MASK_SHAPEKEY) == 0);
1173 
1174  me->totvert = bm->totvert;
1175  me->totedge = bm->totedge;
1176  me->totface = 0;
1177  me->totloop = bm->totloop;
1178  me->totpoly = bm->totface;
1179 
1184 
1185  /* Don't process shape-keys, we only feed them through the modifier stack as needed,
1186  * e.g. for applying modifiers or the like. */
1188  if (cd_mask_extra != nullptr) {
1189  CustomData_MeshMasks_update(&mask, cd_mask_extra);
1190  }
1191  mask.vmask &= ~CD_MASK_SHAPEKEY;
1192  CustomData_merge(&bm->vdata, &me->vdata, mask.vmask, CD_CALLOC, me->totvert);
1193  CustomData_merge(&bm->edata, &me->edata, mask.emask, CD_CALLOC, me->totedge);
1194  CustomData_merge(&bm->ldata, &me->ldata, mask.lmask, CD_CALLOC, me->totloop);
1195  CustomData_merge(&bm->pdata, &me->pdata, mask.pmask, CD_CALLOC, me->totpoly);
1196 
1198 
1199  BMIter iter;
1200  BMVert *eve;
1201  BMEdge *eed;
1202  BMFace *efa;
1203  MVert *mvert = me->mvert;
1204  MEdge *medge = me->medge;
1205  MLoop *mloop = me->mloop;
1206  MPoly *mpoly = me->mpoly;
1207  unsigned int i, j;
1208 
1209  const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
1210  const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
1211  const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE);
1212 
1213  /* Clear normals on the mesh completely, since the original vertex and polygon count might be
1214  * different than the BMesh's. */
1216 
1217  me->runtime.deformed_only = true;
1218 
1219  BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
1220  MVert *mv = &mvert[i];
1221 
1222  copy_v3_v3(mv->co, eve->co);
1223 
1224  BM_elem_index_set(eve, i); /* set_inline */
1225 
1226  mv->flag = BM_vert_flag_to_mflag(eve);
1227 
1228  if (cd_vert_bweight_offset != -1) {
1229  mv->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset);
1230  }
1231 
1232  CustomData_from_bmesh_block(&bm->vdata, &me->vdata, eve->head.data, i);
1233  }
1235 
1236  BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
1237  MEdge *med = &medge[i];
1238 
1239  BM_elem_index_set(eed, i); /* set_inline */
1240 
1241  med->v1 = BM_elem_index_get(eed->v1);
1242  med->v2 = BM_elem_index_get(eed->v2);
1243 
1244  med->flag = BM_edge_flag_to_mflag(eed);
1245 
1246  /* Handle this differently to editmode switching,
1247  * only enable draw for single user edges rather than calculating angle. */
1248  if ((med->flag & ME_EDGEDRAW) == 0) {
1249  if (eed->l && eed->l == eed->l->radial_next) {
1250  med->flag |= ME_EDGEDRAW;
1251  }
1252  }
1253 
1254  if (cd_edge_crease_offset != -1) {
1255  med->crease = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset);
1256  }
1257  if (cd_edge_bweight_offset != -1) {
1258  med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset);
1259  }
1260 
1261  CustomData_from_bmesh_block(&bm->edata, &me->edata, eed->head.data, i);
1262  }
1264 
1265  j = 0;
1266  BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
1267  BMLoop *l_iter;
1268  BMLoop *l_first;
1269  MPoly *mp = &mpoly[i];
1270 
1271  BM_elem_index_set(efa, i); /* set_inline */
1272 
1273  mp->totloop = efa->len;
1274  mp->flag = BM_face_flag_to_mflag(efa);
1275  mp->loopstart = j;
1276  mp->mat_nr = efa->mat_nr;
1277 
1278  l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
1279  do {
1280  mloop->v = BM_elem_index_get(l_iter->v);
1281  mloop->e = BM_elem_index_get(l_iter->e);
1282  CustomData_from_bmesh_block(&bm->ldata, &me->ldata, l_iter->head.data, j);
1283 
1284  BM_elem_index_set(l_iter, j); /* set_inline */
1285 
1286  j++;
1287  mloop++;
1288  } while ((l_iter = l_iter->next) != l_first);
1289 
1290  CustomData_from_bmesh_block(&bm->pdata, &me->pdata, efa->head.data, i);
1291  }
1293 
1295 }
typedef float(TangentPoint)[2]
CustomData interface, see also DNA_customdata_types.h.
bool CustomData_merge(const struct CustomData *source, struct CustomData *dest, eCustomDataMask mask, eCDAllocType alloctype, int totelem)
void CustomData_free(struct CustomData *data, int totelem)
Definition: customdata.cc:2373
int CustomData_number_of_layers(const struct CustomData *data, int type)
@ CD_ASSIGN
@ CD_CALLOC
@ CD_DEFAULT
void CustomData_from_bmesh_block(const struct CustomData *source, struct CustomData *dest, void *src_block, int dest_index)
void CustomData_copy(const struct CustomData *source, struct CustomData *dest, eCustomDataMask mask, eCDAllocType alloctype, int totelem)
bool CustomData_has_layer(const struct CustomData *data, int type)
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition: customdata.cc:77
int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n)
void * CustomData_add_layer_named(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem, const char *name)
Definition: customdata.cc:2792
void CustomData_bmesh_init_pool(struct CustomData *data, int totelem, char htype)
Definition: customdata.cc:3541
const CustomData_MeshMasks CD_MASK_BMESH
Definition: customdata.cc:2090
#define ORIGINDEX_NONE
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
Definition: customdata.cc:2776
int CustomData_get_n_offset(const struct CustomData *data, int type, int n)
const CustomData_MeshMasks CD_MASK_DERIVEDMESH
Definition: customdata.cc:2077
int CustomData_get_offset(const struct CustomData *data, int type)
const CustomData_MeshMasks CD_MASK_MESH
Definition: customdata.cc:2065
bool CustomData_bmesh_merge(const struct CustomData *source, struct CustomData *dest, eCustomDataMask mask, eCDAllocType alloctype, struct BMesh *bm, char htype)
void CustomData_to_bmesh_block(const struct CustomData *source, struct CustomData *dest, int src_index, void **dest_block, bool use_default_init)
bool BKE_keyblock_is_basis(const struct Key *key, int index)
struct KeyBlock * BKE_keyblock_add(struct Key *key, const char *name)
Definition: key.c:1814
const float(* BKE_mesh_vertex_normals_ensure(const struct Mesh *mesh))[3]
void BKE_mesh_update_customdata_pointers(struct Mesh *me, bool do_ensure_tess_cd)
Definition: mesh.cc:874
void BKE_mesh_clear_derived_normals(struct Mesh *mesh)
void BKE_mesh_runtime_clear_geometry(struct Mesh *mesh)
void multires_topology_changed(struct Mesh *me)
Definition: multires.c:1448
#define BLI_array_alloca(arr, realsize)
Definition: BLI_alloca.h:22
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_INLINE
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition: BLI_listbase.h:344
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int min_ii(int a, int b)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3(float r[3], const float a[3])
#define UNLIKELY(x)
#define ELEM(...)
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:189
bool DEG_is_original_id(const struct ID *id)
@ CD_SHAPEKEY
@ CD_MEDGE
@ CD_MVERT
@ CD_BWEIGHT
@ CD_SHAPE_KEYINDEX
#define CD_MASK_SHAPEKEY
@ KEY_RELATIVE
@ ME_CDFLAG_VERT_CREASE
@ ME_CDFLAG_EDGE_CREASE
@ ME_CDFLAG_VERT_BWEIGHT
@ ME_CDFLAG_EDGE_BWEIGHT
@ ME_VSEL
@ ME_FSEL
@ ME_ESEL
@ ME_FACE_SEL
@ ME_EDGEDRAW
@ eModifierType_Hook
Object is a sort of wrapper for general info.
@ PARVERT1
@ PARVERT3
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
#define MEM_reallocN(vmemh, len)
#define BM_ELEM_CD_SET_FLOAT(ele, offset, f)
Definition: bmesh_class.h:545
#define BM_ELEM_CD_GET_INT(ele, offset)
Definition: bmesh_class.h:518
#define BM_ELEM_CD_SET_INT(ele, offset, f)
Definition: bmesh_class.h:510
#define BM_FACE_FIRST_LOOP(p)
Definition: bmesh_class.h:622
@ BM_LOOP
Definition: bmesh_class.h:385
@ BM_FACE
Definition: bmesh_class.h:386
@ BM_VERT
Definition: bmesh_class.h:383
@ BM_EDGE
Definition: bmesh_class.h:384
#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset)
Definition: bmesh_class.h:614
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
Definition: bmesh_class.h:541
char BM_face_flag_from_mflag(const char mflag)
char BM_face_flag_to_mflag(BMFace *f)
short BM_edge_flag_to_mflag(BMEdge *e)
char BM_vert_flag_from_mflag(const char mflag)
char BM_edge_flag_from_mflag(const short mflag)
char BM_vert_flag_to_mflag(BMVert *v)
BMVert * BM_vert_create(BMesh *bm, const float co[3], const BMVert *v_example, const eBMCreateFlag create_flag)
Main function for creating a new vertex.
Definition: bmesh_core.c:41
BMFace * BM_face_create(BMesh *bm, BMVert **verts, BMEdge **edges, const int len, const BMFace *f_example, const eBMCreateFlag create_flag)
Definition: bmesh_core.c:395
BMEdge * BM_edge_create(BMesh *bm, BMVert *v1, BMVert *v2, const BMEdge *e_example, const eBMCreateFlag create_flag)
Main function for creating a new edge.
Definition: bmesh_core.c:123
@ BM_CREATE_SKIP_CD
Definition: bmesh_core.h:20
#define BM_elem_index_get(ele)
Definition: bmesh_inline.h:110
#define BM_elem_index_set(ele, index)
Definition: bmesh_inline.h:111
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
Definition: bmesh_interp.c:875
void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
Definition: bmesh_interp.c:839
#define BM_ITER_MESH(ele, iter, bm, itype)
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_EDGES_OF_MESH
@ BM_VERTS_OF_MESH
@ BM_FACES_OF_MESH
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_select_history_clear(BMesh *bm)
void BM_face_select_set(BMesh *bm, BMFace *f, const bool select)
Select Face.
void BM_vert_select_set(BMesh *bm, BMVert *v, const bool select)
Select Vert.
void BM_edge_select_set(BMesh *bm, BMEdge *e, const bool select)
Select Edge.
#define BM_select_history_store_notest(bm, ele)
static int bm_to_mesh_shape_layer_index_from_kb(BMesh *bm, KeyBlock *currkey)
void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *cd_mask_extra)
BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e)
static BMFace * bm_face_create_from_mpoly(BMesh &bm, Span< MLoop > loops, Span< BMVert * > vtable, Span< BMEdge * > etable)
static BMVert ** bm_to_mesh_vertex_map(BMesh *bm, int ototvert)
BMesh -> Mesh.
static void bm_to_mesh_shape(BMesh *bm, Key *key, MVert *mvert, const bool active_shapekey_to_mvert)
char BM_mesh_cd_flag_from_bmesh(BMesh *bm)
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params)
static CLG_LogRef LOG
void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
void BM_mesh_cd_flag_apply(BMesh *bm, const char cd_flag)
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
void BM_face_normal_update(BMFace *f)
#define BM_CHECK_ELEMENT(el)
Definition: bmesh_private.h:32
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
const T * data() const
Definition: BLI_array.hh:300
void reinitialize(const int64_t new_size)
Definition: BLI_array.hh:387
bool is_empty() const
Definition: BLI_array.hh:252
constexpr int64_t size() const
Definition: BLI_span.hh:240
constexpr IndexRange index_range() const
Definition: BLI_span.hh:401
#define SELECT
static float verts[][3]
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
BMHeader head
Definition: bmesh_class.h:111
BMVert * v1
Definition: bmesh_class.h:122
BMVert * v2
Definition: bmesh_class.h:122
struct BMLoop * l
Definition: bmesh_class.h:128
short mat_nr
Definition: bmesh_class.h:281
int len
Definition: bmesh_class.h:267
BMHeader head
Definition: bmesh_class.h:255
char hflag
Definition: bmesh_class.h:66
void * data
Definition: bmesh_class.h:51
BMHeader head
Definition: bmesh_class.h:145
struct BMVert * v
Definition: bmesh_class.h:153
struct BMEdge * e
Definition: bmesh_class.h:164
struct BMLoop * radial_next
Definition: bmesh_class.h:204
struct BMLoop * next
Definition: bmesh_class.h:233
float co[3]
Definition: bmesh_class.h:87
float no[3]
Definition: bmesh_class.h:88
BMHeader head
Definition: bmesh_class.h:85
int totvert
Definition: bmesh_class.h:297
int shapenr
Definition: bmesh_class.h:353
char elem_index_dirty
Definition: bmesh_class.h:305
CustomData vdata
Definition: bmesh_class.h:337
int totedge
Definition: bmesh_class.h:297
ListBase selected
Definition: bmesh_class.h:356
CustomData edata
Definition: bmesh_class.h:337
int totloop
Definition: bmesh_class.h:297
BMFace * act_face
Definition: bmesh_class.h:366
CustomData pdata
Definition: bmesh_class.h:337
CustomData ldata
Definition: bmesh_class.h:337
int totface
Definition: bmesh_class.h:297
struct BLI_mempool * pool
CustomDataLayer * layers
char name[66]
Definition: DNA_ID.h:378
char name[64]
Definition: DNA_key_types.h:52
struct KeyBlock * next
Definition: DNA_key_types.h:25
void * data
Definition: DNA_key_types.h:50
int uidgen
int elemsize
Definition: DNA_key_types.h:80
char type
Definition: DNA_key_types.h:94
ListBase block
Definition: DNA_key_types.h:84
KeyBlock * refkey
Definition: DNA_key_types.h:72
void * first
Definition: DNA_listBase.h:31
unsigned int v1
unsigned int v2
unsigned int e
unsigned int v
short mat_nr
float co[3]
Definition: BKE_main.h:121
ListBase objects
Definition: BKE_main.h:170
struct MEdge * medge
CustomData vdata
struct MVert * mvert
int totedge
int act_face
char cd_flag
int totvert
struct MLoop * mloop
int totface
Mesh_Runtime runtime
CustomData pdata
CustomData fdata
int totpoly
CustomData edata
int totloop
struct Key * key
int totselect
struct MPoly * mpoly
CustomData ldata
struct MSelect * mselect