Blender V5.3
object_modifier.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdio>
10#include <cstdlib>
11
12#include "CLG_log.h"
13
14#include "DNA_defs.h"
15#include "MEM_guardedalloc.h"
16
17#include "DNA_armature_types.h"
18#include "DNA_array_utils.hh"
19#include "DNA_curve_types.h"
20#include "DNA_key_types.h"
21#include "DNA_lattice_types.h"
22#include "DNA_material_types.h"
23#include "DNA_mesh_types.h"
24#include "DNA_meshdata_types.h"
27#include "DNA_scene_types.h"
28
29#include "BLI_array_utils.hh"
30#include "BLI_bitmap.hh"
32#include "BLI_listbase.hh"
33#include "BLI_string.hh"
34#include "BLI_string_utf8.hh"
35#include "BLI_string_utils.hh"
36#include "BLI_utildefines.hh"
37
38#include "BKE_animsys.hh"
40#include "BKE_armature.hh"
41#include "BKE_context.hh"
42#include "BKE_curve.hh"
43#include "BKE_curves.h"
44#include "BKE_curves.hh"
45#include "BKE_displist.h"
46#include "BKE_editmesh.hh"
47#include "BKE_effect.h"
48#include "BKE_geometry_set.hh"
49#include "BKE_global.hh"
50#include "BKE_grease_pencil.hh"
51#include "BKE_idprop.hh"
52#include "BKE_key.hh"
53#include "BKE_lattice.hh"
54#include "BKE_layer.hh"
55#include "BKE_lib_id.hh"
56#include "BKE_library.hh"
57#include "BKE_main.hh"
59#include "BKE_material.hh"
60#include "BKE_mball.hh"
61#include "BKE_mesh.hh"
62#include "BKE_mesh_mapping.hh"
63#include "BKE_mesh_runtime.hh"
64#include "BKE_modifier.hh"
65#include "BKE_multires.hh"
66#include "BKE_object.hh"
67#include "BKE_object_deform.h"
68#include "BKE_object_types.hh"
69#include "BKE_ocean.h"
70#include "BKE_paint.hh"
71#include "BKE_particle.h"
72#include "BKE_pointcloud.hh"
73#include "BKE_report.hh"
74#include "BKE_scene.hh"
75#include "BKE_softbody.h"
76#include "BKE_volume.hh"
77
78#include "BLT_translation.hh"
79
80#include "DEG_depsgraph.hh"
83
85#include "RNA_access.hh"
86#include "RNA_define.hh"
87#include "RNA_enum_types.hh"
88#include "RNA_prototypes.hh"
89
90#include "ED_armature.hh"
91#include "ED_grease_pencil.hh"
92#include "ED_node.hh"
93#include "ED_object.hh"
94#include "ED_object_vgroup.hh"
95#include "ED_screen.hh"
96
98
99#include "GEO_merge_layers.hh"
100
101#include "UI_interface.hh"
102
103#include "WM_api.hh"
104#include "WM_types.hh"
105
106#include "object_intern.hh"
107
108namespace blender::ed::object {
109
110static CLG_LogRef LOG = {"object"};
111
113
114/* ------------------------------------------------------------------- */
117
118static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Object *ob)
119{
120 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
121 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
122 BKE_object_eval_reset(ob_eval);
123 if (ob->type == OB_MESH) {
125 depsgraph, scene_eval, ob_eval, &CD_MASK_DERIVEDMESH);
126 BKE_id_free(nullptr, mesh_eval);
127 }
128 else if (ob->type == OB_LATTICE) {
129 BKE_lattice_modifiers_calc(depsgraph, scene_eval, ob_eval);
130 }
131 else if (ob->type == OB_MBALL) {
132 BKE_mball_data_update(depsgraph, scene_eval, ob_eval);
133 }
134 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) {
135 BKE_displist_make_curveTypes(depsgraph, scene_eval, ob_eval, false);
136 }
137 else if (ob->type == OB_CURVES) {
138 BKE_curves_data_update(depsgraph, scene_eval, ob);
139 }
140 else if (ob->type == OB_POINTCLOUD) {
141 BKE_pointcloud_data_update(depsgraph, scene_eval, ob);
142 }
143 else if (ob->type == OB_VOLUME) {
144 BKE_volume_data_update(depsgraph, scene_eval, ob);
145 }
146}
147
148static void object_force_modifier_bind_simple_options(Depsgraph *depsgraph,
149 Object *object,
150 ModifierData *md)
151{
152 ModifierData *md_eval = BKE_modifier_get_evaluated(depsgraph, object, md);
153 const ModifierMode mode = md_eval->mode;
154 md_eval->mode |= eModifierMode_Realtime;
155 object_force_modifier_update_for_bind(depsgraph, object);
156 md_eval->mode = mode;
157}
158
160 ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
161{
162 ModifierData *new_md = nullptr;
164
165 /* Check compatibility of modifier [#25291, #50373]. */
167 BKE_reportf(reports, RPT_WARNING, "Modifiers cannot be added to object '%s'", ob->id.name + 2);
168 return nullptr;
169 }
170
171 if (mti->flags & eModifierTypeFlag_Single) {
173 BKE_report(reports, RPT_WARNING, "Only one modifier of this type is allowed");
174 return nullptr;
175 }
176 }
177
178 if (type == eModifierType_ParticleSystem) {
179 /* don't need to worry about the new modifier's name, since that is set to the number
180 * of particle systems which shouldn't have too many duplicates
181 */
182 new_md = object_add_particle_system(bmain, scene, ob, name);
183 }
184 else {
185 /* get new modifier data to add */
186 new_md = BKE_modifier_new(type);
187
190
191 if (name) {
192 STRNCPY_UTF8(new_md->name, name);
193 }
194
195 /* make sure modifier data has unique name */
197
198 /* special cases */
199 if (type == eModifierType_Softbody) {
200 if (!ob->soft) {
201 ob->soft = sbNew();
203 }
204 }
205 else if (type == eModifierType_Collision) {
206 if (!ob->pd) {
208 }
209
210 ob->pd->deflect = 1;
211 }
212 else if (type == eModifierType_Surface) {
213 /* pass */
214 }
215 else if (type == eModifierType_Multires) {
216 /* set totlvl from existing MDISPS layer if object already had it */
217 multiresModifier_set_levels_from_disps(reinterpret_cast<MultiresModifierData *>(new_md), ob);
218
219 if (ob->mode & OB_MODE_SCULPT) {
220 /* ensure that grid paint mask layer is created */
222 nullptr, nullptr, ob, reinterpret_cast<MultiresModifierData *>(new_md));
223 }
224 }
225 else if (type == eModifierType_Skin) {
226 /* ensure skin-node customdata exists */
227 BKE_mesh_ensure_skin_customdata(id_cast<Mesh *>(ob->data));
228 }
229 }
230
232
235
236 return new_md;
237}
238
239/* Return true if the object has a modifier of type 'type' other than
240 * the modifier pointed to be 'exclude', otherwise returns false. */
241static bool object_has_modifier(const Object *ob, const ModifierData *exclude, ModifierType type)
242{
243 for (ModifierData &md : ob->modifiers) {
244 if ((&md != exclude) && (md.type == type)) {
245 return true;
246 }
247 }
248
249 return false;
250}
251
252bool iter_other(Main *bmain,
253 Object *orig_ob,
254 const bool include_orig,
255 bool (*callback)(Object *ob, void *callback_data),
256 void *callback_data)
257{
258 ID *ob_data_id = orig_ob->data;
259 int users = ob_data_id->us;
260
261 if (ob_data_id->flag & ID_FLAG_FAKEUSER) {
262 users--;
263 }
264
265 /* First check that the object's data has multiple users */
266 if (users > 1) {
267 Object *ob;
268 int totfound = include_orig ? 0 : 1;
269
270 for (ob = bmain->objects.first(); ob && totfound < users;
271 ob = reinterpret_cast<Object *>(ob->id.next))
272 {
273 if (((ob != orig_ob) || include_orig) && (ob->data == orig_ob->data)) {
274 if (callback(ob, callback_data)) {
275 return true;
276 }
277
278 totfound++;
279 }
280 }
281 }
282 else if (include_orig) {
283 return callback(orig_ob, callback_data);
284 }
285
286 return false;
287}
288
289static bool object_has_modifier_cb(Object *ob, void *data)
290{
291 ModifierType type = *(static_cast<ModifierType *>(data));
292
293 return object_has_modifier(ob, nullptr, type);
294}
295
296bool multires_update_totlevels(Object *ob, void *totlevel_v)
297{
298 int totlevel = *(static_cast<char *>(totlevel_v));
299
300 for (ModifierData &md : ob->modifiers) {
301 if (md.type == eModifierType_Multires) {
302 multires_set_tot_level(ob, reinterpret_cast<MultiresModifierData *>(&md), totlevel);
304 }
305 }
306 return false;
307}
308
309/* Return true if no modifier of type 'type' other than 'exclude' */
311 Object *ob,
312 ModifierData *exclude,
313 ModifierType type)
314{
315 return (!object_has_modifier(ob, exclude, type) &&
316 !iter_other(bmain, ob, false, object_has_modifier_cb, &type));
317}
318
320 Main *bmain, Scene *scene, Object *ob, ModifierData *md, bool *r_sort_depsgraph)
321{
322 /* It seems on rapid delete it is possible to
323 * get called twice on same modifier, so make
324 * sure it is in list. */
325 if (BLI_findindex(&ob->modifiers, md) == -1) {
326 return false;
327 }
328
329 /* special cases */
332 bmain, scene, ob, (reinterpret_cast<ParticleSystemModifierData *>(md))->psys);
333 return true;
334 }
335
336 if (md->type == eModifierType_Softbody) {
337 if (ob->soft) {
338 sbFree(ob);
339 ob->softflag = 0; /* TODO(Sybren): this should probably be moved into sbFree() */
340 }
341 }
342 else if (md->type == eModifierType_Collision) {
343 if (ob->pd) {
344 ob->pd->deflect = 0;
345 }
346
347 *r_sort_depsgraph = true;
348 }
349 else if (md->type == eModifierType_Surface) {
350 *r_sort_depsgraph = true;
351 }
352 else if (md->type == eModifierType_Multires) {
353 /* Delete MDisps layer if not used by another multires modifier */
355 multires_customdata_delete(id_cast<Mesh *>(ob->data));
356 }
357 }
358 else if (md->type == eModifierType_Skin) {
359 /* Delete skin vertex attributes if not used by another skin modifier */
362 }
363 }
364
366 {
368 }
369
370 BKE_animdata_drivers_remove_for_rna_struct(ob->id, *RNA_Modifier, md);
371
375
376 return true;
377}
378
379bool modifier_remove(ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
380{
381 bool sort_depsgraph = false;
382
383 bool ok = object_modifier_remove(bmain, scene, ob, md, &sort_depsgraph);
384
385 if (!ok) {
386 BKE_reportf(reports, RPT_ERROR, "Modifier '%s' not in object '%s'", md->name, ob->id.name);
387 return false;
388 }
389
392
393 return true;
394}
395
396void modifiers_clear(Main *bmain, Scene *scene, Object *ob)
397{
398 ModifierData *md = ob->modifiers.first();
399 bool sort_depsgraph = false;
400
401 if (!md) {
402 return;
403 }
404
405 while (md) {
406 ModifierData *next_md = md->next;
407
408 object_modifier_remove(bmain, scene, ob, md, &sort_depsgraph);
409
410 md = next_md;
411 }
412
415}
416
418 eReportType error_type,
419 ModifierData *md,
420 ModifierData *md_prev)
421{
422 if (md_prev) {
423 if (md->flag & eModifierFlag_PinLast && !(md_prev->flag & eModifierFlag_PinLast)) {
424 return false;
425 }
427
429 const ModifierTypeInfo *nmti = BKE_modifier_get_info(md_prev->type);
430
432 BKE_report(reports, error_type, "Cannot move above a modifier requiring original data");
433 return false;
434 }
435 }
436 }
437 else {
438 BKE_report(reports, error_type, "Cannot move modifier beyond the start of the list");
439 return false;
440 }
441
442 return true;
443}
444
445bool modifier_move_up(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md)
446{
447 if (object_modifier_check_move_before(reports, error_type, md, md->prev)) {
449 return true;
450 }
451
452 return false;
453}
454
456 eReportType error_type,
457 ModifierData *md,
458 ModifierData *md_next)
459{
460 if (md_next) {
461 if (md_next->flag & eModifierFlag_PinLast && !(md->flag & eModifierFlag_PinLast)) {
462 return false;
463 }
465
467 const ModifierTypeInfo *nmti = BKE_modifier_get_info(md_next->type);
468
469 if (nmti->type != ModifierTypeType::OnlyDeform) {
470 BKE_report(reports, error_type, "Cannot move beyond a non-deforming modifier");
471 return false;
472 }
473 }
474 }
475 else {
476 BKE_report(reports, error_type, "Cannot move modifier beyond the end of the list");
477 return false;
478 }
479
480 return true;
481}
482
483bool modifier_move_down(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md)
484{
485 if (object_modifier_check_move_after(reports, error_type, md, md->next)) {
487 return true;
488 }
489
490 return false;
491}
492
494 eReportType error_type,
495 Object *ob,
496 ModifierData *md,
497 const int index,
498 bool allow_partial)
499{
500 BLI_assert(md != nullptr);
501
502 if (index < 0 || index >= ob->modifiers.count()) {
503 BKE_report(reports, error_type, "Cannot move modifier beyond the end of the stack");
504 return false;
505 }
506
507 int md_index = BLI_findindex(&ob->modifiers, md);
508 BLI_assert(md_index != -1);
509
510 if (md_index < index) {
511 /* Move modifier down in list. */
512 ModifierData *md_target = md;
513
514 for (; md_index < index; md_index++, md_target = md_target->next) {
515 if (!object_modifier_check_move_after(reports, error_type, md, md_target->next)) {
516 if (!allow_partial || md == md_target) {
517 return false;
518 }
519
520 break;
521 }
522 }
523
524 BLI_assert(md != md_target && md_target);
525
526 BLI_remlink(&ob->modifiers, md);
527 BLI_insertlinkafter(&ob->modifiers, md_target, md);
528 }
529 else if (md_index > index) {
530 /* Move modifier up in list. */
531 ModifierData *md_target = md;
532
533 for (; md_index > index; md_index--, md_target = md_target->prev) {
534 if (!object_modifier_check_move_before(reports, error_type, md, md_target->prev)) {
535 if (!allow_partial || md == md_target) {
536 return false;
537 }
538
539 break;
540 }
541 }
542
543 BLI_assert(md != md_target && md_target);
544
545 BLI_remlink(&ob->modifiers, md);
546 BLI_insertlinkbefore(&ob->modifiers, md_target, md);
547 }
548 else {
549 return true;
550 }
551
552 /* NOTE: Dependency graph only uses modifier nodes for visibility updates, and exact order of
553 * modifier nodes in the graph does not matter. */
554
557
558 return true;
559}
560
570
572 const Scene *scene,
573 const Object *ob_src,
574 const ModifierData *md,
575 Object *ob_dst,
576 ReportList *reports)
577{
579
580 BLI_assert(ob_src != ob_dst);
581
582 /* Checked in #BKE_object_copy_modifier, but check here too so we can give a better message. */
584 BKE_reportf(reports,
586 "Object '%s' does not support %s modifiers",
587 ob_dst->id.name + 2,
588 RPT_(mti->name));
589 return nullptr;
590 }
591
592 if (mti->flags & eModifierTypeFlag_Single) {
593 if (BKE_modifiers_findby_type(ob_dst, md->type)) {
594 BKE_reportf(reports,
596 "Modifier can only be added once to object '%s'",
597 ob_dst->id.name + 2);
598 return nullptr;
599 }
600 }
601
602 ModifierData *md_dst = BKE_object_copy_modifier(bmain, scene, ob_dst, ob_src, md);
603 if (!md_dst) {
604 BKE_reportf(reports,
605 RPT_ERROR,
606 "Copying modifier '%s' to object '%s' failed",
607 md->name,
608 ob_dst->id.name + 2);
609 return nullptr;
610 }
611
615 return md_dst;
616}
617
619 Main *bmain,
620 Depsgraph *depsgraph,
621 Scene *scene,
622 ViewLayer *view_layer,
623 Object *ob,
624 ModifierData *md)
625{
626 int cvert = 0;
627
629 return false;
630 }
631 if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
632 return false;
633 }
634
635 ParticleSystem *psys_orig = (reinterpret_cast<ParticleSystemModifierData *>(md))->psys;
636 ParticleSettings *part = psys_orig->part;
637
638 if (part->ren_as != PART_DRAW_PATH) {
639 return false;
640 }
641 ParticleSystem *psys_eval = psys_eval_get(depsgraph, ob, psys_orig);
642 if (psys_eval->pathcache == nullptr) {
643 return false;
644 }
645
646 int part_num = psys_eval->totcached;
647 int child_num = psys_eval->totchildcache;
648
649 if (child_num && (part->draw & PART_DRAW_PARENT) == 0) {
650 part_num = 0;
651 }
652
653 /* count */
654 int verts_num = 0, edges_num = 0;
655 ParticleCacheKey **cache = psys_eval->pathcache;
656 for (int a = 0; a < part_num; a++) {
657 ParticleCacheKey *key = cache[a];
658
659 if (key->segments > 0) {
660 verts_num += key->segments + 1;
661 edges_num += key->segments;
662 }
663 }
664
665 cache = psys_eval->childcache;
666 for (int a = 0; a < child_num; a++) {
667 ParticleCacheKey *key = cache[a];
668
669 if (key->segments > 0) {
670 verts_num += key->segments + 1;
671 edges_num += key->segments;
672 }
673 }
674
675 if (verts_num == 0) {
676 return false;
677 }
678
679 Mesh *mesh = BKE_mesh_new_nomain(verts_num, edges_num, 0, 0);
680 MutableSpan<float3> positions = mesh->vert_positions_for_write();
681 MutableSpan<int2> edges = mesh->edges_for_write();
682
683 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
685 ".select_vert", bke::AttrDomain::Point);
686
687 int edge_index = 0;
688
689 /* copy coordinates */
690 int vert_index = 0;
691 cache = psys_eval->pathcache;
692 for (int a = 0; a < part_num; a++) {
693 ParticleCacheKey *key = cache[a];
694 int kmax = key->segments;
695 for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
696 positions[vert_index] = key->co;
697 if (k) {
698 edges[edge_index] = int2(cvert - 1, cvert);
699 edge_index++;
700 }
701 else {
702 /* cheap trick to select the roots */
703 select_vert.span[vert_index] = true;
704 }
705 }
706 }
707
708 cache = psys_eval->childcache;
709 for (int a = 0; a < child_num; a++) {
710 ParticleCacheKey *key = cache[a];
711 int kmax = key->segments;
712 for (int k = 0; k <= kmax; k++, key++, cvert++, vert_index++) {
713 copy_v3_v3(positions[vert_index], key->co);
714 if (k) {
715 edges[edge_index] = int2(cvert - 1, cvert);
716 edge_index++;
717 }
718 else {
719 /* cheap trick to select the roots */
720 select_vert.span[vert_index] = true;
721 }
722 }
723 }
724
725 select_vert.finish();
726
727 Object *obn = BKE_object_add(bmain, scene, view_layer, OB_MESH, nullptr);
728 BKE_mesh_nomain_to_mesh(mesh, id_cast<Mesh *>(obn->data), obn);
729
731
732 return true;
733}
734
735static void add_shapekey_layers(Mesh &mesh_dest, const Mesh &mesh_src)
736{
737 if (!mesh_src.key) {
738 return;
739 }
740
741 for (const auto [i, kb] : mesh_src.key->block.enumerate()) {
742 void *array;
743 if (mesh_src.verts_num != kb.totelem) {
745 "vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)",
746 mesh_src.id.name + 2,
747 mesh_src.verts_num,
748 kb.name,
749 kb.totelem);
750 array = MEM_new_array_zeroed<float[3]>(mesh_src.verts_num, __func__);
751 }
752 else {
753 array = MEM_new_array_uninitialized<float[3]>(size_t(mesh_src.verts_num), __func__);
754 memcpy(array, kb.data, sizeof(float[3]) * size_t(mesh_src.verts_num));
755 }
756
758 &mesh_dest.vert_data, CD_SHAPEKEY, array, mesh_dest.verts_num, nullptr);
759 const int ci = CustomData_get_layer_index_n(&mesh_dest.vert_data, CD_SHAPEKEY, i);
760
761 mesh_dest.vert_data.layers[ci].uid = kb.uid;
762 }
763}
764
770static Mesh *create_applied_mesh_for_modifier(Depsgraph *depsgraph,
771 Scene *scene,
772 Object *ob_eval,
773 ModifierData *md_eval,
774 const bool use_virtual_modifiers,
775 const bool build_shapekey_layers,
776 ReportList *reports)
777{
778 Mesh *mesh = ob_eval->runtime->data_orig ?
779 reinterpret_cast<Mesh *>(ob_eval->runtime->data_orig) :
780 reinterpret_cast<Mesh *>(ob_eval->data);
781 const ModifierTypeInfo *mti = BKE_modifier_get_info(md_eval->type);
782 const ModifierEvalContext mectx = {depsgraph, ob_eval, MOD_APPLY_TO_ORIGINAL};
783
784 if (!(md_eval->mode & eModifierMode_Realtime)) {
785 return nullptr;
786 }
787
788 if (mti->is_disabled && mti->is_disabled(scene, md_eval, false)) {
789 return nullptr;
790 }
791
792 if (build_shapekey_layers && mesh->key) {
793 if (KeyBlock *kb = static_cast<KeyBlock *>(
794 BLI_findlink(&mesh->key->block, ob_eval->shapenr - 1)))
795 {
796 BKE_keyblock_convert_to_mesh(kb, mesh->vert_positions_for_write());
797 }
798 }
799
800 Mesh *mesh_temp = reinterpret_cast<Mesh *>(
801 BKE_id_copy_ex(nullptr, &mesh->id, nullptr, LIB_ID_COPY_LOCALIZE));
802 MutableSpan<float3> deformedVerts = mesh_temp->vert_positions_for_write();
803
804 if (use_virtual_modifiers) {
805 VirtualModifierData virtual_modifier_data;
806 for (ModifierData *md_eval_virt =
807 BKE_modifiers_get_virtual_modifierlist(ob_eval, &virtual_modifier_data);
808 md_eval_virt && (md_eval_virt != ob_eval->modifiers.first_);
809 md_eval_virt = md_eval_virt->next)
810 {
811 if (!BKE_modifier_is_enabled(scene, md_eval_virt, eModifierMode_Realtime)) {
812 continue;
813 }
814 /* All virtual modifiers are deform modifiers. */
815 const ModifierTypeInfo *mti_virt = BKE_modifier_get_info(md_eval_virt->type);
817 if (mti_virt->type != ModifierTypeType::OnlyDeform) {
818 continue;
819 }
820
821 mti_virt->deform_verts(md_eval_virt, &mectx, mesh_temp, deformedVerts);
822 }
823 }
824
825 Mesh *result = nullptr;
827 result = mesh_temp;
828 mti->deform_verts(md_eval, &mectx, result, deformedVerts);
829 result->tag_positions_changed();
830
831 if (build_shapekey_layers) {
833 }
834 }
835 else {
836 if (build_shapekey_layers) {
837 add_shapekey_layers(*mesh_temp, *mesh);
838 }
839
840 if (mti->modify_geometry_set) {
843 mti->modify_geometry_set(md_eval, &mectx, &geometry_set);
844 if (!geometry_set.has_mesh()) {
845 BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain a mesh");
846 return nullptr;
847 }
848 result = geometry_set.get_component_for_write<bke::MeshComponent>().release();
849 }
850 else {
851 result = mti->modify_mesh(md_eval, &mectx, mesh_temp);
852 if (mesh_temp != result) {
853 BKE_id_free(nullptr, mesh_temp);
854 }
855 }
856 }
857
858 return result;
859}
860
861static bool modifier_apply_shape(Main *bmain,
862 ReportList *reports,
863 Depsgraph *depsgraph,
864 Scene *scene,
865 Object *ob,
866 ModifierData *md_eval)
867{
868 const ModifierTypeInfo *mti = BKE_modifier_get_info(md_eval->type);
869
870 if (mti->is_disabled && mti->is_disabled(scene, md_eval, false)) {
871 BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply");
872 return false;
873 }
874
875 /* We could investigate using the #CD_ORIGINDEX layer
876 * to support other kinds of modifiers besides deforming modifiers.
877 * as this is done in many other places, see: #BKE_mesh_foreach_mapped_vert_coords_get.
878 *
879 * This isn't high priority in practice since most modifiers users
880 * want to apply as a shape are deforming modifiers.
881 *
882 * If a compelling use-case comes up where we want to support other kinds of modifiers
883 * we can look into supporting them. */
884
885 if (ob->type == OB_MESH) {
886 Mesh *mesh = id_cast<Mesh *>(ob->data);
887 Key *key = mesh->key;
888
890 BKE_report(reports, RPT_ERROR, "Only deforming modifiers can be applied to shapes");
891 return false;
892 }
893
894 Mesh *mesh_applied = create_applied_mesh_for_modifier(depsgraph,
895 DEG_get_evaluated_scene(depsgraph),
896 DEG_get_evaluated(depsgraph, ob),
897 md_eval,
898 true,
899 false,
900 reports);
901 if (!mesh_applied) {
902 BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
903 return false;
904 }
905
906 if (key == nullptr) {
907 key = mesh->key = BKE_key_add(bmain, id_cast<ID *>(mesh));
908 key->type = KEY_RELATIVE;
909 /* if that was the first key block added, then it was the basis.
910 * Initialize it with the mesh, and add another for the modifier */
911 KeyBlock *kb = BKE_keyblock_add(key, nullptr);
913 }
914
915 KeyBlock *kb = BKE_keyblock_add(key, md_eval->name);
916 BKE_mesh_nomain_to_meshkey(mesh_applied, mesh, kb);
917
918 BKE_id_free(nullptr, mesh_applied);
919 }
920 else {
921 BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
922 return false;
923 }
924 return true;
925}
926
927static bool apply_grease_pencil_for_modifier(Depsgraph *depsgraph,
928 Object *ob,
929 GreasePencil &grease_pencil_orig,
930 ModifierData *md_eval)
931{
932 using namespace bke;
933 using namespace bke::greasepencil;
934 const ModifierTypeInfo *mti = BKE_modifier_get_info(md_eval->type);
935 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
936 GreasePencil *grease_pencil_for_eval = ob_eval->runtime->data_orig ?
937 reinterpret_cast<GreasePencil *>(
938 ob_eval->runtime->data_orig) :
939 &grease_pencil_orig;
940 const int eval_frame = int(DEG_get_ctime(depsgraph));
941 GreasePencil *grease_pencil_temp = reinterpret_cast<GreasePencil *>(
942 BKE_id_copy_ex(nullptr, &grease_pencil_for_eval->id, nullptr, LIB_ID_COPY_LOCALIZE));
943 grease_pencil_temp->runtime->eval_frame = eval_frame;
944 GeometrySet eval_geometry_set = GeometrySet::from_grease_pencil(grease_pencil_temp,
945 GeometryOwnershipType::Owned);
946
947 ModifierEvalContext mectx = {depsgraph, ob_eval, MOD_APPLY_TO_ORIGINAL};
948 mti->modify_geometry_set(md_eval, &mectx, &eval_geometry_set);
949 if (!eval_geometry_set.has_grease_pencil()) {
950
951 return false;
952 }
953 GreasePencil &grease_pencil_result =
954 *eval_geometry_set.get_component_for_write<GreasePencilComponent>().get_for_write();
955
957 eval_frame,
958 grease_pencil_orig.layers().index_range(),
959 grease_pencil_orig);
960
961 Main *bmain = DEG_get_bmain(depsgraph);
962 /* There might be layers with empty names after evaluation. Make sure to rename them. */
963 bke::greasepencil::ensure_non_empty_layer_names(*bmain, grease_pencil_result);
964 BKE_object_material_from_eval_data(bmain, ob, &grease_pencil_result.id);
965 return true;
966}
967
968static bool apply_grease_pencil_for_modifier_all_keyframes(Depsgraph *depsgraph,
969 Scene *scene,
970 Object *ob,
971 GreasePencil &grease_pencil_orig,
972 ModifierData *md)
973{
974 using namespace bke;
975 using namespace bke::greasepencil;
976 Main *bmain = DEG_get_bmain(depsgraph);
977
979
980 WM_cursor_wait(true);
981
982 Map<int, Vector<int>> layer_indices_to_apply_per_frame;
983 {
984 for (const int layer_i : grease_pencil_orig.layers().index_range()) {
985 const Layer &layer = grease_pencil_orig.layer(layer_i);
986 for (const auto &[key, value] : layer.frames().items()) {
987 if (value.is_end()) {
988 continue;
989 }
990 layer_indices_to_apply_per_frame.lookup_or_add(key, {}).append(layer_i);
991 }
992 }
993 }
994
995 Array<int> sorted_frame_times(layer_indices_to_apply_per_frame.size());
996 int i = 0;
997 for (const int key : layer_indices_to_apply_per_frame.keys()) {
998 sorted_frame_times[i++] = key;
999 }
1000 std::ranges::sort(sorted_frame_times);
1001
1002 const int prev_frame = int(DEG_get_ctime(depsgraph));
1003 bool changed = false;
1004 for (const int eval_frame : sorted_frame_times) {
1005 const Span<int> layer_indices = layer_indices_to_apply_per_frame.lookup(eval_frame).as_span();
1006 scene->r.cfra = eval_frame;
1008
1009 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1010 GreasePencil *grease_pencil_for_eval = ob_eval->runtime->data_orig ?
1011 reinterpret_cast<GreasePencil *>(
1012 ob_eval->runtime->data_orig) :
1013 &grease_pencil_orig;
1014
1015 GreasePencil *grease_pencil_temp = reinterpret_cast<GreasePencil *>(
1016 BKE_id_copy_ex(nullptr, &grease_pencil_for_eval->id, nullptr, LIB_ID_COPY_LOCALIZE));
1017 grease_pencil_temp->runtime->eval_frame = eval_frame;
1018 GeometrySet eval_geometry_set = GeometrySet::from_grease_pencil(grease_pencil_temp,
1019 GeometryOwnershipType::Owned);
1020
1021 ModifierData *md_eval = BKE_modifier_get_evaluated(depsgraph, ob, md);
1022 ModifierEvalContext mectx = {depsgraph, ob_eval, MOD_APPLY_TO_ORIGINAL};
1023 mti->modify_geometry_set(md_eval, &mectx, &eval_geometry_set);
1024 if (!eval_geometry_set.has_grease_pencil()) {
1025 continue;
1026 }
1027 GreasePencil &grease_pencil_result =
1028 *eval_geometry_set.get_component_for_write<GreasePencilComponent>().get_for_write();
1029
1030 IndexMaskMemory memory;
1031 const IndexMask orig_layers_to_apply = IndexMask::from_indices(layer_indices, memory);
1033 grease_pencil_result, eval_frame, orig_layers_to_apply, grease_pencil_orig);
1034
1035 BKE_object_material_from_eval_data(bmain, ob, &grease_pencil_result.id);
1036 changed = true;
1037 }
1038
1039 scene->r.cfra = prev_frame;
1041
1042 /* There might be layers with empty names after evaluation. Make sure to rename them. */
1043 bke::greasepencil::ensure_non_empty_layer_names(*bmain, grease_pencil_orig);
1044
1045 WM_cursor_wait(false);
1046 return changed;
1047}
1048
1050 Depsgraph *depsgraph,
1051 Scene *scene,
1052 Object *ob,
1053 ModifierData *md_eval,
1054 const bool do_all_keyframes)
1055{
1056 const ModifierTypeInfo *mti = BKE_modifier_get_info(md_eval->type);
1057
1058 if (mti->is_disabled && mti->is_disabled(scene, md_eval, false)) {
1059 BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply");
1060 return false;
1061 }
1062
1063 if (ob->type == OB_MESH) {
1064 Mesh *mesh = id_cast<Mesh *>(ob->data);
1066
1067 if (mesh->key && mti->type != ModifierTypeType::NonGeometrical) {
1068 BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to a mesh with shape keys");
1069 return false;
1070 }
1071
1072 /* Multires: ensure that recent sculpting is applied */
1073 if (md_eval->type == eModifierType_Multires) {
1075 }
1076
1077 if (mmd && mmd->totlvl &&
1079 {
1080 if (!multiresModifier_reshapeFromDeformModifier(depsgraph, ob, mmd, md_eval)) {
1081 BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply");
1082 return false;
1083 }
1084 }
1085 else {
1086 Mesh *mesh_applied = create_applied_mesh_for_modifier(
1087 depsgraph,
1088 DEG_get_evaluated_scene(depsgraph),
1089 DEG_get_evaluated(depsgraph, ob),
1090 md_eval,
1091 /* It's important not to apply virtual modifiers (e.g. shape-keys) because they're kept,
1092 * causing them to be applied twice, see: #97758. */
1093 false,
1094 true,
1095 reports);
1096 if (!mesh_applied) {
1097 return false;
1098 }
1099
1100 Main *bmain = DEG_get_bmain(depsgraph);
1101 BKE_object_material_from_eval_data(bmain, ob, &mesh_applied->id);
1102 BKE_mesh_nomain_to_mesh(mesh_applied, mesh, ob);
1103
1104 /* Anonymous attributes shouldn't be available on the applied geometry. */
1105 mesh->attributes_for_write().remove_anonymous();
1106
1107 /* Remove strings referring to attributes if they no longer exist. */
1109
1110 /* Make sure that if there are uv maps, one is marked as active. */
1112
1113 if (md_eval->type == eModifierType_Multires) {
1115 }
1116 }
1117 }
1118 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
1119 Object *object_eval = DEG_get_evaluated(depsgraph, ob);
1120 Curve *curve = id_cast<Curve *>(ob->data);
1121 Curve *curve_eval = id_cast<Curve *>(object_eval->data);
1122 ModifierEvalContext mectx = {depsgraph, object_eval, MOD_APPLY_TO_ORIGINAL};
1123
1125 BKE_report(
1126 reports,
1127 RPT_ERROR,
1128 "Cannot apply constructive modifiers on curve. Convert curve to mesh in order to apply");
1129 return false;
1130 }
1131
1132 BKE_report(reports,
1133 RPT_INFO,
1134 "Applied modifier only changed CV points, not tessellated/bevel vertices");
1135
1136 Array<float3> vertexCos = BKE_curve_nurbs_vert_coords_alloc(&curve_eval->nurb);
1137 mti->deform_verts(md_eval, &mectx, nullptr, vertexCos);
1138 BKE_curve_nurbs_vert_coords_apply(&curve->nurb, vertexCos, false);
1139
1141 }
1142 else if (ob->type == OB_LATTICE) {
1143 Object *object_eval = DEG_get_evaluated(depsgraph, ob);
1144 Lattice *lattice = id_cast<Lattice *>(ob->data);
1145 ModifierEvalContext mectx = {depsgraph, object_eval, MOD_APPLY_TO_ORIGINAL};
1146
1148 BKE_report(reports, RPT_ERROR, "Constructive modifiers cannot be applied");
1149 return false;
1150 }
1151
1152 Array<float3> positions = BKE_lattice_vert_coords_alloc(lattice);
1153 mti->deform_verts(md_eval, &mectx, nullptr, positions);
1154 BKE_lattice_vert_coords_apply(lattice, positions);
1155
1157 }
1158 else if (ob->type == OB_CURVES) {
1159 Curves &curves = *id_cast<Curves *>(ob->data);
1160 if (mti->modify_geometry_set == nullptr) {
1162 return false;
1163 }
1164
1167 bke::curves_store_surface_in_geometry_bundle(*depsgraph, curves, geometry_set);
1168
1169 ModifierEvalContext mectx = {depsgraph, ob, MOD_APPLY_TO_ORIGINAL};
1170 mti->modify_geometry_set(md_eval, &mectx, &geometry_set);
1171 if (!geometry_set.has_curves()) {
1172 BKE_report(reports, RPT_ERROR, "Evaluated geometry from modifier does not contain curves");
1173 return false;
1174 }
1175 Curves &curves_eval = *geometry_set.get_curves_for_write();
1176
1177 /* Anonymous attributes shouldn't be available on original geometry. */
1178 curves_eval.geometry.wrap().attributes_for_write().remove_anonymous();
1179
1180 curves.geometry.wrap() = std::move(curves_eval.geometry.wrap());
1181 Main *bmain = DEG_get_bmain(depsgraph);
1182 BKE_object_material_from_eval_data(bmain, ob, &curves_eval.id);
1183 }
1184 else if (ob->type == OB_POINTCLOUD) {
1185 PointCloud &points = *id_cast<PointCloud *>(ob->data);
1186 if (mti->modify_geometry_set == nullptr) {
1188 return false;
1189 }
1190
1193
1194 ModifierEvalContext mectx = {depsgraph, ob, MOD_APPLY_TO_ORIGINAL};
1195 mti->modify_geometry_set(md_eval, &mectx, &geometry_set);
1196 if (!geometry_set.has_pointcloud()) {
1197 BKE_report(
1198 reports, RPT_ERROR, "Evaluated geometry from modifier does not contain a point cloud");
1199 return false;
1200 }
1201 PointCloud *pointcloud_eval =
1202 geometry_set.get_component_for_write<bke::PointCloudComponent>().release();
1203
1204 /* Anonymous attributes shouldn't be available on original geometry. */
1205 pointcloud_eval->attributes_for_write().remove_anonymous();
1206
1207 Main *bmain = DEG_get_bmain(depsgraph);
1208 BKE_object_material_from_eval_data(bmain, ob, &pointcloud_eval->id);
1209 BKE_pointcloud_nomain_to_pointcloud(pointcloud_eval, &points);
1210 }
1211 else if (ob->type == OB_GREASE_PENCIL) {
1212 if (mti->modify_geometry_set == nullptr) {
1213 BKE_report(reports, RPT_ERROR, "Cannot apply this modifier to Grease Pencil geometry");
1214 return false;
1215 }
1216 GreasePencil &grease_pencil_orig = *id_cast<GreasePencil *>(ob->data);
1217 bool success = false;
1218 if (do_all_keyframes) {
1219 /* The function #apply_grease_pencil_for_modifier_all_keyframes will retrieve
1220 * the evaluated modifier for each keyframe. The original modifier is passed
1221 * to ensure the evaluated modifier is not used, as it will be invalid when
1222 * the scene graph is updated for the next keyframe. */
1223 ModifierData *md = BKE_modifier_get_original(ob, md_eval);
1225 depsgraph, scene, ob, grease_pencil_orig, md);
1226 }
1227 else {
1228 success = apply_grease_pencil_for_modifier(depsgraph, ob, grease_pencil_orig, md_eval);
1229 }
1230 if (!success) {
1231 BKE_report(reports,
1232 RPT_ERROR,
1233 "Evaluated geometry from modifier does not contain Grease Pencil geometry");
1234 return false;
1235 }
1236 }
1237 else {
1238 /* TODO: implement for volumes. */
1239 BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
1240 return false;
1241 }
1242
1243 /* lattice modifier can be applied to particle system too */
1244 if (ob->particlesystem.first_) {
1245 for (ParticleSystem &psys : ob->particlesystem) {
1246 if (psys.part->type != PART_HAIR) {
1247 continue;
1248 }
1249
1250 psys_apply_hair_lattice(depsgraph, scene, ob, &psys);
1251 }
1252 }
1253
1254 return true;
1255}
1256
1258 ReportList *reports,
1259 Depsgraph *depsgraph,
1260 Scene *scene,
1261 Object *ob,
1262 ModifierData *md,
1263 int mode,
1264 bool keep_modifier,
1265 const bool do_all_keyframes)
1266{
1267 if (BKE_object_is_in_editmode(ob)) {
1268 BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode");
1269 return false;
1270 }
1271 if (mode != MODIFIER_APPLY_SHAPE && ID_REAL_USERS(ob->data) > 1) {
1272 BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied to multi-user data");
1273 return false;
1274 }
1275 if ((ob->mode & OB_MODE_SCULPT) && find_multires_modifier_before(scene, md) &&
1276 (BKE_modifier_is_same_topology(md) == false))
1277 {
1278 BKE_report(reports,
1279 RPT_ERROR,
1280 "Constructive modifier cannot be applied to multi-res data in sculpt mode");
1281 return false;
1282 }
1283
1284 if (md != ob->modifiers.first_) {
1285 BKE_report(reports, RPT_INFO, "Applied modifier was not first, result may not be as expected");
1286 }
1287
1288 /* Get evaluated modifier, so object links pointer to evaluated data,
1289 * but still use original object it is applied to the original mesh. */
1290 Object *ob_eval = DEG_get_evaluated(depsgraph, ob);
1291 ModifierData *md_eval = (ob_eval) ? BKE_modifiers_findby_name(ob_eval, md->name) : md;
1292
1293 Depsgraph *apply_depsgraph = depsgraph;
1294 Depsgraph *local_depsgraph = nullptr;
1295
1296 /* If the object is hidden or the modifier is not enabled for the viewport is disabled a special
1297 * handling is required. This is because the viewport dependency graph optimizes out evaluation
1298 * of objects which are used by hidden objects and disabled modifiers.
1299 *
1300 * The idea is to create a dependency graph which does not perform those optimizations. */
1301 if ((ob_eval->base_flag & BASE_ENABLED_VIEWPORT) == 0 ||
1302 (md_eval->mode & eModifierMode_Realtime) == 0)
1303 {
1304 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
1305
1306 local_depsgraph = DEG_graph_new(bmain, scene, view_layer, DAG_EVAL_VIEWPORT);
1307 DEG_disable_visibility_optimization(local_depsgraph);
1308
1309 DEG_graph_build_from_ids(local_depsgraph, {&ob->id});
1310 DEG_evaluate_on_refresh(local_depsgraph);
1311
1312 apply_depsgraph = local_depsgraph;
1313
1314 /* The evaluated object and modifier are now from the different dependency graph. */
1315 ob_eval = DEG_get_evaluated(local_depsgraph, ob);
1316 md_eval = BKE_modifiers_findby_name(ob_eval, md->name);
1317
1318 /* Force mode on the evaluated modifier, enforcing the modifier evaluation in the apply()
1319 * functions. */
1320 md_eval->mode |= eModifierMode_Realtime;
1321 }
1322
1323 bool did_apply = false;
1324 if (mode == MODIFIER_APPLY_SHAPE) {
1325 did_apply = modifier_apply_shape(bmain, reports, apply_depsgraph, scene, ob, md_eval);
1326 }
1327 else {
1328 did_apply = modifier_apply_obdata(
1329 reports, apply_depsgraph, scene, ob, md_eval, do_all_keyframes);
1330 }
1331
1332 if (did_apply) {
1333 if (!keep_modifier) {
1336 }
1338 }
1339
1340 if (local_depsgraph != nullptr) {
1341 DEG_graph_free(local_depsgraph);
1342 }
1343
1344 return true;
1345}
1346
1348 ReportList * /*reports*/, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
1349{
1352 bmain, scene, ob, (reinterpret_cast<ParticleSystemModifierData *>(md))->psys);
1353 BLI_remlink(&ob->modifiers, nmd);
1354 BLI_insertlinkafter(&ob->modifiers, md, nmd);
1356 return true;
1357 }
1358
1360 BKE_modifier_copydata(md, nmd);
1361 BLI_insertlinkafter(&ob->modifiers, md, nmd);
1362 STRNCPY_UTF8(nmd->name, md->name);
1366
1368
1369 return true;
1370}
1371
1373
1375{
1376 Vector<PointerRNA> objects;
1377 if (RNA_boolean_get(op.ptr, "use_selected_objects")) {
1379 }
1380 else {
1381 if (Object *object = context_active_object(&C)) {
1382 objects.append(RNA_id_pointer_create(&object->id));
1383 }
1384 }
1385 return objects;
1386}
1387
1389{
1391 ot->srna,
1392 "use_selected_objects",
1393 false,
1394 "Selected Objects",
1395 "Affect all selected objects instead of just the active object");
1397}
1398
1399/* ------------------------------------------------------------------- */
1402
1404{
1405 Main *bmain = CTX_data_main(C);
1406 Scene *scene = CTX_data_scene(C);
1407 int type = RNA_enum_get(op->ptr, "type");
1408
1409 bool changed = false;
1410 for (const PointerRNA &ptr : modifier_get_edit_objects(*C, *op)) {
1411 Object *ob = static_cast<Object *>(ptr.data);
1412 if (!modifier_add(op->reports, bmain, scene, ob, nullptr, type)) {
1413 continue;
1414 }
1415 changed = true;
1417 }
1418 if (!changed) {
1419 return OPERATOR_CANCELLED;
1420 }
1421
1422 return OPERATOR_FINISHED;
1423}
1424
1426{
1427 if (event->modifier & KM_ALT || CTX_wm_view3d(C)) {
1428 RNA_boolean_set(op->ptr, "use_selected_objects", true);
1429 }
1430 if (!RNA_struct_property_is_set(op->ptr, "type")) {
1431 return WM_menu_invoke(C, op, event);
1432 }
1433 return modifier_add_exec(C, op);
1434}
1435
1437 PointerRNA * /*ptr*/,
1438 PropertyRNA * /*prop*/,
1439 bool *r_free)
1440{
1441 Object *ob = (C) ? context_active_object(C) : nullptr;
1442
1443 if (!ob) {
1445 }
1446
1447 EnumPropertyItem *items = nullptr;
1448 int totitem = 0;
1449
1450 const EnumPropertyItem *group_item = nullptr;
1451 for (int a = 0; rna_enum_object_modifier_type_items[a].identifier; a++) {
1453
1454 if (md_item->identifier[0]) {
1456
1458 continue;
1459 }
1460
1461 if (!BKE_object_support_modifier_type_check(ob, md_item->value)) {
1462 continue;
1463 }
1464 }
1465 else {
1466 group_item = md_item;
1467 continue;
1468 }
1469
1470 if (group_item) {
1471 RNA_enum_item_add(&items, &totitem, group_item);
1472 group_item = nullptr;
1473 }
1474
1475 RNA_enum_item_add(&items, &totitem, md_item);
1476 }
1477
1478 RNA_enum_item_end(&items, &totitem);
1479 *r_free = true;
1480
1481 return items;
1482}
1483
1485{
1486 PropertyRNA *prop;
1487
1488 /* identifiers */
1489 ot->name = "Add Modifier";
1490 ot->description = "Add a procedural operation/effect to the active object";
1491 ot->idname = "OBJECT_OT_modifier_add";
1492
1493 /* API callbacks. */
1495 ot->exec = modifier_add_exec;
1497
1498 /* flags */
1500
1501 /* properties */
1502 prop = RNA_def_enum(
1505 ot->prop = prop;
1507}
1508
1510
1511/* ------------------------------------------------------------------- */
1516
1518{
1519 return CTX_data_pointer_get_type(C, "modifier", rna_type);
1520}
1521
1523{
1524 return (ptr.owner_id != nullptr) ? id_cast<Object *>(ptr.owner_id) : context_active_object(C);
1525}
1526
1528 StructRNA *rna_type,
1529 int obtype_flag,
1530 const bool is_editmode_allowed,
1531 const bool is_liboverride_allowed)
1532{
1533 Main *bmain = CTX_data_main(C);
1534 PointerRNA ptr = edit_modifier_ptr_get(C, rna_type);
1535 Object *ob = edit_modifier_object_get(C, ptr);
1536 ModifierData *mod = static_cast<ModifierData *>(ptr.data); /* May be nullptr. */
1537
1538 if (mod == nullptr && ob != nullptr) {
1540 }
1541
1542 if (!ob || !BKE_id_is_editable(bmain, &ob->id)) {
1543 return false;
1544 }
1545 if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) {
1546 return false;
1547 }
1548 if (ptr.owner_id && !BKE_id_is_editable(bmain, ptr.owner_id)) {
1549 return false;
1550 }
1551
1552 if (!is_liboverride_allowed && BKE_modifier_is_nonlocal_in_liboverride(ob, mod)) {
1554 C, "Cannot edit modifiers coming from linked data in a library override");
1555 return false;
1556 }
1557
1558 if (!is_editmode_allowed && CTX_data_edit_object(C) != nullptr) {
1559 CTX_wm_operator_poll_msg_set(C, "This modifier operation is not allowed from Edit mode");
1560 return false;
1561 }
1562
1563 return true;
1564}
1565
1567{
1568 return edit_modifier_poll_generic(C, RNA_Modifier, 0, true, false);
1569}
1570
1571/* Used by operators performing actions allowed also on modifiers from the overridden linked object
1572 * (not only from added 'local' ones). */
1574{
1575 return edit_modifier_poll_generic(C, RNA_Modifier, 0, true, true);
1576}
1577
1579{
1581 ot->srna, "modifier", nullptr, MAX_NAME, "Modifier", "Name of the modifier to edit");
1583}
1584
1586{
1588 ot->srna, "report", false, "Report", "Create a notification after the operation");
1590}
1591
1593
1594/* ------------------------------------------------------------------- */
1599
1601{
1602 if (RNA_struct_property_is_set(op->ptr, "modifier")) {
1603 return true;
1604 }
1605
1606 PointerRNA ctx_ptr = CTX_data_pointer_get_type(C, "modifier", RNA_Modifier);
1607 if (ctx_ptr) {
1608 ModifierData *md = static_cast<ModifierData *>(ctx_ptr.data);
1609 RNA_string_set(op->ptr, "modifier", md->name);
1610 return true;
1611 }
1612
1613 return false;
1614}
1615
1622 wmOperator *op,
1623 const wmEvent *event,
1624 wmOperatorStatus *r_retval)
1625{
1626 if (RNA_struct_find_property(op->ptr, "use_selected_objects")) {
1627 if (event->modifier & KM_ALT) {
1628 RNA_boolean_set(op->ptr, "use_selected_objects", true);
1629 }
1630 }
1631
1632 if (RNA_struct_property_is_set(op->ptr, "modifier")) {
1633 return true;
1634 }
1635
1636 /* Note that the context pointer is *not* the active modifier, it is set in UI layouts. */
1637 PointerRNA ctx_ptr = CTX_data_pointer_get_type(C, "modifier", RNA_Modifier);
1638 if (ctx_ptr) {
1639 ModifierData *md = static_cast<ModifierData *>(ctx_ptr.data);
1640 RNA_string_set(op->ptr, "modifier", md->name);
1641 return true;
1642 }
1643
1645 if (panel_ptr == nullptr || !*panel_ptr) {
1646 /* The operators using this function can typically be called from UIs that aren't related to
1647 * the modifiers UI at all. So include #OPERATOR_PASS_THROUGH to not block events from reaching
1648 * other operators/handlers. */
1650 return false;
1651 }
1652
1653 if (!RNA_struct_is_a(panel_ptr->type, RNA_Modifier)) {
1654 /* Work around multiple operators using the same shortcut. The operators for the other
1655 * stacks in the property editor use the same key, and will not run after these return
1656 * OPERATOR_CANCELLED. */
1658 return false;
1659 }
1660
1661 const ModifierData *md = static_cast<const ModifierData *>(panel_ptr->data);
1662 RNA_string_set(op->ptr, "modifier", md->name);
1663 return true;
1664}
1665
1667{
1668 char modifier_name[MAX_NAME];
1669 RNA_string_get(op->ptr, "modifier", modifier_name);
1670
1671 ModifierData *md = BKE_modifiers_findby_name(ob, modifier_name);
1672
1673 if (md && type != 0 && md->type != type) {
1674 md = nullptr;
1675 }
1676
1677 return md;
1678}
1679
1681
1682/* ------------------------------------------------------------------- */
1685
1687{
1688 Main *bmain = CTX_data_main(C);
1689 Scene *scene = CTX_data_scene(C);
1690 ViewLayer *view_layer = CTX_data_view_layer(C);
1691
1692 char name[MAX_NAME];
1693 RNA_string_get(op->ptr, "modifier", name);
1694
1695 bool changed = false;
1696 for (const PointerRNA &ptr : modifier_get_edit_objects(*C, *op)) {
1697 Object *ob = static_cast<Object *>(ptr.data);
1699 if (md == nullptr) {
1700 continue;
1701 }
1702
1703 int mode_orig = ob->mode;
1704 if (!modifier_remove(op->reports, bmain, scene, ob, md)) {
1705 continue;
1706 }
1707
1708 changed = true;
1709
1711
1712 /* if cloth/softbody was removed, particle mode could be cleared */
1713 if (mode_orig & OB_MODE_PARTICLE_EDIT) {
1714 if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) {
1715 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1716 if (ob == BKE_view_layer_active_object_get(view_layer)) {
1718 }
1719 }
1720 }
1721 }
1722
1723 if (!changed) {
1724 return OPERATOR_CANCELLED;
1725 }
1726
1727 if (RNA_boolean_get(op->ptr, "report")) {
1728 BKE_reportf(op->reports, RPT_INFO, "Removed modifier: %s", name);
1729 }
1730
1731 return OPERATOR_FINISHED;
1732}
1733
1735{
1736 wmOperatorStatus retval;
1737 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
1738 return modifier_remove_exec(C, op);
1739 }
1740 return retval;
1741}
1742
1744{
1745 ot->name = "Remove Modifier";
1746 ot->description = "Remove a modifier from the active object";
1747 ot->idname = "OBJECT_OT_modifier_remove";
1748
1752
1753 /* flags */
1758}
1759
1761{
1762 Main *bmain = CTX_data_main(C);
1763 Scene *scene = CTX_data_scene(C);
1764
1765 CTX_DATA_BEGIN (C, Object *, object, selected_editable_objects) {
1766 modifiers_clear(bmain, scene, object);
1768 }
1770
1771 return OPERATOR_FINISHED;
1772}
1773
1775{
1777 return false;
1778 }
1779 const Object *object = context_active_object(C);
1780 if (!BKE_object_supports_modifiers(object)) {
1781 return false;
1782 }
1783 return true;
1784}
1785
1787{
1788 ot->name = "Clear Object Modifiers";
1789 ot->description = "Clear all modifiers from the selected objects";
1790 ot->idname = "OBJECT_OT_modifiers_clear";
1791
1794
1796}
1797
1799
1800/* ------------------------------------------------------------------- */
1803
1805{
1808
1809 if (!md || !modifier_move_up(op->reports, RPT_WARNING, ob, md)) {
1810 return OPERATOR_CANCELLED;
1811 }
1812
1815
1816 return OPERATOR_FINISHED;
1817}
1818
1820{
1821 wmOperatorStatus retval;
1822 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
1823 return modifier_move_up_exec(C, op);
1824 }
1825 return retval;
1826}
1827
1829{
1830 ot->name = "Move Up Modifier";
1831 ot->description = "Move modifier up in the stack";
1832 ot->idname = "OBJECT_OT_modifier_move_up";
1833
1837
1838 /* flags */
1841}
1842
1844
1845/* ------------------------------------------------------------------- */
1848
1850{
1853
1854 if (!md || !modifier_move_down(op->reports, RPT_WARNING, ob, md)) {
1855 return OPERATOR_CANCELLED;
1856 }
1857
1860
1861 return OPERATOR_FINISHED;
1862}
1863
1865 wmOperator *op,
1866 const wmEvent *event)
1867{
1868 wmOperatorStatus retval;
1869 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
1870 return modifier_move_down_exec(C, op);
1871 }
1872 return retval;
1873}
1874
1876{
1877 ot->name = "Move Down Modifier";
1878 ot->description = "Move modifier down in the stack";
1879 ot->idname = "OBJECT_OT_modifier_move_down";
1880
1884
1885 /* flags */
1888}
1889
1891
1892/* ------------------------------------------------------------------- */
1895
1897{
1898 char name[MAX_NAME];
1899 RNA_string_get(op->ptr, "modifier", name);
1900
1901 const int index = RNA_int_get(op->ptr, "index");
1902
1903 bool changed = false;
1904 for (const PointerRNA &ptr : modifier_get_edit_objects(*C, *op)) {
1905 Object *ob = static_cast<Object *>(ptr.data);
1907 if (!md) {
1908 continue;
1909 }
1910
1911 if (!modifier_move_to_index(op->reports, RPT_WARNING, ob, md, index, true)) {
1912 continue;
1913 }
1914 changed = true;
1915 }
1916
1917 if (!changed) {
1918 return OPERATOR_CANCELLED;
1919 }
1920
1921 return OPERATOR_FINISHED;
1922}
1923
1925 wmOperator *op,
1926 const wmEvent *event)
1927{
1928 wmOperatorStatus retval;
1929 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
1930 return modifier_move_to_index_exec(C, op);
1931 }
1932 return retval;
1933}
1934
1936{
1937 ot->name = "Move Active Modifier to Index";
1938 ot->description =
1939 "Change the modifier's index in the stack so it evaluates after the set number of others";
1940 ot->idname = "OBJECT_OT_modifier_move_to_index";
1941
1945
1946 /* flags */
1950 ot->srna, "index", 0, 0, INT_MAX, "Index", "The index to move the modifier to", 0, INT_MAX);
1952}
1953
1955
1956/* ------------------------------------------------------------------- */
1959
1961{
1962 if (!edit_modifier_poll_generic(C, RNA_Modifier, 0, false, false)) {
1963 return false;
1964 }
1965
1966 Scene *scene = CTX_data_scene(C);
1967 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_Modifier);
1968 Object *ob = edit_modifier_object_get(C, ptr);
1969 ModifierData *md = static_cast<ModifierData *>(ptr.data); /* May be nullptr. */
1970 if (ob->type == OB_EMPTY) {
1971 CTX_wm_operator_poll_msg_set(C, "Modifiers cannot be applied on empty object type");
1972 return false;
1973 }
1974
1975 if (ID_IS_OVERRIDE_LIBRARY(ob) || ((ob->data != nullptr) && ID_IS_OVERRIDE_LIBRARY(ob->data))) {
1976 CTX_wm_operator_poll_msg_set(C, "Modifiers cannot be applied on override data");
1977 return false;
1978 }
1979 if (md != nullptr) {
1980 if ((ob->mode & OB_MODE_SCULPT) && find_multires_modifier_before(scene, md) &&
1981 (BKE_modifier_is_same_topology(md) == false))
1982 {
1984 C, "Constructive modifier cannot be applied to multi-res data in sculpt mode");
1985 return false;
1986 }
1987 }
1988 return true;
1989}
1990
1992 wmOperator *op,
1993 int apply_as,
1994 bool keep_modifier)
1995{
1996 Main *bmain = CTX_data_main(C);
1997 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
1998 Scene *scene = CTX_data_scene(C);
2000
2001 char name[MAX_NAME];
2002 RNA_string_get(op->ptr, "modifier", name);
2003
2004 const bool do_report = RNA_boolean_get(op->ptr, "report");
2005 const int reports_len = do_report ? op->reports->list.count() : 0;
2006
2007 const bool do_single_user = (apply_as == MODIFIER_APPLY_DATA) ?
2008 RNA_boolean_get(op->ptr, "single_user") :
2009 false;
2010 const bool do_merge_customdata = (apply_as == MODIFIER_APPLY_DATA) ?
2011 RNA_boolean_get(op->ptr, "merge_customdata") :
2012 false;
2013 const bool do_all_keyframes = (apply_as == MODIFIER_APPLY_DATA) ?
2014 RNA_boolean_get(op->ptr, "all_keyframes") :
2015 false;
2016
2017 bool changed = false;
2018 for (const PointerRNA &ptr : objects) {
2019 Object *ob = static_cast<Object *>(ptr.data);
2021 if (md == nullptr) {
2022 continue;
2023 }
2024
2026
2027 if (do_single_user && ID_REAL_USERS(ob->data) > 1) {
2028 single_obdata_user_make(bmain, scene, ob);
2032 }
2033
2034 if (!modifier_apply(bmain,
2035 op->reports,
2036 depsgraph,
2037 scene,
2038 ob,
2039 md,
2040 apply_as,
2041 keep_modifier,
2042 do_all_keyframes))
2043 {
2044 continue;
2045 }
2046 changed = true;
2047
2048 if (ob->type == OB_MESH && do_merge_customdata &&
2050 {
2052 }
2053
2057 }
2058
2059 if (!changed) {
2060 return OPERATOR_CANCELLED;
2061 }
2062
2063 if (do_report) {
2064 /* Only add this report if the operator didn't cause another one. The purpose here is
2065 * to alert that something happened, and the previous report will do that anyway. */
2066 if (op->reports->list.count() == reports_len) {
2067 BKE_reportf(op->reports, RPT_INFO, "Applied modifier: %s", name);
2068 }
2069 }
2070
2071 return OPERATOR_FINISHED;
2072}
2073
2078
2080{
2081 wmOperatorStatus retval;
2082 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
2083 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_Modifier);
2084 Object *ob = edit_modifier_object_get(C, ptr);
2085
2086 if ((ob->data != nullptr) && ID_REAL_USERS(ob->data) > 1) {
2087 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "single_user");
2088 if (!RNA_property_is_set(op->ptr, prop)) {
2089 RNA_property_boolean_set(op->ptr, prop, true);
2090 }
2091 if (RNA_property_boolean_get(op->ptr, prop)) {
2093 C,
2094 op,
2095 IFACE_("Apply Modifier"),
2096 IFACE_("Make data single-user, apply modifier, and remove it from the list."),
2097 IFACE_("Apply"),
2099 false);
2100 }
2101 }
2102 return modifier_apply_exec(C, op);
2103 }
2104 return retval;
2105}
2106
2108{
2109 PropertyRNA *prop;
2110
2111 ot->name = "Apply Modifier";
2112 ot->description = "Apply modifier and remove from the stack";
2113 ot->idname = "OBJECT_OT_modifier_apply";
2114
2118
2119 /* flags */
2121
2124
2126 "merge_customdata",
2127 true,
2128 "Merge UVs",
2129 "For mesh objects, merge UV coordinates that share a vertex to account for "
2130 "imprecision in some modifiers");
2131 prop = RNA_def_boolean(ot->srna,
2132 "single_user",
2133 false,
2134 "Make Data Single User",
2135 "Make the object's data single user if needed");
2137 prop = RNA_def_boolean(ot->srna,
2138 "all_keyframes",
2139 false,
2140 "Apply to all keyframes",
2141 "For Grease Pencil objects, apply the modifier to all the keyframes");
2144}
2145
2147
2148/* ------------------------------------------------------------------- */
2151
2153{
2154 return modifier_apply_poll(C);
2155}
2156
2158{
2159 bool keep = RNA_boolean_get(op->ptr, "keep_modifier");
2160
2162}
2163
2165 wmOperator *op,
2166 const wmEvent *event)
2167{
2168 wmOperatorStatus retval;
2169 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
2171 }
2172 return retval;
2173}
2174
2176 wmOperatorType * /*ot*/,
2177 PointerRNA *ptr)
2178{
2179 bool keep = RNA_boolean_get(ptr, "keep_modifier");
2180 if (keep) {
2181 return TIP_("Apply modifier as a new shapekey and keep it in the stack");
2182 }
2183
2184 return "";
2185}
2186
2188{
2189 ot->name = "Apply Modifier as Shape Key";
2190 ot->description = "Apply modifier as a new shape key and remove from the stack";
2191 ot->idname = "OBJECT_OT_modifier_apply_as_shapekey";
2192
2197
2198 /* flags */
2200
2202 ot->srna, "keep_modifier", false, "Keep Modifier", "Do not remove the modifier from stack");
2206}
2207
2209
2210/* ------------------------------------------------------------------- */
2213
2215{
2216 Main *bmain = CTX_data_main(C);
2217 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2218 Scene *scene = CTX_data_scene(C);
2219 ViewLayer *view_layer = CTX_data_view_layer(C);
2222
2223 if (!md || !convert_psys_to_mesh(op->reports, bmain, depsgraph, scene, view_layer, ob, md)) {
2224 return OPERATOR_CANCELLED;
2225 }
2226
2229
2230 return OPERATOR_FINISHED;
2231}
2232
2234 wmOperator *op,
2235 const wmEvent * /*event*/)
2236{
2238 return modifier_convert_exec(C, op);
2239 }
2240 return OPERATOR_CANCELLED;
2241}
2242
2244{
2245 ot->name = "Convert Particles to Mesh";
2246 ot->description = "Convert particles to a mesh object";
2247 ot->idname = "OBJECT_OT_modifier_convert";
2248
2252
2253 /* flags */
2256}
2257
2259
2260/* ------------------------------------------------------------------- */
2263
2265{
2266 Main *bmain = CTX_data_main(C);
2267 Scene *scene = CTX_data_scene(C);
2268 char name[MAX_NAME];
2269 RNA_string_get(op->ptr, "modifier", name);
2270
2271 bool changed = false;
2272 for (const PointerRNA &ptr : modifier_get_edit_objects(*C, *op)) {
2273 Object *ob = static_cast<Object *>(ptr.data);
2275 if (!md) {
2276 continue;
2277 }
2278
2279 if (!modifier_copy(op->reports, bmain, scene, ob, md)) {
2280 continue;
2281 }
2282 changed = true;
2286 }
2287
2288 if (!changed) {
2289 return OPERATOR_CANCELLED;
2290 }
2291
2292 return OPERATOR_FINISHED;
2293}
2294
2296{
2297 wmOperatorStatus retval;
2298 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
2299 return modifier_copy_exec(C, op);
2300 }
2301 return retval;
2302}
2303
2305{
2306 ot->name = "Copy Modifier";
2307 ot->description = "Duplicate modifier at the same position in the stack";
2308 ot->idname = "OBJECT_OT_modifier_copy";
2309
2313
2314 /* flags */
2318}
2319
2321
2322/* ------------------------------------------------------------------- */
2325
2327{
2330
2331 /* If there is no modifier set for this operator, clear the active modifier field. */
2333
2335
2336 return OPERATOR_FINISHED;
2337}
2338
2340 wmOperator *op,
2341 const wmEvent *event)
2342{
2343 wmOperatorStatus retval;
2344 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
2345 return modifier_set_active_exec(C, op);
2346 }
2347 return retval;
2348}
2349
2351{
2352 ot->name = "Set Active Modifier";
2353 ot->description = "Activate the modifier to use as the context";
2354 ot->idname = "OBJECT_OT_modifier_set_active";
2355
2359
2362}
2363
2365
2366/* ------------------------------------------------------------------- */
2369
2371{
2372 Main *bmain = CTX_data_main(C);
2373 const Scene *scene = CTX_data_scene(C);
2374 Object *obact = context_active_object(C);
2375 ModifierData *md = edit_modifier_property_get(op, obact, 0);
2376 if (!md) {
2377 return OPERATOR_CANCELLED;
2378 }
2379
2380 int num_copied = 0;
2381
2382 Vector<PointerRNA> selected_objects;
2383 CTX_data_selected_objects(C, &selected_objects);
2384 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2385 if (ob == obact) {
2386 continue;
2387 }
2388 if (!ID_IS_EDITABLE(ob)) {
2389 continue;
2390 }
2391 ModifierData *md_dst = modifier_copy_to_object(bmain, scene, obact, md, ob, op->reports);
2392 if (md_dst) {
2395 num_copied++;
2396 }
2397 }
2399
2400 if (num_copied > 0) {
2402 }
2403 else {
2404 BKE_reportf(op->reports, RPT_ERROR, "Modifier '%s' was not copied to any objects", md->name);
2405 return OPERATOR_CANCELLED;
2406 }
2407
2408 return OPERATOR_FINISHED;
2409}
2410
2412 wmOperator *op,
2413 const wmEvent *event)
2414{
2415 wmOperatorStatus retval;
2416 if (edit_modifier_invoke_properties_with_hover(C, op, event, &retval)) {
2418 }
2419 return retval;
2420}
2421
2423{
2424 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_Modifier);
2425 Object *obact = edit_modifier_object_get(C, ptr);
2426 ModifierData *md = static_cast<ModifierData *>(ptr.data);
2427
2428 /* This just mirrors the check in #BKE_object_copy_modifier,
2429 * but there is no reasoning for it there. */
2431 CTX_wm_operator_poll_msg_set(C, R"(Not supported for "Collision" or "Hook" modifiers)");
2432 return false;
2433 }
2434
2435 if (!obact) {
2436 CTX_wm_operator_poll_msg_set(C, "No selected object is active");
2437 return false;
2438 }
2439
2440 if (!BKE_object_supports_modifiers(obact)) {
2441 CTX_wm_operator_poll_msg_set(C, "Object type of source object is not supported");
2442 return false;
2443 }
2444
2445 /* This could have a performance impact in the worst case, where there are many objects selected
2446 * and none of them pass either of the checks. But that should be uncommon, and this operator is
2447 * only exposed in a drop-down menu anyway. */
2448 bool found_supported_objects = false;
2449 CTX_DATA_BEGIN (C, Object *, ob, selected_objects) {
2450 if (ob == obact) {
2451 continue;
2452 }
2453
2454 if (!md) {
2455 /* Skip type check if modifier could not be found ("modifier" context variable not set). */
2457 found_supported_objects = true;
2458 break;
2459 }
2460 }
2461 else if (BKE_object_support_modifier_type_check(ob, md->type)) {
2462 found_supported_objects = true;
2463 break;
2464 }
2465 }
2467
2468 if (!found_supported_objects) {
2469 CTX_wm_operator_poll_msg_set(C, "No supported objects were selected");
2470 return false;
2471 }
2472 return true;
2473}
2474
2476{
2477 ot->name = "Copy Modifier to Selected";
2478 ot->description = "Copy the modifier from the active object to all selected objects";
2479 ot->idname = "OBJECT_OT_modifier_copy_to_selected";
2480
2484
2485 /* flags */
2488}
2489
2491{
2492 Main *bmain = CTX_data_main(C);
2493 const Scene *scene = CTX_data_scene(C);
2494 Object *active_object = context_active_object(C);
2495
2496 Vector<PointerRNA> selected_objects;
2497 CTX_data_selected_objects(C, &selected_objects);
2498 CTX_DATA_BEGIN (C, Object *, object, selected_objects) {
2499 if (object == active_object) {
2500 continue;
2501 }
2502 for (const ModifierData &md : active_object->modifiers) {
2504 bmain, scene, active_object, &md, object, op->reports);
2505 if (md_dst) {
2507 if (md.flag & eModifierFlag_Active) {
2508 BKE_object_modifier_set_active(object, md_dst);
2509 }
2510 }
2511 }
2512 }
2514
2515 return OPERATOR_FINISHED;
2516
2518
2520
2521 return OPERATOR_FINISHED;
2522}
2523
2525{
2527 return false;
2528 }
2529 const Object *active_object = context_active_object(C);
2530 if (!BKE_object_supports_modifiers(active_object)) {
2531 return false;
2532 }
2533 if (active_object->modifiers.is_empty()) {
2534 CTX_wm_operator_poll_msg_set(C, "Active object has no modifiers");
2535 return false;
2536 }
2537 return true;
2538}
2539
2541{
2542 ot->name = "Copy Modifiers to Selected Objects";
2543 ot->idname = "OBJECT_OT_modifiers_copy_to_selected";
2544 ot->description = "Copy modifiers to other selected objects";
2545
2548
2550}
2551
2553
2554/* ------------------------------------------------------------------- */
2557
2559{
2560 Mesh *mesh = id_cast<Mesh *>(ob->data);
2562 BM_data_layer_free_named(bm, &bm->vdata, "skin_modifier_radius");
2563 BM_data_layer_free_named(bm, &bm->vdata, "skin_modifier_root");
2564 BM_data_layer_free_named(bm, &bm->vdata, "skin_modifier_loose");
2565 }
2566 else {
2567 mesh->attributes_for_write().remove("skin_modifier_radius");
2568 mesh->attributes_for_write().remove("skin_modifier_root");
2569 mesh->attributes_for_write().remove("skin_modifier_loose");
2570 }
2571}
2572
2573static bool skin_poll(bContext *C)
2574{
2575 return edit_modifier_poll_generic(C, RNA_SkinModifier, (1 << OB_MESH), false, false);
2576}
2577
2579{
2580 /* Resolve the object the same way the exec functions do (#edit_modifier_object_get),
2581 * so the poll validates the object that will actually be edited. */
2582 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_SkinModifier);
2583 Object *ob = edit_modifier_object_get(C, ptr);
2584 return (ob != nullptr && BKE_object_is_in_editmode(ob) &&
2585 edit_modifier_poll_generic(C, RNA_SkinModifier, (1 << OB_MESH), true, false) &&
2587}
2588
2589static void skin_root_clear(BMVert *bm_vert, Set<BMVert *> &visited, const int cd_skin_root_offset)
2590{
2591 BMEdge *bm_edge;
2592 BMIter bm_iter;
2593
2594 BM_ITER_ELEM (bm_edge, &bm_iter, bm_vert, BM_EDGES_OF_VERT) {
2595 BMVert *v2 = BM_edge_other_vert(bm_edge, bm_vert);
2596
2597 if (visited.add(v2)) {
2598 /* clear vertex root flag and add to visited set */
2599 BM_ELEM_CD_SET_BOOL(v2, cd_skin_root_offset, false);
2600
2601 skin_root_clear(v2, visited, cd_skin_root_offset);
2602 }
2603 }
2604}
2605
2607{
2608 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_SkinModifier);
2609 Object *ob = edit_modifier_object_get(C, ptr);
2611
2612 Set<BMVert *> visited;
2613
2614 BKE_mesh_ensure_skin_customdata(id_cast<Mesh *>(ob->data));
2615
2616 const int cd_skin_root_offset = CustomData_get_offset_named(
2617 &bm->vdata, CD_PROP_BOOL, "skin_modifier_root");
2618
2619 BMVert *bm_vert;
2620 BMIter bm_iter;
2621 BM_ITER_MESH (bm_vert, &bm_iter, bm, BM_VERTS_OF_MESH) {
2622 if (BM_elem_flag_test(bm_vert, BM_ELEM_SELECT) && visited.add(bm_vert)) {
2623 /* mark vertex as root and add to visited set */
2624 BM_ELEM_CD_SET_BOOL(bm_vert, cd_skin_root_offset, true);
2625
2626 /* clear root flag from all connected vertices (recursively) */
2627 skin_root_clear(bm_vert, visited, cd_skin_root_offset);
2628 }
2629 }
2630
2633
2634 return OPERATOR_FINISHED;
2635}
2636
2638{
2639 ot->name = "Skin Root Mark";
2640 ot->description = "Mark selected vertices as roots";
2641 ot->idname = "OBJECT_OT_skin_root_mark";
2642
2643 ot->poll = skin_edit_poll;
2645
2646 /* flags */
2648}
2649
2654
2656{
2657 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_SkinModifier);
2658 Object *ob = edit_modifier_object_get(C, ptr);
2660 SkinLooseAction action = static_cast<SkinLooseAction>(RNA_enum_get(op->ptr, "action"));
2661
2662 if (!CustomData_has_layer_named(&bm->vdata, CD_PROP_FLOAT2, "skin_modifier_radius")) {
2663 return OPERATOR_CANCELLED;
2664 }
2665
2666 BM_data_layer_ensure_named(bm, &bm->vdata, CD_PROP_BOOL, "skin_modifier_loose");
2667 const int cd_skin_loose_offset = CustomData_get_offset_named(
2668 &bm->vdata, CD_PROP_BOOL, "skin_modifier_loose");
2669
2670 BMVert *bm_vert;
2671 BMIter bm_iter;
2672 BM_ITER_MESH (bm_vert, &bm_iter, bm, BM_VERTS_OF_MESH) {
2673 if (BM_elem_flag_test(bm_vert, BM_ELEM_SELECT)) {
2674 switch (action) {
2675 case SKIN_LOOSE_MARK:
2676 BM_ELEM_CD_SET_BOOL(bm_vert, cd_skin_loose_offset, true);
2677 break;
2678 case SKIN_LOOSE_CLEAR:
2679 BM_ELEM_CD_SET_BOOL(bm_vert, cd_skin_loose_offset, false);
2680 break;
2681 }
2682 }
2683 }
2684
2687
2688 return OPERATOR_FINISHED;
2689}
2690
2692{
2693 static const EnumPropertyItem action_items[] = {
2694 {SKIN_LOOSE_MARK, "MARK", 0, "Mark", "Mark selected vertices as loose"},
2695 {SKIN_LOOSE_CLEAR, "CLEAR", 0, "Clear", "Set selected vertices as not loose"},
2696 {0, nullptr, 0, nullptr, nullptr},
2697 };
2698
2699 ot->name = "Skin Mark/Clear Loose";
2700 ot->description = "Mark/clear selected vertices as loose";
2701 ot->idname = "OBJECT_OT_skin_loose_mark_clear";
2702
2703 ot->poll = skin_edit_poll;
2705
2706 /* flags */
2708
2709 RNA_def_enum(ot->srna, "action", action_items, SKIN_LOOSE_MARK, "Action", nullptr);
2710}
2711
2713{
2714 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_SkinModifier);
2715 Object *ob = edit_modifier_object_get(C, ptr);
2717
2718 const int cd_skin_radius_offset = CustomData_get_offset_named(
2719 &bm->vdata, CD_PROP_FLOAT2, "skin_modifier_radius");
2720 if (cd_skin_radius_offset == -1) {
2721 return OPERATOR_CANCELLED;
2722 }
2723
2724 BMVert *bm_vert;
2725 BMIter bm_iter;
2726 BM_ITER_MESH (bm_vert, &bm_iter, bm, BM_VERTS_OF_MESH) {
2727 if (BM_elem_flag_test(bm_vert, BM_ELEM_SELECT)) {
2728 float2 *radius = static_cast<float2 *>(
2729 BM_ELEM_CD_GET_VOID_P(bm_vert, cd_skin_radius_offset));
2730 const float avg = ((*radius)[0] + (*radius)[1]) * 0.5f;
2731 *radius = float2(avg);
2732 }
2733 }
2734
2737
2738 return OPERATOR_FINISHED;
2739}
2740
2742{
2743 ot->name = "Skin Radii Equalize";
2744 ot->description = "Make skin radii of selected vertices equal on each axis";
2745 ot->idname = "OBJECT_OT_skin_radii_equalize";
2746
2747 ot->poll = skin_edit_poll;
2749
2750 /* flags */
2752}
2753
2755 const Span<float3> positions,
2756 const int2 *edges,
2757 bArmature *arm,
2758 BLI_bitmap *edges_visited,
2759 const GroupedSpan<int> emap,
2760 EditBone *parent_bone,
2761 int parent_v)
2762{
2763 for (int i = 0; i < emap[parent_v].size(); i++) {
2764 int endx = emap[parent_v][i];
2765 const int2 &edge = edges[endx];
2766
2767 /* ignore edge if already visited */
2768 if (BLI_BITMAP_TEST(edges_visited, endx)) {
2769 continue;
2770 }
2771 BLI_BITMAP_ENABLE(edges_visited, endx);
2772
2773 int v = bke::mesh::edge_other_vert(edge, parent_v);
2774
2775 EditBone *bone = ED_armature_ebone_add(arm, "Bone");
2776
2777 bone->parent = parent_bone;
2778 if (parent_bone != nullptr) {
2779 bone->flag |= BONE_CONNECTED;
2780 }
2781
2782 copy_v3_v3(bone->head, positions[parent_v]);
2783 copy_v3_v3(bone->tail, positions[v]);
2784 bone->rad_head = bone->rad_tail = 0.25;
2785 SNPRINTF_UTF8(bone->name, "Bone.%.2d", endx);
2786
2787 /* add bDeformGroup */
2788 bDeformGroup *dg = BKE_object_defgroup_add_name(skin_ob, bone->name);
2789 if (dg != nullptr) {
2790 ed::object::vgroup_vert_add(skin_ob, dg, parent_v, 1, WEIGHT_REPLACE);
2792 }
2793
2794 skin_armature_bone_create(skin_ob, positions, edges, arm, edges_visited, emap, bone, v);
2795 }
2796}
2797
2798static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Object *skin_ob)
2799{
2800 Mesh *mesh = id_cast<Mesh *>(skin_ob->data);
2801 const Span<float3> me_positions = mesh->vert_positions();
2802 const Span<int2> me_edges = mesh->edges();
2803
2804 Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
2805 Object *ob_eval = DEG_get_evaluated(depsgraph, skin_ob);
2806
2807 const Mesh *me_eval_deform = bke::mesh_get_eval_deform(
2808 depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH);
2809 const Span<float3> positions_eval = me_eval_deform->vert_positions();
2810
2811 /* add vertex weights to original mesh */
2812 mesh->deform_verts_for_write();
2813
2814 Scene *scene = DEG_get_input_scene(depsgraph);
2815 ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
2816 Object *arm_ob = BKE_object_add(bmain, scene, view_layer, OB_ARMATURE, nullptr);
2817 BKE_object_transform_copy(arm_ob, skin_ob);
2818 bArmature *arm = id_cast<bArmature *>(arm_ob->data);
2820 arm_ob->dtx |= OB_DRAW_IN_FRONT;
2822 arm->edbo = MEM_new_zeroed<ListBaseT<EditBone>>("edbo armature");
2823
2824 const VArray<bool> skin_root = *mesh->attributes().lookup_or_default<bool>(
2825 "skin_modifier_root", bke::AttrDomain::Point, false);
2826
2827 Array<int> vert_to_edge_offsets;
2828 Array<int> vert_to_edge_indices;
2830 me_edges, mesh->verts_num, vert_to_edge_offsets, vert_to_edge_indices);
2831
2832 BLI_bitmap *edges_visited = BLI_BITMAP_NEW(mesh->edges_num, "edge_visited");
2833
2834 /* NOTE: we use EditBones here, easier to set them up and use
2835 * edit-armature functions to convert back to regular bones */
2836 for (int v = 0; v < mesh->verts_num; v++) {
2837 if (skin_root[v]) {
2838 EditBone *bone = nullptr;
2839
2840 /* Unless the skin root has just one adjacent edge, create
2841 * a fake root bone (have it going off in the Y direction
2842 * (arbitrary)) */
2843 if (emap[v].size() > 1) {
2844 bone = ED_armature_ebone_add(arm, "Bone");
2845
2846 copy_v3_v3(bone->head, me_positions[v]);
2847 copy_v3_v3(bone->tail, me_positions[v]);
2848
2849 bone->head[1] = 1.0f;
2850 bone->rad_head = bone->rad_tail = 0.25;
2851 }
2852
2853 if (emap[v].size() >= 1) {
2855 skin_ob, positions_eval, me_edges.data(), arm, edges_visited, emap, bone, v);
2856 }
2857 }
2858 }
2859
2860 MEM_delete(edges_visited);
2861
2862 ED_armature_from_edit(bmain, arm);
2864
2865 return arm_ob;
2866}
2867
2869{
2870 Main *bmain = CTX_data_main(C);
2871 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2872 PointerRNA ptr = edit_modifier_ptr_get(C, RNA_SkinModifier);
2873 Object *ob = edit_modifier_object_get(C, ptr);
2874 Mesh *mesh = id_cast<Mesh *>(ob->data);
2875 ModifierData *skin_md;
2876
2877 if (!mesh->attributes().contains("skin_modifier_radius")) {
2878 BKE_reportf(op->reports, RPT_WARNING, "Mesh '%s' has no skin vertex data", mesh->id.name + 2);
2879 return OPERATOR_CANCELLED;
2880 }
2881
2882 /* create new armature */
2883 Object *arm_ob = modifier_skin_armature_create(depsgraph, bmain, ob);
2884
2885 /* add a modifier to connect the new armature to the mesh */
2886 ArmatureModifierData *arm_md = reinterpret_cast<ArmatureModifierData *>(
2888 if (arm_md) {
2890 BLI_insertlinkafter(&ob->modifiers, skin_md, arm_md);
2893
2894 arm_md->object = arm_ob;
2898 }
2899
2901
2902 return OPERATOR_FINISHED;
2903}
2904
2906 wmOperator *op,
2907 const wmEvent * /*event*/)
2908{
2910 return skin_armature_create_exec(C, op);
2911 }
2912 return OPERATOR_CANCELLED;
2913}
2914
2916{
2917 ot->name = "Skin Armature Create";
2918 ot->description = "Create an armature that parallels the skin layout";
2919 ot->idname = "OBJECT_OT_skin_armature_create";
2920
2921 ot->poll = skin_poll;
2924
2925 /* flags */
2928}
2929
2931
2932/* ------------------------------------------------------------------- */
2935
2937{
2938 return edit_modifier_poll_generic(C, RNA_CorrectiveSmoothModifier, 0, true, false);
2939}
2940
2942{
2943 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
2944 Scene *scene = CTX_data_scene(C);
2948
2949 if (!csmd) {
2950 return OPERATOR_CANCELLED;
2951 }
2952
2954 BKE_report(op->reports, RPT_ERROR, "Modifier is disabled");
2955 return OPERATOR_CANCELLED;
2956 }
2957
2958 const bool is_bind = (csmd->bind_coords != nullptr);
2959
2961 MEM_SAFE_DELETE(csmd->delta_cache.deltas);
2962
2963 if (is_bind) {
2964 /* toggle off */
2965 csmd->bind_coords_num = 0;
2966 }
2967 else {
2968 /* Signal to modifier to recalculate. */
2969 CorrectiveSmoothModifierData *csmd_eval = reinterpret_cast<CorrectiveSmoothModifierData *>(
2970 BKE_modifier_get_evaluated(depsgraph, ob, &csmd->modifier));
2971 csmd_eval->bind_coords_num = uint(-1);
2972
2973 /* Force modifier to run, it will call binding routine
2974 * (this has to happen outside of depsgraph evaluation). */
2976 }
2977
2980
2981 return OPERATOR_FINISHED;
2982}
2983
2985 wmOperator *op,
2986 const wmEvent * /*event*/)
2987{
2989 return correctivesmooth_bind_exec(C, op);
2990 }
2991 return OPERATOR_CANCELLED;
2992}
2993
2995{
2996 /* identifiers */
2997 ot->name = "Corrective Smooth Bind";
2998 ot->description = "Bind base pose in Corrective Smooth modifier";
2999 ot->idname = "OBJECT_OT_correctivesmooth_bind";
3000
3001 /* API callbacks. */
3005
3006 /* flags */
3009}
3010
3012
3013/* ------------------------------------------------------------------- */
3016
3018{
3019 return edit_modifier_poll_generic(C, RNA_MeshDeformModifier, 0, true, false);
3020}
3021
3023{
3024 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3026 MeshDeformModifierData *mmd = reinterpret_cast<MeshDeformModifierData *>(
3028
3029 if (mmd == nullptr) {
3030 return OPERATOR_CANCELLED;
3031 }
3032
3033 if (mmd->bindcagecos != nullptr) {
3040 MEM_SAFE_DELETE(mmd->bindweights); /* Deprecated */
3041 MEM_SAFE_DELETE(mmd->bindcos); /* Deprecated */
3042 mmd->verts_num = 0;
3043 mmd->cage_verts_num = 0;
3044 mmd->influences_num = 0;
3045 }
3046 else {
3047 /* Force modifier to run, it will call binding routine
3048 * (this has to happen outside of depsgraph evaluation). */
3049 MeshDeformModifierData *mmd_eval = reinterpret_cast<MeshDeformModifierData *>(
3050 BKE_modifier_get_evaluated(depsgraph, ob, &mmd->modifier));
3053 mmd_eval->bindfunc = nullptr;
3054 }
3055
3058 return OPERATOR_FINISHED;
3059}
3060
3062 wmOperator *op,
3063 const wmEvent * /*event*/)
3064{
3066 return meshdeform_bind_exec(C, op);
3067 }
3068 return OPERATOR_CANCELLED;
3069}
3070
3072{
3073 /* identifiers */
3074 ot->name = "Mesh Deform Bind";
3075 ot->description = "Bind mesh to cage in mesh deform modifier";
3076 ot->idname = "OBJECT_OT_meshdeform_bind";
3077
3078 /* API callbacks. */
3079 ot->poll = meshdeform_poll;
3082
3083 /* flags */
3086}
3087
3089
3090/* ------------------------------------------------------------------- */
3093
3095{
3096 return edit_modifier_poll_generic(C, RNA_ExplodeModifier, 0, true, false);
3097}
3098
3100{
3102 ExplodeModifierData *emd = reinterpret_cast<ExplodeModifierData *>(
3104
3105 if (!emd) {
3106 return OPERATOR_CANCELLED;
3107 }
3108
3110
3113
3114 return OPERATOR_FINISHED;
3115}
3116
3118 wmOperator *op,
3119 const wmEvent * /*event*/)
3120{
3122 return explode_refresh_exec(C, op);
3123 }
3124 return OPERATOR_CANCELLED;
3125}
3126
3128{
3129 ot->name = "Explode Refresh";
3130 ot->description = "Refresh data in the Explode modifier";
3131 ot->idname = "OBJECT_OT_explode_refresh";
3132
3133 ot->poll = explode_poll;
3136
3137 /* flags */
3140}
3141
3143
3144/* ------------------------------------------------------------------- */
3147
3149{
3150 return edit_modifier_poll_generic(C, RNA_OceanModifier, 0, true, false);
3151}
3152
3163
3164static void oceanbake_free(void *customdata)
3165{
3166 OceanBakeJob *oj = static_cast<OceanBakeJob *>(customdata);
3167 MEM_delete(oj);
3168}
3169
3170/* called by oceanbake, only to check job 'stop' value */
3171static int oceanbake_breakjob(void * /*customdata*/)
3172{
3173 // OceanBakeJob *ob = (OceanBakeJob *)customdata;
3174 // return *(ob->stop);
3175
3176 /* this is not nice yet, need to make the jobs list template better
3177 * for identifying/acting upon various different jobs */
3178 /* but for now we'll reuse the render break... */
3179 return (G.is_break);
3180}
3181
3182/* called by oceanbake, wmJob sends notifier */
3183static void oceanbake_update(void *customdata, float progress, int *cancel)
3184{
3185 OceanBakeJob *oj = static_cast<OceanBakeJob *>(customdata);
3186
3187 if (oceanbake_breakjob(oj)) {
3188 *cancel = 1;
3189 }
3190
3191 *(oj->do_update) = true;
3192 *(oj->progress) = progress;
3193}
3194
3195static void oceanbake_startjob(void *customdata, wmJobWorkerStatus *worker_status)
3196{
3197 OceanBakeJob *oj = static_cast<OceanBakeJob *>(customdata);
3198
3199 oj->stop = &worker_status->stop;
3200 oj->do_update = &worker_status->do_update;
3201 oj->progress = &worker_status->progress;
3202
3203 G.is_break = false; /* XXX shared with render - replace with job 'stop' switch */
3204
3205 BKE_ocean_bake(oj->ocean, oj->och, oceanbake_update, static_cast<void *>(oj));
3206
3207 worker_status->do_update = true;
3208 worker_status->stop = false;
3209}
3210
3211static void oceanbake_endjob(void *customdata)
3212{
3213 OceanBakeJob *oj = static_cast<OceanBakeJob *>(customdata);
3214
3215 if (oj->ocean) {
3216 BKE_ocean_free(oj->ocean);
3217 oj->ocean = nullptr;
3218 }
3219
3220 oj->omd->oceancache = oj->och;
3221 oj->omd->cached = true;
3222
3223 Object *ob = oj->owner;
3225}
3226
3228{
3229 Main *bmain = CTX_data_main(C);
3231 OceanModifierData *omd = reinterpret_cast<OceanModifierData *>(
3233 Scene *scene = CTX_data_scene(C);
3234 const bool free = RNA_boolean_get(op->ptr, "free");
3235
3236 if (!omd) {
3237 return OPERATOR_CANCELLED;
3238 }
3239
3240 if (free) {
3244 return OPERATOR_FINISHED;
3245 }
3246
3248 BKE_modifier_path_relbase(bmain, ob),
3249 omd->bakestart,
3250 omd->bakeend,
3251 omd->wave_scale,
3252 omd->chop_amount,
3253 omd->foam_coverage,
3254 omd->foam_fade,
3255 omd->resolution);
3256
3257 och->time = MEM_new_array_uninitialized<float>(och->duration, "foam bake time");
3258
3259 int cfra = scene->r.cfra;
3260
3261 /* precalculate time variable before baking */
3262 int i = 0;
3263 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
3264 for (int f = omd->bakestart; f <= omd->bakeend; f++) {
3265 /* For now only simple animation of time value is supported, nothing else.
3266 * No drivers or other modifier parameters. */
3267 /* TODO(sergey): This operates on an original data, so no flush is needed. However, baking
3268 * usually should happen on an evaluated objects, so this seems to be deeper issue here. */
3269
3270 const AnimationEvalContext anim_eval_context = BKE_animsys_eval_context_construct(depsgraph,
3271 f);
3273 id_cast<ID *>(ob), ob->adt, &anim_eval_context, ADT_RECALC_ANIM, false);
3274
3275 och->time[i] = omd->time;
3276 i++;
3277 }
3278
3279 /* Make a copy of ocean to use for baking - thread-safety. */
3280 Ocean *ocean = BKE_ocean_add();
3281 BKE_ocean_init_from_modifier(ocean, omd, omd->resolution);
3282
3283#if 0
3284 BKE_ocean_bake(ocean, och);
3285
3286 omd->oceancache = och;
3287 omd->cached = true;
3288
3289 scene->r.cfra = cfra;
3290
3293#endif
3294
3295 /* job stuff */
3296
3297 scene->r.cfra = cfra;
3298
3299 /* setup job */
3300 wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C),
3302 scene,
3303 "Simulating ocean...",
3306 OceanBakeJob *oj = MEM_new_zeroed<OceanBakeJob>("ocean bake job");
3307 oj->owner = ob;
3308 oj->ocean = ocean;
3309 oj->och = och;
3310 oj->omd = omd;
3311
3314 WM_jobs_callbacks(wm_job, oceanbake_startjob, nullptr, nullptr, oceanbake_endjob);
3315
3316 WM_jobs_start(CTX_wm_manager(C), wm_job);
3317
3318 return OPERATOR_FINISHED;
3319}
3320
3322{
3324 return ocean_bake_exec(C, op);
3325 }
3326 return OPERATOR_CANCELLED;
3327}
3328
3330{
3331 ot->name = "Bake Ocean";
3332 ot->description = "Bake an image sequence of ocean data";
3333 ot->idname = "OBJECT_OT_ocean_bake";
3334
3335 ot->poll = ocean_bake_poll;
3337 ot->exec = ocean_bake_exec;
3338
3339 /* flags */
3342
3343 RNA_def_boolean(ot->srna, "free", false, "Free", "Free the bake, rather than generating it");
3344}
3345
3347
3348/* ------------------------------------------------------------------- */
3351
3353{
3354 return edit_modifier_poll_generic(C, RNA_LaplacianDeformModifier, 0, false, false);
3355}
3356
3358{
3360 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3363
3364 if (lmd == nullptr) {
3365 return OPERATOR_CANCELLED;
3366 }
3367
3368 if (lmd->flag & MOD_LAPLACIANDEFORM_BIND) {
3370 }
3371 else {
3373 }
3374
3375 LaplacianDeformModifierData *lmd_eval = reinterpret_cast<LaplacianDeformModifierData *>(
3376 BKE_modifier_get_evaluated(depsgraph, ob, &lmd->modifier));
3377 lmd_eval->flag = lmd->flag;
3378
3379 /* Force modifier to run, it will call binding routine
3380 * (this has to happen outside of depsgraph evaluation). */
3382
3383 /* This is hard to know from the modifier itself whether the evaluation is
3384 * happening for binding or not. So we copy all the required data here. */
3385 lmd->verts_num = lmd_eval->verts_num;
3386 if (lmd_eval->vertexco == nullptr) {
3388 }
3389 else {
3391 lmd_eval->vertexco_sharing_info,
3392 &lmd->vertexco,
3393 &lmd->vertexco_sharing_info);
3394 }
3395
3398 return OPERATOR_FINISHED;
3399}
3400
3402 wmOperator *op,
3403 const wmEvent * /*event*/)
3404{
3406 return laplaciandeform_bind_exec(C, op);
3407 }
3408 return OPERATOR_CANCELLED;
3409}
3410
3412{
3413 /* identifiers */
3414 ot->name = "Laplacian Deform Bind";
3415 ot->description = "Bind mesh to system in laplacian deform modifier";
3416 ot->idname = "OBJECT_OT_laplaciandeform_bind";
3417
3418 /* API callbacks. */
3422
3423 /* flags */
3426}
3427
3429
3430/* ------------------------------------------------------------------- */
3433
3435{
3436 return edit_modifier_poll_generic(C, RNA_SurfaceDeformModifier, 0, true, false);
3437}
3438
3440{
3442 Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
3443 SurfaceDeformModifierData *smd = reinterpret_cast<SurfaceDeformModifierData *>(
3445
3446 if (smd == nullptr) {
3447 return OPERATOR_CANCELLED;
3448 }
3449
3450 if (smd->flags & MOD_SDEF_BIND) {
3451 smd->flags &= ~MOD_SDEF_BIND;
3452 }
3453 else if (smd->target) {
3454 smd->flags |= MOD_SDEF_BIND;
3455 }
3456
3457 SurfaceDeformModifierData *smd_eval = reinterpret_cast<SurfaceDeformModifierData *>(
3458 BKE_modifier_get_evaluated(depsgraph, ob, &smd->modifier));
3459 smd_eval->flags = smd->flags;
3460
3461 /* Force modifier to run, it will call binding routine
3462 * (this has to happen outside of depsgraph evaluation). */
3464
3467 return OPERATOR_FINISHED;
3468}
3469
3471 wmOperator *op,
3472 const wmEvent * /*event*/)
3473{
3475 return surfacedeform_bind_exec(C, op);
3476 }
3477 return OPERATOR_CANCELLED;
3478}
3479
3481{
3482 /* identifiers */
3483 ot->name = "Surface Deform Bind";
3484 ot->description = "Bind mesh to target in surface deform modifier";
3485 ot->idname = "OBJECT_OT_surfacedeform_bind";
3486
3487 /* API callbacks. */
3491
3492 /* flags */
3495}
3496
3498
3499/* ------------------------------------------------------------------- */
3506
3508{
3510
3511 char modifier_name[MAX_NAME];
3512 RNA_string_get(op->ptr, "modifier_name", modifier_name);
3513 NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(
3514 BKE_modifiers_findby_name(ob, modifier_name));
3515 if (nmd == nullptr) {
3516 return OPERATOR_CANCELLED;
3517 }
3518
3519 char input_name[MAX_NAME];
3520 RNA_string_get(op->ptr, "input_name", input_name);
3521
3522 PointerRNA modifier_ptr = RNA_pointer_create_discrete(&ob->id, RNA_NodesModifier, nmd);
3523 PointerRNA properties_ptr = RNA_pointer_get(&modifier_ptr, "properties");
3524 PointerRNA inputs_ptr = RNA_pointer_get(&properties_ptr, "inputs");
3525 PointerRNA input_ptr = RNA_pointer_get(&inputs_ptr, input_name);
3526 PropertyRNA *type_prop = RNA_struct_find_property(&input_ptr, "type");
3527 if (!type_prop) {
3528 return OPERATOR_CANCELLED;
3529 }
3530
3531 int type = RNA_property_enum_get(&input_ptr, type_prop);
3534 }
3535 else {
3537 }
3538 EnumPropertyItem type_item;
3539 if (!RNA_property_enum_item_from_value(nullptr, &input_ptr, type_prop, type, &type_item)) {
3540 return OPERATOR_CANCELLED;
3541 }
3542 RNA_property_enum_set(&input_ptr, type_prop, type);
3543
3546 return OPERATOR_FINISHED;
3547}
3548
3550{
3551 ot->name = "Input Attribute Toggle";
3552 ot->description =
3553 "Switch between an attribute and a single value to define the data for every element";
3554 ot->idname = "OBJECT_OT_geometry_nodes_input_attribute_toggle";
3555
3558
3560
3561 RNA_def_string(ot->srna, "input_name", nullptr, 0, "Input Name", "");
3562 RNA_def_string(ot->srna, "modifier_name", nullptr, MAX_NAME, "Modifier Name", "");
3563}
3564
3566
3567/* ------------------------------------------------------------------- */
3570
3572{
3573 Main *bmain = CTX_data_main(C);
3576 if (!(md && md->type == eModifierType_Nodes)) {
3577 return OPERATOR_CANCELLED;
3578 }
3579
3580 NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
3581 bNodeTree *tree = nmd->node_group;
3582 if (tree == nullptr || ID_MISSING(tree)) {
3583 return OPERATOR_CANCELLED;
3584 }
3585
3586 bNodeTree *new_tree = id_cast<bNodeTree *>(
3587 BKE_id_copy_ex(bmain, &tree->id, nullptr, LIB_ID_COPY_ACTIONS | LIB_ID_COPY_DEFAULT));
3588
3590
3591 if (new_tree == nullptr) {
3592 return OPERATOR_CANCELLED;
3593 }
3594
3595 nmd->node_group = new_tree;
3596 id_us_min(&tree->id);
3597
3602 return OPERATOR_FINISHED;
3603}
3604
3606{
3607 ot->name = "New Geometry Node Group";
3608 ot->description =
3609 "Duplicate the active geometry node group and assign it to the active modifier";
3610 ot->idname = "OBJECT_OT_geometry_node_tree_copy_assign";
3611
3614
3616}
3617
3619
3620/* ------------------------------------------------------------------- */
3623
3625{
3626 return edit_modifier_poll_generic(C, RNA_GreasePencilDashModifierData, 0, false, false);
3627}
3628
3630{
3632 auto *dmd = reinterpret_cast<GreasePencilDashModifierData *>(
3634
3635 if (dmd == nullptr) {
3636 return OPERATOR_CANCELLED;
3637 }
3638
3639 GreasePencilDashModifierSegment *new_segments = MEM_new_array<GreasePencilDashModifierSegment>(
3640 dmd->segments_num + 1, __func__);
3641
3642 const int new_active_index = std::clamp(dmd->segment_active_index + 1, 0, dmd->segments_num);
3643 if (dmd->segments_num != 0) {
3644 /* Copy the segments before the new segment. */
3645 memcpy(new_segments,
3646 dmd->segments_array,
3647 sizeof(GreasePencilDashModifierSegment) * new_active_index);
3648 /* Copy the segments after the new segment. */
3649 memcpy(new_segments + new_active_index + 1,
3650 dmd->segments_array + new_active_index,
3651 sizeof(GreasePencilDashModifierSegment) * (dmd->segments_num - new_active_index));
3652 }
3653
3654 /* Create the new segment. */
3655 GreasePencilDashModifierSegment *ds = &new_segments[new_active_index];
3658 [&](const StringRef name) {
3659 for (const GreasePencilDashModifierSegment &ds : dmd->segments()) {
3660 if (STREQ(ds.name, name.data())) {
3661 return true;
3662 }
3663 }
3664 return false;
3665 },
3666 '.',
3667 ds->name);
3668
3669 MEM_SAFE_DELETE(dmd->segments_array);
3670 dmd->segments_array = new_segments;
3671 dmd->segments_num++;
3672 dmd->segment_active_index = new_active_index;
3673
3676
3677 return OPERATOR_FINISHED;
3678}
3679
3681 wmOperator *op,
3682 const wmEvent * /*event*/)
3683{
3686 }
3687 return OPERATOR_CANCELLED;
3688}
3689
3691{
3692 /* identifiers */
3693 ot->name = "Add Segment";
3694 ot->description = "Add a segment to the dash modifier";
3695 ot->idname = "OBJECT_OT_grease_pencil_dash_modifier_segment_add";
3696
3697 /* API callbacks. */
3701
3702 /* flags */
3705}
3706
3708
3710{
3712 auto *dmd = reinterpret_cast<GreasePencilDashModifierData *>(
3714
3715 if (dmd == nullptr) {
3716 return OPERATOR_CANCELLED;
3717 }
3718
3719 if (!dmd->segments().index_range().contains(dmd->segment_active_index)) {
3720 return OPERATOR_CANCELLED;
3721 }
3722
3723 dna::array::remove_index(&dmd->segments_array,
3724 &dmd->segments_num,
3725 &dmd->segment_active_index,
3726 dmd->segment_active_index,
3728
3731
3732 return OPERATOR_FINISHED;
3733}
3734
3736 wmOperator *op,
3737 const wmEvent * /*event*/)
3738{
3741 }
3742 return OPERATOR_CANCELLED;
3743}
3744
3746{
3747 /* identifiers */
3748 ot->name = "Remove Dash Segment";
3749 ot->description = "Remove the active segment from the dash modifier";
3750 ot->idname = "OBJECT_OT_grease_pencil_dash_modifier_segment_remove";
3751
3752 /* API callbacks. */
3756
3757 /* flags */
3760
3762 ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of the segment to remove", 0, INT_MAX);
3763}
3764
3766 Up = -1,
3767 Down = 1,
3768};
3769
3771{
3773 auto *dmd = reinterpret_cast<GreasePencilDashModifierData *>(
3775
3776 if (dmd == nullptr) {
3777 return OPERATOR_CANCELLED;
3778 }
3779
3780 if (dmd->segments_num < 2) {
3781 return OPERATOR_CANCELLED;
3782 }
3783
3785 RNA_enum_get(op->ptr, "type"));
3786 switch (direction) {
3788 if (dmd->segment_active_index == 0) {
3789 return OPERATOR_CANCELLED;
3790 }
3791
3792 std::swap(dmd->segments_array[dmd->segment_active_index],
3793 dmd->segments_array[dmd->segment_active_index - 1]);
3794
3795 dmd->segment_active_index--;
3796 break;
3798 if (dmd->segment_active_index == dmd->segments_num - 1) {
3799 return OPERATOR_CANCELLED;
3800 }
3801
3802 std::swap(dmd->segments_array[dmd->segment_active_index],
3803 dmd->segments_array[dmd->segment_active_index + 1]);
3804
3805 dmd->segment_active_index++;
3806 break;
3807 default:
3808 return OPERATOR_CANCELLED;
3809 }
3810
3813
3814 return OPERATOR_FINISHED;
3815}
3816
3818 wmOperator *op,
3819 const wmEvent * /*event*/)
3820{
3823 }
3824 return OPERATOR_CANCELLED;
3825}
3826
3828{
3829 static const EnumPropertyItem segment_move[] = {
3830 {int(DashSegmentMoveDirection::Up), "UP", 0, "Up", ""},
3831 {int(DashSegmentMoveDirection::Down), "DOWN", 0, "Down", ""},
3832 {0, nullptr, 0, nullptr, nullptr},
3833 };
3834
3835 /* identifiers */
3836 ot->name = "Move Dash Segment";
3837 ot->description = "Move the active dash segment up or down";
3838 ot->idname = "OBJECT_OT_grease_pencil_dash_modifier_segment_move";
3839
3840 /* API callbacks. */
3844
3845 /* flags */
3848
3849 ot->prop = RNA_def_enum(ot->srna, "type", segment_move, 0, "Type", "");
3850}
3851
3853
3854/* ------------------------------------------------------------------- */
3857
3859{
3860 return edit_modifier_poll_generic(C, RNA_GreasePencilTimeModifier, 0, false, false);
3861}
3862
3864{
3866 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(
3868
3869 if (tmd == nullptr) {
3870 return OPERATOR_CANCELLED;
3871 }
3872
3873 GreasePencilTimeModifierSegment *new_segments = MEM_new_array<GreasePencilTimeModifierSegment>(
3874 tmd->segments_num + 1, __func__);
3875
3876 const int new_active_index = std::clamp(tmd->segment_active_index + 1, 0, tmd->segments_num);
3877 if (tmd->segments_num != 0) {
3878 /* Copy the segments before the new segment. */
3879 memcpy(new_segments,
3880 tmd->segments_array,
3881 sizeof(GreasePencilTimeModifierSegment) * new_active_index);
3882 /* Copy the segments after the new segment. */
3883 memcpy(new_segments + new_active_index + 1,
3884 tmd->segments_array + new_active_index,
3885 sizeof(GreasePencilTimeModifierSegment) * (tmd->segments_num - new_active_index));
3886 }
3887
3888 /* Create the new segment. */
3889 GreasePencilTimeModifierSegment *segment = &new_segments[new_active_index];
3892 [&](const StringRef name) {
3893 for (const GreasePencilTimeModifierSegment &segment : tmd->segments()) {
3894 if (STREQ(segment.name, name.data())) {
3895 return true;
3896 }
3897 }
3898 return false;
3899 },
3900 '.',
3901 segment->name);
3902
3903 MEM_SAFE_DELETE(tmd->segments_array);
3904 tmd->segments_array = new_segments;
3905 tmd->segments_num++;
3906 tmd->segment_active_index++;
3907
3910
3911 return OPERATOR_FINISHED;
3912}
3913
3915 wmOperator *op,
3916 const wmEvent * /*event*/)
3917{
3920 }
3921 return OPERATOR_CANCELLED;
3922}
3923
3925{
3926 /* identifiers */
3927 ot->name = "Add Segment";
3928 ot->description = "Add a segment to the time modifier";
3929 ot->idname = "OBJECT_OT_grease_pencil_time_modifier_segment_add";
3930
3931 /* API callbacks. */
3935
3936 /* flags */
3939}
3940
3942
3944{
3946 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(
3948
3949 if (tmd == nullptr) {
3950 return OPERATOR_CANCELLED;
3951 }
3952
3953 if (!tmd->segments().index_range().contains(tmd->segment_active_index)) {
3954 return OPERATOR_CANCELLED;
3955 }
3956
3957 dna::array::remove_index(&tmd->segments_array,
3958 &tmd->segments_num,
3959 &tmd->segment_active_index,
3960 tmd->segment_active_index,
3962
3965
3966 return OPERATOR_FINISHED;
3967}
3968
3970 wmOperator *op,
3971 const wmEvent * /*event*/)
3972{
3975 }
3976 return OPERATOR_CANCELLED;
3977}
3978
3980{
3981 /* identifiers */
3982 ot->name = "Remove Segment";
3983 ot->description = "Remove the active segment from the time modifier";
3984 ot->idname = "OBJECT_OT_grease_pencil_time_modifier_segment_remove";
3985
3986 /* API callbacks. */
3990
3991 /* flags */
3994
3996 ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of the segment to remove", 0, INT_MAX);
3997}
3998
4000 Up = -1,
4001 Down = 1,
4002};
4003
4005{
4007 auto *tmd = reinterpret_cast<GreasePencilTimeModifierData *>(
4009
4010 if (tmd == nullptr) {
4011 return OPERATOR_CANCELLED;
4012 }
4013
4014 if (tmd->segments_num < 2) {
4015 return OPERATOR_CANCELLED;
4016 }
4017
4019 RNA_enum_get(op->ptr, "type"));
4020 switch (direction) {
4022 if (tmd->segment_active_index == 0) {
4023 return OPERATOR_CANCELLED;
4024 }
4025
4026 std::swap(tmd->segments_array[tmd->segment_active_index],
4027 tmd->segments_array[tmd->segment_active_index - 1]);
4028
4029 tmd->segment_active_index--;
4030 break;
4032 if (tmd->segment_active_index == tmd->segments_num - 1) {
4033 return OPERATOR_CANCELLED;
4034 }
4035
4036 std::swap(tmd->segments_array[tmd->segment_active_index],
4037 tmd->segments_array[tmd->segment_active_index + 1]);
4038
4039 tmd->segment_active_index++;
4040 break;
4041 default:
4042 return OPERATOR_CANCELLED;
4043 }
4044
4047
4048 return OPERATOR_FINISHED;
4049}
4050
4052 wmOperator *op,
4053 const wmEvent * /*event*/)
4054{
4057 }
4058 return OPERATOR_CANCELLED;
4059}
4060
4062{
4063 static const EnumPropertyItem segment_move[] = {
4064 {int(TimeSegmentMoveDirection::Up), "UP", 0, "Up", ""},
4065 {int(TimeSegmentMoveDirection::Down), "DOWN", 0, "Down", ""},
4066 {0, nullptr, 0, nullptr, nullptr},
4067 };
4068
4069 /* identifiers */
4070 ot->name = "Move Segment";
4071 ot->description = "Move the active time segment up or down";
4072 ot->idname = "OBJECT_OT_grease_pencil_time_modifier_segment_move";
4073
4074 /* API callbacks. */
4078
4079 /* flags */
4082
4083 ot->prop = RNA_def_enum(ot->srna, "type", segment_move, 0, "Type", "");
4084}
4085
4087
4088} // namespace blender::ed::object
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
Low-level operations for curves that cannot be defined in the C++ header yet.
Low-level operations for curves.
display list (or rather multi purpose list) stuff.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
General operations for point clouds.
Volume data-block.
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition BLI_bitmap.hh:39
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition BLI_bitmap.hh:63
#define BLI_BITMAP_ENABLE(_bitmap, _index)
Definition BLI_bitmap.hh:80
#define SNPRINTF_UTF8(dst, format,...)
#define STRNCPY_UTF8(dst, src)
#define RPT_(msgid)
#define TIP_(msgid)
#define IFACE_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_REAL_USERS(id)
Definition DNA_ID.h:679
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define ID_MISSING(_id)
Definition DNA_ID.h:695
#define MAX_NAME
Definition DNA_defs.h:63
#define WEIGHT_REPLACE
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_MODE
Definition WM_types.hh:464
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define ND_MODIFIER
Definition WM_types.hh:503
#define NS_MODE_OBJECT
Definition WM_types.hh:610
#define NA_REMOVED
Definition WM_types.hh:637
#define NC_OBJECT
Definition WM_types.hh:392
#define BLI_assert_unreachable()
#define ELEM(...)
#define STREQ(a, b)
#define BM_ELEM_CD_SET_BOOL(ele, offset, f)
#define BM_ELEM_CD_GET_VOID_P(ele, offset)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
static IndexMask from_indices(Span< T > indices, LinearAllocator<> &memory)
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
int64_t size() const
Definition BLI_map.hh:976
KeyIterator keys() const &
Definition BLI_map.hh:875
Value & lookup_or_add(const Key &key, const Value &value)
Definition BLI_map.hh:588
bool add(const Key &key)
Definition BLI_set.hh:248
constexpr const T * data() const
Definition BLI_span.hh:219
void append(const T &value)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
constexpr const char * data() const
#define INT_MAX
#define layer
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
void ensure_non_empty_layer_names(Main &bmain, GreasePencil &grease_pencil)
int edge_other_vert(const int2 edge, const int vert)
Definition BKE_mesh.hh:370
GroupedSpan< int > build_vert_to_edge_map(Span< int2 > edges, int verts_num, Array< int > &r_offsets, Array< int > &r_indices)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
void mesh_remove_invalid_attribute_strings(Mesh &mesh)
void curves_store_surface_in_geometry_bundle(const Depsgraph &depsgraph, const Curves &curves, GeometrySet &geometry)
const Mesh * mesh_get_eval_deform(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
void mesh_ensure_active_uv_map(Mesh &mesh)
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
void remove_index(T **items, int *items_num, int *active_index, const int index, void(*destruct_item)(T *))
void apply_eval_grease_pencil_data(const GreasePencil &eval_grease_pencil, const int eval_frame, const IndexMask &orig_layers, GreasePencil &orig_grease_pencil)
void modifier_register_use_selected_objects_prop(wmOperatorType *ot)
static void skin_armature_bone_create(Object *skin_ob, const Span< float3 > positions, const int2 *edges, bArmature *arm, BLI_bitmap *edges_visited, const GroupedSpan< int > emap, EditBone *parent_bone, int parent_v)
static wmOperatorStatus modifier_apply_exec_ex(bContext *C, wmOperator *op, int apply_as, bool keep_modifier)
ModifierData * modifier_add(ReportList *reports, Main *bmain, Scene *scene, Object *ob, const char *name, int type)
void single_obdata_user_make(Main *bmain, Scene *scene, Object *ob)
static wmOperatorStatus modifier_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus modifier_copy_to_selected_exec(bContext *C, wmOperator *op)
bool modifier_apply(Main *bmain, ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md, int mode, bool keep_modifier, bool do_all_keyframes)
static wmOperatorStatus laplaciandeform_bind_exec(bContext *C, wmOperator *op)
static bool object_modifier_remove(Main *bmain, Scene *scene, Object *ob, ModifierData *md, bool *r_sort_depsgraph)
static int oceanbake_breakjob(void *)
static wmOperatorStatus modifier_move_to_index_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool modifier_apply_shape(Main *bmain, ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md_eval)
static wmOperatorStatus time_modifier_segment_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_geometry_node_tree_copy_assign(wmOperatorType *ot)
static wmOperatorStatus skin_radii_equalize_exec(bContext *C, wmOperator *)
static bool object_modifier_safe_to_delete(Main *bmain, Object *ob, ModifierData *exclude, ModifierType type)
static wmOperatorStatus meshdeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus modifier_apply_exec(bContext *C, wmOperator *op)
static wmOperatorStatus modifier_apply_as_shapekey_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus modifier_move_up_exec(bContext *C, wmOperator *op)
static std::string modifier_apply_as_shapekey_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
static void skin_root_clear(BMVert *bm_vert, Set< BMVert * > &visited, const int cd_skin_root_offset)
static bool correctivesmooth_poll(bContext *C)
static bool object_modifier_check_move_after(ReportList *reports, eReportType error_type, ModifierData *md, ModifierData *md_next)
static const EnumPropertyItem * modifier_add_itemf(bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
static bool edit_modifier_poll(bContext *C)
static wmOperatorStatus modifier_set_active_exec(bContext *C, wmOperator *op)
static void oceanbake_startjob(void *customdata, wmJobWorkerStatus *worker_status)
static wmOperatorStatus dash_modifier_segment_add_exec(bContext *C, wmOperator *op)
bool edit_modifier_invoke_properties(bContext *C, wmOperator *op)
static void edit_modifier_report_property(wmOperatorType *ot)
static wmOperatorStatus modifier_remove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_grease_pencil_dash_modifier_segment_add(wmOperatorType *ot)
static void oceanbake_endjob(void *customdata)
bool iter_other(Main *bmain, Object *orig_ob, bool include_orig, bool(*callback)(Object *ob, void *callback_data), void *callback_data)
static bool ocean_bake_poll(bContext *C)
static wmOperatorStatus modifier_apply_as_shapekey_exec(bContext *C, wmOperator *op)
static wmOperatorStatus geometry_nodes_input_attribute_toggle_exec(bContext *C, wmOperator *op)
static wmOperatorStatus dash_modifier_segment_remove_exec(bContext *C, wmOperator *op)
bool modifier_move_up(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md)
static wmOperatorStatus modifier_copy_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_meshdeform_bind(wmOperatorType *ot)
static wmOperatorStatus meshdeform_bind_exec(bContext *C, wmOperator *op)
static wmOperatorStatus modifier_convert_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus skin_armature_create_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus time_modifier_segment_add_exec(bContext *C, wmOperator *op)
void OBJECT_OT_modifier_move_to_index(wmOperatorType *ot)
static wmOperatorStatus modifiers_clear_exec(bContext *C, wmOperator *)
static void object_force_modifier_bind_simple_options(Depsgraph *depsgraph, Object *object, ModifierData *md)
bool multires_update_totlevels(Object *ob, void *totlevel_v)
void OBJECT_OT_explode_refresh(wmOperatorType *ot)
void OBJECT_OT_ocean_bake(wmOperatorType *ot)
void OBJECT_OT_skin_root_mark(wmOperatorType *ot)
static wmOperatorStatus skin_loose_mark_clear_exec(bContext *C, wmOperator *op)
static bool apply_grease_pencil_for_modifier(Depsgraph *depsgraph, Object *ob, GreasePencil &grease_pencil_orig, ModifierData *md_eval)
static wmOperatorStatus modifier_copy_to_selected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus correctivesmooth_bind_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool edit_modifier_liboverride_allowed_poll(bContext *C)
static wmOperatorStatus time_modifier_segment_remove_exec(bContext *C, wmOperator *op)
static bool modifier_apply_as_shapekey_poll(bContext *C)
static wmOperatorStatus time_modifier_segment_remove_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_modifier_move_down(wmOperatorType *ot)
static bool surfacedeform_bind_poll(bContext *C)
void OBJECT_OT_modifier_remove(wmOperatorType *ot)
static wmOperatorStatus surfacedeform_bind_exec(bContext *C, wmOperator *op)
void OBJECT_OT_grease_pencil_dash_modifier_segment_remove(wmOperatorType *ot)
static wmOperatorStatus dash_modifier_segment_move_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_modifier_apply(wmOperatorType *ot)
static void oceanbake_update(void *customdata, float progress, int *cancel)
ModifierData * modifier_copy_to_object(Main *bmain, const Scene *scene, const Object *ob_src, const ModifierData *md, Object *ob_dst, ReportList *reports)
bool edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag, bool is_editmode_allowed, bool is_liboverride_allowed)
static void dash_modifier_segment_free(GreasePencilDashModifierSegment *)
static Mesh * create_applied_mesh_for_modifier(Depsgraph *depsgraph, Scene *scene, Object *ob_eval, ModifierData *md_eval, const bool use_virtual_modifiers, const bool build_shapekey_layers, ReportList *reports)
void OBJECT_OT_modifier_apply_as_shapekey(wmOperatorType *ot)
static bool modifier_apply_obdata(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md_eval, const bool do_all_keyframes)
static wmOperatorStatus modifier_remove_exec(bContext *C, wmOperator *op)
ModifierData * edit_modifier_property_get(wmOperator *op, Object *ob, int type)
static bool time_modifier_segment_poll(bContext *C)
static bool skin_edit_poll(bContext *C)
void OBJECT_OT_modifier_convert(wmOperatorType *ot)
void OBJECT_OT_grease_pencil_time_modifier_segment_move(wmOperatorType *ot)
bool modifier_copy(ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
static bool edit_modifier_invoke_properties_with_hover(bContext *C, wmOperator *op, const wmEvent *event, wmOperatorStatus *r_retval)
static bool meshdeform_poll(bContext *C)
static bool apply_grease_pencil_for_modifier_all_keyframes(Depsgraph *depsgraph, Scene *scene, Object *ob, GreasePencil &grease_pencil_orig, ModifierData *md)
static bool modifiers_copy_to_selected_poll(bContext *C)
Object * context_active_object(const bContext *C)
static wmOperatorStatus object_modifiers_copy_exec(bContext *C, wmOperator *op)
static bool modifiers_clear_poll(bContext *C)
bool modifier_move_down(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md)
static wmOperatorStatus time_modifier_segment_move_exec(bContext *C, wmOperator *op)
static wmOperatorStatus modifier_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void add_shapekey_layers(Mesh &mesh_dest, const Mesh &mesh_src)
static wmOperatorStatus modifier_apply_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static Object * modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Object *skin_ob)
static wmOperatorStatus explode_refresh_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus laplaciandeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *)
void OBJECT_OT_modifier_move_up(wmOperatorType *ot)
static wmOperatorStatus correctivesmooth_bind_exec(bContext *C, wmOperator *op)
void OBJECT_OT_geometry_nodes_input_attribute_toggle(wmOperatorType *ot)
void OBJECT_OT_modifiers_copy_to_selected(wmOperatorType *ot)
static wmOperatorStatus dash_modifier_segment_remove_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool laplaciandeform_poll(bContext *C)
static wmOperatorStatus skin_root_mark_exec(bContext *C, wmOperator *)
static bool object_modifier_check_move_before(ReportList *reports, eReportType error_type, ModifierData *md, ModifierData *md_prev)
static wmOperatorStatus surfacedeform_bind_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus skin_armature_create_exec(bContext *C, wmOperator *op)
static bool skin_poll(bContext *C)
static void oceanbake_free(void *customdata)
static wmOperatorStatus modifier_convert_exec(bContext *C, wmOperator *op)
void OBJECT_OT_correctivesmooth_bind(wmOperatorType *ot)
static wmOperatorStatus modifier_move_down_exec(bContext *C, wmOperator *op)
void OBJECT_OT_surfacedeform_bind(wmOperatorType *ot)
void OBJECT_OT_skin_radii_equalize(wmOperatorType *ot)
static bool modifier_apply_poll(bContext *C)
static Object * edit_modifier_object_get(bContext *C, const PointerRNA &ptr)
bool convert_psys_to_mesh(ReportList *reports, Main *bmain, Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Object *ob, ModifierData *md)
bool modifier_move_to_index(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md, int index, bool allow_partial)
void OBJECT_OT_modifier_add(wmOperatorType *ot)
static wmOperatorStatus explode_refresh_exec(bContext *C, wmOperator *op)
static wmOperatorStatus modifier_move_to_index_exec(bContext *C, wmOperator *op)
void OBJECT_OT_modifier_copy(wmOperatorType *ot)
void OBJECT_OT_laplaciandeform_bind(wmOperatorType *ot)
static wmOperatorStatus dash_modifier_segment_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
static bool object_has_modifier(const Object *ob, const ModifierData *exclude, ModifierType type)
void vgroup_vert_add(Object *ob, bDeformGroup *dg, int vertnum, float weight, int assignmode)
static wmOperatorStatus dash_modifier_segment_move_exec(bContext *C, wmOperator *op)
static PointerRNA edit_modifier_ptr_get(bContext *C, StructRNA *rna_type)
static wmOperatorStatus geometry_node_tree_copy_assign_exec(bContext *C, wmOperator *)
void OBJECT_OT_skin_loose_mark_clear(wmOperatorType *ot)
static bool object_has_modifier_cb(Object *ob, void *data)
static bool dash_modifier_segment_poll(bContext *C)
void OBJECT_OT_modifier_copy_to_selected(wmOperatorType *ot)
void OBJECT_OT_modifier_set_active(wmOperatorType *ot)
static void time_modifier_segment_free(GreasePencilTimeModifierSegment *)
static wmOperatorStatus ocean_bake_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus time_modifier_segment_move_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus modifier_move_up_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void OBJECT_OT_modifiers_clear(wmOperatorType *ot)
static wmOperatorStatus modifier_copy_exec(bContext *C, wmOperator *op)
static bool modifier_copy_to_selected_poll(bContext *C)
void OBJECT_OT_grease_pencil_time_modifier_segment_remove(wmOperatorType *ot)
Vector< PointerRNA > modifier_get_edit_objects(const bContext &C, const wmOperator &op)
void modifier_link(bContext *C, Object *ob_dst, Object *ob_src)
static CLG_LogRef LOG
void modifiers_clear(Main *bmain, Scene *scene, Object *ob)
void OBJECT_OT_grease_pencil_time_modifier_segment_add(wmOperatorType *ot)
void OBJECT_OT_grease_pencil_dash_modifier_segment_move(wmOperatorType *ot)
static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Object *ob)
static wmOperatorStatus modifier_move_down_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void edit_modifier_properties(wmOperatorType *ot)
static void modifier_skin_customdata_delete(Object *ob)
void OBJECT_OT_skin_armature_create(wmOperatorType *ot)
static bool explode_poll(bContext *C)
static wmOperatorStatus ocean_bake_exec(bContext *C, wmOperator *op)
bool modifier_remove(ReportList *reports, Main *bmain, Scene *scene, Object *ob, ModifierData *md)
static wmOperatorStatus modifier_set_active_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void copy_shared_pointer(T *src_ptr, const ImplicitSharingInfo *src_sharing_info, T **r_dst_ptr, const ImplicitSharingInfo **r_dst_sharing_info)
void free_shared_data(T **data, const ImplicitSharingInfo **sharing_info)
PointerRNA * region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event)
PointCloud * BKE_pointcloud_copy_for_eval(const PointCloud *pointcloud_src)
void WM_main_add_notifier(uint type, void *reference)
bool BM_data_layer_free_named(BMesh *bm, CustomData *data, StringRef name)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
const EnumPropertyItem rna_enum_object_modifier_type_items[]
void BKE_modifier_copydata(const ModifierData *md, ModifierData *target)
Object * BKE_object_add(Main *bmain, Scene *scene, ViewLayer *view_layer, ObjectType type, const char *name) ATTR_NONNULL(1
Definition object.cc:2296
void BKE_object_eval_reset(Object *ob_eval)
struct PartDeflect * BKE_partdeflect_new(ePFieldType type)
Definition effect.cc:76
void BKE_mesh_merge_customdata_for_apply_modifier(Mesh *mesh)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2953
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
ModifierData * BKE_modifiers_findby_name(const Object *ob, const char *name)
struct ModifierData * object_add_particle_system(struct Main *bmain, const struct Scene *scene, struct Object *ob, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void object_remove_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:4031
@ ADT_RECALC_ANIM
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
const CustomData_MeshMasks CD_MASK_BAREMESH
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition mball.cc:648
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void WM_jobs_callbacks(wmJob *wm_job, wm_jobs_start_callback startjob, void(*initjob)(void *), void(*update)(void *), void(*endjob)(void *))
Definition wm_jobs.cc:407
bool BKE_modifier_is_nonlocal_in_liboverride(const Object *ob, const ModifierData *md)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void ED_armature_from_edit(Main *bmain, bArmature *arm)
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
void DEG_graph_free(Depsgraph *graph)
Definition depsgraph.cc:307
PointerRNA RNA_id_pointer_create(ID *id)
@ BASE_ENABLED_VIEWPORT
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void BKE_keyblock_convert_to_mesh(const KeyBlock *kb, MutableSpan< float3 > vert_positions)
Definition key.cc:1697
void BKE_volume_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
@ WM_JOB_TYPE_OBJECT_SIM_OCEAN
Definition WM_api.hh:2015
void BKE_ocean_free_modifier_cache(struct OceanModifierData *omd)
Definition ocean.cc:1682
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
@ eModifierType_LaplacianDeform
@ eModifierType_ParticleSystem
@ eModifierType_GreasePencilDash
@ eModifierType_GreasePencilTime
@ eModifierType_CorrectiveSmooth
@ eModifierType_SurfaceDeform
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
Depsgraph * DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
Definition depsgraph.cc:279
void BKE_ocean_free(struct Ocean *oc)
Definition ocean.cc:1618
struct ModifierData * object_copy_particle_system(struct Main *bmain, const struct Scene *scene, struct Object *ob, const struct ParticleSystem *psys_orig)
int RNA_int_get(PointerRNA *ptr, const char *name)
void BKE_ocean_bake(struct Ocean *o, struct OceanCache *och, void(*update_cb)(void *, float progress, int *cancel), void *update_cb_data)
Definition ocean.cc:1664
ModifierData * BKE_modifier_get_evaluated(Depsgraph *depsgraph, Object *object, ModifierData *md)
wmWindow * CTX_wm_window(const bContext *C)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void(*free)(void *customdata))
Definition wm_jobs.cc:377
Array< float3 > BKE_lattice_vert_coords_alloc(const Lattice *lt)
Definition lattice.cc:502
@ WM_JOB_PROGRESS
Definition WM_api.hh:1997
bool ED_operator_object_active_local_editable(bContext *C)
void DEG_evaluate_on_refresh(Depsgraph *graph, DepsgraphEvaluateSyncWriteback sync_writeback=DEG_EVALUATE_SYNC_WRITEBACK_NO)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool BKE_object_supports_modifiers(const Object *ob)
Definition object.cc:1449
@ LIB_ID_COPY_LOCALIZE
@ LIB_ID_COPY_DEFAULT
@ LIB_ID_COPY_ACTIONS
ViewLayer * CTX_data_view_layer(const bContext *C)
struct OceanCache * BKE_ocean_init_cache(const char *bakepath, const char *relbase, int start, int end, float wave_scale, float chop_amount, float foam_coverage, float foam_fade, int resolution)
Definition ocean.cc:1647
void BKE_sculpt_mask_layers_ensure(Depsgraph *depsgraph, Main *bmain, Object *ob, MultiresModifierData *mmd)
AnimationEvalContext BKE_animsys_eval_context_construct(Depsgraph *depsgraph, float eval_time) ATTR_WARN_UNUSED_RESULT
Definition anim_sys.cc:602
ModifierData * BKE_object_active_modifier(const Object *ob)
Definition object.cc:1427
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition wm_jobs.cc:498
struct SoftBody * sbNew()
Definition softbody.cc:3068
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
Global G
Definition blender.cc:57
void BKE_modifier_unique_name(ListBaseT< ModifierData > *modifiers, ModifierData *md)
const char * BKE_modifier_path_relbase(Main *bmain, Object *ob)
size_t void BLI_uniquename_cb(FunctionRef< bool(StringRefNull)> unique_check, const char *defname, char delim, char *name, size_t name_maxncpy) ATTR_NONNULL(2
void multires_customdata_delete(Mesh *mesh)
Definition multires.cc:57
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
const void * CustomData_add_layer_with_data(CustomData *data, eCustomDataType type, void *layer_data, int totelem, const ImplicitSharingInfo *sharing_info)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
ViewLayer * DEG_get_input_view_layer(const Depsgraph *graph)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
Key * BKE_key_add(Main *bmain, ID *id)
Definition key.cc:228
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
Main * DEG_get_bmain(const Depsgraph *graph)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void BKE_lattice_modifiers_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition lattice.cc:528
@ OB_MODE_PARTICLE_EDIT
BMesh const char void * data
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:339
bool BKE_object_support_modifier_type_check(const Object *ob, int modifier_type)
Definition object.cc:1464
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void BKE_modifiers_add_at_end_if_possible(Object *ob, ModifierData *new_md)
@ MOD_APPLY_TO_ORIGINAL
wmWindowManager * CTX_wm_manager(const bContext *C)
ModifierData * BKE_modifier_new(int type)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
Object * CTX_data_edit_object(const bContext *C)
void DEG_graph_build_from_ids(Depsgraph *graph, Span< ID * > ids)
void BKE_curves_data_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *object)
int CustomData_get_offset_named(const CustomData *data, eCustomDataType type, StringRef name)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
bool ED_operator_object_active_only(bContext *C)
void BKE_curve_nurbs_vert_coords_apply(ListBaseT< Nurb > *lb, const Span< float3 > vert_coords, bool constrain_2d)
Definition curve.cc:4635
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)
void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb) ATTR_NONNULL(1
Definition listbase.cc:171
void BKE_modifier_free(ModifierData *md)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
@ DAG_EVAL_VIEWPORT
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
struct bDeformGroup * BKE_object_defgroup_add_name(struct Object *ob, const char *name)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
bool CTX_data_selected_editable_objects(const bContext *C, Vector< PointerRNA > *list)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
bool ED_operator_object_active(bContext *C)
void multires_force_sculpt_rebuild(Object *object)
Definition multires.cc:332
void ED_armature_edit_free(bArmature *arm)
void BKE_modifier_remove_from_list(Object *ob, ModifierData *md)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
bool ED_operator_object_active_editable(bContext *C)
void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl)
Definition multires.cc:232
void BKE_id_free(Main *bmain, void *idv)
@ eModifierTypeFlag_NoUserAdd
@ eModifierTypeFlag_RequiresOriginalData
@ eModifierTypeFlag_Single
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:378
bool BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData const *omd, int resolution)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_mesh_ensure_skin_customdata(Mesh *mesh)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
bool RNA_property_enum_item_from_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
void psys_apply_hair_lattice(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys)
Definition particle.cc:5282
void ANIM_armature_bonecoll_show_all(bArmature *armature)
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
Definition object.cc:2648
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
void BKE_main_id_newptr_and_tag_clear(Main *bmain)
Definition lib_id.cc:2097
void BKE_animsys_evaluate_animdata(ID *id, AnimData *adt, const AnimationEvalContext *anim_eval_context, eAnimData_Recalc recalc, bool flush_to_original)
Definition anim_sys.cc:3716
const CustomData_MeshMasks CD_MASK_DERIVEDMESH
void ED_mesh_deform_bind_callback(Object *object, MeshDeformModifierData *mmd, Mesh *cagemesh, float *vertexcos, int verts_num, float cagemat[4][4])
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
Array< float3 > BKE_curve_nurbs_vert_coords_alloc(const ListBaseT< Nurb > *lb)
Definition curve.cc:4592
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
int CustomData_get_layer_index_n(const CustomData *data, eCustomDataType type, int n)
void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const StringRef name)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
unsigned int BLI_bitmap
Definition BLI_bitmap.hh:15
Main * CTX_data_main(const bContext *C)
@ NODES_MODIFIER_HIDE_DATABLOCK_SELECTOR
ModifierData * BKE_object_copy_modifier(Main *bmain, const Scene *scene, Object *ob_dst, const Object *ob_src, const ModifierData *md)
Definition object.cc:1542
ATTR_WARN_UNUSED_RESULT const BMVert * v2
wmJob * WM_jobs_get(wmWindowManager *wm, wmWindow *win, const void *owner, const char *name, const eWM_JobFlag flag, const eWM_JobType job_type)
Definition wm_jobs.cc:228
EditBone * ED_armature_ebone_add(bArmature *arm, const char *name)
MultiresModifierData * find_multires_modifier_before(Scene *scene, ModifierData *lastmd)
Definition multires.cc:171
KeyBlock * BKE_keyblock_add(Key *key, const char *name)
Definition key.cc:1322
bool BKE_modifier_is_same_topology(ModifierData *md)
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
Scene * DEG_get_input_scene(const Depsgraph *graph)
bool multiresModifier_reshapeFromDeformModifier(Depsgraph *depsgraph, Object *ob, MultiresModifierData *mmd, ModifierData *deform_md)
void sbFree(struct Object *ob)
Definition softbody.cc:3120
@ eModifierFlag_OverrideLibrary_Local
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void DEG_relations_tag_update(Main *bmain)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
@ ID_FLAG_FAKEUSER
Definition DNA_ID.h:770
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
bool BKE_animdata_drivers_remove_for_rna_struct(ID &owner_id, struct StructRNA &type, void *data)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
bool CTX_data_selected_objects(const bContext *C, Vector< PointerRNA > *list)
void BKE_object_modifier_set_active(Object *ob, ModifierData *md)
Definition object.cc:1415
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void BKE_object_link_modifiers(Object *ob_dst, const Object *ob_src)
Definition object.cc:1682
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
bool CustomData_has_layer_named(const CustomData *data, eCustomDataType type, StringRef name)
void BKE_pointcloud_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2782
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
void BKE_lattice_vert_coords_apply(Lattice *lt, Span< float3 > vert_coordss)
Definition lattice.cc:520
void WM_cursor_wait(bool val)
void BKE_keyblock_convert_from_mesh(const Mesh *mesh, const Key *key, KeyBlock *kb)
Definition key.cc:1681
ModifierData * BKE_modifier_get_original(const Object *object, ModifierData *md)
void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *ob)
Definition multires.cc:389
void id_us_min(ID *id)
Definition lib_id.cc:441
float DEG_get_ctime(const Depsgraph *graph)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void WM_jobs_timer(wmJob *wm_job, double time_step, uint note, uint endnote, void(*timer_step)(void *))
Definition wm_jobs.cc:393
struct ParticleSystem * psys_eval_get(struct Depsgraph *depsgraph, struct Object *object, struct ParticleSystem *psys)
Definition particle.cc:697
void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *data_eval)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
void DEG_disable_visibility_optimization(Depsgraph *depsgraph)
Definition depsgraph.cc:350
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
struct Ocean * BKE_ocean_add()
Definition ocean.cc:1583
CustomData vdata
const ImplicitSharingInfoHandle * bind_coords_sharing_info
ListBaseT< Nurb > nurb
static GeometrySet from_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
char name[258]
Definition DNA_ID.h:433
short flag
Definition DNA_ID.h:439
void * next
Definition DNA_ID.h:418
ListBaseT< KeyBlock > block
ShapekeyContainerType type
const ImplicitSharingInfoHandle * vertexco_sharing_info
ListBaseT< Object > objects
Definition BKE_main.hh:388
const ImplicitSharingInfoHandle * bindcagecos_sharing_info
const ImplicitSharingInfoHandle * bindoffsets_sharing_info
const ImplicitSharingInfoHandle * dyngrid_sharing_info
void(*) bindfunc(struct Object *object, struct MeshDeformModifierData *mmd, struct Mesh *cagemesh, float *vertexcos, int verts_num, float cagemat[4][4])
const ImplicitSharingInfoHandle * bindinfluences_sharing_info
const ImplicitSharingInfoHandle * dynverts_sharing_info
const ImplicitSharingInfoHandle * dyninfluences_sharing_info
struct Key * key
CustomData vert_data
struct ModifierData * next
struct ModifierData * prev
void(*) deform_verts(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh, MutableSpan< float3 > positions)
Mesh *(*) modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
bool(*) is_disabled(const Scene *scene, ModifierData *md, bool use_render_params)
void(*) modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
struct PartDeflect * pd
ListBaseT< ModifierData > modifiers
eObject_DrawExtraFlag dtx
bke::ObjectRuntime * runtime
ListBaseT< struct ParticleSystem > particlesystem
struct AnimData * adt
struct SoftBody * soft
struct ParticleCacheKey ** childcache
struct ParticleCacheKey ** pathcache
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< Report > list
Definition BKE_report.hh:79
struct RenderData r
ListBaseT< EditBone > * edbo
eArmature_Drawtype drawtype
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports