Blender  V2.93
DerivedMesh.cc
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) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <climits>
25 #include <cstring>
26 
27 #include "MEM_guardedalloc.h"
28 
29 #include "DNA_cloth_types.h"
30 #include "DNA_customdata_types.h"
31 #include "DNA_key_types.h"
32 #include "DNA_material_types.h"
33 #include "DNA_mesh_types.h"
34 #include "DNA_meshdata_types.h"
35 #include "DNA_object_types.h"
36 #include "DNA_scene_types.h"
37 
38 #include "BLI_array.h"
39 #include "BLI_bitmap.h"
40 #include "BLI_blenlib.h"
41 #include "BLI_float2.hh"
42 #include "BLI_linklist.h"
43 #include "BLI_math.h"
44 #include "BLI_task.h"
45 #include "BLI_utildefines.h"
46 #include "BLI_vector.hh"
47 
48 #include "BKE_DerivedMesh.h"
49 #include "BKE_bvhutils.h"
50 #include "BKE_colorband.h"
51 #include "BKE_deform.h"
52 #include "BKE_editmesh.h"
53 #include "BKE_geometry_set.hh"
55 #include "BKE_key.h"
56 #include "BKE_layer.h"
57 #include "BKE_lib_id.h"
58 #include "BKE_material.h"
59 #include "BKE_mesh.h"
60 #include "BKE_mesh_iterators.h"
61 #include "BKE_mesh_mapping.h"
62 #include "BKE_mesh_runtime.h"
63 #include "BKE_mesh_tangent.h"
64 #include "BKE_mesh_wrapper.h"
65 #include "BKE_modifier.h"
66 #include "BKE_multires.h"
67 #include "BKE_object.h"
68 #include "BKE_object_deform.h"
69 #include "BKE_paint.h"
70 
71 #include "BLI_sys_types.h" /* for intptr_t support */
72 
73 #include "BKE_shrinkwrap.h"
74 #include "DEG_depsgraph.h"
75 #include "DEG_depsgraph_query.h"
76 
77 #include "CLG_log.h"
78 
79 #ifdef WITH_OPENSUBDIV
80 # include "DNA_userdef_types.h"
81 #endif
82 
83 /* very slow! enable for testing only! */
84 //#define USE_MODIFIER_VALIDATE
85 
86 #ifdef USE_MODIFIER_VALIDATE
87 # define ASSERT_IS_VALID_MESH(mesh) \
88  (BLI_assert((mesh == nullptr) || (BKE_mesh_is_valid(mesh) == true)))
89 #else
90 # define ASSERT_IS_VALID_MESH(mesh)
91 #endif
92 
93 static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER;
94 
95 static void mesh_init_origspace(Mesh *mesh);
96 static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
97  const CustomData_MeshMasks *final_datamask);
98 
99 /* -------------------------------------------------------------------- */
100 
102 {
103  MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
104 
105  if (!mvert) {
106  mvert = (MVert *)CustomData_add_layer(
107  &dm->vertData, CD_MVERT, CD_CALLOC, nullptr, dm->getNumVerts(dm));
109  dm->copyVertArray(dm, mvert);
110  }
111 
112  return mvert;
113 }
114 
116 {
117  MEdge *medge = (MEdge *)CustomData_get_layer(&dm->edgeData, CD_MEDGE);
118 
119  if (!medge) {
120  medge = (MEdge *)CustomData_add_layer(
121  &dm->edgeData, CD_MEDGE, CD_CALLOC, nullptr, dm->getNumEdges(dm));
123  dm->copyEdgeArray(dm, medge);
124  }
125 
126  return medge;
127 }
128 
130 {
131  MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
132 
133  if (!mface) {
134  int numTessFaces = dm->getNumTessFaces(dm);
135 
136  if (!numTessFaces) {
137  /* Do not add layer if there's no elements in it, this leads to issues later when
138  * this layer is needed with non-zero size, but currently CD stuff does not check
139  * for requested layer size on creation and just returns layer which was previously
140  * added (sergey) */
141  return nullptr;
142  }
143 
144  mface = (MFace *)CustomData_add_layer(
145  &dm->faceData, CD_MFACE, CD_CALLOC, nullptr, numTessFaces);
147  dm->copyTessFaceArray(dm, mface);
148  }
149 
150  return mface;
151 }
152 
154 {
155  MLoop *mloop = (MLoop *)CustomData_get_layer(&dm->loopData, CD_MLOOP);
156 
157  if (!mloop) {
158  mloop = (MLoop *)CustomData_add_layer(
159  &dm->loopData, CD_MLOOP, CD_CALLOC, nullptr, dm->getNumLoops(dm));
161  dm->copyLoopArray(dm, mloop);
162  }
163 
164  return mloop;
165 }
166 
168 {
169  MPoly *mpoly = (MPoly *)CustomData_get_layer(&dm->polyData, CD_MPOLY);
170 
171  if (!mpoly) {
172  mpoly = (MPoly *)CustomData_add_layer(
173  &dm->polyData, CD_MPOLY, CD_CALLOC, nullptr, dm->getNumPolys(dm));
175  dm->copyPolyArray(dm, mpoly);
176  }
177 
178  return mpoly;
179 }
180 
182 {
183  MVert *tmp = (MVert *)MEM_malloc_arrayN(
184  dm->getNumVerts(dm), sizeof(*tmp), "dm_dupVertArray tmp");
185 
186  if (tmp) {
187  dm->copyVertArray(dm, tmp);
188  }
189 
190  return tmp;
191 }
192 
194 {
195  MEdge *tmp = (MEdge *)MEM_malloc_arrayN(
196  dm->getNumEdges(dm), sizeof(*tmp), "dm_dupEdgeArray tmp");
197 
198  if (tmp) {
199  dm->copyEdgeArray(dm, tmp);
200  }
201 
202  return tmp;
203 }
204 
206 {
207  MFace *tmp = (MFace *)MEM_malloc_arrayN(
208  dm->getNumTessFaces(dm), sizeof(*tmp), "dm_dupFaceArray tmp");
209 
210  if (tmp) {
211  dm->copyTessFaceArray(dm, tmp);
212  }
213 
214  return tmp;
215 }
216 
218 {
219  MLoop *tmp = (MLoop *)MEM_malloc_arrayN(
220  dm->getNumLoops(dm), sizeof(*tmp), "dm_dupLoopArray tmp");
221 
222  if (tmp) {
223  dm->copyLoopArray(dm, tmp);
224  }
225 
226  return tmp;
227 }
228 
230 {
231  MPoly *tmp = (MPoly *)MEM_malloc_arrayN(
232  dm->getNumPolys(dm), sizeof(*tmp), "dm_dupPolyArray tmp");
233 
234  if (tmp) {
235  dm->copyPolyArray(dm, tmp);
236  }
237 
238  return tmp;
239 }
240 
242 {
243  const int numlooptris = poly_to_tri_count(dm->getNumPolys(dm), dm->getNumLoops(dm));
244  BLI_assert(ELEM(dm->looptris.num, 0, numlooptris));
245  return numlooptris;
246 }
247 
249 {
250  MLoopTri *looptri;
251 
253  looptri = dm->looptris.array;
255 
256  if (looptri != nullptr) {
257  BLI_assert(dm->getNumLoopTri(dm) == dm->looptris.num);
258  }
259  else {
261  /* We need to ensure array is still nullptr inside mutex-protected code,
262  * some other thread might have already recomputed those looptris. */
263  if (dm->looptris.array == nullptr) {
264  dm->recalcLoopTri(dm);
265  }
266  looptri = dm->looptris.array;
268  }
269  return looptri;
270 }
271 
273 {
274  return &dm->vertData;
275 }
276 
278 {
279  return &dm->edgeData;
280 }
281 
283 {
284  return &dm->faceData;
285 }
286 
288 {
289  return &dm->loopData;
290 }
291 
293 {
294  return &dm->polyData;
295 }
296 
302 {
303  /* default function implementations */
314 
316 
317  /* subtypes handle getting actual data */
319 
325 
335 }
336 
344  int numVerts,
345  int numEdges,
346  int numTessFaces,
347  int numLoops,
348  int numPolys)
349 {
350  dm->type = type;
351  dm->numVertData = numVerts;
352  dm->numEdgeData = numEdges;
353  dm->numTessFaceData = numTessFaces;
354  dm->numLoopData = numLoops;
355  dm->numPolyData = numPolys;
356 
357  DM_init_funcs(dm);
358 
359  dm->needsFree = 1;
360  dm->dirty = (DMDirtyFlag)0;
361 
362  /* Don't use CustomData_reset(...); because we don't want to touch custom-data. */
368 }
369 
375  DerivedMesh *source,
377  int numVerts,
378  int numEdges,
379  int numTessFaces,
380  int numLoops,
381  int numPolys,
382  const CustomData_MeshMasks *mask)
383 {
384  CustomData_copy(&source->vertData, &dm->vertData, mask->vmask, CD_CALLOC, numVerts);
385  CustomData_copy(&source->edgeData, &dm->edgeData, mask->emask, CD_CALLOC, numEdges);
386  CustomData_copy(&source->faceData, &dm->faceData, mask->fmask, CD_CALLOC, numTessFaces);
387  CustomData_copy(&source->loopData, &dm->loopData, mask->lmask, CD_CALLOC, numLoops);
388  CustomData_copy(&source->polyData, &dm->polyData, mask->pmask, CD_CALLOC, numPolys);
389 
390  dm->cd_flag = source->cd_flag;
391 
392  dm->type = type;
393  dm->numVertData = numVerts;
394  dm->numEdgeData = numEdges;
395  dm->numTessFaceData = numTessFaces;
396  dm->numLoopData = numLoops;
397  dm->numPolyData = numPolys;
398 
399  DM_init_funcs(dm);
400 
401  dm->needsFree = 1;
402  dm->dirty = (DMDirtyFlag)0;
403 }
405  DerivedMesh *source,
407  int numVerts,
408  int numEdges,
409  int numTessFaces,
410  int numLoops,
411  int numPolys)
412 {
414  source,
415  type,
416  numVerts,
417  numEdges,
418  numTessFaces,
419  numLoops,
420  numPolys,
422 }
423 
425 {
426  if (dm->needsFree) {
432 
434  dm->looptris.num = 0;
435  dm->looptris.num_alloc = 0;
436 
437  return true;
438  }
439 
445 
446  return false;
447 }
448 
449 void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
450 {
451  CustomData_free(&target->loopData, source->numLoopData);
452  CustomData_free(&target->polyData, source->numPolyData);
453 
454  CustomData_copy(&source->loopData,
455  &target->loopData,
457  CD_DUPLICATE,
458  source->numLoopData);
459  CustomData_copy(&source->polyData,
460  &target->polyData,
462  CD_DUPLICATE,
463  source->numPolyData);
464 
465  target->numLoopData = source->numLoopData;
466  target->numPolyData = source->numPolyData;
467 
468  if (!CustomData_has_layer(&target->polyData, CD_MPOLY)) {
469  MPoly *mpoly;
470  MLoop *mloop;
471 
472  mloop = source->dupLoopArray(source);
473  mpoly = source->dupPolyArray(source);
474  CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
475  CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->numPolyData);
476  }
477 }
478 
480 {
481  if (dm->dirty & DM_DIRTY_NORMALS) {
482  dm->calcNormals(dm);
483  }
484  BLI_assert((dm->dirty & DM_DIRTY_NORMALS) == 0);
485 }
486 
494 {
495  const unsigned int totpoly = dm->numPolyData;
496  const unsigned int totloop = dm->numLoopData;
497  const int looptris_num = poly_to_tri_count(totpoly, totloop);
498 
499  BLI_assert(dm->looptris.array_wip == nullptr);
500 
502 
503  if ((looptris_num > dm->looptris.num_alloc) || (looptris_num < dm->looptris.num_alloc * 2) ||
504  (totpoly == 0)) {
506  dm->looptris.num_alloc = 0;
507  dm->looptris.num = 0;
508  }
509 
510  if (totpoly) {
511  if (dm->looptris.array_wip == nullptr) {
513  looptris_num, sizeof(*dm->looptris.array_wip), __func__);
514  dm->looptris.num_alloc = looptris_num;
515  }
516 
517  dm->looptris.num = looptris_num;
518  }
519 }
520 
522 /* Just a shallow wrapper around BKE_keyblock_convert_from_mesh,
523  * that ensures both evaluated mesh and original one has same number of vertices. */
525 {
526  const int totvert = me_deformed->totvert;
527 
528  if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) {
529  return;
530  }
531 
532  BKE_keyblock_convert_from_mesh(me_deformed, me->key, kb);
533 }
534 
541 {
542  CustomData_set_only_copy(&dm->vertData, mask->vmask);
543  CustomData_set_only_copy(&dm->edgeData, mask->emask);
544  CustomData_set_only_copy(&dm->faceData, mask->fmask);
545  /* this wasn't in 2.63 and is disabled for 2.64 because it gives problems with
546  * weight paint mode when there are modifiers applied, needs further investigation,
547  * see replies to r50969, Campbell */
548 #if 0
549  CustomData_set_only_copy(&dm->loopData, mask->lmask);
550  CustomData_set_only_copy(&dm->polyData, mask->pmask);
551 #endif
552 }
553 
555 {
556  CustomData_set_only_copy(&mesh->vdata, mask->vmask);
557  CustomData_set_only_copy(&mesh->edata, mask->emask);
559  /* this wasn't in 2.63 and is disabled for 2.64 because it gives problems with
560  * weight paint mode when there are modifiers applied, needs further investigation,
561  * see replies to r50969, Campbell */
562 #if 0
564  CustomData_set_only_copy(&mesh->pdata, mask->pmask);
565 #endif
566 }
567 
568 void DM_add_vert_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
569 {
570  CustomData_add_layer(&dm->vertData, type, alloctype, layer, dm->numVertData);
571 }
572 
573 void DM_add_edge_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
574 {
575  CustomData_add_layer(&dm->edgeData, type, alloctype, layer, dm->numEdgeData);
576 }
577 
578 void DM_add_tessface_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
579 {
580  CustomData_add_layer(&dm->faceData, type, alloctype, layer, dm->numTessFaceData);
581 }
582 
583 void DM_add_loop_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
584 {
585  CustomData_add_layer(&dm->loopData, type, alloctype, layer, dm->numLoopData);
586 }
587 
588 void DM_add_poly_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
589 {
590  CustomData_add_layer(&dm->polyData, type, alloctype, layer, dm->numPolyData);
591 }
592 
593 void *DM_get_vert_data(DerivedMesh *dm, int index, int type)
594 {
595  BLI_assert(index >= 0 && index < dm->getNumVerts(dm));
596  return CustomData_get(&dm->vertData, index, type);
597 }
598 
599 void *DM_get_edge_data(DerivedMesh *dm, int index, int type)
600 {
601  BLI_assert(index >= 0 && index < dm->getNumEdges(dm));
602  return CustomData_get(&dm->edgeData, index, type);
603 }
604 
605 void *DM_get_tessface_data(DerivedMesh *dm, int index, int type)
606 {
607  BLI_assert(index >= 0 && index < dm->getNumTessFaces(dm));
608  return CustomData_get(&dm->faceData, index, type);
609 }
610 
611 void *DM_get_poly_data(DerivedMesh *dm, int index, int type)
612 {
613  BLI_assert(index >= 0 && index < dm->getNumPolys(dm));
614  return CustomData_get(&dm->polyData, index, type);
615 }
616 
618 {
619  if (type == CD_MVERT) {
620  return dm->getVertArray(dm);
621  }
622 
623  return CustomData_get_layer(&dm->vertData, type);
624 }
625 
627 {
628  if (type == CD_MEDGE) {
629  return dm->getEdgeArray(dm);
630  }
631 
632  return CustomData_get_layer(&dm->edgeData, type);
633 }
634 
636 {
637  if (type == CD_MFACE) {
638  return dm->getTessFaceArray(dm);
639  }
640 
641  return CustomData_get_layer(&dm->faceData, type);
642 }
643 
645 {
646  return CustomData_get_layer(&dm->polyData, type);
647 }
648 
650 {
651  return CustomData_get_layer(&dm->loopData, type);
652 }
653 
655  DerivedMesh *source, DerivedMesh *dest, int source_index, int dest_index, int count)
656 {
657  CustomData_copy_data(&source->vertData, &dest->vertData, source_index, dest_index, count);
658 }
659 
666  DerivedMesh *dest,
667  int *src_indices,
668  float *weights,
669  int count,
670  int dest_index)
671 {
673  &source->vertData, &dest->vertData, src_indices, weights, nullptr, count, dest_index);
674 }
675 
677 {
678  BMIter iter;
679  BMVert *eve;
680  float(*orco)[3];
681  int i;
682 
683  /* these may not really be the orco's, but it's only for preview.
684  * could be solver better once, but isn't simple */
685 
686  orco = (float(*)[3])MEM_malloc_arrayN(em->bm->totvert, sizeof(float[3]), "BMEditMesh Orco");
687 
688  BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
689  copy_v3_v3(orco[i], eve->co);
690  }
691 
692  return orco;
693 }
694 
695 /* orco custom data layer */
696 static float (*get_orco_coords(Object *ob, BMEditMesh *em, int layer, int *free))[3]
697 {
698  *free = 0;
699 
700  if (layer == CD_ORCO) {
701  /* get original coordinates */
702  *free = 1;
703 
704  if (em) {
705  return get_editbmesh_orco_verts(em);
706  }
707  return BKE_mesh_orco_verts_get(ob);
708  }
709  if (layer == CD_CLOTH_ORCO) {
710  /* apply shape key for cloth, this should really be solved
711  * by a more flexible customdata system, but not simple */
712  if (!em) {
714  ob, eModifierType_Cloth);
715  if (clmd) {
717  clmd->sim_parms->shapekey_rest);
718 
719  if (kb && kb->data) {
720  return (float(*)[3])kb->data;
721  }
722  }
723  }
724 
725  return nullptr;
726  }
727 
728  return nullptr;
729 }
730 
731 static Mesh *create_orco_mesh(Object *ob, Mesh *me, BMEditMesh *em, int layer)
732 {
733  Mesh *mesh;
734  float(*orco)[3];
735  int free;
736 
737  if (em) {
738  mesh = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, nullptr, me);
739  }
740  else {
741  mesh = BKE_mesh_copy_for_eval(me, true);
742  }
743 
744  orco = get_orco_coords(ob, em, layer, &free);
745 
746  if (orco) {
748  if (free) {
749  MEM_freeN(orco);
750  }
751  }
752 
753  return mesh;
754 }
755 
756 static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh *mesh, Mesh *mesh_orco, int layer)
757 {
758  float(*orco)[3], (*layerorco)[3];
759  int totvert, free;
760 
761  totvert = mesh->totvert;
762 
763  if (mesh_orco) {
764  free = 1;
765 
766  if (mesh_orco->totvert == totvert) {
767  orco = BKE_mesh_vert_coords_alloc(mesh_orco, nullptr);
768  }
769  else {
770  orco = BKE_mesh_vert_coords_alloc(mesh, nullptr);
771  }
772  }
773  else {
774  /* TODO(sybren): totvert should potentially change here, as ob->data
775  * or em may have a different number of vertices than dm. */
776  orco = get_orco_coords(ob, em, layer, &free);
777  }
778 
779  if (orco) {
780  if (layer == CD_ORCO) {
781  BKE_mesh_orco_verts_transform((Mesh *)ob->data, orco, totvert, 0);
782  }
783 
784  if (!(layerorco = (float(*)[3])CustomData_get_layer(&mesh->vdata, layer))) {
785  CustomData_add_layer(&mesh->vdata, layer, CD_CALLOC, nullptr, mesh->totvert);
787 
788  layerorco = (float(*)[3])CustomData_get_layer(&mesh->vdata, layer);
789  }
790 
791  memcpy(layerorco, orco, sizeof(float[3]) * totvert);
792  if (free) {
793  MEM_freeN(orco);
794  }
795  }
796 }
797 
798 static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
799  const CustomData_MeshMasks *final_datamask,
800  const bool sculpt_dyntopo,
801  Mesh *mesh_final)
802 {
803  /* Compute normals. */
804  const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 ||
805  (final_datamask->lmask & CD_MASK_NORMAL) != 0);
806  /* Some modifiers may need this info from their target (other) object,
807  * simpler to generate it here as well.
808  * Note that they will always be generated when no loop normals are computed,
809  * since they are needed by drawing code. */
810  const bool do_poly_normals = ((final_datamask->pmask & CD_MASK_NORMAL) != 0);
811 
812  /* In case we also need poly normals, add the layer and compute them here
813  * (BKE_mesh_calc_normals_split() assumes that if that data exists, it is always valid). */
814  if (do_poly_normals) {
815  if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
816  float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
817  &mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
818  BKE_mesh_calc_normals_poly(mesh_final->mvert,
819  nullptr,
820  mesh_final->totvert,
821  mesh_final->mloop,
822  mesh_final->mpoly,
823  mesh_final->totloop,
824  mesh_final->totpoly,
825  polynors,
826  false);
827  }
828  }
829 
830  if (do_loop_normals) {
831  /* Compute loop normals (note: will compute poly and vert normals as well, if needed!) */
832  BKE_mesh_calc_normals_split(mesh_final);
833  BKE_mesh_tessface_clear(mesh_final);
834  }
835 
836  if (sculpt_dyntopo == false) {
837  /* watch this! after 2.75a we move to from tessface to looptri (by default) */
838  if (final_datamask->fmask & CD_MASK_MFACE) {
839  BKE_mesh_tessface_ensure(mesh_final);
840  }
841 
842  /* without this, drawing ngon tri's faces will show ugly tessellated face
843  * normals and will also have to calculate normals on the fly, try avoid
844  * this where possible since calculating polygon normals isn't fast,
845  * note that this isn't a problem for subsurf (only quads) or editmode
846  * which deals with drawing differently.
847  *
848  * Only calc vertex normals if they are flagged as dirty.
849  * If using loop normals, poly nors have already been computed.
850  */
851  if (!do_loop_normals) {
853  }
854  }
855 
856  /* Some modifiers, like data-transfer, may generate those data as temp layer,
857  * we do not want to keep them, as they are used by display code when available
858  * (i.e. even if autosmooth is disabled). */
859  if (!do_loop_normals && CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) {
860  CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop);
861  }
862 }
863 
864 /* Does final touches to the final evaluated mesh, making sure it is perfectly usable.
865  *
866  * This is needed because certain information is not passed along intermediate meshes allocated
867  * during stack evaluation.
868  */
869 static void mesh_calc_finalize(const Mesh *mesh_input, Mesh *mesh_eval)
870 {
871  /* Make sure the name is the same. This is because mesh allocation from template does not
872  * take care of naming. */
873  BLI_strncpy(mesh_eval->id.name, mesh_input->id.name, sizeof(mesh_eval->id.name));
874  /* Make evaluated mesh to share same edit mesh pointer as original and copied meshes. */
875  mesh_eval->edit_mesh = mesh_input->edit_mesh;
876 }
877 
879  const CustomData_MeshMasks *cd_mask_finalize)
880 {
881  if (me_eval->runtime.wrapper_type_finalize & (1 << ME_WRAPPER_TYPE_BMESH)) {
882  editbmesh_calc_modifier_final_normals(me_eval, cd_mask_finalize);
884  }
886 }
887 
894 {
895  if (!r_geometry_set.has_instances() && !r_geometry_set.has_pointcloud()) {
896  return mesh;
897  }
898 
899  {
900  /* Add the mesh to the geometry set. */
901  MeshComponent &mesh_component = r_geometry_set.get_component_for_write<MeshComponent>();
903  }
904  {
905  /* Combine mesh and all instances into a single mesh that can be passed to the modifier. */
907  r_geometry_set);
908  MeshComponent &mesh_component = new_geometry_set.get_component_for_write<MeshComponent>();
909  Mesh *new_mesh = mesh_component.release();
910  r_geometry_set = new_geometry_set;
911  return new_mesh;
912  }
913 }
914 
924  const ModifierEvalContext &mectx,
925  Mesh *input_mesh,
926  GeometrySet &geometry_set)
927 {
928  Mesh *mesh_output = nullptr;
930  if (mti->modifyGeometrySet == nullptr) {
931  Mesh *new_input_mesh = prepare_geometry_set_for_mesh_modifier(input_mesh, geometry_set);
932  mesh_output = BKE_modifier_modify_mesh(md, &mectx, new_input_mesh);
933 
934  /* The caller is responsible for freeing `input_mesh` and `mesh_output`. The intermediate
935  * `new_input_mesh` has to be freed here. */
936  if (!ELEM(new_input_mesh, input_mesh, mesh_output)) {
937  BKE_id_free(nullptr, new_input_mesh);
938  }
939  }
940  else {
941  /* For performance reasons, this should be called by the modifier and/or nodes themselves at
942  * some point. */
943  BKE_mesh_wrapper_ensure_mdata(input_mesh);
944 
945  /* Adds a new mesh component to the geometry set based on the #input_mesh. */
946  MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
947  /* Replace only the mesh rather than the whole component, because the entire #MeshComponent
948  * might have been replaced by data from a different object in the node tree, which means the
949  * component contains vertex group name data for that object that should not be removed. */
950  mesh_component.replace_mesh_but_keep_vertex_group_names(input_mesh,
952 
953  /* Let the modifier change the geometry set. */
954  mti->modifyGeometrySet(md, &mectx, &geometry_set);
955 
956  /* Release the mesh from the geometry set again. */
957  if (geometry_set.has<MeshComponent>()) {
958  MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
959  mesh_output = mesh_component.release();
960  }
961 
962  /* Return an empty mesh instead of null. */
963  if (mesh_output == nullptr) {
964  mesh_output = BKE_mesh_new_nomain(0, 0, 0, 0, 0);
965  BKE_mesh_copy_settings(mesh_output, input_mesh);
966  }
967  }
968 
969  return mesh_output;
970 }
971 
973  Scene *scene,
974  Object *ob,
975  int useDeform,
976  const bool need_mapping,
977  const CustomData_MeshMasks *dataMask,
978  const int index,
979  const bool use_cache,
980  const bool allow_shared_mesh,
981  /* return args */
982  Mesh **r_deform,
983  Mesh **r_final,
984  GeometrySet **r_geometry_set)
985 {
986  /* Input and final mesh. Final mesh is only created the moment the first
987  * constructive modifier is executed, or a deform modifier needs normals
988  * or certain data layers. */
989  Mesh *mesh_input = (Mesh *)ob->data;
990  Mesh *mesh_final = nullptr;
991  Mesh *mesh_deform = nullptr;
992  /* This geometry set contains the non-mesh data that might be generated by modifiers. */
993  GeometrySet geometry_set_final;
994 
995  /* Add the initial mesh component, with a copy of the vertex group names from the object,
996  * since they need to be stored in the geometry set for evaluation. */
997  MeshComponent &initial_mesh_component =
998  geometry_set_final.get_component_for_write<MeshComponent>();
999  initial_mesh_component.copy_vertex_group_names_from_object(*ob);
1000 
1001  BLI_assert((mesh_input->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
1002 
1003  /* Deformed vertex locations array. Deform only modifier need this type of
1004  * float array rather than MVert*. Tracked along with mesh_final as an
1005  * optimization to avoid copying coordinates back and forth if there are
1006  * multiple sequential deform only modifiers. */
1007  float(*deformed_verts)[3] = nullptr;
1008  int num_deformed_verts = mesh_input->totvert;
1009  bool isPrevDeform = false;
1010 
1011  /* Mesh with constructive modifiers but no deformation applied. Tracked
1012  * along with final mesh if undeformed / orco coordinates are requested
1013  * for texturing. */
1014  Mesh *mesh_orco = nullptr;
1015  Mesh *mesh_orco_cloth = nullptr;
1016 
1017  /* Modifier evaluation modes. */
1018  const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
1019  const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
1020 
1021  /* Sculpt can skip certain modifiers. */
1022  const bool has_multires = BKE_sculpt_multires_active(scene, ob) != nullptr;
1023  bool multires_applied = false;
1024  const bool sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt && !use_render;
1025  const bool sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm) && !use_render;
1026 
1027  /* Modifier evaluation contexts for different types of modifiers. */
1028  ModifierApplyFlag apply_render = use_render ? MOD_APPLY_RENDER : (ModifierApplyFlag)0;
1029  ModifierApplyFlag apply_cache = use_cache ? MOD_APPLY_USECACHE : (ModifierApplyFlag)0;
1030  const ModifierEvalContext mectx = {
1031  depsgraph, ob, (ModifierApplyFlag)(apply_render | apply_cache)};
1032  const ModifierEvalContext mectx_orco = {
1033  depsgraph, ob, (ModifierApplyFlag)(apply_render | MOD_APPLY_ORCO)};
1034 
1035  /* Get effective list of modifiers to execute. Some effects like shape keys
1036  * are added as virtual modifiers before the user created modifiers. */
1037  VirtualModifierData virtualModifierData;
1038  ModifierData *firstmd = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
1039  ModifierData *md = firstmd;
1040 
1041  /* Preview colors by modifiers such as dynamic paint, to show the results
1042  * even if the resulting data is not used in a material. Only in object mode.
1043  * TODO: this is broken, not drawn by the drawn manager. */
1044  const bool do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
1045  ModifierData *previewmd = nullptr;
1046  CustomData_MeshMasks previewmask = {0};
1047  if (do_mod_mcol) {
1048  /* Find the last active modifier generating a preview, or nullptr if none. */
1049  /* XXX Currently, DPaint modifier just ignores this.
1050  * Needs a stupid hack...
1051  * The whole "modifier preview" thing has to be (re?)designed, anyway! */
1052  previewmd = BKE_modifier_get_last_preview(scene, md, required_mode);
1053  }
1054 
1055  /* Compute accumulated datamasks needed by each modifier. It helps to do
1056  * this fine grained so that for example vertex groups are preserved up to
1057  * an armature modifier, but not through a following subsurf modifier where
1058  * subdividing them is expensive. */
1059  CustomData_MeshMasks final_datamask = *dataMask;
1061  scene, ob, md, &final_datamask, required_mode, previewmd, &previewmask);
1062  CDMaskLink *md_datamask = datamasks;
1063  /* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
1065 
1066  /* Clear errors before evaluation. */
1068 
1069  /* Apply all leading deform modifiers. */
1070  if (useDeform) {
1071  for (; md; md = md->next, md_datamask = md_datamask->next) {
1073 
1074  if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
1075  continue;
1076  }
1077 
1078  if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) {
1079  continue;
1080  }
1081 
1082  if (mti->type == eModifierTypeType_OnlyDeform && !sculpt_dyntopo) {
1083  if (!deformed_verts) {
1084  deformed_verts = BKE_mesh_vert_coords_alloc(mesh_input, &num_deformed_verts);
1085  }
1086  else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
1087  if (mesh_final == nullptr) {
1088  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
1089  ASSERT_IS_VALID_MESH(mesh_final);
1090  }
1091  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1092  }
1093 
1094  BKE_modifier_deform_verts(md, &mectx, mesh_final, deformed_verts, num_deformed_verts);
1095 
1096  isPrevDeform = true;
1097  }
1098  else {
1099  break;
1100  }
1101 
1102  /* grab modifiers until index i */
1103  if ((index != -1) && (BLI_findindex(&ob->modifiers, md) >= index)) {
1104  md = nullptr;
1105  break;
1106  }
1107  }
1108 
1109  /* Result of all leading deforming modifiers is cached for
1110  * places that wish to use the original mesh but with deformed
1111  * coordinates (like vertex paint). */
1112  if (r_deform) {
1113  mesh_deform = BKE_mesh_copy_for_eval(mesh_input, true);
1114 
1115  if (deformed_verts) {
1116  BKE_mesh_vert_coords_apply(mesh_deform, deformed_verts);
1117  }
1118  }
1119  }
1120 
1121  /* Apply all remaining constructive and deforming modifiers. */
1122  bool have_non_onlydeform_modifiers_appled = false;
1123  for (; md; md = md->next, md_datamask = md_datamask->next) {
1125 
1126  if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
1127  continue;
1128  }
1129 
1130  if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) {
1131  continue;
1132  }
1133 
1135  have_non_onlydeform_modifiers_appled) {
1136  BKE_modifier_set_error(ob, md, "Modifier requires original data, bad stack position");
1137  continue;
1138  }
1139 
1140  if (sculpt_mode && (!has_multires || multires_applied || sculpt_dyntopo)) {
1141  bool unsupported = false;
1142 
1143  if (md->type == eModifierType_Multires && ((MultiresModifierData *)md)->sculptlvl == 0) {
1144  /* If multires is on level 0 skip it silently without warning message. */
1145  if (!sculpt_dyntopo) {
1146  continue;
1147  }
1148  }
1149 
1150  if (sculpt_dyntopo) {
1151  unsupported = true;
1152  }
1153 
1155  unsupported |= (mti->type != eModifierTypeType_OnlyDeform);
1156  }
1157 
1158  unsupported |= multires_applied;
1159 
1160  if (unsupported) {
1161  if (sculpt_dyntopo) {
1162  BKE_modifier_set_error(ob, md, "Not supported in dyntopo");
1163  }
1164  else {
1165  BKE_modifier_set_error(ob, md, "Not supported in sculpt mode");
1166  }
1167  continue;
1168  }
1169  }
1170 
1171  if (need_mapping && !BKE_modifier_supports_mapping(md)) {
1172  continue;
1173  }
1174 
1175  if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) {
1176  continue;
1177  }
1178 
1179  /* Add orco mesh as layer if needed by this modifier. */
1180  if (mesh_final && mesh_orco && mti->requiredDataMask) {
1181  CustomData_MeshMasks mask = {0};
1182  mti->requiredDataMask(ob, md, &mask);
1183  if (mask.vmask & CD_MASK_ORCO) {
1184  add_orco_mesh(ob, nullptr, mesh_final, mesh_orco, CD_ORCO);
1185  }
1186  }
1187 
1188  /* How to apply modifier depends on (a) what we already have as
1189  * a result of previous modifiers (could be a Mesh or just
1190  * deformed vertices) and (b) what type the modifier is. */
1191  if (mti->type == eModifierTypeType_OnlyDeform) {
1192  /* No existing verts to deform, need to build them. */
1193  if (!deformed_verts) {
1194  if (mesh_final) {
1195  Mesh *mesh_final_new = prepare_geometry_set_for_mesh_modifier(mesh_final,
1196  geometry_set_final);
1197  if (mesh_final_new != mesh_final) {
1198  BLI_assert(mesh_final != mesh_input);
1199  BKE_id_free(nullptr, mesh_final);
1200  mesh_final = mesh_final_new;
1201  }
1202 
1203  /* Deforming a mesh, read the vertex locations
1204  * out of the mesh and deform them. Once done with this
1205  * run of deformers verts will be written back. */
1206  deformed_verts = BKE_mesh_vert_coords_alloc(mesh_final, &num_deformed_verts);
1207  }
1208  else {
1209  deformed_verts = BKE_mesh_vert_coords_alloc(mesh_input, &num_deformed_verts);
1210  }
1211  }
1212  /* if this is not the last modifier in the stack then recalculate the normals
1213  * to avoid giving bogus normals to the next modifier see: T23673. */
1214  else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
1215  if (mesh_final == nullptr) {
1216  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
1217  ASSERT_IS_VALID_MESH(mesh_final);
1218  }
1219  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1220  }
1221  BKE_modifier_deform_verts(md, &mectx, mesh_final, deformed_verts, num_deformed_verts);
1222  }
1223  else {
1224  bool check_for_needs_mapping = false;
1225  /* apply vertex coordinates or build a Mesh as necessary */
1226  if (mesh_final != nullptr) {
1227  if (have_non_onlydeform_modifiers_appled == false) {
1228  /* If we only deformed, we won't have initialized #CD_ORIGINDEX.
1229  * as this is the only part of the function that initializes mapping. */
1230  check_for_needs_mapping = true;
1231  }
1232  }
1233  else {
1234  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
1235  ASSERT_IS_VALID_MESH(mesh_final);
1236  check_for_needs_mapping = true;
1237  }
1238 
1239  if (deformed_verts) {
1240  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1241  }
1242 
1243  have_non_onlydeform_modifiers_appled = true;
1244 
1245  /* determine which data layers are needed by following modifiers */
1246  CustomData_MeshMasks nextmask = md_datamask->next ? md_datamask->next->mask : final_datamask;
1247 
1248  if (check_for_needs_mapping) {
1249  /* Initialize original indices the first time we evaluate a
1250  * constructive modifier. Modifiers will then do mapping mostly
1251  * automatic by copying them through CustomData_copy_data along
1252  * with other data.
1253  *
1254  * These are created when either requested by evaluation, or if
1255  * following modifiers requested them. */
1256  if (need_mapping ||
1257  ((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX)) {
1258  /* calc */
1260  &mesh_final->vdata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totvert);
1262  &mesh_final->edata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totedge);
1264  &mesh_final->pdata, CD_ORIGINDEX, CD_CALLOC, nullptr, mesh_final->totpoly);
1265 
1266  /* Not worth parallelizing this,
1267  * gives less than 0.1% overall speedup in best of best cases... */
1268  range_vn_i((int *)CustomData_get_layer(&mesh_final->vdata, CD_ORIGINDEX),
1269  mesh_final->totvert,
1270  0);
1271  range_vn_i((int *)CustomData_get_layer(&mesh_final->edata, CD_ORIGINDEX),
1272  mesh_final->totedge,
1273  0);
1274  range_vn_i((int *)CustomData_get_layer(&mesh_final->pdata, CD_ORIGINDEX),
1275  mesh_final->totpoly,
1276  0);
1277  }
1278  }
1279 
1280  /* set the Mesh to only copy needed data */
1281  CustomData_MeshMasks mask = md_datamask->mask;
1282  /* needMapping check here fixes bug T28112, otherwise it's
1283  * possible that it won't be copied */
1284  CustomData_MeshMasks_update(&mask, &append_mask);
1285  if (need_mapping) {
1286  mask.vmask |= CD_MASK_ORIGINDEX;
1287  mask.emask |= CD_MASK_ORIGINDEX;
1288  mask.pmask |= CD_MASK_ORIGINDEX;
1289  }
1290  mesh_set_only_copy(mesh_final, &mask);
1291 
1292  /* add cloth rest shape key if needed */
1293  if (mask.vmask & CD_MASK_CLOTH_ORCO) {
1294  add_orco_mesh(ob, nullptr, mesh_final, mesh_orco, CD_CLOTH_ORCO);
1295  }
1296 
1297  /* add an origspace layer if needed */
1298  if ((md_datamask->mask.lmask) & CD_MASK_ORIGSPACE_MLOOP) {
1299  if (!CustomData_has_layer(&mesh_final->ldata, CD_ORIGSPACE_MLOOP)) {
1301  &mesh_final->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, nullptr, mesh_final->totloop);
1302  mesh_init_origspace(mesh_final);
1303  }
1304  }
1305 
1307  md, mectx, mesh_final, geometry_set_final);
1308  ASSERT_IS_VALID_MESH(mesh_next);
1309 
1310  if (mesh_next) {
1311  /* if the modifier returned a new mesh, release the old one */
1312  if (mesh_final != mesh_next) {
1313  BLI_assert(mesh_final != mesh_input);
1314  BKE_id_free(nullptr, mesh_final);
1315  }
1316  mesh_final = mesh_next;
1317 
1318  if (deformed_verts) {
1319  MEM_freeN(deformed_verts);
1320  deformed_verts = nullptr;
1321  }
1322  }
1323 
1324  /* create an orco mesh in parallel */
1325  if (nextmask.vmask & CD_MASK_ORCO) {
1326  if (!mesh_orco) {
1327  mesh_orco = create_orco_mesh(ob, mesh_input, nullptr, CD_ORCO);
1328  }
1329 
1330  nextmask.vmask &= ~CD_MASK_ORCO;
1331  CustomData_MeshMasks temp_cddata_masks = {0};
1332  temp_cddata_masks.vmask = CD_MASK_ORIGINDEX;
1333  temp_cddata_masks.emask = CD_MASK_ORIGINDEX;
1334  temp_cddata_masks.fmask = CD_MASK_ORIGINDEX;
1335  temp_cddata_masks.pmask = CD_MASK_ORIGINDEX;
1336 
1337  if (mti->requiredDataMask != nullptr) {
1338  mti->requiredDataMask(ob, md, &temp_cddata_masks);
1339  }
1340  CustomData_MeshMasks_update(&temp_cddata_masks, &nextmask);
1341  mesh_set_only_copy(mesh_orco, &temp_cddata_masks);
1342 
1343  mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco);
1344  ASSERT_IS_VALID_MESH(mesh_next);
1345 
1346  if (mesh_next) {
1347  /* if the modifier returned a new mesh, release the old one */
1348  if (mesh_orco != mesh_next) {
1349  BLI_assert(mesh_orco != mesh_input);
1350  BKE_id_free(nullptr, mesh_orco);
1351  }
1352 
1353  mesh_orco = mesh_next;
1354  }
1355  }
1356 
1357  /* create cloth orco mesh in parallel */
1358  if (nextmask.vmask & CD_MASK_CLOTH_ORCO) {
1359  if (!mesh_orco_cloth) {
1360  mesh_orco_cloth = create_orco_mesh(ob, mesh_input, nullptr, CD_CLOTH_ORCO);
1361  }
1362 
1363  nextmask.vmask &= ~CD_MASK_CLOTH_ORCO;
1364  nextmask.vmask |= CD_MASK_ORIGINDEX;
1365  nextmask.emask |= CD_MASK_ORIGINDEX;
1366  nextmask.pmask |= CD_MASK_ORIGINDEX;
1367  mesh_set_only_copy(mesh_orco_cloth, &nextmask);
1368 
1369  mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco_cloth);
1370  ASSERT_IS_VALID_MESH(mesh_next);
1371 
1372  if (mesh_next) {
1373  /* if the modifier returned a new mesh, release the old one */
1374  if (mesh_orco_cloth != mesh_next) {
1375  BLI_assert(mesh_orco != mesh_input);
1376  BKE_id_free(nullptr, mesh_orco_cloth);
1377  }
1378 
1379  mesh_orco_cloth = mesh_next;
1380  }
1381  }
1382 
1383  /* in case of dynamic paint, make sure preview mask remains for following modifiers */
1384  /* XXX Temp and hackish solution! */
1385  if (md->type == eModifierType_DynamicPaint) {
1386  append_mask.lmask |= CD_MASK_PREVIEW_MLOOPCOL;
1387  }
1388 
1389  mesh_final->runtime.deformed_only = false;
1390  }
1391 
1392  isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
1393 
1394  /* grab modifiers until index i */
1395  if ((index != -1) && (BLI_findindex(&ob->modifiers, md) >= index)) {
1396  break;
1397  }
1398 
1399  if (sculpt_mode && md->type == eModifierType_Multires) {
1400  multires_applied = true;
1401  }
1402  }
1403 
1404  BLI_linklist_free((LinkNode *)datamasks, nullptr);
1405 
1406  for (md = firstmd; md; md = md->next) {
1408  }
1409 
1410  /* Yay, we are done. If we have a Mesh and deformed vertices,
1411  * we need to apply these back onto the Mesh. If we have no
1412  * Mesh then we need to build one. */
1413  if (mesh_final == nullptr) {
1414  /* Note: this check on cdmask is a bit dodgy, it handles the issue at stake here (see T68211),
1415  * but other cases might require similar handling?
1416  * Could be a good idea to define a proper CustomData_MeshMask for that then. */
1417  if (deformed_verts == nullptr && allow_shared_mesh &&
1418  (final_datamask.lmask & CD_MASK_NORMAL) == 0 &&
1419  (final_datamask.pmask & CD_MASK_NORMAL) == 0) {
1420  mesh_final = mesh_input;
1421  }
1422  else {
1423  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
1424  }
1425  }
1426  if (deformed_verts) {
1427  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1428  MEM_freeN(deformed_verts);
1429  deformed_verts = nullptr;
1430  }
1431 
1432  /* Denotes whether the object which the modifier stack came from owns the mesh or whether the
1433  * mesh is shared across multiple objects since there are no effective modifiers. */
1434  const bool is_own_mesh = (mesh_final != mesh_input);
1435 
1436  /* Add orco coordinates to final and deformed mesh if requested. */
1437  if (final_datamask.vmask & CD_MASK_ORCO) {
1438  /* No need in ORCO layer if the mesh was not deformed or modified: undeformed mesh in this case
1439  * matches input mesh. */
1440  if (is_own_mesh) {
1441  add_orco_mesh(ob, nullptr, mesh_final, mesh_orco, CD_ORCO);
1442  }
1443 
1444  if (mesh_deform) {
1445  add_orco_mesh(ob, nullptr, mesh_deform, nullptr, CD_ORCO);
1446  }
1447  }
1448 
1449  if (mesh_orco) {
1450  BKE_id_free(nullptr, mesh_orco);
1451  }
1452  if (mesh_orco_cloth) {
1453  BKE_id_free(nullptr, mesh_orco_cloth);
1454  }
1455 
1456  /* Compute normals. */
1457  if (is_own_mesh) {
1458  mesh_calc_modifier_final_normals(mesh_input, &final_datamask, sculpt_dyntopo, mesh_final);
1459  }
1460  else {
1461  Mesh_Runtime *runtime = &mesh_input->runtime;
1462  if (runtime->mesh_eval == nullptr) {
1463  BLI_assert(runtime->eval_mutex != nullptr);
1464  BLI_mutex_lock((ThreadMutex *)runtime->eval_mutex);
1465  if (runtime->mesh_eval == nullptr) {
1466  mesh_final = BKE_mesh_copy_for_eval(mesh_input, true);
1467  mesh_calc_modifier_final_normals(mesh_input, &final_datamask, sculpt_dyntopo, mesh_final);
1468  mesh_calc_finalize(mesh_input, mesh_final);
1469  runtime->mesh_eval = mesh_final;
1470  }
1472  }
1473  mesh_final = runtime->mesh_eval;
1474  }
1475 
1476  if (is_own_mesh) {
1477  mesh_calc_finalize(mesh_input, mesh_final);
1478  }
1479 
1480  /* Return final mesh */
1481  *r_final = mesh_final;
1482  if (r_deform) {
1483  *r_deform = mesh_deform;
1484  }
1485  if (r_geometry_set) {
1486  *r_geometry_set = new GeometrySet(std::move(geometry_set_final));
1487  }
1488 }
1489 
1490 float (*editbmesh_vert_coords_alloc(BMEditMesh *em, int *r_vert_len))[3]
1491 {
1492  BMIter iter;
1493  BMVert *eve;
1494  float(*cos)[3];
1495  int i;
1496 
1497  *r_vert_len = em->bm->totvert;
1498 
1499  cos = (float(*)[3])MEM_malloc_arrayN(em->bm->totvert, sizeof(float[3]), "vertexcos");
1500 
1501  BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
1502  copy_v3_v3(cos[i], eve->co);
1503  }
1504 
1505  return cos;
1506 }
1507 
1509  const Object *ob,
1510  ModifierData *md,
1511  bool has_prev_mesh)
1512 {
1514  const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
1515 
1516  if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
1517  return false;
1518  }
1519 
1520  if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && has_prev_mesh) {
1521  BKE_modifier_set_error(ob, md, "Modifier requires original data, bad stack position");
1522  return false;
1523  }
1524 
1525  return true;
1526 }
1527 
1529  const CustomData_MeshMasks *final_datamask)
1530 {
1531  if (mesh_final->runtime.wrapper_type != ME_WRAPPER_TYPE_MDATA) {
1532  /* Generated at draw time. */
1533  mesh_final->runtime.wrapper_type_finalize = (1 << mesh_final->runtime.wrapper_type);
1534  return;
1535  }
1536 
1537  const bool do_loop_normals = ((mesh_final->flag & ME_AUTOSMOOTH) != 0 ||
1538  (final_datamask->lmask & CD_MASK_NORMAL) != 0);
1539  /* Some modifiers may need this info from their target (other) object,
1540  * simpler to generate it here as well. */
1541  const bool do_poly_normals = ((final_datamask->pmask & CD_MASK_NORMAL) != 0);
1542 
1543  /* In case we also need poly normals, add the layer and compute them here
1544  * (BKE_mesh_calc_normals_split() assumes that if that data exists, it is always valid). */
1545  if (do_poly_normals) {
1546  if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) {
1547  float(*polynors)[3] = (float(*)[3])CustomData_add_layer(
1548  &mesh_final->pdata, CD_NORMAL, CD_CALLOC, nullptr, mesh_final->totpoly);
1549  BKE_mesh_calc_normals_poly(mesh_final->mvert,
1550  nullptr,
1551  mesh_final->totvert,
1552  mesh_final->mloop,
1553  mesh_final->mpoly,
1554  mesh_final->totloop,
1555  mesh_final->totpoly,
1556  polynors,
1557  false);
1558  }
1559  }
1560 
1561  if (do_loop_normals) {
1562  /* Compute loop normals */
1563  BKE_mesh_calc_normals_split(mesh_final);
1564  BKE_mesh_tessface_clear(mesh_final);
1565  }
1566 
1567  /* BMESH_ONLY, ensure tessface's used for drawing,
1568  * but don't recalculate if the last modifier in the stack gives us tessfaces
1569  * check if the derived meshes are DM_TYPE_EDITBMESH before calling, this isn't essential
1570  * but quiets annoying error messages since tessfaces wont be created. */
1571  if (final_datamask->fmask & CD_MASK_MFACE) {
1572  if (mesh_final->edit_mesh == nullptr) {
1573  BKE_mesh_tessface_ensure(mesh_final);
1574  }
1575  }
1576 
1577  /* same as mesh_calc_modifiers (if using loop normals, poly nors have already been computed). */
1578  if (!do_loop_normals) {
1580 
1581  /* Some modifiers, like data-transfer, may generate those data, we do not want to keep them,
1582  * as they are used by display code when available (i.e. even if autosmooth is disabled). */
1583  if (CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) {
1584  CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop);
1585  }
1586  }
1587 }
1588 
1590  Scene *scene,
1591  Object *ob,
1592  BMEditMesh *em_input,
1593  const CustomData_MeshMasks *dataMask,
1594  /* return args */
1595  Mesh **r_cage,
1596  Mesh **r_final,
1597  GeometrySet **r_geometry_set)
1598 {
1599  /* Input and final mesh. Final mesh is only created the moment the first
1600  * constructive modifier is executed, or a deform modifier needs normals
1601  * or certain data layers. */
1602  Mesh *mesh_input = (Mesh *)ob->data;
1603  Mesh *mesh_final = nullptr;
1604  Mesh *mesh_cage = nullptr;
1605  /* This geometry set contains the non-mesh data that might be generated by modifiers. */
1606  GeometrySet geometry_set_final;
1607 
1608  /* Add the initial mesh component, with a copy of the vertex group names from the object,
1609  * since they need to be stored in the geometry set for evaluation. */
1610  MeshComponent &initial_mesh_component =
1611  geometry_set_final.get_component_for_write<MeshComponent>();
1612  initial_mesh_component.copy_vertex_group_names_from_object(*ob);
1613 
1614  /* Deformed vertex locations array. Deform only modifier need this type of
1615  * float array rather than MVert*. Tracked along with mesh_final as an
1616  * optimization to avoid copying coordinates back and forth if there are
1617  * multiple sequential deform only modifiers. */
1618  float(*deformed_verts)[3] = nullptr;
1619  int num_deformed_verts = 0;
1620  bool isPrevDeform = false;
1621 
1622  /* Mesh with constructive modifiers but no deformation applied. Tracked
1623  * along with final mesh if undeformed / orco coordinates are requested
1624  * for texturing. */
1625  Mesh *mesh_orco = nullptr;
1626 
1627  /* Modifier evaluation modes. */
1628  const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
1629 
1630  const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
1631  /* Modifier evaluation contexts for different types of modifiers. */
1632  ModifierApplyFlag apply_render = use_render ? MOD_APPLY_RENDER : (ModifierApplyFlag)0;
1633  const ModifierEvalContext mectx = {
1634  depsgraph, ob, (ModifierApplyFlag)(MOD_APPLY_USECACHE | apply_render)};
1635  const ModifierEvalContext mectx_orco = {depsgraph, ob, MOD_APPLY_ORCO};
1636 
1637  /* Get effective list of modifiers to execute. Some effects like shape keys
1638  * are added as virtual modifiers before the user created modifiers. */
1639  VirtualModifierData virtualModifierData;
1640  ModifierData *md = BKE_modifiers_get_virtual_modifierlist(ob, &virtualModifierData);
1641 
1642  /* Compute accumulated datamasks needed by each modifier. It helps to do
1643  * this fine grained so that for example vertex groups are preserved up to
1644  * an armature modifier, but not through a following subsurf modifier where
1645  * subdividing them is expensive. */
1646  CustomData_MeshMasks final_datamask = *dataMask;
1648  scene, ob, md, &final_datamask, required_mode, nullptr, nullptr);
1649  CDMaskLink *md_datamask = datamasks;
1650  CustomData_MeshMasks append_mask = CD_MASK_BAREMESH;
1651 
1652  /* Evaluate modifiers up to certain index to get the mesh cage. */
1653  int cageIndex = BKE_modifiers_get_cage_index(scene, ob, nullptr, true);
1654  if (r_cage && cageIndex == -1) {
1656  em_input, &final_datamask, nullptr, mesh_input);
1657  }
1658 
1659  /* Clear errors before evaluation. */
1661 
1662  for (int i = 0; md; i++, md = md->next, md_datamask = md_datamask->next) {
1664 
1665  if (!editbmesh_modifier_is_enabled(scene, ob, md, mesh_final != nullptr)) {
1666  continue;
1667  }
1668 
1669  /* Add an orco mesh as layer if needed by this modifier. */
1670  if (mesh_final && mesh_orco && mti->requiredDataMask) {
1671  CustomData_MeshMasks mask = {0};
1672  mti->requiredDataMask(ob, md, &mask);
1673  if (mask.vmask & CD_MASK_ORCO) {
1674  add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO);
1675  }
1676  }
1677 
1678  /* How to apply modifier depends on (a) what we already have as
1679  * a result of previous modifiers (could be a mesh or just
1680  * deformed vertices) and (b) what type the modifier is. */
1681  if (mti->type == eModifierTypeType_OnlyDeform) {
1682  /* No existing verts to deform, need to build them. */
1683  if (!deformed_verts) {
1684  if (mesh_final) {
1685  /* Deforming a derived mesh, read the vertex locations
1686  * out of the mesh and deform them. Once done with this
1687  * run of deformers verts will be written back. */
1688  deformed_verts = BKE_mesh_vert_coords_alloc(mesh_final, &num_deformed_verts);
1689  }
1690  else {
1691  deformed_verts = editbmesh_vert_coords_alloc(em_input, &num_deformed_verts);
1692  }
1693  }
1694  else if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
1695  if (mesh_final == nullptr) {
1696  mesh_final = BKE_mesh_from_bmesh_for_eval_nomain(em_input->bm, nullptr, mesh_input);
1697  ASSERT_IS_VALID_MESH(mesh_final);
1698  }
1699  BLI_assert(deformed_verts != nullptr);
1700  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1701  }
1702 
1703  if (mti->deformVertsEM) {
1705  md, &mectx, em_input, mesh_final, deformed_verts, num_deformed_verts);
1706  }
1707  else {
1708  BKE_modifier_deform_verts(md, &mectx, mesh_final, deformed_verts, num_deformed_verts);
1709  }
1710  }
1711  else {
1712  /* apply vertex coordinates or build a DerivedMesh as necessary */
1713  if (mesh_final) {
1714  if (deformed_verts) {
1715  Mesh *mesh_tmp = BKE_mesh_copy_for_eval(mesh_final, false);
1716  if (mesh_final != mesh_cage) {
1717  BKE_id_free(nullptr, mesh_final);
1718  }
1719  mesh_final = mesh_tmp;
1720  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1721  }
1722  else if (mesh_final == mesh_cage) {
1723  /* 'me' may be changed by this modifier, so we need to copy it. */
1724  mesh_final = BKE_mesh_copy_for_eval(mesh_final, false);
1725  }
1726  }
1727  else {
1729  em_input, nullptr, deformed_verts, mesh_input);
1730  deformed_verts = nullptr;
1731  }
1732 
1733  /* create an orco derivedmesh in parallel */
1734  CustomData_MeshMasks mask = md_datamask->mask;
1735  if (mask.vmask & CD_MASK_ORCO) {
1736  if (!mesh_orco) {
1737  mesh_orco = create_orco_mesh(ob, mesh_input, em_input, CD_ORCO);
1738  }
1739 
1740  mask.vmask &= ~CD_MASK_ORCO;
1741  mask.vmask |= CD_MASK_ORIGINDEX;
1742  mask.emask |= CD_MASK_ORIGINDEX;
1743  mask.pmask |= CD_MASK_ORIGINDEX;
1744  mesh_set_only_copy(mesh_orco, &mask);
1745 
1746  Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco);
1747  ASSERT_IS_VALID_MESH(mesh_next);
1748 
1749  if (mesh_next) {
1750  /* if the modifier returned a new dm, release the old one */
1751  if (mesh_orco && mesh_orco != mesh_next) {
1752  BKE_id_free(nullptr, mesh_orco);
1753  }
1754  mesh_orco = mesh_next;
1755  }
1756  }
1757 
1758  /* set the DerivedMesh to only copy needed data */
1759  CustomData_MeshMasks_update(&mask, &append_mask);
1760  /* XXX WHAT? ovewrites mask ??? */
1761  /* CD_MASK_ORCO may have been cleared above */
1762  mask = md_datamask->mask;
1763  mask.vmask |= CD_MASK_ORIGINDEX;
1764  mask.emask |= CD_MASK_ORIGINDEX;
1765  mask.pmask |= CD_MASK_ORIGINDEX;
1766 
1767  mesh_set_only_copy(mesh_final, &mask);
1768 
1769  if (mask.lmask & CD_MASK_ORIGSPACE_MLOOP) {
1770  if (!CustomData_has_layer(&mesh_final->ldata, CD_ORIGSPACE_MLOOP)) {
1772  &mesh_final->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, nullptr, mesh_final->totloop);
1773  mesh_init_origspace(mesh_final);
1774  }
1775  }
1776 
1778  md, mectx, mesh_final, geometry_set_final);
1779  ASSERT_IS_VALID_MESH(mesh_next);
1780 
1781  if (mesh_next) {
1782  if (mesh_final && mesh_final != mesh_next) {
1783  BKE_id_free(nullptr, mesh_final);
1784  }
1785  mesh_final = mesh_next;
1786 
1787  if (deformed_verts) {
1788  MEM_freeN(deformed_verts);
1789  deformed_verts = nullptr;
1790  }
1791  }
1792  mesh_final->runtime.deformed_only = false;
1793  }
1794 
1795  if (r_cage && i == cageIndex) {
1796  if (mesh_final && deformed_verts) {
1797  mesh_cage = BKE_mesh_copy_for_eval(mesh_final, false);
1798  BKE_mesh_vert_coords_apply(mesh_cage, deformed_verts);
1799  }
1800  else if (mesh_final) {
1801  mesh_cage = mesh_final;
1802  }
1803  else {
1804  Mesh *me_orig = mesh_input;
1805  if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) {
1806  if (!BKE_mesh_runtime_ensure_edit_data(me_orig)) {
1808  }
1809  me_orig->runtime.edit_data->vertexCos = (const float(*)[3])MEM_dupallocN(deformed_verts);
1810  }
1812  em_input,
1813  &final_datamask,
1814  deformed_verts ? (const float(*)[3])MEM_dupallocN(deformed_verts) : nullptr,
1815  mesh_input);
1816  }
1817  }
1818 
1819  isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
1820  }
1821 
1822  BLI_linklist_free((LinkNode *)datamasks, nullptr);
1823 
1824  /* Yay, we are done. If we have a DerivedMesh and deformed vertices need
1825  * to apply these back onto the DerivedMesh. If we have no DerivedMesh
1826  * then we need to build one. */
1827  if (mesh_final) {
1828  if (deformed_verts) {
1829  Mesh *mesh_tmp = BKE_mesh_copy_for_eval(mesh_final, false);
1830  if (mesh_final != mesh_cage) {
1831  BKE_id_free(nullptr, mesh_final);
1832  }
1833  mesh_final = mesh_tmp;
1834  BKE_mesh_vert_coords_apply(mesh_final, deformed_verts);
1835  }
1836  }
1837  else if (!deformed_verts && mesh_cage) {
1838  /* cage should already have up to date normals */
1839  mesh_final = mesh_cage;
1840  }
1841  else {
1842  /* this is just a copy of the editmesh, no need to calc normals */
1844  em_input, &final_datamask, deformed_verts, mesh_input);
1845  deformed_verts = nullptr;
1846  }
1847 
1848  if (deformed_verts) {
1849  MEM_freeN(deformed_verts);
1850  }
1851 
1852  /* Add orco coordinates to final and deformed mesh if requested. */
1853  if (final_datamask.vmask & CD_MASK_ORCO) {
1854  /* FIXME(Campbell): avoid the need to convert to mesh data just to add an orco layer. */
1855  BKE_mesh_wrapper_ensure_mdata(mesh_final);
1856 
1857  add_orco_mesh(ob, em_input, mesh_final, mesh_orco, CD_ORCO);
1858  }
1859 
1860  if (mesh_orco) {
1861  BKE_id_free(nullptr, mesh_orco);
1862  }
1863 
1864  /* Ensure normals calculation below is correct. */
1865  BLI_assert((mesh_input->flag & ME_AUTOSMOOTH) == (mesh_final->flag & ME_AUTOSMOOTH));
1866  BLI_assert(mesh_input->smoothresh == mesh_final->smoothresh);
1867  BLI_assert(mesh_input->smoothresh == mesh_cage->smoothresh);
1868 
1869  /* Compute normals. */
1870  editbmesh_calc_modifier_final_normals(mesh_final, &final_datamask);
1871  if (mesh_cage && (mesh_cage != mesh_final)) {
1872  editbmesh_calc_modifier_final_normals(mesh_cage, &final_datamask);
1873  }
1874 
1875  /* Return final mesh. */
1876  *r_final = mesh_final;
1877  if (r_cage) {
1878  *r_cage = mesh_cage;
1879  }
1880  if (r_geometry_set) {
1881  *r_geometry_set = new GeometrySet(std::move(geometry_set_final));
1882  }
1883 }
1884 
1885 static void mesh_build_extra_data(struct Depsgraph *depsgraph, Object *ob, Mesh *mesh_eval)
1886 {
1887  uint32_t eval_flags = DEG_get_eval_flags_for_id(depsgraph, &ob->id);
1888 
1889  if (eval_flags & DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY) {
1891  }
1892 }
1893 
1895 {
1900 }
1901 
1903  Scene *scene,
1904  Object *ob,
1905  const CustomData_MeshMasks *dataMask,
1906  const bool need_mapping)
1907 {
1908  BLI_assert(ob->type == OB_MESH);
1909 
1910  /* Evaluated meshes aren't supposed to be created on original instances. If you do,
1911  * they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
1913 
1915  if (DEG_is_active(depsgraph)) {
1917  }
1918 
1919 #if 0 /* XXX This is already taken care of in mesh_calc_modifiers()... */
1920  if (need_mapping) {
1921  /* Also add the flag so that it is recorded in lastDataMask. */
1922  dataMask->vmask |= CD_MASK_ORIGINDEX;
1923  dataMask->emask |= CD_MASK_ORIGINDEX;
1924  dataMask->pmask |= CD_MASK_ORIGINDEX;
1925  }
1926 #endif
1927 
1928  Mesh *mesh_eval = nullptr, *mesh_deform_eval = nullptr;
1929  GeometrySet *geometry_set_eval = nullptr;
1931  scene,
1932  ob,
1933  1,
1934  need_mapping,
1935  dataMask,
1936  -1,
1937  true,
1938  true,
1939  &mesh_deform_eval,
1940  &mesh_eval,
1941  &geometry_set_eval);
1942 
1943  /* The modifier stack evaluation is storing result in mesh->runtime.mesh_eval, but this result
1944  * is not guaranteed to be owned by object.
1945  *
1946  * Check ownership now, since later on we can not go to a mesh owned by someone else via
1947  * object's runtime: this could cause access freed data on depsgraph destruction (mesh who owns
1948  * the final result might be freed prior to object). */
1949  Mesh *mesh = (Mesh *)ob->data;
1950  const bool is_mesh_eval_owned = (mesh_eval != mesh->runtime.mesh_eval);
1951  BKE_object_eval_assign_data(ob, &mesh_eval->id, is_mesh_eval_owned);
1952 
1953  /* Add the final mesh as read-only non-owning component to the geometry set. */
1954  MeshComponent &mesh_component = geometry_set_eval->get_component_for_write<MeshComponent>();
1955  mesh_component.replace_mesh_but_keep_vertex_group_names(mesh_eval,
1957  ob->runtime.geometry_set_eval = geometry_set_eval;
1958 
1959  ob->runtime.mesh_deform_eval = mesh_deform_eval;
1960  ob->runtime.last_data_mask = *dataMask;
1961  ob->runtime.last_need_mapping = need_mapping;
1962 
1963  BKE_object_boundbox_calc_from_mesh(ob, mesh_eval);
1964 
1965  /* Make sure that drivers can target shapekey properties.
1966  * Note that this causes a potential inconsistency, as the shapekey may have a
1967  * different topology than the evaluated mesh. */
1968  BLI_assert(mesh->key == nullptr || DEG_is_evaluated_id(&mesh->key->id));
1969  mesh_eval->key = mesh->key;
1970 
1971  if ((ob->mode & OB_MODE_ALL_SCULPT) && ob->sculpt) {
1972  if (DEG_is_active(depsgraph)) {
1974  }
1975  }
1976 
1978  mesh_build_extra_data(depsgraph, ob, mesh_eval);
1979 }
1980 
1982  Scene *scene,
1983  Object *obedit,
1984  BMEditMesh *em,
1985  CustomData_MeshMasks *dataMask)
1986 {
1988 
1990  if (DEG_is_active(depsgraph)) {
1992  }
1993 
1995 
1996  Mesh *me_cage;
1997  Mesh *me_final;
1998  GeometrySet *non_mesh_components;
1999 
2001  depsgraph, scene, obedit, em, dataMask, &me_cage, &me_final, &non_mesh_components);
2002 
2003  em->mesh_eval_final = me_final;
2004  em->mesh_eval_cage = me_cage;
2005  obedit->runtime.geometry_set_eval = non_mesh_components;
2006 
2008 
2009  em->lastDataMask = *dataMask;
2010 
2012 }
2013 
2015  Object *ob,
2016  CustomData_MeshMasks *r_mask,
2017  bool *r_need_mapping)
2018 {
2020 
2022 
2023  if (r_need_mapping) {
2024  *r_need_mapping = false;
2025  }
2026 
2027  /* Must never access original objects when dependency graph is not active: it might be already
2028  * freed. */
2029  if (!DEG_is_active(depsgraph)) {
2030  return;
2031  }
2032 
2033  Object *actob = view_layer->basact ? DEG_get_original_object(view_layer->basact->object) :
2034  nullptr;
2035  if (DEG_get_original_object(ob) == actob) {
2036  bool editing = BKE_paint_select_face_test(actob);
2037 
2038  /* weight paint and face select need original indices because of selection buffer drawing */
2039  if (r_need_mapping) {
2040  *r_need_mapping = (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT)));
2041  }
2042 
2043  /* check if we need tfaces & mcols due to face select or texture paint */
2044  if ((ob->mode & OB_MODE_TEXTURE_PAINT) || editing) {
2045  r_mask->lmask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL;
2046  r_mask->fmask |= CD_MASK_MTFACE;
2047  }
2048 
2049  /* check if we need mcols due to vertex paint or weightpaint */
2050  if (ob->mode & OB_MODE_VERTEX_PAINT) {
2051  r_mask->lmask |= CD_MASK_MLOOPCOL;
2052  }
2053 
2054  if (ob->mode & OB_MODE_WEIGHT_PAINT) {
2055  r_mask->vmask |= CD_MASK_MDEFORMVERT;
2056  }
2057 
2058  if (ob->mode & OB_MODE_EDIT) {
2059  r_mask->vmask |= CD_MASK_MVERT_SKIN;
2060  }
2061  }
2062 }
2063 
2065  Scene *scene,
2066  Object *ob,
2067  BMEditMesh *em,
2068  const CustomData_MeshMasks *dataMask)
2069 {
2070  bool need_mapping;
2071  CustomData_MeshMasks cddata_masks = *dataMask;
2072  object_get_datamask(depsgraph, ob, &cddata_masks, &need_mapping);
2073 
2074  if (em) {
2075  editbmesh_build_data(depsgraph, scene, ob, em, &cddata_masks);
2076  }
2077  else {
2078  mesh_build_data(depsgraph, scene, ob, &cddata_masks, need_mapping);
2079  }
2080 }
2081 
2082 /***/
2083 
2085  Scene *scene,
2086  Object *ob,
2087  const CustomData_MeshMasks *dataMask)
2088 {
2089  /* This function isn't thread-safe and can't be used during evaluation. */
2091 
2092  /* Evaluated meshes aren't supposed to be created on original instances. If you do,
2093  * they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
2095 
2096  /* if there's no evaluated mesh or the last data mask used doesn't include
2097  * the data we need, rebuild the derived mesh
2098  */
2099  bool need_mapping;
2100  CustomData_MeshMasks cddata_masks = *dataMask;
2101  object_get_datamask(depsgraph, ob, &cddata_masks, &need_mapping);
2102 
2103  Mesh *mesh_eval = BKE_object_get_evaluated_mesh(ob);
2104  if ((mesh_eval == nullptr) ||
2105  !CustomData_MeshMasks_are_matching(&(ob->runtime.last_data_mask), &cddata_masks) ||
2106  (need_mapping && !ob->runtime.last_need_mapping)) {
2107  CustomData_MeshMasks_update(&cddata_masks, &ob->runtime.last_data_mask);
2109  depsgraph, scene, ob, &cddata_masks, need_mapping || ob->runtime.last_need_mapping);
2110  mesh_eval = BKE_object_get_evaluated_mesh(ob);
2111  }
2112 
2113  if (mesh_eval != nullptr) {
2115  }
2116  return mesh_eval;
2117 }
2118 
2120  Scene *scene,
2121  Object *ob,
2122  const CustomData_MeshMasks *dataMask)
2123 {
2124  /* This function isn't thread-safe and can't be used during evaluation. */
2126 
2127  /* Evaluated meshes aren't supposed to be created on original instances. If you do,
2128  * they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
2130 
2131  /* if there's no derived mesh or the last data mask used doesn't include
2132  * the data we need, rebuild the derived mesh
2133  */
2134  bool need_mapping;
2135 
2136  CustomData_MeshMasks cddata_masks = *dataMask;
2137  object_get_datamask(depsgraph, ob, &cddata_masks, &need_mapping);
2138 
2139  if (!ob->runtime.mesh_deform_eval ||
2140  !CustomData_MeshMasks_are_matching(&(ob->runtime.last_data_mask), &cddata_masks) ||
2141  (need_mapping && !ob->runtime.last_need_mapping)) {
2142  CustomData_MeshMasks_update(&cddata_masks, &ob->runtime.last_data_mask);
2144  depsgraph, scene, ob, &cddata_masks, need_mapping || ob->runtime.last_need_mapping);
2145  }
2146 
2147  return ob->runtime.mesh_deform_eval;
2148 }
2149 
2151  Scene *scene,
2152  Object *ob,
2153  const CustomData_MeshMasks *dataMask)
2154 {
2155  Mesh *final;
2156 
2158  depsgraph, scene, ob, 1, false, dataMask, -1, false, false, nullptr, &final, nullptr);
2159 
2160  return final;
2161 }
2162 
2164  Scene *scene,
2165  Object *ob,
2166  const CustomData_MeshMasks *dataMask,
2167  int index)
2168 {
2169  Mesh *final;
2170 
2172  depsgraph, scene, ob, 1, false, dataMask, index, false, false, nullptr, &final, nullptr);
2173 
2174  return final;
2175 }
2176 
2178  Scene *scene,
2179  Object *ob,
2180  const CustomData_MeshMasks *dataMask)
2181 {
2182  Mesh *final;
2183 
2185  depsgraph, scene, ob, 0, false, dataMask, -1, false, false, nullptr, &final, nullptr);
2186 
2187  return final;
2188 }
2189 
2191  Scene *scene,
2192  Object *ob,
2193  const CustomData_MeshMasks *dataMask)
2194 {
2195  Mesh *final;
2196 
2198  depsgraph, scene, ob, 0, false, dataMask, -1, false, false, nullptr, &final, nullptr);
2199 
2200  return final;
2201 }
2202 
2203 /***/
2204 
2206  Scene *scene,
2207  Object *obedit,
2208  BMEditMesh *em,
2209  const CustomData_MeshMasks *dataMask,
2210  /* return args */
2211  Mesh **r_final)
2212 {
2213  CustomData_MeshMasks cddata_masks = *dataMask;
2214 
2215  /* if there's no derived mesh or the last data mask used doesn't include
2216  * the data we need, rebuild the derived mesh
2217  */
2218  object_get_datamask(depsgraph, obedit, &cddata_masks, nullptr);
2219 
2220  if (!em->mesh_eval_cage ||
2221  !CustomData_MeshMasks_are_matching(&(em->lastDataMask), &cddata_masks)) {
2222  editbmesh_build_data(depsgraph, scene, obedit, em, &cddata_masks);
2223  }
2224 
2225  *r_final = em->mesh_eval_final;
2226  if (em->mesh_eval_final) {
2228  }
2229  return em->mesh_eval_cage;
2230 }
2231 
2233  Scene *scene,
2234  Object *obedit,
2235  BMEditMesh *em,
2236  const CustomData_MeshMasks *dataMask)
2237 {
2238  CustomData_MeshMasks cddata_masks = *dataMask;
2239 
2240  /* if there's no derived mesh or the last data mask used doesn't include
2241  * the data we need, rebuild the derived mesh
2242  */
2243  object_get_datamask(depsgraph, obedit, &cddata_masks, nullptr);
2244 
2245  if (!em->mesh_eval_cage ||
2246  !CustomData_MeshMasks_are_matching(&(em->lastDataMask), &cddata_masks)) {
2247  editbmesh_build_data(depsgraph, scene, obedit, em, &cddata_masks);
2248  }
2249 
2250  return em->mesh_eval_cage;
2251 }
2252 
2254  Scene *scene,
2255  Object *obedit,
2256  const CustomData_MeshMasks *dataMask)
2257 {
2258  BLI_assert((obedit->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0);
2259  Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id);
2260  Object *obedit_eval = (Object *)DEG_get_evaluated_id(depsgraph, &obedit->id);
2261  BMEditMesh *em_eval = BKE_editmesh_from_object(obedit_eval);
2262  return editbmesh_get_eval_cage(depsgraph, scene_eval, obedit_eval, em_eval, dataMask);
2263 }
2264 
2265 /***/
2266 
2267 /* same as above but for vert coords */
2271 };
2272 
2273 static void make_vertexcos__mapFunc(void *userData,
2274  int index,
2275  const float co[3],
2276  const float UNUSED(no_f[3]),
2277  const short UNUSED(no_s[3]))
2278 {
2279  MappedUserData *mappedData = (MappedUserData *)userData;
2280 
2281  if (BLI_BITMAP_TEST(mappedData->vertex_visit, index) == 0) {
2282  /* we need coord from prototype vertex, not from copies,
2283  * assume they stored in the beginning of vertex array stored in DM
2284  * (mirror modifier for eg does this) */
2285  copy_v3_v3(mappedData->vertexcos[index], co);
2286  BLI_BITMAP_ENABLE(mappedData->vertex_visit, index);
2287  }
2288 }
2289 
2290 void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int totcos)
2291 {
2292  if (me_eval->runtime.deformed_only == false) {
2293  MappedUserData userData;
2294  memset(r_cos, 0, sizeof(*r_cos) * totcos);
2295  userData.vertexcos = r_cos;
2296  userData.vertex_visit = BLI_BITMAP_NEW(totcos, "vertexcos flags");
2298  MEM_freeN(userData.vertex_visit);
2299  }
2300  else {
2301  MVert *mv = me_eval->mvert;
2302  for (int i = 0; i < totcos; i++, mv++) {
2303  copy_v3_v3(r_cos[i], mv->co);
2304  }
2305  }
2306 }
2307 
2309  bool calc_active_tangent,
2310  const char (*tangent_names)[MAX_NAME],
2311  int tangent_names_len)
2312 {
2314  dm->getVertArray(dm),
2315  dm->getPolyArray(dm),
2316  dm->getNumPolys(dm),
2317  dm->getLoopArray(dm),
2318  dm->getLoopTriArray(dm),
2319  dm->getNumLoopTri(dm),
2320  &dm->loopData,
2321  calc_active_tangent,
2322  tangent_names,
2323  tangent_names_len,
2324  (const float(*)[3])CustomData_get_layer(&dm->polyData, CD_NORMAL),
2325  (const float(*)[3])dm->getLoopDataArray(dm, CD_NORMAL),
2326  (const float(*)[3])dm->getVertDataArray(dm, CD_ORCO), /* may be nullptr */
2327  /* result */
2328  &dm->loopData,
2329  dm->getNumLoops(dm),
2330  &dm->tangent_mask);
2331 }
2332 
2334 {
2335  const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
2336 
2339  const int numpoly = mesh->totpoly;
2340  // const int numloop = mesh->totloop;
2341  MVert *mv = mesh->mvert;
2342  MLoop *ml = mesh->mloop;
2343  MPoly *mp = mesh->mpoly;
2344  int i, j, k;
2345 
2347 
2348  for (i = 0; i < numpoly; i++, mp++) {
2349  OrigSpaceLoop *lof = lof_array + mp->loopstart;
2350 
2351  if (ELEM(mp->totloop, 3, 4)) {
2352  for (j = 0; j < mp->totloop; j++, lof++) {
2353  copy_v2_v2(lof->uv, default_osf[j]);
2354  }
2355  }
2356  else {
2357  MLoop *l = &ml[mp->loopstart];
2358  float p_nor[3], co[3];
2359  float mat[3][3];
2360 
2361  float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
2362  float translate[2], scale[2];
2363 
2364  BKE_mesh_calc_poly_normal(mp, l, mv, p_nor);
2365  axis_dominant_v3_to_m3(mat, p_nor);
2366 
2367  vcos_2d.resize(mp->totloop);
2368  for (j = 0; j < mp->totloop; j++, l++) {
2369  mul_v3_m3v3(co, mat, mv[l->v].co);
2370  copy_v2_v2(vcos_2d[j], co);
2371 
2372  for (k = 0; k < 2; k++) {
2373  if (co[k] > max[k]) {
2374  max[k] = co[k];
2375  }
2376  else if (co[k] < min[k]) {
2377  min[k] = co[k];
2378  }
2379  }
2380  }
2381 
2382  /* Brings min to (0, 0). */
2383  negate_v2_v2(translate, min);
2384 
2385  /* Scale will bring max to (1, 1). */
2386  sub_v2_v2v2(scale, max, min);
2387  if (scale[0] == 0.0f) {
2388  scale[0] = 1e-9f;
2389  }
2390  if (scale[1] == 0.0f) {
2391  scale[1] = 1e-9f;
2392  }
2393  invert_v2(scale);
2394 
2395  /* Finally, transform all vcos_2d into ((0, 0), (1, 1))
2396  * square and assign them as origspace. */
2397  for (j = 0; j < mp->totloop; j++, lof++) {
2398  add_v2_v2v2(lof->uv, vcos_2d[j], translate);
2399  mul_v2_v2(lof->uv, scale);
2400  }
2401  }
2402  }
2403 
2405 }
2406 
2407 /* derivedmesh info printing function,
2408  * to help track down differences DM output */
2409 
2410 #ifndef NDEBUG
2411 # include "BLI_dynstr.h"
2412 
2413 static void dm_debug_info_layers(DynStr *dynstr,
2414  DerivedMesh *dm,
2415  CustomData *cd,
2416  void *(*getElemDataArray)(DerivedMesh *, int))
2417 {
2418  int type;
2419 
2420  for (type = 0; type < CD_NUMTYPES; type++) {
2421  if (CustomData_has_layer(cd, type)) {
2422  /* note: doesn't account for multiple layers */
2423  const char *name = CustomData_layertype_name(type);
2424  const int size = CustomData_sizeof(type);
2425  const void *pt = getElemDataArray(dm, type);
2426  const int pt_size = pt ? (int)(MEM_allocN_len(pt) / size) : 0;
2427  const char *structname;
2428  int structnum;
2429  CustomData_file_write_info(type, &structname, &structnum);
2431  dynstr,
2432  " dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
2433  name,
2434  structname,
2435  type,
2436  (const void *)pt,
2437  size,
2438  pt_size);
2439  }
2440  }
2441 }
2442 
2444 {
2445  DynStr *dynstr = BLI_dynstr_new();
2446  char *ret;
2447  const char *tstr;
2448 
2449  BLI_dynstr_append(dynstr, "{\n");
2450  BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)dm);
2451  switch (dm->type) {
2452  case DM_TYPE_CDDM:
2453  tstr = "DM_TYPE_CDDM";
2454  break;
2455  case DM_TYPE_CCGDM:
2456  tstr = "DM_TYPE_CCGDM";
2457  break;
2458  default:
2459  tstr = "UNKNOWN";
2460  break;
2461  }
2462  BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr);
2463  BLI_dynstr_appendf(dynstr, " 'numVertData': %d,\n", dm->numVertData);
2464  BLI_dynstr_appendf(dynstr, " 'numEdgeData': %d,\n", dm->numEdgeData);
2465  BLI_dynstr_appendf(dynstr, " 'numTessFaceData': %d,\n", dm->numTessFaceData);
2466  BLI_dynstr_appendf(dynstr, " 'numPolyData': %d,\n", dm->numPolyData);
2467  BLI_dynstr_appendf(dynstr, " 'deformedOnly': %d,\n", dm->deformedOnly);
2468 
2469  BLI_dynstr_append(dynstr, " 'vertexLayers': (\n");
2470  dm_debug_info_layers(dynstr, dm, &dm->vertData, dm->getVertDataArray);
2471  BLI_dynstr_append(dynstr, " ),\n");
2472 
2473  BLI_dynstr_append(dynstr, " 'edgeLayers': (\n");
2474  dm_debug_info_layers(dynstr, dm, &dm->edgeData, dm->getEdgeDataArray);
2475  BLI_dynstr_append(dynstr, " ),\n");
2476 
2477  BLI_dynstr_append(dynstr, " 'loopLayers': (\n");
2478  dm_debug_info_layers(dynstr, dm, &dm->loopData, dm->getLoopDataArray);
2479  BLI_dynstr_append(dynstr, " ),\n");
2480 
2481  BLI_dynstr_append(dynstr, " 'polyLayers': (\n");
2482  dm_debug_info_layers(dynstr, dm, &dm->polyData, dm->getPolyDataArray);
2483  BLI_dynstr_append(dynstr, " ),\n");
2484 
2485  BLI_dynstr_append(dynstr, " 'tessFaceLayers': (\n");
2486  dm_debug_info_layers(dynstr, dm, &dm->faceData, dm->getTessFaceDataArray);
2487  BLI_dynstr_append(dynstr, " ),\n");
2488 
2489  BLI_dynstr_append(dynstr, "}\n");
2490 
2491  ret = BLI_dynstr_get_cstring(dynstr);
2492  BLI_dynstr_free(dynstr);
2493  return ret;
2494 }
2495 
2497 {
2498  char *str = DM_debug_info(dm);
2499  puts(str);
2500  fflush(stdout);
2501  MEM_freeN(str);
2502 }
2503 
2505 {
2506  const bool do_verbose = true;
2507  const bool do_fixes = false;
2508 
2509  bool is_valid = true;
2510  bool changed = true;
2511 
2513  dm->getVertDataLayout(dm),
2514  dm->getNumVerts(dm),
2515  dm->getEdgeDataLayout(dm),
2516  dm->getNumEdges(dm),
2517  dm->getLoopDataLayout(dm),
2518  dm->getNumLoops(dm),
2519  dm->getPolyDataLayout(dm),
2520  dm->getNumPolys(dm),
2521  false, /* setting mask here isn't useful, gives false positives */
2522  do_verbose,
2523  do_fixes,
2524  &changed);
2525 
2527  dm->getVertArray(dm),
2528  dm->getNumVerts(dm),
2529  dm->getEdgeArray(dm),
2530  dm->getNumEdges(dm),
2531  dm->getTessFaceArray(dm),
2532  dm->getNumTessFaces(dm),
2533  dm->getLoopArray(dm),
2534  dm->getNumLoops(dm),
2535  dm->getPolyArray(dm),
2536  dm->getNumPolys(dm),
2538  do_verbose,
2539  do_fixes,
2540  &changed);
2541 
2542  BLI_assert(changed == false);
2543 
2544  return is_valid;
2545 }
2546 
2547 #endif /* NDEBUG */
typedef float(TangentPoint)[2]
DerivedMeshType
@ DM_TYPE_CDDM
@ DM_TYPE_CCGDM
DMDirtyFlag
@ DM_DIRTY_NORMALS
void CustomData_free(struct CustomData *data, int totelem)
Definition: customdata.c:2239
const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX
Definition: customdata.c:1926
eCDAllocType
@ CD_ASSIGN
@ CD_CALLOC
@ CD_DUPLICATE
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_set_only_copy(const struct CustomData *data, CustomDataMask mask)
Definition: customdata.c:2871
bool CustomData_MeshMasks_are_matching(const CustomData_MeshMasks *mask_ref, const CustomData_MeshMasks *mask_required)
Definition: customdata.c:87
const CustomData_MeshMasks CD_MASK_BAREMESH
Definition: customdata.c:1919
void CustomData_interp(const struct CustomData *source, struct CustomData *dest, const int *src_indices, const float *weights, const float *sub_weights, int count, int dest_index)
const char * CustomData_layertype_name(int type)
Definition: customdata.c:4284
void * CustomData_get_layer(const struct CustomData *data, int type)
int CustomData_sizeof(int type)
Definition: customdata.c:4277
void CustomData_file_write_info(int type, const char **r_struct_name, int *r_struct_num)
Definition: customdata.c:4210
void CustomData_free_temporary(struct CustomData *data, int totelem)
Definition: customdata.c:2839
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_get(const struct CustomData *data, int index, int type)
void CustomData_copy_data(const struct CustomData *source, struct CustomData *dest, int source_index, int dest_index, int count)
support for deformation groups and hooks.
void BKE_editmesh_free_derivedmesh(BMEditMesh *em)
Definition: editmesh.c:151
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:85
struct KeyBlock * BKE_keyblock_from_key(struct Key *key, int index)
Definition: key.c:1926
struct Key * BKE_key_from_object(const struct Object *ob)
void BKE_keyblock_convert_from_mesh(struct Mesh *me, struct Key *key, struct KeyBlock *kb)
Definition: key.c:2208
void BKE_id_free(struct Main *bmain, void *idv)
General operations, lookup, etc. for materials.
float(* BKE_mesh_orco_verts_get(struct Object *ob))[3]
Definition: mesh.c:1162
void BKE_mesh_tessface_clear(struct Mesh *mesh)
Definition: mesh.c:1567
bool BKE_mesh_validate_all_customdata(struct CustomData *vdata, const uint totvert, struct CustomData *edata, const uint totedge, struct CustomData *ldata, const uint totloop, struct CustomData *pdata, const uint totpoly, const bool check_meshmask, const bool do_verbose, const bool do_fixes, bool *r_change)
void BKE_mesh_vert_coords_apply(struct Mesh *mesh, const float(*vert_coords)[3])
Definition: mesh.c:1755
void BKE_mesh_tessface_ensure(struct Mesh *mesh)
Definition: mesh.c:1560
struct Mesh * BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
Definition: mesh.c:995
struct Mesh * BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
Definition: mesh.c:877
struct Mesh * BKE_mesh_from_bmesh_for_eval_nomain(struct BMesh *bm, const struct CustomData_MeshMasks *cd_mask_extra, const struct Mesh *me_settings)
void BKE_mesh_calc_poly_normal(const struct MPoly *mpoly, const struct MLoop *loopstart, const struct MVert *mvarray, float r_no[3])
void BKE_mesh_calc_normals_split(struct Mesh *mesh)
Definition: mesh.c:1865
void BKE_mesh_orco_verts_transform(struct Mesh *me, float(*orco)[3], int totvert, int invert)
Definition: mesh.c:1179
void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd)
Definition: mesh.c:766
void BKE_mesh_copy_settings(struct Mesh *me_dst, const struct Mesh *me_src)
float(* BKE_mesh_vert_coords_alloc(const struct Mesh *mesh, int *r_vert_len))[3]
void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh)
bool BKE_mesh_validate_arrays(struct Mesh *me, struct MVert *mverts, unsigned int totvert, struct MEdge *medges, unsigned int totedge, struct MFace *mfaces, unsigned int totface, struct MLoop *mloops, unsigned int totloop, struct MPoly *mpolys, unsigned int totpoly, struct MDeformVert *dverts, const bool do_verbose, const bool do_fixes, bool *r_change)
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)
@ MESH_FOREACH_NOP
void BKE_mesh_foreach_mapped_vert(struct Mesh *mesh, void(*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), void *userData, MeshForeachFlag flag)
bool BKE_mesh_runtime_reset_edit_data(struct Mesh *mesh)
Definition: mesh_runtime.c:198
bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh)
Definition: mesh_runtime.c:188
void BKE_mesh_calc_loop_tangent_ex(const struct MVert *mvert, const struct MPoly *mpoly, const uint mpoly_len, const struct MLoop *mloop, const struct MLoopTri *looptri, const uint looptri_len, struct CustomData *loopdata, bool calc_active_tangent, const char(*tangent_names)[64], int tangent_names_len, const float(*poly_normals)[3], const float(*loop_normals)[3], const float(*vert_orco)[3], struct CustomData *loopdata_out, const uint loopdata_out_len, short *tangent_mask_curr_p)
void BKE_mesh_wrapper_ensure_mdata(struct Mesh *me)
Definition: mesh_wrapper.c:98
struct Mesh * BKE_mesh_wrapper_from_editmesh_with_coords(struct BMEditMesh *em, const struct CustomData_MeshMasks *cd_mask_extra, const float(*vert_coords)[3], const struct Mesh *me_settings)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void BKE_modifier_deform_vertsEM(ModifierData *md, const struct ModifierEvalContext *ctx, struct BMEditMesh *em, struct Mesh *me, float(*vertexCos)[3], int numVerts)
bool BKE_modifier_is_enabled(const struct Scene *scene, struct ModifierData *md, int required_mode)
struct Mesh * BKE_modifier_modify_mesh(ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *me)
@ eModifierTypeFlag_RequiresOriginalData
Definition: BKE_modifier.h:98
void BKE_modifier_deform_verts(ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *me, float(*vertexCos)[3], int numVerts)
struct ModifierData * BKE_modifier_get_last_preview(const struct Scene *scene, struct ModifierData *md, int required_mode)
struct ModifierData * BKE_modifiers_get_virtual_modifierlist(const struct Object *ob, struct VirtualModifierData *data)
struct ModifierData * BKE_modifiers_findby_type(const struct Object *ob, ModifierType type)
bool BKE_modifier_supports_mapping(struct ModifierData *md)
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:58
void BKE_modifier_free_temporary_data(struct ModifierData *md)
void BKE_modifier_set_error(const struct Object *ob, struct ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_modifiers_clear_errors(struct Object *ob)
struct CDMaskLink * BKE_modifier_calc_data_masks(const struct Scene *scene, struct Object *ob, struct ModifierData *md, struct CustomData_MeshMasks *final_datamask, int required_mode, ModifierData *previewmd, const struct CustomData_MeshMasks *previewmask)
ModifierApplyFlag
Definition: BKE_modifier.h:126
@ MOD_APPLY_USECACHE
Definition: BKE_modifier.h:131
@ MOD_APPLY_RENDER
Definition: BKE_modifier.h:128
@ MOD_APPLY_ORCO
Definition: BKE_modifier.h:133
int BKE_modifiers_get_cage_index(const struct Scene *scene, struct Object *ob, int *r_lastPossibleCageIndex, bool is_virtual)
General operations, lookup, etc. for blender objects.
struct Mesh * BKE_object_get_evaluated_mesh(struct Object *object)
Definition: object.c:4459
void BKE_object_free_derived_caches(struct Object *ob)
Definition: object.c:1719
void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval)
Definition: object.c:3873
void BKE_object_eval_assign_data(struct Object *object, struct ID *data, bool is_owned)
Definition: object.c:1687
Functions for dealing with objects and deform verts, used by painting and tools.
void BKE_sculpt_update_object_before_eval(struct Object *ob_eval)
Definition: paint.c:1757
bool BKE_paint_select_face_test(struct Object *ob)
Definition: paint.c:968
void BKE_sculpt_update_object_after_eval(struct Depsgraph *depsgraph, struct Object *ob_eval)
Definition: paint.c:1789
struct MultiresModifierData * BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob)
Definition: paint.c:1527
void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh)
Definition: shrinkwrap.c:341
A (mainly) macro array library.
#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_NEW(_tot, _alloc_string)
Definition: BLI_bitmap.h:50
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:32
A dynamically sized string ADT.
DynStr * BLI_dynstr_new(void) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition: BLI_dynstr.c:71
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
Definition: BLI_dynstr.c:358
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
char * BLI_dynstr_get_cstring(DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition: BLI_dynstr.c:323
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition: BLI_dynstr.c:107
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE int poly_to_tri_count(const int poly_count, const int corner_count)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
Definition: math_geom.c:3752
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:901
void copy_vn_i(int *array_tar, const int size, const int val)
Definition: math_vector.c:1374
MINLINE void mul_v2_v2(float r[2], const float a[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void negate_v2_v2(float r[2], const float a[2])
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
void range_vn_i(int *array_tar, const int size, const int start)
Definition: math_vector.c:1172
MINLINE void invert_v2(float r[2])
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
pthread_rwlock_t ThreadRWMutex
Definition: BLI_threads.h:126
#define THREAD_LOCK_READ
Definition: BLI_threads.h:121
#define THREAD_LOCK_WRITE
Definition: BLI_threads.h:122
void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode)
Definition: threads.cc:516
void BLI_mutex_lock(ThreadMutex *mutex)
Definition: threads.cc:401
void BLI_mutex_unlock(ThreadMutex *mutex)
Definition: threads.cc:406
void BLI_rw_mutex_unlock(ThreadRWMutex *mutex)
Definition: threads.cc:526
pthread_mutex_t ThreadMutex
Definition: BLI_threads.h:83
#define SWAP(type, a, b)
#define UNUSED_VARS_NDEBUG(...)
#define UNUSED(x)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
bool DEG_is_active(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:331
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:62
@ DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY
Definition: DEG_depsgraph.h:73
bool DEG_is_evaluating(const struct Depsgraph *depsgraph)
Definition: depsgraph.cc:325
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
struct Object * DEG_get_original_object(struct Object *object)
uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id)
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
struct ViewLayer * DEG_get_evaluated_view_layer(const struct Depsgraph *graph)
bool DEG_is_evaluated_id(const struct ID *id)
void DEG_get_customdata_mask_for_object(const struct Depsgraph *graph, struct Object *object, struct CustomData_MeshMasks *r_mask)
@ LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT
Definition: DNA_ID.h:567
@ LIB_TAG_COPIED_ON_WRITE
Definition: DNA_ID.h:565
#define CD_MASK_NORMAL
#define CD_MASK_ORIGINDEX
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_MLOOPCOL
#define CD_MASK_MVERT_SKIN
@ CD_MDEFORMVERT
@ CD_ORIGINDEX
@ CD_NUMTYPES
@ CD_ORIGSPACE_MLOOP
@ CD_CLOTH_ORCO
@ CD_MVERT
#define CD_MASK_MTFACE
#define CD_MASK_ORIGSPACE_MLOOP
#define CD_MASK_CLOTH_ORCO
#define CD_MASK_PREVIEW_MLOOPCOL
#define CD_MASK_MLOOPUV
#define CD_MASK_MFACE
@ CD_FLAG_TEMPORARY
#define MAX_NAME
Definition: DNA_defs.h:62
@ ME_WRAPPER_TYPE_MDATA
@ ME_WRAPPER_TYPE_BMESH
@ ME_AUTOSMOOTH
@ eModifierMode_Render
@ eModifierMode_Editmode
@ eModifierMode_Realtime
ModifierType
@ eModifierType_Cloth
@ eModifierType_DynamicPaint
@ eModifierType_Multires
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_SCULPT
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
#define OB_MODE_ALL_SCULPT
Object is a sort of wrapper for general info.
@ OB_MESH
@ SCULPT_ONLY_DEFORM
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
void makeDerivedMesh(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em, const CustomData_MeshMasks *dataMask)
static float(* get_editbmesh_orco_verts(BMEditMesh *em))[3]
Definition: DerivedMesh.cc:676
static CustomData * dm_getVertCData(DerivedMesh *dm)
Definition: DerivedMesh.cc:272
void DM_add_edge_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:573
void BKE_mesh_wrapper_deferred_finalize(Mesh *me_eval, const CustomData_MeshMasks *cd_mask_finalize)
Definition: DerivedMesh.cc:878
static ThreadRWMutex loops_cache_lock
Definition: DerivedMesh.cc:93
static void mesh_calc_modifiers(struct Depsgraph *depsgraph, Scene *scene, Object *ob, int useDeform, const bool need_mapping, const CustomData_MeshMasks *dataMask, const int index, const bool use_cache, const bool allow_shared_mesh, Mesh **r_deform, Mesh **r_final, GeometrySet **r_geometry_set)
Definition: DerivedMesh.cc:972
void mesh_get_mapped_verts_coords(Mesh *me_eval, float(*r_cos)[3], const int totcos)
void DM_ensure_normals(DerivedMesh *dm)
Definition: DerivedMesh.cc:479
bool editbmesh_modifier_is_enabled(Scene *scene, const Object *ob, ModifierData *md, bool has_prev_mesh)
void DM_from_template_ex(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys, const CustomData_MeshMasks *mask)
Definition: DerivedMesh.cc:374
static MFace * dm_getTessFaceArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:129
void * DM_get_poly_data(DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:611
static float(* get_orco_coords(Object *ob, BMEditMesh *em, int layer, int *free))[3]
Definition: DerivedMesh.cc:696
static void mesh_build_extra_data(struct Depsgraph *depsgraph, Object *ob, Mesh *mesh_eval)
bool DM_is_valid(DerivedMesh *dm)
static MEdge * dm_getEdgeArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:115
void DM_add_poly_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:588
static void mesh_build_data(struct Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask, const bool need_mapping)
static void mesh_calc_modifier_final_normals(const Mesh *mesh_input, const CustomData_MeshMasks *final_datamask, const bool sculpt_dyntopo, Mesh *mesh_final)
Definition: DerivedMesh.cc:798
void DM_calc_loop_tangents(DerivedMesh *dm, bool calc_active_tangent, const char(*tangent_names)[MAX_NAME], int tangent_names_len)
static CustomData * dm_getTessFaceCData(DerivedMesh *dm)
Definition: DerivedMesh.cc:282
static void mesh_calc_finalize(const Mesh *mesh_input, Mesh *mesh_eval)
Definition: DerivedMesh.cc:869
void * DM_get_loop_data_layer(DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:649
static CustomData * dm_getPolyCData(DerivedMesh *dm)
Definition: DerivedMesh.cc:292
void DM_debug_print(DerivedMesh *dm)
void * DM_get_poly_data_layer(DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:644
static MEdge * dm_dupEdgeArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:193
void * DM_get_vert_data(DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:593
static CustomData * dm_getLoopCData(DerivedMesh *dm)
Definition: DerivedMesh.cc:287
Mesh * mesh_get_eval_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static MVert * dm_dupVertArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:181
void BKE_mesh_runtime_eval_to_meshkey(Mesh *me_deformed, Mesh *me, KeyBlock *kb)
Definition: DerivedMesh.cc:524
char * DM_debug_info(DerivedMesh *dm)
static void mesh_init_origspace(Mesh *mesh)
float(* editbmesh_vert_coords_alloc(BMEditMesh *em, int *r_vert_len))[3]
Mesh * mesh_create_eval_no_deform_render(Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys)
Definition: DerivedMesh.cc:342
static MLoop * dm_dupLoopArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:217
Mesh * mesh_get_eval_final(struct Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static int dm_getNumLoopTri(DerivedMesh *dm)
Definition: DerivedMesh.cc:241
void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest, int *src_indices, float *weights, int count, int dest_index)
Definition: DerivedMesh.cc:665
Mesh * mesh_create_eval_no_deform(Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
bool DM_release(DerivedMesh *dm)
Definition: DerivedMesh.cc:424
static void editbmesh_calc_modifiers(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em_input, const CustomData_MeshMasks *dataMask, Mesh **r_cage, Mesh **r_final, GeometrySet **r_geometry_set)
void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys)
Definition: DerivedMesh.cc:404
void DM_ensure_looptri_data(DerivedMesh *dm)
Definition: DerivedMesh.cc:493
static MPoly * dm_getPolyArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:167
static void make_vertexcos__mapFunc(void *userData, int index, const float co[3], const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
static void editbmesh_build_data(struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, CustomData_MeshMasks *dataMask)
void * DM_get_edge_data_layer(DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:626
static MPoly * dm_dupPolyArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:229
static void object_get_datamask(const Depsgraph *depsgraph, Object *ob, CustomData_MeshMasks *r_mask, bool *r_need_mapping)
static MVert * dm_getVertArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:101
void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
Definition: DerivedMesh.cc:449
static CustomData * dm_getEdgeCData(DerivedMesh *dm)
Definition: DerivedMesh.cc:277
static void mesh_runtime_check_normals_valid(const Mesh *mesh)
Mesh * editbmesh_get_eval_cage_and_final(Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, const CustomData_MeshMasks *dataMask, Mesh **r_final)
void DM_add_vert_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:568
void DM_copy_vert_data(DerivedMesh *source, DerivedMesh *dest, int source_index, int dest_index, int count)
Definition: DerivedMesh.cc:654
static void dm_debug_info_layers(DynStr *dynstr, DerivedMesh *dm, CustomData *cd, void *(*getElemDataArray)(DerivedMesh *, int))
void DM_init_funcs(DerivedMesh *dm)
Definition: DerivedMesh.cc:301
void DM_add_tessface_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:578
static MFace * dm_dupFaceArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:205
static void mesh_set_only_copy(Mesh *mesh, const CustomData_MeshMasks *mask)
Definition: DerivedMesh.cc:554
Mesh * editbmesh_get_eval_cage_from_orig(struct Depsgraph *depsgraph, Scene *scene, Object *obedit, const CustomData_MeshMasks *dataMask)
static void add_orco_mesh(Object *ob, BMEditMesh *em, Mesh *mesh, Mesh *mesh_orco, int layer)
Definition: DerivedMesh.cc:756
Mesh * mesh_create_eval_final_index_render(Depsgraph *depsgraph, Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask, int index)
void * DM_get_tessface_data_layer(DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:635
void * DM_get_tessface_data(DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:605
static Mesh * prepare_geometry_set_for_mesh_modifier(Mesh *mesh, GeometrySet &r_geometry_set)
Definition: DerivedMesh.cc:893
static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final, const CustomData_MeshMasks *final_datamask)
Mesh * editbmesh_get_eval_cage(struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em, const CustomData_MeshMasks *dataMask)
static const MLoopTri * dm_getLoopTriArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:248
void DM_add_loop_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
Definition: DerivedMesh.cc:583
#define ASSERT_IS_VALID_MESH(mesh)
Definition: DerivedMesh.cc:90
static Mesh * modifier_modify_mesh_and_geometry_set(ModifierData *md, const ModifierEvalContext &mectx, Mesh *input_mesh, GeometrySet &geometry_set)
Definition: DerivedMesh.cc:923
void * DM_get_vert_data_layer(DerivedMesh *dm, int type)
Definition: DerivedMesh.cc:617
static MLoop * dm_getLoopArray(DerivedMesh *dm)
Definition: DerivedMesh.cc:153
static Mesh * create_orco_mesh(Object *ob, Mesh *me, BMEditMesh *em, int layer)
Definition: DerivedMesh.cc:731
void * DM_get_edge_data(DerivedMesh *dm, int index, int type)
Definition: DerivedMesh.cc:599
void DM_set_only_copy(DerivedMesh *dm, const CustomData_MeshMasks *mask)
Definition: DerivedMesh.cc:540
_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
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
static bool dependsOnTime(GpencilModifierData *UNUSED(md))
#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar)
@ BM_VERTS_OF_MESH
ATTR_WARN_UNUSED_RESULT const BMLoop * l
virtual int getNumEdges() const
Definition: btBox2dShape.h:174
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void replace_mesh_but_keep_vertex_group_names(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void copy_vertex_group_names_from_object(const struct Object &object)
void resize(const int64_t new_size)
Definition: BLI_vector.hh:368
Scene scene
bool is_valid
const Depsgraph * depsgraph
#define str(s)
int count
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
size_t(* MEM_allocN_len)(const void *vmemh)
Definition: mallocn.c:40
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:319
GeometrySet geometry_set_realize_mesh_for_modifier(const GeometrySet &geometry_set)
return ret
#define min(a, b)
Definition: sort.c:51
unsigned int uint32_t
Definition: stdint.h:83
struct Mesh * mesh_eval_final
Definition: BKE_editmesh.h:63
CustomData_MeshMasks lastDataMask
Definition: BKE_editmesh.h:69
struct Mesh * mesh_eval_cage
Definition: BKE_editmesh.h:63
struct BMesh * bm
Definition: BKE_editmesh.h:52
struct BMVert * v
Definition: bmesh_class.h:165
float co[3]
Definition: bmesh_class.h:99
struct Object * object
struct ClothSimSettings * sim_parms
struct DerivedMesh::@15 looptris
struct MLoop *(* getLoopArray)(DerivedMesh *dm)
CustomData faceData
void *(* getVertDataArray)(DerivedMesh *dm, int type)
CustomData vertData
struct MPoly *(* dupPolyArray)(DerivedMesh *dm)
struct MVert *(* getVertArray)(DerivedMesh *dm)
struct MFace *(* dupTessFaceArray)(DerivedMesh *dm)
CustomData *(* getEdgeDataLayout)(DerivedMesh *dm)
void(* copyLoopArray)(DerivedMesh *dm, struct MLoop *r_loop)
void(* copyEdgeArray)(DerivedMesh *dm, struct MEdge *r_edge)
int(* getNumVerts)(DerivedMesh *dm)
const struct MLoopTri *(* getLoopTriArray)(DerivedMesh *dm)
int(* getNumLoopTri)(DerivedMesh *dm)
void(* copyPolyArray)(DerivedMesh *dm, struct MPoly *r_poly)
int(* getNumPolys)(DerivedMesh *dm)
CustomData *(* getTessFaceDataLayout)(DerivedMesh *dm)
void *(* getPolyData)(DerivedMesh *dm, int index, int type)
struct MEdge *(* dupEdgeArray)(DerivedMesh *dm)
int(* getNumEdges)(DerivedMesh *dm)
struct MFace *(* getTessFaceArray)(DerivedMesh *dm)
void *(* getLoopDataArray)(DerivedMesh *dm, int type)
void *(* getEdgeData)(DerivedMesh *dm, int index, int type)
void *(* getTessFaceDataArray)(DerivedMesh *dm, int type)
CustomData *(* getPolyDataLayout)(DerivedMesh *dm)
CustomData polyData
struct MLoop *(* dupLoopArray)(DerivedMesh *dm)
struct MVert *(* dupVertArray)(DerivedMesh *dm)
int(* getNumTessFaces)(DerivedMesh *dm)
struct MLoopTri * array_wip
void(* copyVertArray)(DerivedMesh *dm, struct MVert *r_vert)
void *(* getTessFaceData)(DerivedMesh *dm, int index, int type)
void *(* getVertData)(DerivedMesh *dm, int index, int type)
void *(* getPolyDataArray)(DerivedMesh *dm, int type)
void(* calcNormals)(DerivedMesh *dm)
void *(* getEdgeDataArray)(DerivedMesh *dm, int type)
struct MEdge *(* getEdgeArray)(DerivedMesh *dm)
CustomData edgeData
void(* copyTessFaceArray)(DerivedMesh *dm, struct MFace *r_face)
CustomData *(* getVertDataLayout)(DerivedMesh *dm)
struct MPoly *(* getPolyArray)(DerivedMesh *dm)
CustomData loopData
void(* recalcLoopTri)(DerivedMesh *dm)
struct MLoopTri * array
DMDirtyFlag dirty
int(* getNumLoops)(DerivedMesh *dm)
CustomData *(* getLoopDataLayout)(DerivedMesh *dm)
DerivedMeshType type
const float(* vertexCos)[3]
GeometryComponent & get_component_for_write(GeometryComponentType component_type)
bool has(const GeometryComponentType component_type) const
bool has_instances() const
bool has_pointcloud() const
int tag
Definition: DNA_ID.h:292
char name[66]
Definition: DNA_ID.h:283
void * data
Definition: DNA_key_types.h:66
ID id
Definition: DNA_key_types.h:79
BLI_bitmap * vertex_visit
float(* vertexcos)[3]
int64_t cd_dirty_poly
struct Mesh * mesh_eval
struct EditMeshData * edit_data
char wrapper_type_finalize
int64_t cd_dirty_loop
int64_t cd_dirty_vert
void * eval_mutex
struct BMEditMesh * edit_mesh
float smoothresh
struct CustomData pdata ldata
struct MVert * mvert
int totvert
short flag
struct MLoop * mloop
Mesh_Runtime runtime
struct CustomData vdata edata fdata
int totpoly
int totloop
struct Key * key
struct MPoly * mpoly
struct ModifierData * next
void(* modifyGeometrySet)(struct ModifierData *md, const struct ModifierEvalContext *ctx, struct GeometrySet *geometry_set)
Definition: BKE_modifier.h:257
ModifierTypeFlag flags
Definition: BKE_modifier.h:174
void(* deformVertsEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx, struct BMEditMesh *editData, struct Mesh *mesh, float(*vertexCos)[3], int numVerts)
Definition: BKE_modifier.h:215
ModifierTypeType type
Definition: BKE_modifier.h:173
void(* requiredDataMask)(struct Object *ob, struct ModifierData *md, struct CustomData_MeshMasks *r_cddata_masks)
Definition: BKE_modifier.h:289
bool(* dependsOnNormals)(struct ModifierData *md)
Definition: BKE_modifier.h:337
bool(* dependsOnTime)(struct ModifierData *md)
Definition: BKE_modifier.h:327
CustomData_MeshMasks last_data_mask
struct Mesh * mesh_deform_eval
struct GeometrySet * geometry_set_eval
ListBase modifiers
Object_Runtime runtime
struct SculptSession * sculpt
void * data
struct ToolSettings * toolsettings
struct BMesh * bm
Definition: BKE_paint.h:493
struct Base * basact
float max
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)