Blender  V2.93
mesh.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "MEM_guardedalloc.h"
25 
26 /* Allow using deprecated functionality for .blend file I/O. */
27 #define DNA_DEPRECATED_ALLOW
28 
29 #include "DNA_defaults.h"
30 #include "DNA_key_types.h"
31 #include "DNA_material_types.h"
32 #include "DNA_mesh_types.h"
33 #include "DNA_meshdata_types.h"
34 #include "DNA_object_types.h"
35 
36 #include "BLI_bitmap.h"
37 #include "BLI_edgehash.h"
38 #include "BLI_endian_switch.h"
39 #include "BLI_ghash.h"
40 #include "BLI_hash.h"
41 #include "BLI_linklist.h"
42 #include "BLI_math.h"
43 #include "BLI_memarena.h"
44 #include "BLI_string.h"
45 #include "BLI_utildefines.h"
46 
47 #include "BLT_translation.h"
48 
49 #include "BKE_anim_data.h"
50 #include "BKE_deform.h"
51 #include "BKE_editmesh.h"
52 #include "BKE_global.h"
53 #include "BKE_idtype.h"
54 #include "BKE_key.h"
55 #include "BKE_lib_id.h"
56 #include "BKE_lib_query.h"
57 #include "BKE_main.h"
58 #include "BKE_material.h"
59 #include "BKE_mesh.h"
60 #include "BKE_mesh_runtime.h"
61 #include "BKE_mesh_wrapper.h"
62 #include "BKE_modifier.h"
63 #include "BKE_multires.h"
64 #include "BKE_object.h"
65 
66 #include "PIL_time.h"
67 
68 #include "DEG_depsgraph.h"
69 #include "DEG_depsgraph_query.h"
70 
71 #include "BLO_read_write.h"
72 
73 static void mesh_clear_geometry(Mesh *mesh);
74 static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata);
75 
76 static void mesh_init_data(ID *id)
77 {
78  Mesh *mesh = (Mesh *)id;
79 
81 
83 
84  CustomData_reset(&mesh->vdata);
85  CustomData_reset(&mesh->edata);
87  CustomData_reset(&mesh->pdata);
89 
91 
93 }
94 
95 static void mesh_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
96 {
97  Mesh *mesh_dst = (Mesh *)id_dst;
98  const Mesh *mesh_src = (const Mesh *)id_src;
99 
100  BKE_mesh_runtime_reset_on_copy(mesh_dst, flag);
101  if ((mesh_src->id.tag & LIB_TAG_NO_MAIN) == 0) {
102  /* This is a direct copy of a main mesh, so for now it has the same topology. */
103  mesh_dst->runtime.deformed_only = true;
104  }
105  /* This option is set for run-time meshes that have been copied from the current objects mode.
106  * Currently this is used for edit-mesh although it could be used for sculpt or other
107  * kinds of data specific to an objects mode.
108  *
109  * The flag signals that the mesh hasn't been modified from the data that generated it,
110  * allowing us to use the object-mode data for drawing.
111  *
112  * While this could be the callers responsibility, keep here since it's
113  * highly unlikely we want to create a duplicate and not use it for drawing. */
114  mesh_dst->runtime.is_original = false;
115 
116  /* Only do tessface if we have no polys. */
117  const bool do_tessface = ((mesh_src->totface != 0) && (mesh_src->totpoly == 0));
118 
120 
121  if (mesh_src->id.tag & LIB_TAG_NO_MAIN) {
122  /* For copies in depsgraph, keep data like origindex and orco. */
124  }
125 
126  mesh_dst->mat = MEM_dupallocN(mesh_src->mat);
127 
128  const eCDAllocType alloc_type = (flag & LIB_ID_COPY_CD_REFERENCE) ? CD_REFERENCE : CD_DUPLICATE;
129  CustomData_copy(&mesh_src->vdata, &mesh_dst->vdata, mask.vmask, alloc_type, mesh_dst->totvert);
130  CustomData_copy(&mesh_src->edata, &mesh_dst->edata, mask.emask, alloc_type, mesh_dst->totedge);
131  CustomData_copy(&mesh_src->ldata, &mesh_dst->ldata, mask.lmask, alloc_type, mesh_dst->totloop);
132  CustomData_copy(&mesh_src->pdata, &mesh_dst->pdata, mask.pmask, alloc_type, mesh_dst->totpoly);
133  if (do_tessface) {
134  CustomData_copy(&mesh_src->fdata, &mesh_dst->fdata, mask.fmask, alloc_type, mesh_dst->totface);
135  }
136  else {
137  mesh_tessface_clear_intern(mesh_dst, false);
138  }
139 
140  BKE_mesh_update_customdata_pointers(mesh_dst, do_tessface);
141 
142  mesh_dst->edit_mesh = NULL;
143 
144  mesh_dst->mselect = MEM_dupallocN(mesh_dst->mselect);
145 
146  /* TODO Do we want to add flag to prevent this? */
147  if (mesh_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
148  BKE_id_copy_ex(bmain, &mesh_src->key->id, (ID **)&mesh_dst->key, flag);
149  /* XXX This is not nice, we need to make BKE_id_copy_ex fully re-entrant... */
150  mesh_dst->key->from = &mesh_dst->id;
151  }
152 }
153 
154 static void mesh_free_data(ID *id)
155 {
156  Mesh *mesh = (Mesh *)id;
157 
161 }
162 
164 {
165  Mesh *mesh = (Mesh *)id;
168  for (int i = 0; i < mesh->totcol; i++) {
170  }
171 }
172 
173 static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address)
174 {
175  Mesh *mesh = (Mesh *)id;
176  const bool is_undo = BLO_write_is_undo(writer);
177  if (mesh->id.us > 0 || is_undo) {
178  CustomDataLayer *vlayers = NULL, vlayers_buff[CD_TEMP_CHUNK_SIZE];
179  CustomDataLayer *elayers = NULL, elayers_buff[CD_TEMP_CHUNK_SIZE];
180  CustomDataLayer *flayers = NULL, flayers_buff[CD_TEMP_CHUNK_SIZE];
181  CustomDataLayer *llayers = NULL, llayers_buff[CD_TEMP_CHUNK_SIZE];
182  CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
183 
184  /* cache only - don't write */
185  mesh->mface = NULL;
186  mesh->totface = 0;
187  memset(&mesh->fdata, 0, sizeof(mesh->fdata));
188  memset(&mesh->runtime, 0, sizeof(mesh->runtime));
189  flayers = flayers_buff;
190 
191  /* Do not store actual geometry data in case this is a library override ID. */
192  if (ID_IS_OVERRIDE_LIBRARY(mesh) && !is_undo) {
193  mesh->mvert = NULL;
194  mesh->totvert = 0;
195  memset(&mesh->vdata, 0, sizeof(mesh->vdata));
196  vlayers = vlayers_buff;
197 
198  mesh->medge = NULL;
199  mesh->totedge = 0;
200  memset(&mesh->edata, 0, sizeof(mesh->edata));
201  elayers = elayers_buff;
202 
203  mesh->mloop = NULL;
204  mesh->totloop = 0;
205  memset(&mesh->ldata, 0, sizeof(mesh->ldata));
206  llayers = llayers_buff;
207 
208  mesh->mpoly = NULL;
209  mesh->totpoly = 0;
210  memset(&mesh->pdata, 0, sizeof(mesh->pdata));
211  players = players_buff;
212  }
213  else {
215  &mesh->vdata, &vlayers, vlayers_buff, ARRAY_SIZE(vlayers_buff));
217  &mesh->edata, &elayers, elayers_buff, ARRAY_SIZE(elayers_buff));
219  &mesh->ldata, &llayers, llayers_buff, ARRAY_SIZE(llayers_buff));
221  &mesh->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
222  }
223 
224  BLO_write_id_struct(writer, Mesh, id_address, &mesh->id);
225  BKE_id_blend_write(writer, &mesh->id);
226 
227  /* direct data */
228  if (mesh->adt) {
230  }
231 
233  BLO_write_raw(writer, sizeof(MSelect) * mesh->totselect, mesh->mselect);
234 
236  writer, &mesh->vdata, vlayers, mesh->totvert, CD_MASK_MESH.vmask, &mesh->id);
238  writer, &mesh->edata, elayers, mesh->totedge, CD_MASK_MESH.emask, &mesh->id);
239  /* fdata is really a dummy - written so slots align */
241  writer, &mesh->fdata, flayers, mesh->totface, CD_MASK_MESH.fmask, &mesh->id);
243  writer, &mesh->ldata, llayers, mesh->totloop, CD_MASK_MESH.lmask, &mesh->id);
245  writer, &mesh->pdata, players, mesh->totpoly, CD_MASK_MESH.pmask, &mesh->id);
246 
247  /* Free temporary data */
248 
249 /* Free custom-data layers, when not assigned a buffer value. */
250 #define CD_LAYERS_FREE(id) \
251  if (id && id != id##_buff) { \
252  MEM_freeN(id); \
253  } \
254  ((void)0)
255 
256  CD_LAYERS_FREE(vlayers);
257  CD_LAYERS_FREE(elayers);
258  /* CD_LAYER_FREE(flayers); */ /* Never allocated. */
259  CD_LAYERS_FREE(llayers);
260  CD_LAYERS_FREE(players);
261 
262 #undef CD_LAYERS_FREE
263  }
264 }
265 
266 static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
267 {
268  Mesh *mesh = (Mesh *)id;
269  BLO_read_pointer_array(reader, (void **)&mesh->mat);
270 
271  BLO_read_data_address(reader, &mesh->mvert);
272  BLO_read_data_address(reader, &mesh->medge);
273  BLO_read_data_address(reader, &mesh->mface);
274  BLO_read_data_address(reader, &mesh->mloop);
275  BLO_read_data_address(reader, &mesh->mpoly);
276  BLO_read_data_address(reader, &mesh->tface);
277  BLO_read_data_address(reader, &mesh->mtface);
278  BLO_read_data_address(reader, &mesh->mcol);
279  BLO_read_data_address(reader, &mesh->dvert);
283 
284  /* animdata */
285  BLO_read_data_address(reader, &mesh->adt);
287 
288  /* Normally BKE_defvert_blend_read should be called in CustomData_blend_read,
289  * but for backwards compatibility in do_versions to work we do it here. */
291 
292  CustomData_blend_read(reader, &mesh->vdata, mesh->totvert);
293  CustomData_blend_read(reader, &mesh->edata, mesh->totedge);
296  CustomData_blend_read(reader, &mesh->pdata, mesh->totpoly);
297 
299  mesh->edit_mesh = NULL;
301 
302  /* happens with old files */
303  if (mesh->mselect == NULL) {
304  mesh->totselect = 0;
305  }
306 
307  if ((BLO_read_requires_endian_switch(reader)) && mesh->tface) {
308  TFace *tf = mesh->tface;
309  for (int i = 0; i < mesh->totface; i++, tf++) {
310  BLI_endian_switch_uint32_array(tf->col, 4);
311  }
312  }
313 }
314 
315 static void mesh_blend_read_lib(BlendLibReader *reader, ID *id)
316 {
317  Mesh *me = (Mesh *)id;
318  /* this check added for python created meshes */
319  if (me->mat) {
320  for (int i = 0; i < me->totcol; i++) {
321  BLO_read_id_address(reader, me->id.lib, &me->mat[i]);
322  }
323  }
324  else {
325  me->totcol = 0;
326  }
327 
328  BLO_read_id_address(reader, me->id.lib, &me->ipo); // XXX: deprecated: old anim sys
329  BLO_read_id_address(reader, me->id.lib, &me->key);
330  BLO_read_id_address(reader, me->id.lib, &me->texcomesh);
331 }
332 
333 static void mesh_read_expand(BlendExpander *expander, ID *id)
334 {
335  Mesh *me = (Mesh *)id;
336  for (int a = 0; a < me->totcol; a++) {
337  BLO_expand(expander, me->mat[a]);
338  }
339 
340  BLO_expand(expander, me->key);
341  BLO_expand(expander, me->texcomesh);
342 }
343 
345  .id_code = ID_ME,
346  .id_filter = FILTER_ID_ME,
347  .main_listbase_index = INDEX_ID_ME,
348  .struct_size = sizeof(Mesh),
349  .name = "Mesh",
350  .name_plural = "meshes",
351  .translation_context = BLT_I18NCONTEXT_ID_MESH,
352  .flags = 0,
353 
355  .copy_data = mesh_copy_data,
356  .free_data = mesh_free_data,
357  .make_local = NULL,
358  .foreach_id = mesh_foreach_id,
359  .foreach_cache = NULL,
360  .owner_get = NULL,
361 
362  .blend_write = mesh_blend_write,
363  .blend_read_data = mesh_blend_read_data,
364  .blend_read_lib = mesh_blend_read_lib,
365  .blend_read_expand = mesh_read_expand,
366 
367  .blend_read_undo_preserve = NULL,
368 
369  .lib_override_apply_post = NULL,
370 };
371 
372 enum {
384 };
385 
386 static const char *cmpcode_to_str(int code)
387 {
388  switch (code) {
390  return "Vertex Weight Mismatch";
392  return "Vertex Group Mismatch";
394  return "Vertex Doesn't Belong To Same Number Of Groups";
396  return "Vertex Color Mismatch";
398  return "UV Mismatch";
400  return "Loop Mismatch";
402  return "Loop Vert Mismatch In Poly Test";
404  return "Loop Vert Mismatch";
405  case MESHCMP_EDGEUNKNOWN:
406  return "Edge Mismatch";
408  return "Vertex Coordinate Mismatch";
410  return "CustomData Layer Count Mismatch";
411  default:
412  return "Mesh Comparison Code Unknown";
413  }
414 }
415 
416 /* thresh is threshold for comparing vertices, uvs, vertex colors,
417  * weights, etc.*/
419  CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, const float thresh)
420 {
421  const float thresh_sq = thresh * thresh;
422  CustomDataLayer *l1, *l2;
423  int i, i1 = 0, i2 = 0, tot, j;
424 
425  for (i = 0; i < c1->totlayer; i++) {
426  if (ELEM(c1->layers[i].type,
427  CD_MVERT,
428  CD_MEDGE,
429  CD_MPOLY,
430  CD_MLOOPUV,
431  CD_MLOOPCOL,
432  CD_MDEFORMVERT)) {
433  i1++;
434  }
435  }
436 
437  for (i = 0; i < c2->totlayer; i++) {
438  if (ELEM(c2->layers[i].type,
439  CD_MVERT,
440  CD_MEDGE,
441  CD_MPOLY,
442  CD_MLOOPUV,
443  CD_MLOOPCOL,
444  CD_MDEFORMVERT)) {
445  i2++;
446  }
447  }
448 
449  if (i1 != i2) {
451  }
452 
453  l1 = c1->layers;
454  l2 = c2->layers;
455  tot = i1;
456  i1 = 0;
457  i2 = 0;
458  for (i = 0; i < tot; i++) {
459  while (
460  i1 < c1->totlayer &&
462  i1++;
463  l1++;
464  }
465 
466  while (
467  i2 < c2->totlayer &&
469  i2++;
470  l2++;
471  }
472 
473  if (l1->type == CD_MVERT) {
474  MVert *v1 = l1->data;
475  MVert *v2 = l2->data;
476  int vtot = m1->totvert;
477 
478  for (j = 0; j < vtot; j++, v1++, v2++) {
479  if (len_squared_v3v3(v1->co, v2->co) > thresh_sq) {
480  return MESHCMP_VERTCOMISMATCH;
481  }
482  /* I don't care about normals, let's just do coordinates */
483  }
484  }
485 
486  /*we're order-agnostic for edges here*/
487  if (l1->type == CD_MEDGE) {
488  MEdge *e1 = l1->data;
489  MEdge *e2 = l2->data;
490  int etot = m1->totedge;
491  EdgeHash *eh = BLI_edgehash_new_ex(__func__, etot);
492 
493  for (j = 0; j < etot; j++, e1++) {
494  BLI_edgehash_insert(eh, e1->v1, e1->v2, e1);
495  }
496 
497  for (j = 0; j < etot; j++, e2++) {
498  if (!BLI_edgehash_lookup(eh, e2->v1, e2->v2)) {
499  return MESHCMP_EDGEUNKNOWN;
500  }
501  }
502  BLI_edgehash_free(eh, NULL);
503  }
504 
505  if (l1->type == CD_MPOLY) {
506  MPoly *p1 = l1->data;
507  MPoly *p2 = l2->data;
508  int ptot = m1->totpoly;
509 
510  for (j = 0; j < ptot; j++, p1++, p2++) {
511  MLoop *lp1, *lp2;
512  int k;
513 
514  if (p1->totloop != p2->totloop) {
515  return MESHCMP_POLYMISMATCH;
516  }
517 
518  lp1 = m1->mloop + p1->loopstart;
519  lp2 = m2->mloop + p2->loopstart;
520 
521  for (k = 0; k < p1->totloop; k++, lp1++, lp2++) {
522  if (lp1->v != lp2->v) {
524  }
525  }
526  }
527  }
528  if (l1->type == CD_MLOOP) {
529  MLoop *lp1 = l1->data;
530  MLoop *lp2 = l2->data;
531  int ltot = m1->totloop;
532 
533  for (j = 0; j < ltot; j++, lp1++, lp2++) {
534  if (lp1->v != lp2->v) {
535  return MESHCMP_LOOPMISMATCH;
536  }
537  }
538  }
539  if (l1->type == CD_MLOOPUV) {
540  MLoopUV *lp1 = l1->data;
541  MLoopUV *lp2 = l2->data;
542  int ltot = m1->totloop;
543 
544  for (j = 0; j < ltot; j++, lp1++, lp2++) {
545  if (len_squared_v2v2(lp1->uv, lp2->uv) > thresh_sq) {
546  return MESHCMP_LOOPUVMISMATCH;
547  }
548  }
549  }
550 
551  if (l1->type == CD_MLOOPCOL) {
552  MLoopCol *lp1 = l1->data;
553  MLoopCol *lp2 = l2->data;
554  int ltot = m1->totloop;
555 
556  for (j = 0; j < ltot; j++, lp1++, lp2++) {
557  if (abs(lp1->r - lp2->r) > thresh || abs(lp1->g - lp2->g) > thresh ||
558  abs(lp1->b - lp2->b) > thresh || abs(lp1->a - lp2->a) > thresh) {
560  }
561  }
562  }
563 
564  if (l1->type == CD_MDEFORMVERT) {
565  MDeformVert *dv1 = l1->data;
566  MDeformVert *dv2 = l2->data;
567  int dvtot = m1->totvert;
568 
569  for (j = 0; j < dvtot; j++, dv1++, dv2++) {
570  int k;
571  MDeformWeight *dw1 = dv1->dw, *dw2 = dv2->dw;
572 
573  if (dv1->totweight != dv2->totweight) {
575  }
576 
577  for (k = 0; k < dv1->totweight; k++, dw1++, dw2++) {
578  if (dw1->def_nr != dw2->def_nr) {
580  }
581  if (fabsf(dw1->weight - dw2->weight) > thresh) {
583  }
584  }
585  }
586  }
587  }
588 
589  return 0;
590 }
591 
598 const char *BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh)
599 {
600  int c;
601 
602  if (!me1 || !me2) {
603  return "Requires two input meshes";
604  }
605 
606  if (me1->totvert != me2->totvert) {
607  return "Number of verts don't match";
608  }
609 
610  if (me1->totedge != me2->totedge) {
611  return "Number of edges don't match";
612  }
613 
614  if (me1->totpoly != me2->totpoly) {
615  return "Number of faces don't match";
616  }
617 
618  if (me1->totloop != me2->totloop) {
619  return "Number of loops don't match";
620  }
621 
622  if ((c = customdata_compare(&me1->vdata, &me2->vdata, me1, me2, thresh))) {
623  return cmpcode_to_str(c);
624  }
625 
626  if ((c = customdata_compare(&me1->edata, &me2->edata, me1, me2, thresh))) {
627  return cmpcode_to_str(c);
628  }
629 
630  if ((c = customdata_compare(&me1->ldata, &me2->ldata, me1, me2, thresh))) {
631  return cmpcode_to_str(c);
632  }
633 
634  if ((c = customdata_compare(&me1->pdata, &me2->pdata, me1, me2, thresh))) {
635  return cmpcode_to_str(c);
636  }
637 
638  return NULL;
639 }
640 
642 {
643  if (UNLIKELY((me->totface != 0) && (me->totpoly == 0))) {
644  /* Pass, otherwise this function clears 'mface' before
645  * versioning 'mface -> mpoly' code kicks in T30583.
646  *
647  * Callers could also check but safer to do here - campbell */
648  }
649  else {
650  const int tottex_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
651  const int totcol_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
652 
653  const int tottex_tessface = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
654  const int totcol_tessface = CustomData_number_of_layers(&me->fdata, CD_MCOL);
655 
656  if (tottex_tessface != tottex_original || totcol_tessface != totcol_original) {
658 
659  CustomData_from_bmeshpoly(&me->fdata, &me->ldata, me->totface);
660 
661  /* TODO - add some --debug-mesh option */
662  if (G.debug & G_DEBUG) {
663  /* note: this warning may be un-called for if we are initializing the mesh for the
664  * first time from bmesh, rather than giving a warning about this we could be smarter
665  * and check if there was any data to begin with, for now just print the warning with
666  * some info to help troubleshoot what's going on - campbell */
667  printf(
668  "%s: warning! Tessellation uvs or vcol data got out of sync, "
669  "had to reset!\n CD_MTFACE: %d != CD_MLOOPUV: %d || CD_MCOL: %d != CD_MLOOPCOL: "
670  "%d\n",
671  __func__,
672  tottex_tessface,
673  tottex_original,
674  totcol_tessface,
675  totcol_original);
676  }
677  }
678  }
679 }
680 
682 {
683  BMesh *bm = me->edit_mesh ? me->edit_mesh->bm : NULL;
684  MVertSkin *vs;
685 
686  if (bm) {
688  BMVert *v;
689  BMIter iter;
690 
692 
693  /* Mark an arbitrary vertex as root */
694  BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
696  vs->flag |= MVERT_SKIN_ROOT;
697  break;
698  }
699  }
700  }
701  else {
702  if (!CustomData_has_layer(&me->vdata, CD_MVERT_SKIN)) {
703  vs = CustomData_add_layer(&me->vdata, CD_MVERT_SKIN, CD_DEFAULT, NULL, me->totvert);
704 
705  /* Mark an arbitrary vertex as root */
706  if (vs) {
707  vs->flag |= MVERT_SKIN_ROOT;
708  }
709  }
710  }
711 }
712 
714 {
715  BMesh *bm = me->edit_mesh ? me->edit_mesh->bm : NULL;
716  bool changed = false;
717  if (bm) {
720  changed = true;
721  }
722  }
723  else {
724  if (!CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
726  changed = true;
727  }
728  }
729  return changed;
730 }
731 
733 {
734  BMesh *bm = me->edit_mesh ? me->edit_mesh->bm : NULL;
735  bool changed = false;
736  if (bm) {
739  changed = true;
740  }
741  }
742  else {
743  if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
744  CustomData_free_layers(&me->pdata, CD_FACEMAP, me->totpoly);
745  changed = true;
746  }
747  }
748  return changed;
749 }
750 
751 /* this ensures grouped customdata (e.g. mtexpoly and mloopuv and mtface, or
752  * mloopcol and mcol) have the same relative active/render/clone/mask indices.
753  *
754  * note that for undo mesh data we want to skip 'ensure_tess_cd' call since
755  * we don't want to store memory for tessface when its only used for older
756  * versions of the mesh. - campbell*/
757 static void mesh_update_linked_customdata(Mesh *me, const bool do_ensure_tess_cd)
758 {
759  if (do_ensure_tess_cd) {
761  }
762 
764 }
765 
766 void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
767 {
768  mesh_update_linked_customdata(me, do_ensure_tess_cd);
769 
770  me->mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
771  me->dvert = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT);
772 
773  me->medge = CustomData_get_layer(&me->edata, CD_MEDGE);
774 
776  me->mcol = CustomData_get_layer(&me->fdata, CD_MCOL);
778 
779  me->mpoly = CustomData_get_layer(&me->pdata, CD_MPOLY);
781 
784 }
785 
787 {
788  if (me->edit_mesh) {
790  }
791 
793 }
794 
797 {
798  mesh_free_data(&me->id);
799 }
800 
802 {
803  CustomData_free(&mesh->vdata, mesh->totvert);
804  CustomData_free(&mesh->edata, mesh->totedge);
807  CustomData_free(&mesh->pdata, mesh->totpoly);
808 
811 
812  /* Note that materials and shape keys are not freed here. This is intentional, as freeing
813  * shape keys requires tagging the depsgraph for updated relations, which is expensive.
814  * Material slots should be kept in sync with the object.*/
815 
816  mesh->totvert = 0;
817  mesh->totedge = 0;
818  mesh->totface = 0;
819  mesh->totloop = 0;
820  mesh->totpoly = 0;
821  mesh->act_face = -1;
822  mesh->totselect = 0;
823 
825 }
826 
828 {
829  BKE_animdata_free(&mesh->id, false);
832 }
833 
834 static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
835 {
836  if (free_customdata) {
838  }
839  else {
841  }
842 
843  mesh->mface = NULL;
844  mesh->mtface = NULL;
845  mesh->mcol = NULL;
846  mesh->totface = 0;
847 }
848 
849 Mesh *BKE_mesh_add(Main *bmain, const char *name)
850 {
851  Mesh *me = BKE_id_new(bmain, ID_ME, name);
852 
853  return me;
854 }
855 
856 /* Custom data layer functions; those assume that totXXX are set correctly. */
857 static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
858 {
859  if (!CustomData_get_layer(&mesh->vdata, CD_MVERT)) {
861  }
862  if (!CustomData_get_layer(&mesh->edata, CD_MEDGE)) {
864  }
867  }
868  if (!CustomData_get_layer(&mesh->pdata, CD_MPOLY)) {
870  }
871 
872  if (do_tessface && !CustomData_get_layer(&mesh->fdata, CD_MFACE)) {
874  }
875 }
876 
878  int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
879 {
883 
884  /* Don't use CustomData_reset(...); because we don't want to touch custom-data. */
885  copy_vn_i(mesh->vdata.typemap, CD_NUMTYPES, -1);
886  copy_vn_i(mesh->edata.typemap, CD_NUMTYPES, -1);
889  copy_vn_i(mesh->pdata.typemap, CD_NUMTYPES, -1);
890 
891  mesh->totvert = verts_len;
892  mesh->totedge = edges_len;
893  mesh->totface = tessface_len;
894  mesh->totloop = loops_len;
895  mesh->totpoly = polys_len;
896 
899 
900  return mesh;
901 }
902 
903 /* Copy user editable settings that we want to preserve through the modifier stack
904  * or operations where a mesh with new topology is created based on another mesh. */
905 void BKE_mesh_copy_settings(Mesh *me_dst, const Mesh *me_src)
906 {
907  /* Copy general settings. */
908  me_dst->editflag = me_src->editflag;
909  me_dst->flag = me_src->flag;
910  me_dst->smoothresh = me_src->smoothresh;
911  me_dst->remesh_voxel_size = me_src->remesh_voxel_size;
913  me_dst->remesh_mode = me_src->remesh_mode;
914  me_dst->symmetry = me_src->symmetry;
915 
916  me_dst->face_sets_color_seed = me_src->face_sets_color_seed;
918 
919  /* Copy texture space. */
920  me_dst->texflag = me_src->texflag;
921  copy_v3_v3(me_dst->loc, me_src->loc);
922  copy_v3_v3(me_dst->size, me_src->size);
923 
924  /* Copy materials. */
925  if (me_dst->mat != NULL) {
926  MEM_freeN(me_dst->mat);
927  }
928  me_dst->mat = MEM_dupallocN(me_src->mat);
929  me_dst->totcol = me_src->totcol;
930 }
931 
933  int verts_len,
934  int edges_len,
935  int tessface_len,
936  int loops_len,
937  int polys_len,
939 {
940  /* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */
941  const bool do_tessface = (tessface_len || ((me_src->totface != 0) && (me_src->totpoly == 0)));
942 
943  Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL);
944 
945  me_dst->mselect = MEM_dupallocN(me_src->mselect);
946 
947  me_dst->totvert = verts_len;
948  me_dst->totedge = edges_len;
949  me_dst->totface = tessface_len;
950  me_dst->totloop = loops_len;
951  me_dst->totpoly = polys_len;
952 
953  me_dst->cd_flag = me_src->cd_flag;
954  BKE_mesh_copy_settings(me_dst, me_src);
955 
956  CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_CALLOC, verts_len);
957  CustomData_copy(&me_src->edata, &me_dst->edata, mask.emask, CD_CALLOC, edges_len);
958  CustomData_copy(&me_src->ldata, &me_dst->ldata, mask.lmask, CD_CALLOC, loops_len);
959  CustomData_copy(&me_src->pdata, &me_dst->pdata, mask.pmask, CD_CALLOC, polys_len);
960  if (do_tessface) {
961  CustomData_copy(&me_src->fdata, &me_dst->fdata, mask.fmask, CD_CALLOC, tessface_len);
962  }
963  else {
964  mesh_tessface_clear_intern(me_dst, false);
965  }
966 
967  /* The destination mesh should at least have valid primary CD layers,
968  * even in cases where the source mesh does not. */
969  mesh_ensure_cdlayers_primary(me_dst, do_tessface);
971 
972  return me_dst;
973 }
974 
976  int verts_len,
977  int edges_len,
978  int tessface_len,
979  int loops_len,
980  int polys_len)
981 {
983  me_src, verts_len, edges_len, tessface_len, loops_len, polys_len, CD_MASK_EVERYTHING);
984 }
985 
986 void BKE_mesh_eval_delete(struct Mesh *mesh_eval)
987 {
988  /* Evaluated mesh may point to edit mesh, but never owns it. */
989  mesh_eval->edit_mesh = NULL;
990  BKE_mesh_free_data(mesh_eval);
991  BKE_libblock_free_data(&mesh_eval->id, false);
992  MEM_freeN(mesh_eval);
993 }
994 
995 Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
996 {
997  int flags = LIB_ID_COPY_LOCALIZE;
998 
999  if (reference) {
1000  flags |= LIB_ID_COPY_CD_REFERENCE;
1001  }
1002 
1003  Mesh *result = (Mesh *)BKE_id_copy_ex(NULL, &source->id, NULL, flags);
1004  return result;
1005 }
1006 
1008  const struct BMeshCreateParams *create_params,
1009  const struct BMeshFromMeshParams *convert_params)
1010 {
1011  const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
1012 
1013  BMesh *bm = BM_mesh_create(&allocsize, create_params);
1014  BM_mesh_bm_from_me(bm, me, convert_params);
1015 
1016  return bm;
1017 }
1018 
1020  Object *ob,
1021  const bool add_key_index,
1022  const struct BMeshCreateParams *params)
1023 {
1024  return BKE_mesh_to_bmesh_ex(me,
1025  params,
1026  &(struct BMeshFromMeshParams){
1027  .calc_face_normal = false,
1028  .add_key_index = add_key_index,
1029  .use_shapekey = true,
1030  .active_shapekey = ob->shapenr,
1031  });
1032 }
1033 
1035  const struct BMeshToMeshParams *params,
1036  const Mesh *me_settings)
1037 {
1038  BLI_assert(params->calc_object_remap == false);
1041  BKE_mesh_copy_settings(mesh, me_settings);
1042  return mesh;
1043 }
1044 
1046  const CustomData_MeshMasks *cd_mask_extra,
1047  const Mesh *me_settings)
1048 {
1050  BM_mesh_bm_to_me_for_eval(bm, mesh, cd_mask_extra);
1051  BKE_mesh_copy_settings(mesh, me_settings);
1052  return mesh;
1053 }
1054 
1056 {
1057  /* This is Object-level data access,
1058  * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
1059  if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
1060  Mesh *me = ob->data;
1061  float min[3], max[3];
1062 
1063  INIT_MINMAX(min, max);
1064  if (!BKE_mesh_wrapper_minmax(me, min, max)) {
1065  min[0] = min[1] = min[2] = -1.0f;
1066  max[0] = max[1] = max[2] = 1.0f;
1067  }
1068 
1069  if (ob->runtime.bb == NULL) {
1070  ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
1071  }
1073  ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
1074  }
1075 
1076  return ob->runtime.bb;
1077 }
1078 
1080 {
1081  if (me->texflag & ME_AUTOSPACE) {
1082  float min[3], max[3];
1083 
1084  INIT_MINMAX(min, max);
1085  if (!BKE_mesh_wrapper_minmax(me, min, max)) {
1086  min[0] = min[1] = min[2] = -1.0f;
1087  max[0] = max[1] = max[2] = 1.0f;
1088  }
1089 
1090  float loc[3], size[3];
1091  mid_v3_v3v3(loc, min, max);
1092 
1093  size[0] = (max[0] - min[0]) / 2.0f;
1094  size[1] = (max[1] - min[1]) / 2.0f;
1095  size[2] = (max[2] - min[2]) / 2.0f;
1096 
1097  for (int a = 0; a < 3; a++) {
1098  if (size[a] == 0.0f) {
1099  size[a] = 1.0f;
1100  }
1101  else if (size[a] > 0.0f && size[a] < 0.00001f) {
1102  size[a] = 0.00001f;
1103  }
1104  else if (size[a] < 0.0f && size[a] > -0.00001f) {
1105  size[a] = -0.00001f;
1106  }
1107  }
1108 
1109  copy_v3_v3(me->loc, loc);
1110  copy_v3_v3(me->size, size);
1111 
1113  }
1114 }
1115 
1117 {
1118  if ((me->texflag & ME_AUTOSPACE) && !(me->texflag & ME_AUTOSPACE_EVALUATED)) {
1120  }
1121 }
1122 
1123 void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_size[3])
1124 {
1126 
1127  if (r_loc) {
1128  copy_v3_v3(r_loc, me->loc);
1129  }
1130  if (r_size) {
1131  copy_v3_v3(r_size, me->size);
1132  }
1133 }
1134 
1135 void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc, float **r_size)
1136 {
1138 
1139  if (r_texflag != NULL) {
1140  *r_texflag = &me->texflag;
1141  }
1142  if (r_loc != NULL) {
1143  *r_loc = me->loc;
1144  }
1145  if (r_size != NULL) {
1146  *r_size = me->size;
1147  }
1148 }
1149 
1151 {
1152  float *texloc, *texsize;
1153  short *texflag;
1154 
1155  if (BKE_object_obdata_texspace_get(ob, &texflag, &texloc, &texsize)) {
1156  me->texflag = *texflag;
1157  copy_v3_v3(me->loc, texloc);
1158  copy_v3_v3(me->size, texsize);
1159  }
1160 }
1161 
1163 {
1164  Mesh *me = ob->data;
1165  Mesh *tme = me->texcomesh ? me->texcomesh : me;
1166 
1167  /* Get appropriate vertex coordinates */
1168  float(*vcos)[3] = MEM_calloc_arrayN(me->totvert, sizeof(*vcos), "orco mesh");
1169  MVert *mvert = tme->mvert;
1170  int totvert = min_ii(tme->totvert, me->totvert);
1171 
1172  for (int a = 0; a < totvert; a++, mvert++) {
1173  copy_v3_v3(vcos[a], mvert->co);
1174  }
1175 
1176  return vcos;
1177 }
1178 
1179 void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int invert)
1180 {
1181  float loc[3], size[3];
1182 
1183  BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, size);
1184 
1185  if (invert) {
1186  for (int a = 0; a < totvert; a++) {
1187  float *co = orco[a];
1188  madd_v3_v3v3v3(co, loc, co, size);
1189  }
1190  }
1191  else {
1192  for (int a = 0; a < totvert; a++) {
1193  float *co = orco[a];
1194  co[0] = (co[0] - loc[0]) / size[0];
1195  co[1] = (co[1] - loc[1]) / size[1];
1196  co[2] = (co[2] - loc[2]) / size[2];
1197  }
1198  }
1199 }
1200 
1201 /* rotates the vertices of a face in case v[2] or v[3] (vertex index) is = 0.
1202  * this is necessary to make the if (mface->v4) check for quads work */
1203 int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr)
1204 {
1205  /* first test if the face is legal */
1206  if ((mface->v3 || nr == 4) && mface->v3 == mface->v4) {
1207  mface->v4 = 0;
1208  nr--;
1209  }
1210  if ((mface->v2 || mface->v4) && mface->v2 == mface->v3) {
1211  mface->v3 = mface->v4;
1212  mface->v4 = 0;
1213  nr--;
1214  }
1215  if (mface->v1 == mface->v2) {
1216  mface->v2 = mface->v3;
1217  mface->v3 = mface->v4;
1218  mface->v4 = 0;
1219  nr--;
1220  }
1221 
1222  /* Check corrupt cases, bow-tie geometry,
1223  * can't handle these because edge data won't exist so just return 0. */
1224  if (nr == 3) {
1225  if (
1226  /* real edges */
1227  mface->v1 == mface->v2 || mface->v2 == mface->v3 || mface->v3 == mface->v1) {
1228  return 0;
1229  }
1230  }
1231  else if (nr == 4) {
1232  if (
1233  /* real edges */
1234  mface->v1 == mface->v2 || mface->v2 == mface->v3 || mface->v3 == mface->v4 ||
1235  mface->v4 == mface->v1 ||
1236  /* across the face */
1237  mface->v1 == mface->v3 || mface->v2 == mface->v4) {
1238  return 0;
1239  }
1240  }
1241 
1242  /* prevent a zero at wrong index location */
1243  if (nr == 3) {
1244  if (mface->v3 == 0) {
1245  static int corner_indices[4] = {1, 2, 0, 3};
1246 
1247  SWAP(unsigned int, mface->v1, mface->v2);
1248  SWAP(unsigned int, mface->v2, mface->v3);
1249 
1250  if (fdata) {
1251  CustomData_swap_corners(fdata, mfindex, corner_indices);
1252  }
1253  }
1254  }
1255  else if (nr == 4) {
1256  if (mface->v3 == 0 || mface->v4 == 0) {
1257  static int corner_indices[4] = {2, 3, 0, 1};
1258 
1259  SWAP(unsigned int, mface->v1, mface->v3);
1260  SWAP(unsigned int, mface->v2, mface->v4);
1261 
1262  if (fdata) {
1263  CustomData_swap_corners(fdata, mfindex, corner_indices);
1264  }
1265  }
1266  }
1267 
1268  return nr;
1269 }
1270 
1272 {
1273  if (ob == NULL) {
1274  return NULL;
1275  }
1276  if (ob->type == OB_MESH) {
1277  return ob->data;
1278  }
1279 
1280  return NULL;
1281 }
1282 
1283 void BKE_mesh_assign_object(Main *bmain, Object *ob, Mesh *me)
1284 {
1285  Mesh *old = NULL;
1286 
1287  if (ob == NULL) {
1288  return;
1289  }
1290 
1292 
1293  if (ob->type == OB_MESH) {
1294  old = ob->data;
1295  if (old) {
1296  id_us_min(&old->id);
1297  }
1298  ob->data = me;
1299  id_us_plus((ID *)me);
1300  }
1301 
1302  BKE_object_materials_test(bmain, ob, (ID *)me);
1303 
1305 }
1306 
1307 void BKE_mesh_material_index_remove(Mesh *me, short index)
1308 {
1309  MPoly *mp;
1310  MFace *mf;
1311  int i;
1312 
1313  for (mp = me->mpoly, i = 0; i < me->totpoly; i++, mp++) {
1314  if (mp->mat_nr && mp->mat_nr >= index) {
1315  mp->mat_nr--;
1316  }
1317  }
1318 
1319  for (mf = me->mface, i = 0; i < me->totface; i++, mf++) {
1320  if (mf->mat_nr && mf->mat_nr >= index) {
1321  mf->mat_nr--;
1322  }
1323  }
1324 }
1325 
1326 bool BKE_mesh_material_index_used(Mesh *me, short index)
1327 {
1328  MPoly *mp;
1329  MFace *mf;
1330  int i;
1331 
1332  for (mp = me->mpoly, i = 0; i < me->totpoly; i++, mp++) {
1333  if (mp->mat_nr == index) {
1334  return true;
1335  }
1336  }
1337 
1338  for (mf = me->mface, i = 0; i < me->totface; i++, mf++) {
1339  if (mf->mat_nr == index) {
1340  return true;
1341  }
1342  }
1343 
1344  return false;
1345 }
1346 
1348 {
1349  MPoly *mp;
1350  MFace *mf;
1351  int i;
1352 
1353  for (mp = me->mpoly, i = 0; i < me->totpoly; i++, mp++) {
1354  mp->mat_nr = 0;
1355  }
1356 
1357  for (mf = me->mface, i = 0; i < me->totface; i++, mf++) {
1358  mf->mat_nr = 0;
1359  }
1360 }
1361 
1362 void BKE_mesh_material_remap(Mesh *me, const unsigned int *remap, unsigned int remap_len)
1363 {
1364  const short remap_len_short = (short)remap_len;
1365 
1366 #define MAT_NR_REMAP(n) \
1367  if (n < remap_len_short) { \
1368  BLI_assert(n >= 0 && remap[n] < remap_len_short); \
1369  n = remap[n]; \
1370  } \
1371  ((void)0)
1372 
1373  if (me->edit_mesh) {
1374  BMEditMesh *em = me->edit_mesh;
1375  BMIter iter;
1376  BMFace *efa;
1377 
1378  BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
1379  MAT_NR_REMAP(efa->mat_nr);
1380  }
1381  }
1382  else {
1383  int i;
1384  for (i = 0; i < me->totpoly; i++) {
1385  MAT_NR_REMAP(me->mpoly[i].mat_nr);
1386  }
1387  }
1388 
1389 #undef MAT_NR_REMAP
1390 }
1391 
1392 void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth)
1393 {
1394  if (use_smooth) {
1395  for (int i = 0; i < me->totpoly; i++) {
1396  me->mpoly[i].flag |= ME_SMOOTH;
1397  }
1398  }
1399  else {
1400  for (int i = 0; i < me->totpoly; i++) {
1401  me->mpoly[i].flag &= ~ME_SMOOTH;
1402  }
1403  }
1404 }
1405 
1410 int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, uint vert)
1411 {
1412  for (int j = 0; j < poly->totloop; j++, loopstart++) {
1413  if (loopstart->v == vert) {
1414  return j;
1415  }
1416  }
1417 
1418  return -1;
1419 }
1420 
1427  const MLoop *mloop,
1428  unsigned int vert,
1429  unsigned int r_adj[2])
1430 {
1431  int corner = poly_find_loop_from_vert(poly, &mloop[poly->loopstart], vert);
1432 
1433  if (corner != -1) {
1434  /* vertex was found */
1435  r_adj[0] = ME_POLY_LOOP_PREV(mloop, poly, corner)->v;
1436  r_adj[1] = ME_POLY_LOOP_NEXT(mloop, poly, corner)->v;
1437  }
1438 
1439  return corner;
1440 }
1441 
1447 {
1448  if (e->v1 == v) {
1449  return e->v2;
1450  }
1451  if (e->v2 == v) {
1452  return e->v1;
1453  }
1454 
1455  return -1;
1456 }
1457 
1461 void BKE_mesh_looptri_get_real_edges(const Mesh *mesh, const MLoopTri *looptri, int r_edges[3])
1462 {
1463  for (int i = 2, i_next = 0; i_next < 3; i = i_next++) {
1464  const MLoop *l1 = &mesh->mloop[looptri->tri[i]], *l2 = &mesh->mloop[looptri->tri[i_next]];
1465  const MEdge *e = &mesh->medge[l1->e];
1466 
1467  bool is_real = (l1->v == e->v1 && l2->v == e->v2) || (l1->v == e->v2 && l2->v == e->v1);
1468 
1469  r_edges[i] = is_real ? l1->e : -1;
1470  }
1471 }
1472 
1473 /* basic vertex data functions */
1474 bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
1475 {
1476  int i = me->totvert;
1477  MVert *mvert;
1478  for (mvert = me->mvert; i--; mvert++) {
1479  minmax_v3v3_v3(r_min, r_max, mvert->co);
1480  }
1481 
1482  return (me->totvert != 0);
1483 }
1484 
1485 void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
1486 {
1487  int i;
1488  MVert *mvert = CustomData_duplicate_referenced_layer(&me->vdata, CD_MVERT, me->totvert);
1490 
1491  /* If the referenced l;ayer has been re-allocated need to update pointers stored in the mesh. */
1493 
1494  for (i = 0; i < me->totvert; i++, mvert++) {
1495  mul_m4_v3(mat, mvert->co);
1496  }
1497 
1498  if (do_keys && me->key) {
1499  KeyBlock *kb;
1500  for (kb = me->key->block.first; kb; kb = kb->next) {
1501  float *fp = kb->data;
1502  for (i = kb->totelem; i--; fp += 3) {
1503  mul_m4_v3(mat, fp);
1504  }
1505  }
1506  }
1507 
1508  /* don't update normals, caller can do this explicitly.
1509  * We do update loop normals though, those may not be auto-generated
1510  * (see e.g. STL import script)! */
1511  if (lnors) {
1512  float m3[3][3];
1513 
1514  copy_m3_m4(m3, mat);
1515  normalize_m3(m3);
1516  for (i = 0; i < me->totloop; i++, lnors++) {
1517  mul_m3_v3(m3, *lnors);
1518  }
1519  }
1520 }
1521 
1522 void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys)
1523 {
1524  MVert *mvert = CustomData_duplicate_referenced_layer(&me->vdata, CD_MVERT, me->totvert);
1525  /* If the referenced layer has been re-allocated need to update pointers stored in the mesh. */
1527 
1528  int i = me->totvert;
1529  for (mvert = me->mvert; i--; mvert++) {
1530  add_v3_v3(mvert->co, offset);
1531  }
1532 
1533  if (do_keys && me->key) {
1534  KeyBlock *kb;
1535  for (kb = me->key->block.first; kb; kb = kb->next) {
1536  float *fp = kb->data;
1537  for (i = kb->totelem; i--; fp += 3) {
1538  add_v3_v3(fp, offset);
1539  }
1540  }
1541  }
1542 }
1543 
1545 {
1547  &mesh->fdata,
1548  &mesh->ldata,
1549  &mesh->pdata,
1550  mesh->mvert,
1551  mesh->totface,
1552  mesh->totloop,
1553  mesh->totpoly,
1554  /* calc normals right after, don't copy from polys here */
1555  false);
1556 
1558 }
1559 
1561 {
1562  if (mesh->totpoly && mesh->totface == 0) {
1564  }
1565 }
1566 
1568 {
1570 }
1571 
1573 {
1574  if (UNLIKELY(mesh->cd_flag)) {
1575  return;
1576  }
1577 
1578  MVert *mv;
1579  MEdge *med;
1580  int i;
1581 
1582  for (mv = mesh->mvert, i = 0; i < mesh->totvert; mv++, i++) {
1583  if (mv->bweight != 0) {
1585  break;
1586  }
1587  }
1588 
1589  for (med = mesh->medge, i = 0; i < mesh->totedge; med++, i++) {
1590  if (med->bweight != 0) {
1593  break;
1594  }
1595  }
1596  if (med->crease != 0) {
1599  break;
1600  }
1601  }
1602  }
1603 }
1604 
1605 /* -------------------------------------------------------------------- */
1606 /* MSelect functions (currently used in weight paint mode) */
1607 
1609 {
1610  if (me->mselect) {
1611  MEM_freeN(me->mselect);
1612  me->mselect = NULL;
1613  }
1614  me->totselect = 0;
1615 }
1616 
1618 {
1619  MSelect *mselect_src, *mselect_dst;
1620  int i_src, i_dst;
1621 
1622  if (me->totselect == 0) {
1623  return;
1624  }
1625 
1626  mselect_src = me->mselect;
1627  mselect_dst = MEM_malloc_arrayN((me->totselect), sizeof(MSelect), "Mesh selection history");
1628 
1629  for (i_src = 0, i_dst = 0; i_src < me->totselect; i_src++) {
1630  int index = mselect_src[i_src].index;
1631  switch (mselect_src[i_src].type) {
1632  case ME_VSEL: {
1633  if (me->mvert[index].flag & SELECT) {
1634  mselect_dst[i_dst] = mselect_src[i_src];
1635  i_dst++;
1636  }
1637  break;
1638  }
1639  case ME_ESEL: {
1640  if (me->medge[index].flag & SELECT) {
1641  mselect_dst[i_dst] = mselect_src[i_src];
1642  i_dst++;
1643  }
1644  break;
1645  }
1646  case ME_FSEL: {
1647  if (me->mpoly[index].flag & SELECT) {
1648  mselect_dst[i_dst] = mselect_src[i_src];
1649  i_dst++;
1650  }
1651  break;
1652  }
1653  default: {
1654  BLI_assert(0);
1655  break;
1656  }
1657  }
1658  }
1659 
1660  MEM_freeN(mselect_src);
1661 
1662  if (i_dst == 0) {
1663  MEM_freeN(mselect_dst);
1664  mselect_dst = NULL;
1665  }
1666  else if (i_dst != me->totselect) {
1667  mselect_dst = MEM_reallocN(mselect_dst, sizeof(MSelect) * i_dst);
1668  }
1669 
1670  me->totselect = i_dst;
1671  me->mselect = mselect_dst;
1672 }
1673 
1677 int BKE_mesh_mselect_find(Mesh *me, int index, int type)
1678 {
1680 
1681  for (int i = 0; i < me->totselect; i++) {
1682  if ((me->mselect[i].index == index) && (me->mselect[i].type == type)) {
1683  return i;
1684  }
1685  }
1686 
1687  return -1;
1688 }
1689 
1694 {
1696 
1697  if (me->totselect) {
1698  if (me->mselect[me->totselect - 1].type == type) {
1699  return me->mselect[me->totselect - 1].index;
1700  }
1701  }
1702  return -1;
1703 }
1704 
1705 void BKE_mesh_mselect_active_set(Mesh *me, int index, int type)
1706 {
1707  const int msel_index = BKE_mesh_mselect_find(me, index, type);
1708 
1709  if (msel_index == -1) {
1710  /* add to the end */
1711  me->mselect = MEM_reallocN(me->mselect, sizeof(MSelect) * (me->totselect + 1));
1712  me->mselect[me->totselect].index = index;
1713  me->mselect[me->totselect].type = type;
1714  me->totselect++;
1715  }
1716  else if (msel_index != me->totselect - 1) {
1717  /* move to the end */
1718  SWAP(MSelect, me->mselect[msel_index], me->mselect[me->totselect - 1]);
1719  }
1720 
1721  BLI_assert((me->mselect[me->totselect - 1].index == index) &&
1722  (me->mselect[me->totselect - 1].type == type));
1723 }
1724 
1725 void BKE_mesh_count_selected_items(const Mesh *mesh, int r_count[3])
1726 {
1727  r_count[0] = r_count[1] = r_count[2] = 0;
1728  if (mesh->edit_mesh) {
1729  BMesh *bm = mesh->edit_mesh->bm;
1730  r_count[0] = bm->totvertsel;
1731  r_count[1] = bm->totedgesel;
1732  r_count[2] = bm->totfacesel;
1733  }
1734  /* We could support faces in paint modes. */
1735 }
1736 
1737 void BKE_mesh_vert_coords_get(const Mesh *mesh, float (*vert_coords)[3])
1738 {
1739  const MVert *mv = mesh->mvert;
1740  for (int i = 0; i < mesh->totvert; i++, mv++) {
1741  copy_v3_v3(vert_coords[i], mv->co);
1742  }
1743 }
1744 
1745 float (*BKE_mesh_vert_coords_alloc(const Mesh *mesh, int *r_vert_len))[3]
1746 {
1747  float(*vert_coords)[3] = MEM_mallocN(sizeof(float[3]) * mesh->totvert, __func__);
1748  BKE_mesh_vert_coords_get(mesh, vert_coords);
1749  if (r_vert_len) {
1750  *r_vert_len = mesh->totvert;
1751  }
1752  return vert_coords;
1753 }
1754 
1755 void BKE_mesh_vert_coords_apply(Mesh *mesh, const float (*vert_coords)[3])
1756 {
1757  /* This will just return the pointer if it wasn't a referenced layer. */
1759  mesh->mvert = mv;
1760  for (int i = 0; i < mesh->totvert; i++, mv++) {
1761  copy_v3_v3(mv->co, vert_coords[i]);
1762  }
1764 }
1765 
1767  const float (*vert_coords)[3],
1768  const float mat[4][4])
1769 {
1770  /* This will just return the pointer if it wasn't a referenced layer. */
1772  mesh->mvert = mv;
1773  for (int i = 0; i < mesh->totvert; i++, mv++) {
1774  mul_v3_m4v3(mv->co, mat, vert_coords[i]);
1775  }
1777 }
1778 
1779 void BKE_mesh_vert_normals_apply(Mesh *mesh, const short (*vert_normals)[3])
1780 {
1781  /* This will just return the pointer if it wasn't a referenced layer. */
1783  mesh->mvert = mv;
1784  for (int i = 0; i < mesh->totvert; i++, mv++) {
1785  copy_v3_v3_short(mv->no, vert_normals[i]);
1786  }
1788 }
1789 
1798 {
1799  float(*r_loopnors)[3];
1800  float(*polynors)[3];
1801  short(*clnors)[2] = NULL;
1802  bool free_polynors = false;
1803 
1804  /* Note that we enforce computing clnors when the clnor space array is requested by caller here.
1805  * However, we obviously only use the autosmooth angle threshold
1806  * only in case autosmooth is enabled. */
1807  const bool use_split_normals = (r_lnors_spacearr != NULL) || ((mesh->flag & ME_AUTOSMOOTH) != 0);
1808  const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : (float)M_PI;
1809 
1811  r_loopnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
1812  memset(r_loopnors, 0, sizeof(float[3]) * mesh->totloop);
1813  }
1814  else {
1817  }
1818 
1819  /* may be NULL */
1821 
1822  if (CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
1823  /* This assume that layer is always up to date, not sure this is the case
1824  * (esp. in Edit mode?)... */
1825  polynors = CustomData_get_layer(&mesh->pdata, CD_NORMAL);
1826  free_polynors = false;
1827  }
1828  else {
1829  polynors = MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__);
1831  NULL,
1832  mesh->totvert,
1833  mesh->mloop,
1834  mesh->mpoly,
1835  mesh->totloop,
1836  mesh->totpoly,
1837  polynors,
1838  false);
1839  free_polynors = true;
1840  }
1841 
1843  mesh->totvert,
1844  mesh->medge,
1845  mesh->totedge,
1846  mesh->mloop,
1847  r_loopnors,
1848  mesh->totloop,
1849  mesh->mpoly,
1850  (const float(*)[3])polynors,
1851  mesh->totpoly,
1852  use_split_normals,
1853  split_angle,
1854  r_lnors_spacearr,
1855  clnors,
1856  NULL);
1857 
1858  if (free_polynors) {
1859  MEM_freeN(polynors);
1860  }
1861 
1863 }
1864 
1866 {
1868 }
1869 
1870 /* Split faces helper functions. */
1871 
1872 typedef struct SplitFaceNewVert {
1876  float *vnor;
1878 
1879 typedef struct SplitFaceNewEdge {
1883  int v1;
1884  int v2;
1886 
1887 /* Detect needed new vertices, and update accordingly loops' vertex indices.
1888  * WARNING! Leaves mesh in invalid state. */
1890  MLoopNorSpaceArray *lnors_spacearr,
1891  SplitFaceNewVert **new_verts,
1892  MemArena *memarena)
1893 {
1894  /* This is now mandatory, trying to do the job in simple way without that data is doomed to fail,
1895  * even when only dealing with smooth/flat faces one can find cases that no simple algorithm
1896  * can handle properly. */
1897  BLI_assert(lnors_spacearr != NULL);
1898 
1899  const int loops_len = mesh->totloop;
1900  int verts_len = mesh->totvert;
1901  MVert *mvert = mesh->mvert;
1902  MLoop *mloop = mesh->mloop;
1903 
1904  BLI_bitmap *verts_used = BLI_BITMAP_NEW(verts_len, __func__);
1905  BLI_bitmap *done_loops = BLI_BITMAP_NEW(loops_len, __func__);
1906 
1907  MLoop *ml = mloop;
1908  MLoopNorSpace **lnor_space = lnors_spacearr->lspacearr;
1909 
1910  BLI_assert(lnors_spacearr->data_type == MLNOR_SPACEARR_LOOP_INDEX);
1911 
1912  for (int loop_idx = 0; loop_idx < loops_len; loop_idx++, ml++, lnor_space++) {
1913  if (!BLI_BITMAP_TEST(done_loops, loop_idx)) {
1914  const int vert_idx = ml->v;
1915  const bool vert_used = BLI_BITMAP_TEST_BOOL(verts_used, vert_idx);
1916  /* If vert is already used by another smooth fan, we need a new vert for this one. */
1917  const int new_vert_idx = vert_used ? verts_len++ : vert_idx;
1918 
1919  BLI_assert(*lnor_space);
1920 
1921  if ((*lnor_space)->flags & MLNOR_SPACE_IS_SINGLE) {
1922  /* Single loop in this fan... */
1923  BLI_assert(POINTER_AS_INT((*lnor_space)->loops) == loop_idx);
1924  BLI_BITMAP_ENABLE(done_loops, loop_idx);
1925  if (vert_used) {
1926  ml->v = new_vert_idx;
1927  }
1928  }
1929  else {
1930  for (LinkNode *lnode = (*lnor_space)->loops; lnode; lnode = lnode->next) {
1931  const int ml_fan_idx = POINTER_AS_INT(lnode->link);
1932  BLI_BITMAP_ENABLE(done_loops, ml_fan_idx);
1933  if (vert_used) {
1934  mloop[ml_fan_idx].v = new_vert_idx;
1935  }
1936  }
1937  }
1938 
1939  if (!vert_used) {
1940  BLI_BITMAP_ENABLE(verts_used, vert_idx);
1941  /* We need to update that vertex's normal here, we won't go over it again. */
1942  /* This is important! *DO NOT* set vnor to final computed lnor,
1943  * vnor should always be defined to 'automatic normal' value computed from its polys,
1944  * not some custom normal.
1945  * Fortunately, that's the loop normal space's 'lnor' reference vector. ;) */
1946  normal_float_to_short_v3(mvert[vert_idx].no, (*lnor_space)->vec_lnor);
1947  }
1948  else {
1949  /* Add new vert to list. */
1950  SplitFaceNewVert *new_vert = BLI_memarena_alloc(memarena, sizeof(*new_vert));
1951  new_vert->orig_index = vert_idx;
1952  new_vert->new_index = new_vert_idx;
1953  new_vert->vnor = (*lnor_space)->vec_lnor; /* See note above. */
1954  new_vert->next = *new_verts;
1955  *new_verts = new_vert;
1956  }
1957  }
1958  }
1959 
1960  MEM_freeN(done_loops);
1961  MEM_freeN(verts_used);
1962 
1963  return verts_len - mesh->totvert;
1964 }
1965 
1966 /* Detect needed new edges, and update accordingly loops' edge indices.
1967  * WARNING! Leaves mesh in invalid state. */
1969  SplitFaceNewEdge **new_edges,
1970  MemArena *memarena)
1971 {
1972  const int num_polys = mesh->totpoly;
1973  int num_edges = mesh->totedge;
1974  MEdge *medge = mesh->medge;
1975  MLoop *mloop = mesh->mloop;
1976  const MPoly *mpoly = mesh->mpoly;
1977 
1978  BLI_bitmap *edges_used = BLI_BITMAP_NEW(num_edges, __func__);
1979  EdgeHash *edges_hash = BLI_edgehash_new_ex(__func__, num_edges);
1980 
1981  const MPoly *mp = mpoly;
1982  for (int poly_idx = 0; poly_idx < num_polys; poly_idx++, mp++) {
1983  MLoop *ml_prev = &mloop[mp->loopstart + mp->totloop - 1];
1984  MLoop *ml = &mloop[mp->loopstart];
1985  for (int loop_idx = 0; loop_idx < mp->totloop; loop_idx++, ml++) {
1986  void **eval;
1987  if (!BLI_edgehash_ensure_p(edges_hash, ml_prev->v, ml->v, &eval)) {
1988  const int edge_idx = ml_prev->e;
1989 
1990  /* That edge has not been encountered yet, define it. */
1991  if (BLI_BITMAP_TEST(edges_used, edge_idx)) {
1992  /* Original edge has already been used, we need to define a new one. */
1993  const int new_edge_idx = num_edges++;
1994  *eval = POINTER_FROM_INT(new_edge_idx);
1995  ml_prev->e = new_edge_idx;
1996 
1997  SplitFaceNewEdge *new_edge = BLI_memarena_alloc(memarena, sizeof(*new_edge));
1998  new_edge->orig_index = edge_idx;
1999  new_edge->new_index = new_edge_idx;
2000  new_edge->v1 = ml_prev->v;
2001  new_edge->v2 = ml->v;
2002  new_edge->next = *new_edges;
2003  *new_edges = new_edge;
2004  }
2005  else {
2006  /* We can re-use original edge. */
2007  medge[edge_idx].v1 = ml_prev->v;
2008  medge[edge_idx].v2 = ml->v;
2009  *eval = POINTER_FROM_INT(edge_idx);
2010  BLI_BITMAP_ENABLE(edges_used, edge_idx);
2011  }
2012  }
2013  else {
2014  /* Edge already known, just update loop's edge index. */
2015  ml_prev->e = POINTER_AS_INT(*eval);
2016  }
2017 
2018  ml_prev = ml;
2019  }
2020  }
2021 
2022  MEM_freeN(edges_used);
2023  BLI_edgehash_free(edges_hash, NULL);
2024 
2025  return num_edges - mesh->totedge;
2026 }
2027 
2028 /* Perform actual split of vertices. */
2030  SplitFaceNewVert *new_verts,
2031  const int num_new_verts)
2032 {
2033  const int verts_len = mesh->totvert - num_new_verts;
2034  MVert *mvert = mesh->mvert;
2035 
2036  /* Remember new_verts is a single linklist, so its items are in reversed order... */
2037  MVert *new_mv = &mvert[mesh->totvert - 1];
2038  for (int i = mesh->totvert - 1; i >= verts_len; i--, new_mv--, new_verts = new_verts->next) {
2039  BLI_assert(new_verts->new_index == i);
2040  BLI_assert(new_verts->new_index != new_verts->orig_index);
2041  CustomData_copy_data(&mesh->vdata, &mesh->vdata, new_verts->orig_index, i, 1);
2042  if (new_verts->vnor) {
2043  normal_float_to_short_v3(new_mv->no, new_verts->vnor);
2044  }
2045  }
2046 }
2047 
2048 /* Perform actual split of edges. */
2050  SplitFaceNewEdge *new_edges,
2051  const int num_new_edges)
2052 {
2053  const int num_edges = mesh->totedge - num_new_edges;
2054  MEdge *medge = mesh->medge;
2055 
2056  /* Remember new_edges is a single linklist, so its items are in reversed order... */
2057  MEdge *new_med = &medge[mesh->totedge - 1];
2058  for (int i = mesh->totedge - 1; i >= num_edges; i--, new_med--, new_edges = new_edges->next) {
2059  BLI_assert(new_edges->new_index == i);
2060  BLI_assert(new_edges->new_index != new_edges->orig_index);
2061  CustomData_copy_data(&mesh->edata, &mesh->edata, new_edges->orig_index, i, 1);
2062  new_med->v1 = new_edges->v1;
2063  new_med->v2 = new_edges->v2;
2064  }
2065 }
2066 
2067 /* Split faces based on the edge angle and loop normals.
2068  * Matches behavior of face splitting in render engines.
2069  *
2070  * NOTE: Will leave CD_NORMAL loop data layer which is
2071  * used by render engines to set shading up.
2072  */
2073 void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals)
2074 {
2075  const int num_polys = mesh->totpoly;
2076 
2077  if (num_polys == 0) {
2078  return;
2079  }
2081 
2082  MLoopNorSpaceArray lnors_spacearr = {NULL};
2083  /* Compute loop normals and loop normal spaces (a.k.a. smooth fans of faces around vertices). */
2084  BKE_mesh_calc_normals_split_ex(mesh, &lnors_spacearr);
2085  /* Stealing memarena from loop normals space array. */
2086  MemArena *memarena = lnors_spacearr.mem;
2087 
2088  SplitFaceNewVert *new_verts = NULL;
2089  SplitFaceNewEdge *new_edges = NULL;
2090 
2091  /* Ensure we own the layers, we need to do this before split_faces_prepare_new_verts as it will
2092  * directly assign new indices to existing edges and loops. */
2096  /* Update pointers in case we duplicated referenced layers. */
2098 
2099  /* Detect loop normal spaces (a.k.a. smooth fans) that will need a new vert. */
2100  const int num_new_verts = split_faces_prepare_new_verts(
2101  mesh, &lnors_spacearr, &new_verts, memarena);
2102 
2103  if (num_new_verts > 0) {
2104  /* Reminder: beyond this point, there is no way out, mesh is in invalid state
2105  * (due to early-reassignment of loops' vertex and edge indices to new,
2106  * to-be-created split ones). */
2107 
2108  const int num_new_edges = split_faces_prepare_new_edges(mesh, &new_edges, memarena);
2109  /* We can have to split a vertex without having to add a single new edge... */
2110  const bool do_edges = (num_new_edges > 0);
2111 
2112  /* Reallocate all vert and edge related data. */
2113  mesh->totvert += num_new_verts;
2114  CustomData_realloc(&mesh->vdata, mesh->totvert);
2115  if (do_edges) {
2116  mesh->totedge += num_new_edges;
2117  CustomData_realloc(&mesh->edata, mesh->totedge);
2118  }
2119  /* Update pointers to a newly allocated memory. */
2121 
2122  /* Perform actual split of vertices and edges. */
2123  split_faces_split_new_verts(mesh, new_verts, num_new_verts);
2124  if (do_edges) {
2125  split_faces_split_new_edges(mesh, new_edges, num_new_edges);
2126  }
2127  }
2128 
2129  /* Note: after this point mesh is expected to be valid again. */
2130 
2131  /* CD_NORMAL is expected to be temporary only. */
2132  if (free_loop_normals) {
2134  }
2135 
2136  /* Also frees new_verts/edges temp data, since we used its memarena to allocate them. */
2137  BKE_lnor_spacearr_free(&lnors_spacearr);
2138 
2139 #ifdef VALIDATE_MESH
2140  BKE_mesh_validate(mesh, true, true);
2141 #endif
2142 }
2143 
2144 /* **** Depsgraph evaluation **** */
2145 
2147 {
2150  /* We are here because something did change in the mesh. This means we can not trust the existing
2151  * evaluated mesh, and we don't know what parts of the mesh did change. So we simply delete the
2152  * evaluated mesh and let objects to re-create it with updated settings. */
2153  if (mesh->runtime.mesh_eval != NULL) {
2157  }
2158  if (DEG_is_active(depsgraph)) {
2159  Mesh *mesh_orig = (Mesh *)DEG_get_original_id(&mesh->id);
2161  mesh_orig->texflag |= ME_AUTOSPACE_EVALUATED;
2162  copy_v3_v3(mesh_orig->loc, mesh->loc);
2163  copy_v3_v3(mesh_orig->size, mesh->size);
2164  }
2165  }
2166 }
typedef float(TangentPoint)[2]
void BKE_animdata_free(struct ID *id, const bool do_id_user)
Definition: anim_data.c:230
void BKE_animdata_blend_read_data(struct BlendDataReader *reader, struct AnimData *adt)
Definition: anim_data.c:1574
void BKE_animdata_blend_write(struct BlendWriter *writer, struct AnimData *adt)
Definition: anim_data.c:1552
const CustomData_MeshMasks CD_MASK_EVERYTHING
Definition: customdata.c:1986
void CustomData_free(struct CustomData *data, int totelem)
Definition: customdata.c:2239
void CustomData_blend_read(struct BlendDataReader *reader, struct CustomData *data, int count)
Definition: customdata.c:5180
int CustomData_number_of_layers(const struct CustomData *data, int type)
void CustomData_blend_write(struct BlendWriter *writer, struct CustomData *data, CustomDataLayer *layers, int count, CustomDataMask cddata_mask, struct ID *id)
Definition: customdata.c:5073
eCDAllocType
@ CD_REFERENCE
@ CD_CALLOC
@ CD_DUPLICATE
@ CD_DEFAULT
void CustomData_free_layers(struct CustomData *data, int type, int totelem)
Definition: customdata.c:2716
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.c:76
void CustomData_blend_write_prepare(struct CustomData *data, struct CustomDataLayer **r_write_layers, struct CustomDataLayer *write_layers_buff, size_t write_layers_size)
Definition: customdata.c:4237
void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *ldata)
Definition: customdata.c:3411
void * CustomData_duplicate_referenced_layer(struct CustomData *data, const int type, const int totelem)
Definition: customdata.c:2788
void * CustomData_get_layer(const struct CustomData *data, int type)
void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int total)
Definition: customdata.c:3338
void * CustomData_bmesh_get(const struct CustomData *data, void *block, int type)
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
Definition: customdata.c:2620
void CustomData_set_layer_flag(struct CustomData *data, int type, int flag)
Definition: customdata.c:2475
const CustomData_MeshMasks CD_MASK_DERIVEDMESH
Definition: customdata.c:1952
void CustomData_copy(const struct CustomData *source, struct CustomData *dest, CustomDataMask mask, eCDAllocType alloctype, int totelem)
Definition: customdata.c:2193
void CustomData_realloc(struct CustomData *data, int totelem)
Definition: customdata.c:2180
void CustomData_swap_corners(struct CustomData *data, int index, const int *corner_indices)
Definition: customdata.c:3122
void CustomData_duplicate_referenced_layers(CustomData *data, int totelem)
Definition: customdata.c:2818
void CustomData_copy_data(const struct CustomData *source, struct CustomData *dest, int source_index, int dest_index, int count)
const CustomData_MeshMasks CD_MASK_MESH
Definition: customdata.c:1933
void CustomData_reset(struct CustomData *data)
Definition: customdata.c:2233
support for deformation groups and hooks.
void BKE_defvert_blend_read(struct BlendDataReader *reader, int count, struct MDeformVert *mdverts)
Definition: deform.c:1542
@ G_DEBUG
Definition: BKE_global.h:133
const char * BKE_idtype_idcode_to_name(const short idcode)
Definition: idtype.c:168
void id_us_min(struct ID *id)
Definition: lib_id.c:297
void * BKE_id_new_nomain(const short type, const char *name)
Definition: lib_id.c:1196
void BKE_libblock_free_data(struct ID *id, const bool do_id_user) ATTR_NONNULL()
Definition: lib_id_delete.c:55
@ LIB_ID_CREATE_LOCALIZE
Definition: BKE_lib_id.h:142
@ LIB_ID_COPY_CD_REFERENCE
Definition: BKE_lib_id.h:122
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
@ LIB_ID_COPY_SHAPEKEY
Definition: BKE_lib_id.h:133
void * BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT
Definition: lib_id.c:1062
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_id_free(struct Main *bmain, void *idv)
void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1)
Definition: lib_id.c:1122
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
void BKE_id_blend_write(struct BlendWriter *writer, struct ID *id)
Definition: lib_id.c:2395
void * BKE_id_new(struct Main *bmain, const short type, const char *name)
Definition: lib_id.c:1177
#define BKE_LIB_FOREACHID_PROCESS(_data, _id_super, _cb_flag)
@ IDWALK_CB_NEVER_SELF
Definition: BKE_lib_query.h:49
@ IDWALK_CB_USER
Definition: BKE_lib_query.h:87
General operations, lookup, etc. for materials.
void BKE_object_materials_test(struct Main *bmain, struct Object *ob, struct ID *id)
Definition: material.c:772
@ MLNOR_SPACE_IS_SINGLE
Definition: BKE_mesh.h:365
@ MLNOR_SPACEARR_LOOP_INDEX
Definition: BKE_mesh.h:383
int BKE_mesh_tessface_calc_ex(struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, struct MVert *mvert, int totface, int totloop, int totpoly, const bool do_face_nor_copy)
void BKE_mesh_normals_loop_split(const struct MVert *mverts, const int numVerts, struct MEdge *medges, const int numEdges, struct MLoop *mloops, float(*r_loopnors)[3], const int numLoops, struct MPoly *mpolys, const float(*polynors)[3], const int numPolys, const bool use_split_normals, const float split_angle, MLoopNorSpaceArray *r_lnors_spacearr, short(*clnors_data)[2], int *r_loop_to_poly)
void BKE_lnor_spacearr_free(MLoopNorSpaceArray *lnors_spacearr)
bool BKE_mesh_validate(struct Mesh *me, const bool do_verbose, const bool cddata_check_mask)
void BKE_mesh_calc_normals_poly(struct MVert *mverts, float(*r_vertnors)[3], int numVerts, const struct MLoop *mloop, const struct MPoly *mpolys, int numLoops, int numPolys, float(*r_polyNors)[3], const bool only_face_normals)
void BKE_mesh_runtime_clear_cache(struct Mesh *mesh)
Definition: mesh_runtime.c:75
void BKE_mesh_runtime_reset(struct Mesh *mesh)
Definition: mesh_runtime.c:49
void BKE_mesh_runtime_reset_on_copy(struct Mesh *mesh, const int flag)
bool BKE_mesh_wrapper_minmax(const struct Mesh *me, float min[3], float max[3])
void BKE_modifiers_test_object(struct Object *ob)
void multires_force_sculpt_rebuild(struct Object *object)
Definition: multires.c:456
General operations, lookup, etc. for blender objects.
void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3])
Definition: object.c:3778
bool BKE_object_obdata_texspace_get(struct Object *ob, short **r_texflag, float **r_loc, float **r_size)
Definition: object.c:4413
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition: BLI_bitmap.h:78
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
Definition: BLI_bitmap.h:73
#define BLI_BITMAP_NEW(_tot, _alloc_string)
Definition: BLI_bitmap.h:50
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP free_value)
Definition: edgehash.c:244
EdgeHash * BLI_edgehash_new_ex(const char *info, const unsigned int nentries_reserve)
Definition: edgehash.c:226
void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *val)
Definition: edgehash.c:279
bool BLI_edgehash_ensure_p(EdgeHash *eh, unsigned int v0, unsigned int v1, void ***r_val) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:355
void * BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) ATTR_WARN_UNUSED_RESULT
Definition: edgehash.c:325
void BLI_endian_switch_uint32_array(unsigned int *val, const int size) ATTR_NONNULL(1)
Definition: endian_switch.c:55
BLI_INLINE unsigned int BLI_hash_int(unsigned int k)
Definition: BLI_hash.h:103
MINLINE int min_ii(int a, int b)
#define M_PI
Definition: BLI_math_base.h:38
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void copy_m3_m4(float m1[3][3], const float m2[4][4])
Definition: math_matrix.c:105
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:732
void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3])
Definition: math_matrix.c:742
MINLINE void madd_v3_v3v3v3(float r[3], const float a[3], const float b[3], const float c[3])
void minmax_v3v3_v3(float min[3], float max[3], const float vec[3])
Definition: math_vector.c:1020
MINLINE float len_squared_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
void copy_vn_i(int *array_tar, const int size, const int val)
Definition: math_vector.c:1374
MINLINE void normal_float_to_short_v3(short r[3], const float n[3])
MINLINE float len_squared_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_v3_short(short r[3], const short a[3])
void mid_v3_v3v3(float r[3], const float a[3], const float b[3])
Definition: math_vector.c:270
MINLINE void add_v3_v3(float r[3], const float a[3])
void * BLI_memarena_alloc(struct MemArena *ma, size_t size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_ALLOC_SIZE(2)
Definition: BLI_memarena.c:131
unsigned int uint
Definition: BLI_sys_types.h:83
#define INIT_MINMAX(min, max)
#define ARRAY_SIZE(arr)
#define SWAP(type, a, b)
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define UNLIKELY(x)
#define ELEM(...)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define BLO_read_data_address(reader, ptr_p)
#define BLO_write_id_struct(writer, struct_name, id_address, id)
#define BLO_read_id_address(reader, lib, id_ptr_p)
#define BLO_expand(expander, id)
bool BLO_read_requires_endian_switch(BlendDataReader *reader)
Definition: readfile.c:5620
void BLO_write_raw(BlendWriter *writer, size_t size_in_bytes, const void *data_ptr)
Definition: writefile.c:1286
void BLO_read_pointer_array(BlendDataReader *reader, void **ptr_p)
Definition: readfile.c:5727
bool BLO_write_is_undo(BlendWriter *writer)
Definition: writefile.c:1412
void BLO_write_pointer_array(BlendWriter *writer, uint num, const void *data_ptr)
Definition: writefile.c:1388
#define BLT_I18NCONTEXT_ID_MESH
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
bool DEG_is_active(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:331
void DEG_debug_print_eval(struct Depsgraph *depsgraph, const char *function_name, const char *object_name, const void *object_address)
struct ID * DEG_get_original_id(struct ID *id)
@ LIB_TAG_NO_MAIN
Definition: DNA_ID.h:572
#define FILTER_ID_ME
Definition: DNA_ID.h:719
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition: DNA_ID.h:445
@ INDEX_ID_ME
Definition: DNA_ID.h:827
@ ID_ME
Definition: DNA_ID_enums.h:60
#define CD_MASK_NORMAL
@ CD_FACEMAP
@ CD_MVERT_SKIN
@ CD_CUSTOMLOOPNORMAL
@ CD_MDEFORMVERT
@ CD_NUMTYPES
@ CD_MLOOPCOL
@ CD_MVERT
@ CD_MLOOPUV
#define CD_TEMP_CHUNK_SIZE
@ CD_FLAG_TEMPORARY
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
struct Mesh Mesh
@ ME_CDFLAG_EDGE_CREASE
@ ME_CDFLAG_VERT_BWEIGHT
@ ME_CDFLAG_EDGE_BWEIGHT
@ ME_AUTOSMOOTH
@ ME_AUTOSPACE_EVALUATED
@ ME_AUTOSPACE
@ ME_VSEL
@ ME_FSEL
@ ME_ESEL
#define ME_POLY_LOOP_PREV(mloop, mp, i)
@ MVERT_SKIN_ROOT
#define ME_POLY_LOOP_NEXT(mloop, mp, i)
@ ME_SMOOTH
Object is a sort of wrapper for general info.
@ BOUNDBOX_DIRTY
@ OB_MESH
_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 type
_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 i1
_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)
static void init_data(ModifierData *md)
Platform independent time functions.
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
Definition: bmesh_interp.c:930
void BM_data_layer_add(BMesh *bm, CustomData *data, int type)
Definition: bmesh_interp.c:894
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_VERTS_OF_MESH
@ BM_FACES_OF_MESH
ATTR_WARN_UNUSED_RESULT BMesh * bm
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const struct BMeshCreateParams *params)
BMesh Make Mesh.
Definition: bmesh_mesh.c:157
#define BMALLOC_TEMPLATE_FROM_ME(...)
Definition: bmesh_mesh.h:163
void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *cd_mask_extra)
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshParams *params)
Mesh -> BMesh.
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMeshParams *params)
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define SELECT
const Depsgraph * depsgraph
#define UINT_MAX
Definition: hash_md5.c:58
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define fabsf(x)
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:48
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:46
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth)
Definition: mesh.c:1392
void BKE_mesh_mselect_validate(Mesh *me)
Definition: mesh.c:1617
void BKE_mesh_vert_normals_apply(Mesh *mesh, const short(*vert_normals)[3])
Definition: mesh.c:1779
void BKE_mesh_texspace_calc(Mesh *me)
Definition: mesh.c:1079
void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
Definition: mesh.c:766
@ MESHCMP_DVERT_TOTGROUPMISMATCH
Definition: mesh.c:375
@ MESHCMP_CDLAYERS_MISMATCH
Definition: mesh.c:383
@ MESHCMP_DVERT_WEIGHTMISMATCH
Definition: mesh.c:373
@ MESHCMP_LOOPCOLMISMATCH
Definition: mesh.c:376
@ MESHCMP_DVERT_GROUPMISMATCH
Definition: mesh.c:374
@ MESHCMP_EDGEUNKNOWN
Definition: mesh.c:381
@ MESHCMP_LOOPMISMATCH
Definition: mesh.c:378
@ MESHCMP_LOOPUVMISMATCH
Definition: mesh.c:377
@ MESHCMP_VERTCOMISMATCH
Definition: mesh.c:382
@ MESHCMP_POLYMISMATCH
Definition: mesh.c:380
@ MESHCMP_POLYVERTMISMATCH
Definition: mesh.c:379
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
Definition: mesh.c:1045
static const char * cmpcode_to_str(int code)
Definition: mesh.c:386
void BKE_mesh_translate(Mesh *me, const float offset[3], const bool do_keys)
Definition: mesh.c:1522
int poly_get_adj_loops_from_vert(const MPoly *poly, const MLoop *mloop, unsigned int vert, unsigned int r_adj[2])
Definition: mesh.c:1426
bool BKE_mesh_clear_facemap_customdata(struct Mesh *me)
Definition: mesh.c:732
static void mesh_read_expand(BlendExpander *expander, ID *id)
Definition: mesh.c:333
void BKE_mesh_vert_coords_apply(Mesh *mesh, const float(*vert_coords)[3])
Definition: mesh.c:1755
void BKE_mesh_texspace_copy_from_object(Mesh *me, Object *ob)
Definition: mesh.c:1150
bool BKE_mesh_material_index_used(Mesh *me, short index)
Definition: mesh.c:1326
void BKE_mesh_tessface_clear(Mesh *mesh)
Definition: mesh.c:1567
void BKE_mesh_material_remap(Mesh *me, const unsigned int *remap, unsigned int remap_len)
Definition: mesh.c:1362
Mesh * BKE_mesh_new_nomain_from_template(const Mesh *me_src, int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
Definition: mesh.c:975
const char * BKE_mesh_cmp(Mesh *me1, Mesh *me2, float thresh)
Definition: mesh.c:598
Mesh * BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params, const Mesh *me_settings)
Definition: mesh.c:1034
void BKE_mesh_tessface_calc(Mesh *mesh)
Definition: mesh.c:1544
Mesh * BKE_mesh_add(Main *bmain, const char *name)
Definition: mesh.c:849
#define CD_LAYERS_FREE(id)
void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr)
Definition: mesh.c:1797
Mesh * BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src, int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len, CustomData_MeshMasks mask)
Definition: mesh.c:932
static void mesh_clear_geometry(Mesh *mesh)
Definition: mesh.c:801
void BKE_mesh_ensure_skin_customdata(Mesh *me)
Definition: mesh.c:681
void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
Definition: mesh.c:1485
static void split_faces_split_new_verts(Mesh *mesh, SplitFaceNewVert *new_verts, const int num_new_verts)
Definition: mesh.c:2029
static void mesh_ensure_cdlayers_primary(Mesh *mesh, bool do_tessface)
Definition: mesh.c:857
void BKE_mesh_looptri_get_real_edges(const Mesh *mesh, const MLoopTri *looptri, int r_edges[3])
Definition: mesh.c:1461
static int split_faces_prepare_new_verts(const Mesh *mesh, MLoopNorSpaceArray *lnors_spacearr, SplitFaceNewVert **new_verts, MemArena *memarena)
Definition: mesh.c:1889
bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me)
Definition: mesh.c:713
static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address)
Definition: mesh.c:173
float(* BKE_mesh_vert_coords_alloc(const Mesh *mesh, int *r_vert_len))[3]
Definition: mesh.c:1745
static int split_faces_prepare_new_edges(const Mesh *mesh, SplitFaceNewEdge **new_edges, MemArena *memarena)
Definition: mesh.c:1968
#define MAT_NR_REMAP(n)
void BKE_mesh_eval_delete(struct Mesh *mesh_eval)
Definition: mesh.c:986
void BKE_mesh_count_selected_items(const Mesh *mesh, int r_count[3])
Definition: mesh.c:1725
void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals)
Definition: mesh.c:2073
static void mesh_update_linked_customdata(Mesh *me, const bool do_ensure_tess_cd)
Definition: mesh.c:757
Mesh * BKE_mesh_from_object(Object *ob)
Definition: mesh.c:1271
int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart, uint vert)
Definition: mesh.c:1410
static void mesh_blend_read_lib(BlendLibReader *reader, ID *id)
Definition: mesh.c:315
void BKE_mesh_copy_settings(Mesh *me_dst, const Mesh *me_src)
Definition: mesh.c:905
BoundBox * BKE_mesh_boundbox_get(Object *ob)
Definition: mesh.c:1055
static void split_faces_split_new_edges(Mesh *mesh, SplitFaceNewEdge *new_edges, const int num_new_edges)
Definition: mesh.c:2049
Mesh * BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
Definition: mesh.c:995
void BKE_mesh_calc_normals_split(Mesh *mesh)
Definition: mesh.c:1865
void BKE_mesh_vert_coords_apply_with_mat4(Mesh *mesh, const float(*vert_coords)[3], const float mat[4][4])
Definition: mesh.c:1766
void BKE_mesh_mselect_active_set(Mesh *me, int index, int type)
Definition: mesh.c:1705
static void mesh_free_data(ID *id)
Definition: mesh.c:154
void BKE_mesh_vert_coords_get(const Mesh *mesh, float(*vert_coords)[3])
Definition: mesh.c:1737
BMesh * BKE_mesh_to_bmesh(Mesh *me, Object *ob, const bool add_key_index, const struct BMeshCreateParams *params)
Definition: mesh.c:1019
static void mesh_blend_read_data(BlendDataReader *reader, ID *id)
Definition: mesh.c:266
void BKE_mesh_mselect_clear(Mesh *me)
Definition: mesh.c:1608
int BKE_mesh_edge_other_vert(const MEdge *e, int v)
Definition: mesh.c:1446
struct SplitFaceNewEdge SplitFaceNewEdge
static void mesh_init_data(ID *id)
Definition: mesh.c:76
static void mesh_foreach_id(ID *id, LibraryForeachIDData *data)
Definition: mesh.c:163
static void mesh_ensure_tessellation_customdata(Mesh *me)
Definition: mesh.c:641
Mesh * BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
Definition: mesh.c:877
void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_size[3])
Definition: mesh.c:1123
bool BKE_mesh_has_custom_loop_normals(Mesh *me)
Definition: mesh.c:786
void BKE_mesh_texspace_ensure(Mesh *me)
Definition: mesh.c:1116
int BKE_mesh_mselect_active_get(Mesh *me, int type)
Definition: mesh.c:1693
static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, const float thresh)
Definition: mesh.c:418
static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
Definition: mesh.c:834
static void mesh_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
Definition: mesh.c:95
int BKE_mesh_mselect_find(Mesh *me, int index, int type)
Definition: mesh.c:1677
void BKE_mesh_free_data(Mesh *me)
Definition: mesh.c:796
int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr)
Definition: mesh.c:1203
bool BKE_mesh_minmax(const Mesh *me, float r_min[3], float r_max[3])
Definition: mesh.c:1474
void BKE_mesh_tessface_ensure(Mesh *mesh)
Definition: mesh.c:1560
void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
Definition: mesh.c:2146
void BKE_mesh_clear_geometry(Mesh *mesh)
Definition: mesh.c:827
float(* BKE_mesh_orco_verts_get(Object *ob))[3]
Definition: mesh.c:1162
IDTypeInfo IDType_ID_ME
Definition: mesh.c:344
void BKE_mesh_material_index_clear(Mesh *me)
Definition: mesh.c:1347
void BKE_mesh_orco_verts_transform(Mesh *me, float(*orco)[3], int totvert, int invert)
Definition: mesh.c:1179
void BKE_mesh_assign_object(Main *bmain, Object *ob, Mesh *me)
Definition: mesh.c:1283
struct SplitFaceNewVert SplitFaceNewVert
void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
Definition: mesh.c:1572
void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc, float **r_size)
Definition: mesh.c:1135
BMesh * BKE_mesh_to_bmesh_ex(const Mesh *me, const struct BMeshCreateParams *create_params, const struct BMeshFromMeshParams *convert_params)
Definition: mesh.c:1007
void BKE_mesh_material_index_remove(Mesh *me, short index)
Definition: mesh.c:1307
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
#define min(a, b)
Definition: sort.c:51
struct BMesh * bm
Definition: BKE_editmesh.h:52
short mat_nr
Definition: bmesh_class.h:281
void * data
Definition: bmesh_class.h:63
float co[3]
Definition: bmesh_class.h:99
BMHeader head
Definition: bmesh_class.h:97
int totfacesel
Definition: bmesh_class.h:298
CustomData vdata
Definition: bmesh_class.h:337
int totvertsel
Definition: bmesh_class.h:298
int totedgesel
Definition: bmesh_class.h:298
CustomData pdata
Definition: bmesh_class.h:337
CustomData ldata
Definition: bmesh_class.h:337
CustomDataLayer * layers
short id_code
Definition: BKE_idtype.h:120
Definition: DNA_ID.h:273
int tag
Definition: DNA_ID.h:292
struct Library * lib
Definition: DNA_ID.h:277
int us
Definition: DNA_ID.h:293
char name[66]
Definition: DNA_ID.h:283
struct KeyBlock * next
Definition: DNA_key_types.h:41
void * data
Definition: DNA_key_types.h:66
ID * from
ID id
Definition: DNA_key_types.h:79
ListBase block
struct LinkNode * next
Definition: BLI_linklist.h:39
void * first
Definition: DNA_listBase.h:47
struct MDeformWeight * dw
unsigned int def_nr
unsigned int v1
unsigned int v2
unsigned int v2
unsigned int v1
unsigned int v4
unsigned int v3
unsigned char a
unsigned char b
unsigned char r
unsigned char g
struct MemArena * mem
Definition: BKE_mesh.h:377
MLoopNorSpace ** lspacearr
Definition: BKE_mesh.h:372
unsigned int tri[3]
unsigned int e
unsigned int v
short mat_nr
float co[3]
short no[3]
Definition: BKE_main.h:116
struct Mesh * mesh_eval
int64_t cd_dirty_vert
struct MEdge * medge
struct BMEditMesh * edit_mesh
float remesh_voxel_adaptivity
float smoothresh
struct Mesh * texcomesh
struct MTFace * mtface
struct CustomData pdata ldata
char symmetry
struct MVert * mvert
struct MLoopCol * mloopcol
float size[3]
struct AnimData * adt
struct Material ** mat
struct MDeformVert * dvert
float remesh_voxel_size
int totedge
struct MLoopUV * mloopuv
int act_face
char cd_flag
char editflag
int totvert
short flag
struct MLoop * mloop
int totface
Mesh_Runtime runtime
struct CustomData vdata edata fdata
short texflag
int totpoly
short totcol
int face_sets_color_seed
struct MCol * mcol
int face_sets_color_default
int totloop
struct Key * key
int totselect
char remesh_mode
struct MFace * mface
struct MPoly * mpoly
float loc[3]
struct MSelect * mselect
struct BoundBox * bb
short shapenr
Object_Runtime runtime
void * data
int orig_index
Definition: mesh.c:1882
struct SplitFaceNewEdge * next
Definition: mesh.c:1880
int orig_index
Definition: mesh.c:1875
struct SplitFaceNewVert * next
Definition: mesh.c:1873
float * vnor
Definition: mesh.c:1876
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: svm_invert.h:19
long int PIL_check_seconds_timer_i(void)
Definition: time.c:90
float max
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
#define G(x, y, z)