Blender V5.3
mesh_data_update.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_cloth_types.h"
11#include "DNA_key_types.h"
12#include "DNA_mesh_types.h"
13#include "DNA_meshdata_types.h"
14#include "DNA_object_types.h"
15#include "DNA_scene_types.h"
16
17#include "BLI_array_utils.hh"
18#include "BLI_linklist.hh"
19#include "BLI_math_geom_c.hh"
20#include "BLI_math_matrix_c.hh"
22#include "BLI_span.hh"
23#include "BLI_task.hh"
24#include "BLI_utildefines.hh"
25#include "BLI_vector.hh"
26
27#include "BKE_editmesh.hh"
28#include "BKE_editmesh_cache.hh"
29#include "BKE_geometry_set.hh"
30#include "BKE_key.hh"
31#include "BKE_layer.hh"
32#include "BKE_lib_id.hh"
33#include "BKE_material.hh"
34#include "BKE_mesh.hh"
35#include "BKE_mesh_iterators.hh"
36#include "BKE_mesh_runtime.hh"
37#include "BKE_mesh_wrapper.hh"
38#include "BKE_modifier.hh"
39#include "BKE_multires.hh"
40#include "BKE_object.hh"
41#include "BKE_object_types.hh"
42#include "BKE_paint.hh"
43
44#include "BKE_shrinkwrap.hh"
45#include "DEG_depsgraph.hh"
47
48namespace blender::bke {
49
57// #define USE_MODIFIER_VALIDATE
58
59#ifdef USE_MODIFIER_VALIDATE
60# define ASSERT_IS_VALID_MESH_INPUT(mesh) (BLI_assert(mesh_is_valid(*mesh)))
61# define ASSERT_IS_VALID_MESH_OUTPUT(mesh) \
62 (BLI_assert((mesh == nullptr) || (mesh_is_valid(*mesh))))
63#else
64# define ASSERT_IS_VALID_MESH_INPUT(mesh) \
65 { \
66 (void)mesh; \
67 };
68# define ASSERT_IS_VALID_MESH_OUTPUT(mesh) \
69 { \
70 (void)mesh; \
71 };
72
73#endif
74
75static void mesh_init_origspace(Mesh &mesh);
76
78{
79 CustomData_set_only_copy(&mesh->vert_data, mask->vmask);
80 CustomData_set_only_copy(&mesh->edge_data, mask->emask);
81 CustomData_set_only_copy(&mesh->fdata_legacy, mask->fmask);
82 /* this wasn't in 2.63 and is disabled for 2.64 because it gives problems with
83 * weight paint mode when there are modifiers applied, needs further investigation,
84 * see replies to r50969, Campbell */
85#if 0
86 CustomData_set_only_copy(&mesh->ldata, mask->lmask);
87 CustomData_set_only_copy(&mesh->pdata, mask->pmask);
88#endif
89}
90
91/* orco custom data layer */
93 BMesh *bm,
94 eCustomDataType layer_type,
96{
97 if (layer_type == CD_ORCO) {
98
99 if (bm) {
101 return storage;
102 }
104 return storage;
105 }
106 if (layer_type == CD_CLOTH_ORCO) {
107 /* apply shape key for cloth, this should really be solved
108 * by a more flexible customdata system, but not simple */
109 if (!bm) {
110 const ClothModifierData *clmd = reinterpret_cast<const ClothModifierData *>(
112 if (clmd && clmd->sim_parms->shapekey_rest) {
114 BKE_key_from_object(const_cast<Object *>(&ob)), clmd->sim_parms->shapekey_rest);
115
116 if (kb && kb->data) {
117 return {static_cast<const float3 *>(kb->data), kb->totelem};
118 }
119 }
120 }
121
122 return {};
123 }
124
125 return {};
126}
127
129{
130 Mesh *orco_mesh;
131 if (bm) {
132 orco_mesh = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, &mesh);
134 }
135 else {
136 orco_mesh = BKE_mesh_copy_for_eval(mesh);
137 }
138
140 const Span<float3> orco = get_orco_coords(ob, bm, layer, storage);
141
142 if (!orco.is_empty()) {
143 orco_mesh->vert_positions_for_write().copy_from(orco);
144 orco_mesh->tag_positions_changed();
145 }
146
147 return orco_mesh;
148}
149
151{
152 void *data = CustomData_get_layer_for_write(&mesh.vert_data, layer, mesh.verts_num);
153 if (!data) {
154 data = CustomData_add_layer(&mesh.vert_data, layer, CD_CONSTRUCT, mesh.verts_num);
155 }
156 return MutableSpan(reinterpret_cast<float3 *>(data), mesh.verts_num);
157}
158
159static void add_orco_mesh(
160 Object &ob, BMesh *bm, Mesh &mesh, const Mesh *mesh_orco, const eCustomDataType layer)
161{
162 const int totvert = mesh.verts_num;
163
164 MutableSpan<float3> layer_orco;
165 if (mesh_orco) {
166 layer_orco = orco_coord_layer_ensure(mesh, layer);
167
168 if (mesh_orco->verts_num == totvert) {
169 layer_orco.copy_from(mesh_orco->vert_positions());
170 }
171 else {
172 layer_orco.copy_from(mesh.vert_positions());
173 }
174 }
175 else {
176 /* TODO(@sybren): `totvert` should potentially change here, as `ob->data`
177 * or `em` may have a different number of vertices than the evaluated `mesh`. */
179 const Span<float3> orco = get_orco_coords(ob, bm, layer, storage);
180 if (!orco.is_empty()) {
181 layer_orco = orco_coord_layer_ensure(mesh, layer);
182 layer_orco.copy_from(orco);
183 }
184 }
185
186 if (!layer_orco.is_empty()) {
187 if (layer == CD_ORCO) {
188 BKE_mesh_orco_verts_transform(id_cast<Mesh *>(ob.data), layer_orco, false);
189 }
190 }
191}
192
202 const ModifierEvalContext &mectx,
203 const Mesh &input_mesh,
204 GeometrySet &geometry_set)
205{
207 if (mti->modify_geometry_set) {
208 if (const Mesh *mesh = geometry_set.get_mesh()) {
209 if (mesh->runtime->wrapper_type != ME_WRAPPER_TYPE_MDATA) {
210 Mesh *mesh_mut = geometry_set.get_mesh_for_write();
211 /* For performance reasons, this should be called by the modifier and/or
212 * nodes themselves at some point. */
214 }
215 ASSERT_IS_VALID_MESH_INPUT(geometry_set.get_mesh());
216 }
217 mti->modify_geometry_set(md, &mectx, &geometry_set);
218 if (const Mesh *mesh = geometry_set.get_mesh()) {
220 }
221 }
222 else {
223 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
227 geometry_set.replace_mesh(result);
228 }
229 }
230
231 if (!geometry_set.has_mesh()) {
232 Mesh *mesh = BKE_mesh_new_nomain(0, 0, 0, 0);
234 geometry_set.replace_mesh(mesh);
235 }
236}
237
239{
240 MutableAttributeAccessor attributes = mesh.attributes_for_write();
241 const AttributeReader positions = attributes.lookup<float3>("position");
242 attributes.remove("rest_position");
243 if (positions) {
244 if (positions.sharing_info && positions.varray.is_span()) {
245 attributes.add<float3>("rest_position",
247 AttributeInitShared(positions.varray.get_internal_span().data(),
248 *positions.sharing_info));
249 }
250 else {
251 attributes.add<float3>(
252 "rest_position", AttrDomain::Point, AttributeInitVArray(positions.varray));
253 }
254 }
255}
256
258{
259 auto &edit_data = geometry.get_component_for_write<GeometryComponentEditData>();
260 if (!edit_data.mesh_edit_hints_) {
261 edit_data.mesh_edit_hints_ = std::make_unique<MeshEditHints>();
262 }
263 return *edit_data.mesh_edit_hints_;
264}
265
267{
269 if (const Mesh *mesh = geometry.get_mesh(); mesh && mesh->key != key) {
270 geometry.get_mesh_for_write()->key = key;
271 }
272}
273
274static GeometrySet mesh_calc_modifiers(Depsgraph &depsgraph,
275 const Scene &scene,
276 Object &ob,
277 const bool use_deform,
278 const bool need_mapping,
279 const CustomData_MeshMasks &dataMask,
280 const bool use_cache)
281{
282 /* Add the deform mesh to the geometry set after evaluating all modifiers in case
283 * it's removed. */
284 GeometryComponentPtr mesh_deform;
285 const Mesh &mesh_input = *id_cast<const Mesh *>(ob.data);
286
287 GeometrySet geometry_set = GeometrySet::from_mesh(const_cast<Mesh *>(&mesh_input),
289
290 /* Mesh with constructive modifiers but no deformation applied. Tracked
291 * along with final mesh if undeformed / orco coordinates are requested
292 * for texturing. */
293 Mesh *mesh_orco = nullptr;
294 Mesh *mesh_orco_cloth = nullptr;
295
296 /* Modifier evaluation modes. */
297 const bool use_render = (DEG_get_mode(&depsgraph) == DAG_EVAL_RENDER);
298 const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
299
300 /* Sculpt can skip certain modifiers. */
301 const bool has_multires = BKE_sculpt_multires_active(&scene, &ob) != nullptr;
302 bool multires_applied = false;
303 const bool sculpt_mode = ob.mode & OB_MODE_SCULPT && ob.runtime->sculpt_session && !use_render;
304 const bool sculpt_dyntopo = (sculpt_mode && ob.runtime->sculpt_session->bm) && !use_render;
305
306 /* Modifier evaluation contexts for different types of modifiers. */
307 ModifierApplyFlag apply_render = use_render ? MOD_APPLY_RENDER : ModifierApplyFlag(0);
308 ModifierApplyFlag apply_cache = use_cache ? MOD_APPLY_USECACHE : ModifierApplyFlag(0);
309 const ModifierEvalContext mectx = {&depsgraph, &ob, apply_render | apply_cache};
310 const ModifierEvalContext mectx_orco = {&depsgraph, &ob, apply_render | MOD_APPLY_ORCO};
311
312 /* Get effective list of modifiers to execute. Some effects like shape keys
313 * are added as virtual modifiers before the user created modifiers. */
314 VirtualModifierData virtual_modifier_data;
315 ModifierData *firstmd = BKE_modifiers_get_virtual_modifierlist(&ob, &virtual_modifier_data);
316 ModifierData *md = firstmd;
317
318 /* Compute accumulated datamasks needed by each modifier. It helps to do
319 * this fine grained so that for example vertex groups are preserved up to
320 * an armature modifier, but not through a following subsurf modifier where
321 * subdividing them is expensive. */
322 CustomData_MeshMasks final_datamask = dataMask;
323 CDMaskLink *datamasks = BKE_modifier_calc_data_masks(&scene, md, &final_datamask, required_mode);
324 CDMaskLink *md_datamask = datamasks;
325 /* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
327
328 /* Clear errors before evaluation. */
330
332 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
334 }
335 }
336
337 /* Apply all leading deform modifiers. */
338 if (use_deform) {
339 for (; md; md = md->next, md_datamask = md_datamask->next) {
341
342 if (!BKE_modifier_is_enabled(&scene, md, required_mode)) {
343 continue;
344 }
345
346 if (mti->type == ModifierTypeType::OnlyDeform && !sculpt_dyntopo) {
347 ScopedModifierTimer modifier_timer{*md};
348 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
349 if (mti->required_data_mask) {
351 mti->required_data_mask(md, &mask);
352 if (mask.vmask & CD_MASK_ORCO) {
353 add_orco_mesh(ob, nullptr, *mesh, nullptr, CD_ORCO);
354 }
355 }
356
357 BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
358 }
359 }
360 else {
361 break;
362 }
363 }
364
365 /* Result of all leading deforming modifiers is cached for
366 * places that wish to use the original mesh but with deformed
367 * coordinates (like vertex paint). */
368 mesh_deform = geometry_set.get_component_ptr(GeometryComponent::Type::Mesh);
369 }
370
371 /* Apply all remaining constructive and deforming modifiers. */
372 bool have_non_onlydeform_modifiers_applied = false;
373 for (; md; md = md->next, md_datamask = md_datamask->next) {
375
376 if (!BKE_modifier_is_enabled(&scene, md, required_mode)) {
377 continue;
378 }
379
380 if (mti->type == ModifierTypeType::OnlyDeform && !use_deform) {
381 continue;
382 }
383
385 have_non_onlydeform_modifiers_applied)
386 {
387 BKE_modifier_set_error(&ob, md, "Modifier requires original data, bad stack position");
388 continue;
389 }
390
391 if (sculpt_mode && (!has_multires || multires_applied || sculpt_dyntopo)) {
392 bool unsupported = false;
393
394 if (md->type == eModifierType_Multires &&
395 (reinterpret_cast<MultiresModifierData *>(md))->sculptlvl == 0)
396 {
397 /* If multires is on level 0 skip it silently without warning message. */
398 if (!sculpt_dyntopo) {
399 continue;
400 }
401 }
402
403 if (sculpt_dyntopo) {
404 unsupported = true;
405 }
406
407 /* While rare, it's possible for a sculpt object to be loaded into a scene
408 * that doesn't have sculpt tool-settings initialized, see #159457. */
409 if (Sculpt *sculpt = scene.toolsettings->sculpt) {
410 if (sculpt->flags & SCULPT_ONLY_DEFORM) {
411 unsupported |= (mti->type != ModifierTypeType::OnlyDeform);
412 }
413 }
414
415 unsupported |= multires_applied;
416
417 if (unsupported) {
418 if (sculpt_dyntopo) {
419 BKE_modifier_set_error(&ob, md, "Not supported in dyntopo");
420 }
421 else {
422 BKE_modifier_set_error(&ob, md, "Not supported in sculpt mode");
423 }
424 continue;
425 }
426 }
427
428 if (need_mapping && !BKE_modifier_supports_mapping(md)) {
429 continue;
430 }
431
432 ScopedModifierTimer modifier_timer{*md};
433
434 /* Add orco mesh as layer if needed by this modifier. */
435 if (mesh_orco && mti->required_data_mask) {
436 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
438 mti->required_data_mask(md, &mask);
439 if (mask.vmask & CD_MASK_ORCO) {
440 add_orco_mesh(ob, nullptr, *mesh, mesh_orco, CD_ORCO);
441 }
442 }
443 }
444
446 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
448 BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
450 }
451 }
452 else {
453 bool check_for_needs_mapping = false;
454 if (have_non_onlydeform_modifiers_applied == false) {
455 check_for_needs_mapping = true;
456 }
457 have_non_onlydeform_modifiers_applied = true;
458
459 /* determine which data layers are needed by following modifiers */
460 CustomData_MeshMasks nextmask = md_datamask->next ? md_datamask->next->mask : final_datamask;
461
462 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
463 if (check_for_needs_mapping) {
464 /* Initialize original indices the first time we evaluate a
465 * constructive modifier. Modifiers will then do mapping mostly
466 * automatic by copying them through CustomData_copy_data along
467 * with other data.
468 *
469 * These are created when either requested by evaluation, or if
470 * following modifiers requested them. */
471 if (need_mapping ||
472 ((nextmask.vmask | nextmask.emask | nextmask.pmask) & CD_MASK_ORIGINDEX))
473 {
474 /* Not worth parallelizing this,
475 * gives less than 0.1% overall speedup in best of best cases... */
477 {static_cast<int *>(CustomData_add_layer(
478 &mesh->vert_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->verts_num)),
479 mesh->verts_num});
481 {static_cast<int *>(CustomData_add_layer(
482 &mesh->edge_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->edges_num)),
483 mesh->edges_num});
485 {static_cast<int *>(CustomData_add_layer(
486 &mesh->face_data, CD_ORIGINDEX, CD_CONSTRUCT, mesh->faces_num)),
487 mesh->faces_num});
488 }
489 }
490
491 /* set the Mesh to only copy needed data */
492 CustomData_MeshMasks mask = md_datamask->mask;
493 /* needMapping check here fixes bug #28112, otherwise it's
494 * possible that it won't be copied */
495 CustomData_MeshMasks_update(&mask, &append_mask);
496 if (need_mapping) {
497 mask.vmask |= CD_MASK_ORIGINDEX;
498 mask.emask |= CD_MASK_ORIGINDEX;
499 mask.pmask |= CD_MASK_ORIGINDEX;
500 }
502
503 /* add cloth rest shape key if needed */
504 if (mask.vmask & CD_MASK_CLOTH_ORCO) {
505 add_orco_mesh(ob, nullptr, *mesh, mesh_orco, CD_CLOTH_ORCO);
506 }
507
508 /* add an origspace layer if needed */
509 if ((md_datamask->mask.lmask) & CD_MASK_ORIGSPACE_MLOOP) {
510 if (!CustomData_has_layer(&mesh->corner_data, CD_ORIGSPACE_MLOOP)) {
512 &mesh->corner_data, CD_ORIGSPACE_MLOOP, CD_SET_DEFAULT, mesh->corners_num);
514 }
515 }
516 }
517
518 modifier_modify_mesh_and_geometry_set(md, mectx, mesh_input, geometry_set);
519
520 /* create an orco mesh in parallel */
521 if (nextmask.vmask & CD_MASK_ORCO) {
522 if (!mesh_orco) {
523 mesh_orco = create_orco_mesh(ob, mesh_input, nullptr, CD_ORCO);
524 }
525
526 nextmask.vmask &= ~CD_MASK_ORCO;
527 CustomData_MeshMasks temp_cddata_masks = {0};
528 temp_cddata_masks.vmask = CD_MASK_ORIGINDEX;
529 temp_cddata_masks.emask = CD_MASK_ORIGINDEX;
530 temp_cddata_masks.fmask = CD_MASK_ORIGINDEX;
531 temp_cddata_masks.pmask = CD_MASK_ORIGINDEX;
532
533 if (mti->required_data_mask != nullptr) {
534 mti->required_data_mask(md, &temp_cddata_masks);
535 }
536 CustomData_MeshMasks_update(&temp_cddata_masks, &nextmask);
537 mesh_set_only_copy(mesh_orco, &temp_cddata_masks);
538
540 Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco);
542
543 if (mesh_next) {
544 /* if the modifier returned a new mesh, release the old one */
545 if (mesh_orco != mesh_next) {
546 BLI_assert(mesh_orco != &mesh_input);
547 BKE_id_free(nullptr, mesh_orco);
548 }
549
550 mesh_orco = mesh_next;
551 }
552 }
553
554 /* create cloth orco mesh in parallel */
555 if (nextmask.vmask & CD_MASK_CLOTH_ORCO) {
556 if (!mesh_orco_cloth) {
557 mesh_orco_cloth = create_orco_mesh(ob, mesh_input, nullptr, CD_CLOTH_ORCO);
558 }
559
560 nextmask.vmask &= ~CD_MASK_CLOTH_ORCO;
561 nextmask.vmask |= CD_MASK_ORIGINDEX;
562 nextmask.emask |= CD_MASK_ORIGINDEX;
563 nextmask.pmask |= CD_MASK_ORIGINDEX;
564 mesh_set_only_copy(mesh_orco_cloth, &nextmask);
565
566 ASSERT_IS_VALID_MESH_INPUT(mesh_orco_cloth);
567 Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco_cloth);
569
570 if (mesh_next) {
571 /* if the modifier returned a new mesh, release the old one */
572 if (mesh_orco_cloth != mesh_next) {
573 BLI_assert(mesh_orco != &mesh_input);
574 BKE_id_free(nullptr, mesh_orco_cloth);
575 }
576
577 mesh_orco_cloth = mesh_next;
578 }
579 }
580
581 if (const Mesh *mesh = geometry_set.get_mesh()) {
582 if (mesh->runtime->deformed_only) {
583 Mesh *mesh_mut = geometry_set.get_mesh_for_write();
584 mesh_mut->runtime->deformed_only = false;
585 }
586 }
587 }
588
589 if (sculpt_mode && md->type == eModifierType_Multires) {
590 multires_applied = true;
591 }
592 }
593
594 if (mesh_deform) {
595 MeshEditHints &edit_data = geometry_mesh_edit_hints_ensure(geometry_set);
596 edit_data.mesh_deform = std::move(mesh_deform);
597 }
598
599 BLI_linklist_free(reinterpret_cast<LinkNode *>(datamasks), nullptr);
600
601 for (md = firstmd; md; md = md->next) {
603 }
604
605 /* Add orco coordinates to final and deformed mesh if requested. */
606 if (final_datamask.vmask & CD_MASK_ORCO) {
607 /* No need in ORCO layer if the mesh was not deformed or modified: undeformed mesh in this case
608 * matches input mesh. */
609 if (geometry_set.get_mesh() != &mesh_input) {
610 add_orco_mesh(ob, nullptr, *geometry_set.get_mesh_for_write(), mesh_orco, CD_ORCO);
611 }
612
613 if (geometry_set.has<GeometryComponentEditData>()) {
614 auto &component = geometry_set.get_component_for_write<GeometryComponentEditData>();
615 if (component.mesh_edit_hints_ && component.mesh_edit_hints_->mesh_deform) {
616 auto &mesh_deform = static_cast<MeshComponent &>(
617 component.mesh_edit_hints_->mesh_deform.ensure_mutable_inplace());
618 add_orco_mesh(ob, nullptr, *mesh_deform.get_for_write(), nullptr, CD_ORCO);
619 }
620 }
621 }
622
623 if (mesh_orco) {
624 BKE_id_free(nullptr, mesh_orco);
625 }
626 if (mesh_orco_cloth) {
627 BKE_id_free(nullptr, mesh_orco_cloth);
628 }
629
630 /* Remove temporary data layer only needed for modifier evaluation.
631 * Save some memory, and ensure GPU subdivision does not need to deal with this. */
632 if (const Mesh *mesh = geometry_set.get_mesh()) {
633 if (CustomData_has_layer(&mesh->vert_data, CD_CLOTH_ORCO)) {
634 Mesh *mesh_mut = geometry_set.get_mesh_for_write();
636 }
637 }
638
639 return geometry_set;
640}
641
643 const Object *ob,
644 ModifierData *md,
645 bool has_prev_mesh)
646{
648 const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
649
650 if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
651 return false;
652 }
653
654 if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && has_prev_mesh) {
655 BKE_modifier_set_error(ob, md, "Modifier requires original data, bad stack position");
656 return false;
657 }
658
659 return true;
660}
661
663{
664 switch (mesh->runtime->wrapper_type) {
666 if (mesh->runtime->edit_data->vert_positions.is_empty()) {
667 mesh->runtime->edit_data->vert_positions = BM_mesh_vert_coords_alloc(
669 }
670 return mesh->runtime->edit_data->vert_positions;
673 return mesh->vert_positions_for_write();
674 }
676 return {};
677}
678
680 const GeometrySet &geometry,
681 const Mesh &mesh_input,
682 const CustomData_MeshMasks &cd_mask_extra)
683{
684 const Mesh *mesh = geometry.get_mesh();
685 /* NOTE(@ideasman42): Workaround for geometry-nodes where the cage mesh may not have
686 * the mapping data needed to relate it back to the original elements,
687 * causing problems with transform & selection. See: !160540.
688 *
689 * Detect this and replace the cage with a thin edit-mesh wrapper, so at least
690 * the user sees an editable mesh (with no modifiers applied). Ideally it would be
691 * possible to know which modifier index is guaranteed to produce a usable cage
692 * instead of this place-holder. */
693 if ((mesh != nullptr) && !BKE_editmesh_eval_orig_map_available(*mesh, &mesh_input) &&
694 !(CustomData_has_layer(&mesh->vert_data, CD_ORIGINDEX) &&
695 CustomData_has_layer(&mesh->edge_data, CD_ORIGINDEX) &&
697 {
698 /* This only occurs with node-groups, assert it doesn't happen with other modifiers. */
701
703 mesh_input.runtime->edit_mesh, &cd_mask_extra, &mesh_input);
704
705 /* A non-empty `positions` array is needed because #BKE_mesh_wrapper_vert_coords
706 * is expected to be able to return vertex coordinates.
707 * Otherwise crazy-space calculation crashes, see: #160540. */
708 const BMesh *bm = BKE_editmesh_bmesh_get(&mesh_input);
709 if (bm->totvert) {
710 mesh_cage->runtime->edit_data->vert_positions = BM_mesh_vert_coords_alloc(bm);
711 }
712 return GeometryComponentPtr(new MeshComponent(mesh_cage));
713 }
714 return geometry.get_component_ptr(GeometryComponent::Type::Mesh);
715}
716
717static GeometrySet editbmesh_calc_modifiers(Depsgraph &depsgraph,
718 const Scene &scene,
719 Object &ob,
720 const CustomData_MeshMasks &dataMask)
721{
722 const Mesh &mesh_input = *id_cast<const Mesh *>(ob.data);
724
725 /* Mesh with constructive modifiers but no deformation applied. Tracked
726 * along with final mesh if undeformed / orco coordinates are requested
727 * for texturing. */
728 Mesh *mesh_orco = nullptr;
729
730 /* Modifier evaluation modes. */
731 const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
732
733 const bool use_render = (DEG_get_mode(&depsgraph) == DAG_EVAL_RENDER);
734 /* Modifier evaluation contexts for different types of modifiers. */
735 ModifierApplyFlag apply_render = use_render ? MOD_APPLY_RENDER : ModifierApplyFlag(0);
736 const ModifierEvalContext mectx = {&depsgraph, &ob, MOD_APPLY_USECACHE | apply_render};
737 const ModifierEvalContext mectx_orco = {&depsgraph, &ob, MOD_APPLY_ORCO};
738
739 /* Get effective list of modifiers to execute. Some effects like shape keys
740 * are added as virtual modifiers before the user created modifiers. */
741 VirtualModifierData virtual_modifier_data;
742 ModifierData *md = BKE_modifiers_get_virtual_modifierlist(&ob, &virtual_modifier_data);
743
744 /* Compute accumulated datamasks needed by each modifier. It helps to do
745 * this fine grained so that for example vertex groups are preserved up to
746 * an armature modifier, but not through a following subsurf modifier where
747 * subdividing them is expensive. */
748 CustomData_MeshMasks final_datamask = dataMask;
749 CDMaskLink *datamasks = BKE_modifier_calc_data_masks(&scene, md, &final_datamask, required_mode);
750 CDMaskLink *md_datamask = datamasks;
752
753 GeometrySet geometry_set = GeometrySet::from_mesh(
754 BKE_mesh_wrapper_from_editmesh(mesh_input.runtime->edit_mesh, &final_datamask, &mesh_input));
755
756 int cageIndex = BKE_modifiers_get_cage_index(&scene, &ob, nullptr, true);
757
758 /* Mesh before evaluation, to detect if a modifier replaces it (only use for comparison). */
759 const Mesh *mesh_geometry_set_init = cageIndex == -1 ? geometry_set.get_mesh() : nullptr;
760
761 /* Cage mesh, set by a cage modifier or from the final mesh below. */
762 GeometryComponentPtr cage_mesh;
763
764 /* The mesh from edit mode should not have any original index layers already, since those
765 * are added during evaluation when necessary and are redundant on an original mesh. */
767 CustomData_get_layer(&bm->edata, CD_ORIGINDEX) == nullptr &&
769
770 /* Clear errors before evaluation. */
772
774 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
777 }
778 }
779
780 bool non_deform_modifier_applied = false;
781 bool deform_modifier_applied = false;
782 for (int i = 0; md; i++, md = md->next, md_datamask = md_datamask->next) {
784 if (!editbmesh_modifier_is_enabled(&scene, &ob, md, non_deform_modifier_applied)) {
785 continue;
786 }
787
788 ScopedModifierTimer modifier_timer{*md};
789
790 /* Add an orco mesh as layer if needed by this modifier. */
791 if (mesh_orco && mti->required_data_mask) {
793 mti->required_data_mask(md, &mask);
794 if (mask.vmask & CD_MASK_ORCO) {
795 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
796 add_orco_mesh(ob, bm, *mesh, mesh_orco, CD_ORCO);
797 }
798 }
799 }
800
802 deform_modifier_applied = true;
803 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
804 if (mti->deform_verts_EM) {
808 }
809 else {
811 BKE_modifier_deform_verts(md, &mectx, mesh, mesh->vert_positions_for_write());
812 mesh->tag_positions_changed();
813 }
814 }
815 }
816 else {
817 non_deform_modifier_applied = true;
818
819 /* create an orco derivedmesh in parallel */
820 CustomData_MeshMasks mask = md_datamask->mask;
821 if (mask.vmask & CD_MASK_ORCO) {
822 if (!mesh_orco) {
823 mesh_orco = create_orco_mesh(ob, mesh_input, bm, CD_ORCO);
824 }
825
826 mask.vmask &= ~CD_MASK_ORCO;
827 mask.vmask |= CD_MASK_ORIGINDEX;
828 mask.emask |= CD_MASK_ORIGINDEX;
829 mask.pmask |= CD_MASK_ORIGINDEX;
830 mesh_set_only_copy(mesh_orco, &mask);
831
833 Mesh *mesh_next = BKE_modifier_modify_mesh(md, &mectx_orco, mesh_orco);
835
836 if (mesh_next) {
837 /* if the modifier returned a new dm, release the old one */
838 if (mesh_orco && mesh_orco != mesh_next) {
839 BKE_id_free(nullptr, mesh_orco);
840 }
841 mesh_orco = mesh_next;
842 }
843 }
844
845 /* set the DerivedMesh to only copy needed data */
846 CustomData_MeshMasks_update(&mask, &append_mask);
847 /* XXX WHAT? overwrites mask ??? */
848 /* CD_MASK_ORCO may have been cleared above */
849 mask = md_datamask->mask;
850 mask.vmask |= CD_MASK_ORIGINDEX;
851 mask.emask |= CD_MASK_ORIGINDEX;
852 mask.pmask |= CD_MASK_ORIGINDEX;
853
854 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
856
857 if (mask.lmask & CD_MASK_ORIGSPACE_MLOOP) {
858 if (!CustomData_has_layer(&mesh->corner_data, CD_ORIGSPACE_MLOOP)) {
860 &mesh->corner_data, CD_ORIGSPACE_MLOOP, CD_SET_DEFAULT, mesh->corners_num);
862 }
863 }
864
865 mesh->runtime->deformed_only = false;
866 }
867
868 modifier_modify_mesh_and_geometry_set(md, mectx, mesh_input, geometry_set);
869 }
870
871 if (i == cageIndex) {
872 if (Key *key = mesh_input.key) {
873 mesh_eval_assign_key(geometry_set, key);
874 }
875 cage_mesh = cage_mesh_or_fallback(ob, geometry_set, mesh_input, final_datamask);
876 }
877 }
878
879 BLI_linklist_free(reinterpret_cast<LinkNode *>(datamasks), nullptr);
880
881 /* Add orco coordinates to final and deformed mesh if requested. */
882 if (final_datamask.vmask & CD_MASK_ORCO) {
883 /* FIXME(@ideasman42): avoid the need to convert to mesh data just to add an orco layer. */
884 if (Mesh *mesh = geometry_set.get_mesh_for_write()) {
886
887 add_orco_mesh(ob, bm, *mesh, mesh_orco, CD_ORCO);
888 }
889 }
890
891 if (mesh_orco) {
892 BKE_id_free(nullptr, mesh_orco);
893 }
894
895 /* Assign the key before sharing the final mesh component with the cage. Writable access after
896 * sharing can copy the BMesh wrapper without the required Edit Mode runtime state. */
897 if (Key *key = mesh_input.key) {
898 mesh_eval_assign_key(geometry_set, key);
899 }
900
901 /* In all likelihood, when `cageIndex == -1`. */
902 if (!cage_mesh) {
903 /* It's important to reuse the `geometry_set` mesh when not deformed
904 * so the overlay engine sees these as the same mesh (pointer compassing is used).
905 * Otherwise there are subtle artifacts from the mesh Z-fighting with itself, See: !161224. */
906 if ((deform_modifier_applied == false) && (non_deform_modifier_applied == false) &&
907 (mesh_geometry_set_init && mesh_geometry_set_init == geometry_set.get_mesh()))
908 {
909 cage_mesh = geometry_set.get_component_ptr(GeometryComponent::Type::Mesh);
910 }
911 else {
913 mesh_input.runtime->edit_mesh, &final_datamask, &mesh_input)));
914 }
915 }
916
917 MeshEditHints &edit_data = geometry_mesh_edit_hints_ensure(geometry_set);
918 edit_data.mesh_cage = std::move(cage_mesh);
919
920 return geometry_set;
921}
922
923static void mesh_build_extra_data(const Depsgraph &depsgraph,
924 const Object &ob,
925 const Mesh &mesh_eval)
926{
927 uint32_t eval_flags = DEG_get_eval_flags_for_id(&depsgraph, &ob.id);
928
929 if (eval_flags & DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY) {
931 }
932}
933
934static void mesh_build_data(Depsgraph &depsgraph,
935 const Scene &scene,
936 Object &ob,
937 const CustomData_MeshMasks &dataMask,
938 const bool need_mapping)
939{
940 const Mesh &mesh_input = *id_cast<const Mesh *>(ob.data);
941 GeometrySet geometry_set = mesh_calc_modifiers(
942 depsgraph, scene, ob, true, need_mapping, dataMask, true);
943
944 /* Make sure that drivers can target shapekey properties.
945 * Note that this causes a potential inconsistency, as the shapekey may have a different topology
946 * than the evaluated mesh. */
947 if (Key *key = mesh_input.key) {
948 mesh_eval_assign_key(geometry_set, key);
949 }
950 const Mesh *mesh_eval = geometry_set.get_mesh();
951
952 BKE_object_eval_assign_data(&ob, &const_cast<ID &>(mesh_eval->id), false);
953 ob.runtime->geometry_set_eval = new GeometrySet(std::move(geometry_set));
954 ob.runtime->last_data_mask = dataMask;
955 ob.runtime->last_need_mapping = need_mapping;
956
958 if (DEG_is_active(&depsgraph)) {
960 }
961 }
962
963 mesh_build_extra_data(depsgraph, ob, *mesh_eval);
964}
965
966static void editbmesh_build_data(Depsgraph &depsgraph,
967 const Scene &scene,
968 Object &obedit,
969 CustomData_MeshMasks &dataMask)
970{
971 GeometrySet geometry_set = editbmesh_calc_modifiers(depsgraph, scene, obedit, dataMask);
972
974 &obedit, id_cast<ID *>(const_cast<Mesh *>(geometry_set.get_mesh())), false);
975
976 obedit.runtime->geometry_set_eval = new GeometrySet(std::move(geometry_set));
977
978 obedit.runtime->last_data_mask = dataMask;
979}
980
981static void object_get_datamask(const Depsgraph &depsgraph,
982 Object &ob,
983 CustomData_MeshMasks &r_mask,
984 bool *r_need_mapping)
985{
986 Scene *scene = DEG_get_evaluated_scene(&depsgraph);
987 ViewLayer *view_layer = DEG_get_evaluated_view_layer(&depsgraph);
988
989 DEG_get_customdata_mask_for_object(&depsgraph, &ob, &r_mask);
990
991 if (r_need_mapping) {
992 *r_need_mapping = false;
993 }
994
995 /* Must never access original objects when dependency graph is not active: it might be already
996 * freed. */
997 if (!DEG_is_active(&depsgraph)) {
998 return;
999 }
1000
1001 BKE_view_layer_synced_ensure(*DEG_get_bmain(&depsgraph), scene, view_layer);
1002 Object *actob = BKE_view_layer_active_object_get(view_layer);
1003 if (actob) {
1004 actob = DEG_get_original(actob);
1005 }
1006 if (DEG_get_original(&ob) == actob) {
1007 bool editing = BKE_paint_select_face_test(actob);
1008
1009 /* weight paint and face select need original indices because of selection buffer drawing */
1010 if (r_need_mapping) {
1011 *r_need_mapping = (editing || (ob.mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT)));
1012 }
1013
1014 /* Check if we need #MTFace & loop-color due to face select or texture paint. */
1015 if ((ob.mode & OB_MODE_TEXTURE_PAINT) || editing) {
1017 r_mask.fmask |= CD_MASK_MTFACE;
1018 }
1019
1020 /* Check if we need loop-color due to vertex paint or weight-paint. */
1021 if (ob.mode & OB_MODE_VERTEX_PAINT) {
1023 }
1024
1025 if (ob.mode & OB_MODE_WEIGHT_PAINT) {
1026 r_mask.vmask |= CD_MASK_MDEFORMVERT;
1027 }
1028 }
1029}
1030
1031void mesh_data_update(Depsgraph &depsgraph,
1032 const Scene &scene,
1033 Object &ob,
1034 const CustomData_MeshMasks &dataMask)
1035{
1036 BLI_assert(ob.type == OB_MESH);
1037
1038 /* Evaluated meshes aren't supposed to be created on original instances. If you do,
1039 * they aren't cleaned up properly on mode switch, causing crashes, e.g #58150. */
1041
1043 if (DEG_is_active(&depsgraph)) {
1045 }
1046
1047 /* NOTE: Access the `edit_mesh` after freeing the derived caches, so that `ob.data` is restored
1048 * to the pre-evaluated state. This is because the evaluated state is not necessarily sharing the
1049 * `edit_mesh` pointer with the input. For example, if the object is first evaluated in the
1050 * object mode, and then user in another scene moves object to edit mode. */
1051 Mesh *mesh = id_cast<Mesh *>(ob.data);
1052
1053 bool need_mapping;
1054 CustomData_MeshMasks cddata_masks = dataMask;
1055 object_get_datamask(depsgraph, ob, cddata_masks, &need_mapping);
1056
1057 if (mesh->runtime->edit_mesh) {
1058 editbmesh_build_data(depsgraph, scene, ob, cddata_masks);
1059 }
1060 else {
1061 mesh_build_data(depsgraph, scene, ob, cddata_masks, need_mapping);
1062 }
1063}
1064
1065const Mesh *mesh_get_eval_deform(Depsgraph *depsgraph,
1066 const Scene *scene,
1067 Object *ob,
1068 const CustomData_MeshMasks *dataMask)
1069{
1070 BMEditMesh *em = (id_cast<Mesh *>(ob->data))->runtime->edit_mesh.get();
1071 if (em != nullptr) {
1072 /* There is no such a concept as deformed mesh in edit mode.
1073 * Explicitly disallow this request so that the evaluated result is not modified with evaluated
1074 * result from the wrong mode. */
1075 BLI_assert_msg(0, "Request of deformed mesh of object which is in edit mode");
1076 return nullptr;
1077 }
1078
1079 /* This function isn't thread-safe and can't be used during evaluation. */
1080 BLI_assert(DEG_is_evaluating(depsgraph) == false);
1081
1082 /* Evaluated meshes aren't supposed to be created on original instances. If you do,
1083 * they aren't cleaned up properly on mode switch, causing crashes, e.g #58150. */
1085
1086 /* If there's no evaluated mesh or the last data mask used doesn't include
1087 * the data we need, rebuild the evaluated mesh. */
1088 bool need_mapping;
1089
1090 CustomData_MeshMasks cddata_masks = *dataMask;
1091 object_get_datamask(*depsgraph, *ob, cddata_masks, &need_mapping);
1092
1094 !CustomData_MeshMasks_are_matching(&(ob->runtime->last_data_mask), &cddata_masks) ||
1095 (need_mapping && !ob->runtime->last_need_mapping))
1096 {
1097 /* FIXME: this block may leak memory (& assert) because it runs #BKE_object_eval_assign_data
1098 * intended only to run during depsgraph-evaluation that overwrites the evaluated mesh
1099 * without freeing beforehand, see: !128228. */
1102 *depsgraph, *scene, *ob, cddata_masks, need_mapping || ob->runtime->last_need_mapping);
1103 }
1104
1106}
1107
1108Mesh *mesh_create_eval_final(Depsgraph *depsgraph,
1109 const Scene *scene,
1110 Object *ob,
1111 const CustomData_MeshMasks *dataMask)
1112{
1113 GeometrySet geometry_set = mesh_calc_modifiers(
1114 *depsgraph, *scene, *ob, true, false, *dataMask, false);
1115 geometry_set.ensure_owns_direct_data();
1116 return geometry_set.get_component_for_write<MeshComponent>().release();
1117}
1118
1119Mesh *mesh_create_eval_no_deform(Depsgraph *depsgraph,
1120 const Scene *scene,
1121 Object *ob,
1122 const CustomData_MeshMasks *dataMask)
1123{
1124 GeometrySet geometry_set = mesh_calc_modifiers(
1125 *depsgraph, *scene, *ob, false, false, *dataMask, false);
1126 geometry_set.ensure_owns_direct_data();
1127 return geometry_set.get_component_for_write<MeshComponent>().release();
1128}
1129
1131 const Scene *scene,
1132 Object *ob,
1133 const CustomData_MeshMasks *dataMask)
1134{
1135 GeometrySet geometry_set = mesh_calc_modifiers(
1136 *depsgraph, *scene, *ob, false, false, *dataMask, false);
1137 geometry_set.ensure_owns_direct_data();
1138 return geometry_set.get_component_for_write<MeshComponent>().release();
1139}
1140
1141const Mesh *editbmesh_get_eval_cage(Depsgraph *depsgraph,
1142 const Scene *scene,
1143 Object *obedit,
1144 const CustomData_MeshMasks *dataMask)
1145{
1146 CustomData_MeshMasks cddata_masks = *dataMask;
1147
1148 /* If there's no evaluated mesh or the last data mask used doesn't include
1149 * the data we need, rebuild the evaluated mesh. */
1150 object_get_datamask(*depsgraph, *obedit, cddata_masks, nullptr);
1151
1152 if (!BKE_object_get_editmesh_eval_cage(obedit) ||
1153 !CustomData_MeshMasks_are_matching(&(obedit->runtime->last_data_mask), &cddata_masks))
1154 {
1155 /* FIXME: this block may leak memory (& assert) because it runs #BKE_object_eval_assign_data
1156 * intended only to run during depsgraph-evaluation that overwrites the evaluated mesh
1157 * without freeing beforehand, see: !128228. */
1158 editbmesh_build_data(*depsgraph, *scene, *obedit, cddata_masks);
1159 }
1160
1161 return BKE_object_get_editmesh_eval_cage(obedit);
1162}
1163
1164const Mesh *editbmesh_get_eval_cage_from_orig(Depsgraph *depsgraph,
1165 const Scene *scene,
1166 Object *obedit,
1167 const CustomData_MeshMasks *dataMask)
1168{
1169 BLI_assert((obedit->id.tag & ID_TAG_COPIED_ON_EVAL) == 0);
1170 const Scene *scene_eval = DEG_get_evaluated(depsgraph, scene);
1171 Object *obedit_eval = DEG_get_evaluated(depsgraph, obedit);
1172 return editbmesh_get_eval_cage(depsgraph, scene_eval, obedit_eval, dataMask);
1173}
1174
1179
1180static void make_vertexcos__mapFunc(void *user_data,
1181 int index,
1182 const float co[3],
1183 const float /*no*/[3])
1184{
1185 MappedUserData *mappedData = static_cast<MappedUserData *>(user_data);
1186
1187 if (!mappedData->vertex_visit[index]) {
1188 mappedData->vertexcos[index] = float3(co);
1189 mappedData->vertex_visit[index].set();
1190 }
1191}
1192
1194{
1195 if (mesh_eval->runtime->deformed_only == false) {
1196 MappedUserData user_data;
1197 r_cos.fill(float3(0));
1198 user_data.vertexcos = r_cos;
1199 user_data.vertex_visit.resize(r_cos.size());
1201 }
1202 else {
1203 r_cos.copy_from(BKE_mesh_wrapper_vert_coords(mesh_eval));
1204 }
1205}
1206
1208{
1209 const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1210
1211 OrigSpaceLoop *lof_array = static_cast<OrigSpaceLoop *>(
1212 CustomData_get_layer_for_write(&mesh.corner_data, CD_ORIGSPACE_MLOOP, mesh.corners_num));
1213 const Span<float3> positions = mesh.vert_positions();
1214 const OffsetIndices faces = mesh.faces();
1215 const Span<int> corner_verts = mesh.corner_verts();
1216
1217 int j, k;
1218
1219 Vector<float2, 64> vcos_2d;
1220
1221 for (const int i : faces.index_range()) {
1222 const IndexRange face = faces[i];
1223 OrigSpaceLoop *lof = lof_array + face.start();
1224
1225 if (ELEM(face.size(), 3, 4)) {
1226 for (j = 0; j < face.size(); j++, lof++) {
1227 copy_v2_v2(lof->uv, default_osf[j]);
1228 }
1229 }
1230 else {
1231 float co[3];
1232 float mat[3][3];
1233
1234 float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
1235 float translate[2], scale[2];
1236
1237 const float3 p_nor = mesh::face_normal_calc(positions, corner_verts.slice(face));
1238
1239 axis_dominant_v3_to_m3(mat, p_nor);
1240
1241 vcos_2d.resize(face.size());
1242 for (j = 0; j < face.size(); j++) {
1243 mul_v3_m3v3(co, mat, positions[corner_verts[face[j]]]);
1244 copy_v2_v2(vcos_2d[j], co);
1245
1246 for (k = 0; k < 2; k++) {
1247 if (co[k] > max[k]) {
1248 max[k] = co[k];
1249 }
1250 else if (co[k] < min[k]) {
1251 min[k] = co[k];
1252 }
1253 }
1254 }
1255
1256 /* Brings min to (0, 0). */
1258
1259 /* Scale will bring max to (1, 1). */
1261 if (scale[0] == 0.0f) {
1262 scale[0] = 1e-9f;
1263 }
1264 if (scale[1] == 0.0f) {
1265 scale[1] = 1e-9f;
1266 }
1268
1269 /* Finally, transform all vcos_2d into ((0, 0), (1, 1))
1270 * square and assign them as origspace. */
1271 for (j = 0; j < face.size(); j++, lof++) {
1272 add_v2_v2v2(lof->uv, vcos_2d[j], translate);
1273 mul_v2_v2(lof->uv, scale);
1274 }
1275 }
1276 }
1277
1279}
1280
1281} // namespace blender::bke
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define CD_MASK_PROP_BYTE_COLOR
#define CD_MASK_ORIGINDEX
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_FLOAT2
#define CD_MASK_MTFACE
#define CD_MASK_ORIGSPACE_MLOOP
#define CD_MASK_CLOTH_ORCO
btScalar max
constexpr int64_t size() const
constexpr int64_t start() const
constexpr MutableSpan()=default
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr bool is_empty() const
Definition BLI_span.hh:515
constexpr void fill(const T &value) const
Definition BLI_span.hh:523
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr bool is_empty() const
Definition BLI_span.hh:264
void resize(const int64_t new_size)
void resize(const int64_t new_size_in_bits, const bool value=false)
GAttributeReader lookup(const StringRef name) const
std::unique_ptr< MeshEditHints > mesh_edit_hints_
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
#define FLT_MAX
#define storage(slot, qualifiers)
#define layer
float3x3 scale(float3x3 mat, float2 scale)
float4x4 translate(float4x4 mat, float3 translation)
#define ASSERT_IS_VALID_MESH_INPUT(mesh)
#define ASSERT_IS_VALID_MESH_OUTPUT(mesh)
void fill_index_range(MutableSpan< T > span, const T start=0)
float3 face_normal_calc(Span< float3 > vert_positions, Span< int > face_verts)
const ShrinkwrapBoundaryData & boundary_cache_ensure(const Mesh &mesh)
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
static void mesh_build_data(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask, const bool need_mapping)
static void object_get_datamask(const Depsgraph &depsgraph, Object &ob, CustomData_MeshMasks &r_mask, bool *r_need_mapping)
static GeometrySet mesh_calc_modifiers(Depsgraph &depsgraph, const Scene &scene, Object &ob, const bool use_deform, const bool need_mapping, const CustomData_MeshMasks &dataMask, const bool use_cache)
Mesh * mesh_create_eval_no_deform_render(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static void mesh_init_origspace(Mesh &mesh)
Mesh * mesh_create_eval_no_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
void mesh_get_mapped_verts_coords(const Mesh *mesh_eval, MutableSpan< float3 > r_cos)
static void mesh_eval_assign_key(GeometrySet &geometry, Key *key)
static Span< float3 > get_orco_coords(const Object &ob, BMesh *bm, eCustomDataType layer_type, Array< float3 > &storage)
static GeometryComponentPtr cage_mesh_or_fallback(Object &ob, const GeometrySet &geometry, const Mesh &mesh_input, const CustomData_MeshMasks &cd_mask_extra)
static void make_vertexcos__mapFunc(void *user_data, int index, const float co[3], const float[3])
bool editbmesh_modifier_is_enabled(const Scene *scene, const Object *ob, ModifierData *md, bool has_prev_mesh)
static void mesh_build_extra_data(const Depsgraph &depsgraph, const Object &ob, const Mesh &mesh_eval)
static void add_orco_mesh(Object &ob, BMesh *bm, Mesh &mesh, const Mesh *mesh_orco, const eCustomDataType layer)
static void mesh_set_only_copy(Mesh *mesh, const CustomData_MeshMasks *mask)
static MutableSpan< float3 > orco_coord_layer_ensure(Mesh &mesh, const eCustomDataType layer)
const Mesh * mesh_get_eval_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
static GeometrySet editbmesh_calc_modifiers(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask)
static void editbmesh_build_data(Depsgraph &depsgraph, const Scene &scene, Object &obedit, CustomData_MeshMasks &dataMask)
void mesh_data_update(Depsgraph &depsgraph, const Scene &scene, Object &ob, const CustomData_MeshMasks &dataMask)
static void modifier_modify_mesh_and_geometry_set(ModifierData *md, const ModifierEvalContext &mectx, const Mesh &input_mesh, GeometrySet &geometry_set)
static MeshEditHints & geometry_mesh_edit_hints_ensure(GeometrySet &geometry)
const Mesh * editbmesh_get_eval_cage_from_orig(Depsgraph *depsgraph, const Scene *scene, Object *obedit, const CustomData_MeshMasks *dataMask)
static MutableSpan< float3 > mesh_wrapper_vert_coords_ensure_for_write(Mesh *mesh)
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
const Mesh * editbmesh_get_eval_cage(Depsgraph *depsgraph, const Scene *scene, Object *obedit, const CustomData_MeshMasks *dataMask)
static void set_rest_position(Mesh &mesh)
static Mesh * create_orco_mesh(const Object &ob, const Mesh &mesh, BMesh *bm, eCustomDataType layer)
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:89
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
Definition object.cc:4492
CDMaskLink * BKE_modifier_calc_data_masks(const Scene *scene, ModifierData *md, CustomData_MeshMasks *final_datamask, int required_mode)
void BKE_modifier_set_error(const Object *ob, ModifierData *md, const char *format,...) ATTR_PRINTF_FORMAT(3
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
const CustomData_MeshMasks CD_MASK_BAREMESH
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
MultiresModifierData * BKE_sculpt_multires_active(const Scene *scene, Object *ob)
MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2])
bool CustomData_free_layers(CustomData *data, eCustomDataType type)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
MINLINE void negate_v2_v2(float r[2], const float a[2])
MINLINE void copy_v2_v2(float r[2], const float a[2])
void BKE_object_eval_assign_data(Object *object, ID *data, bool is_owned)
Definition object.cc:1786
bool CustomData_MeshMasks_are_matching(const CustomData_MeshMasks *mask_ref, const CustomData_MeshMasks *mask_required)
Definition customdata.cc:99
void BKE_sculptsession_update_before_eval(Object *ob_eval)
bool BKE_modifier_supports_mapping(ModifierData *md)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
uint32_t DEG_get_eval_flags_for_id(const Depsgraph *graph, const ID *id)
void BKE_mesh_tessface_clear(Mesh *mesh)
void DEG_get_customdata_mask_for_object(const Depsgraph *graph, Object *object, CustomData_MeshMasks *r_mask)
@ OB_MODIFIER_FLAG_ADD_REST_POSITION
MINLINE void mul_v2_v2(float r[2], const float a[2])
void BKE_modifier_free_temporary_data(ModifierData *md)
void BKE_mesh_copy_parameters_for_eval(Mesh *me_dst, const Mesh *me_src)
KeyBlock * BKE_keyblock_find_by_index(Key *key, int index)
Definition key.cc:1425
unsigned int uint32_t
Definition BKE_text.h:81
bool BKE_modifier_deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
Main * DEG_get_bmain(const Depsgraph *graph)
@ OB_MODE_TEXTURE_PAINT
BMesh const char void * data
void BKE_sculptsession_update_after_eval(Depsgraph *depsgraph, Object *ob_eval)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ MOD_APPLY_USECACHE
void BKE_mesh_wrapper_tag_positions_changed(Mesh *mesh)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
bool BKE_object_use_sculptsession(eObjectMode mode)
Definition object.cc:4328
ViewLayer * DEG_get_evaluated_view_layer(const Depsgraph *graph)
int BKE_modifiers_get_cage_index(const Scene *scene, Object *ob, int *r_lastPossibleCageIndex, bool is_virtual)
Array< float3 > BM_mesh_vert_coords_alloc(const BMesh *bm)
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void BKE_modifiers_clear_errors(Object *ob)
bool BKE_paint_select_face_test(const Object *ob)
bool BKE_editmesh_eval_orig_map_available(const Mesh &mesh_eval, const Mesh *mesh_orig)
Definition editmesh.cc:93
void BKE_id_free(Main *bmain, void *idv)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
@ eModifierTypeFlag_RequiresOriginalData
void BKE_mesh_orco_verts_transform(Mesh *mesh, MutableSpan< float3 > orco, bool invert)
bool DEG_is_evaluated_id(const ID *id)
@ DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
Mesh * BKE_modifier_modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
T * DEG_get_original(T *id)
void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc)
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
void BKE_modifier_deform_vertsEM(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
@ ID_TAG_COPIED_ON_EVAL
Definition DNA_ID.h:1000
void BKE_mesh_foreach_mapped_vert(const Mesh *mesh, void(*func)(void *user_data, int index, const float co[3], const float no[3]), void *user_data, MeshForeachFlag flag)
Span< float3 > BKE_mesh_wrapper_vert_coords(const Mesh *mesh)
void BKE_mesh_ensure_default_orig_index_customdata(Mesh *mesh)
const BMesh * BKE_editmesh_bmesh_get(const Object *ob)
Definition editmesh.cc:65
Mesh * BKE_mesh_wrapper_from_editmesh(std::shared_ptr< BMEditMesh > em, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
void * CustomData_get_layer_for_write(CustomData *data, eCustomDataType type, int totelem)
VecBase< float, 3 > float3
@ ME_WRAPPER_TYPE_SUBD
@ ME_WRAPPER_TYPE_MDATA
@ ME_WRAPPER_TYPE_BMESH
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1311
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
bool DEG_is_evaluating(const Depsgraph *depsgraph)
Definition depsgraph.cc:318
MINLINE void invert_v2(float r[2])
const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void CustomData_set_only_copy(const CustomData *data, eCustomDataMask mask)
void axis_dominant_v3_to_m3(float r_mat[3][3], const float normal[3])
Normal to x,y matrix.
const Mesh * BKE_object_get_mesh_deform_eval(const Object *object)
Definition object.cc:4519
Array< float3 > BKE_mesh_orco_verts_get(const Object *ob)
void * CustomData_add_layer(CustomData *data, eCustomDataType type, eCDAllocType alloctype, int totelem)
#define min(a, b)
Definition sort.cc:38
CustomData pdata
CustomData edata
struct ClothSimSettings * sim_parms
bke::MeshRuntime * runtime
struct Key * key
CustomData vert_data
struct ModifierData * next
void(*) required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
void(*) deform_verts_EM(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
void(*) modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
ObjectModifierFlag modifier_flag
bke::ObjectRuntime * runtime
struct ToolSettings * toolsettings
AttributeInitShared(const void *data, const ImplicitSharingInfo &sharing_info)
const ImplicitSharingInfo * sharing_info
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
GeometryComponentPtr get_component_ptr(GeometryComponent::Type component_type) const
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool has(const GeometryComponent::Type component_type) const
const Mesh * get_mesh() const
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
MutableSpan< float3 > vertexcos
GeometryComponentPtr mesh_deform
GeometryComponentPtr mesh_cage
std::shared_ptr< BMEditMesh > edit_mesh
std::unique_ptr< EditMeshData > edit_data
CustomData_MeshMasks last_data_mask