Blender V4.5
render_shading.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10#include <cstring>
11
12#include "MEM_guardedalloc.h"
13
14#include "DNA_ID.h"
15#include "DNA_curve_types.h"
16#include "DNA_light_types.h"
18#include "DNA_material_types.h"
19#include "DNA_node_types.h"
20#include "DNA_object_types.h"
21#include "DNA_particle_types.h"
22#include "DNA_scene_types.h"
23#include "DNA_space_types.h"
24#include "DNA_world_types.h"
25
26#include "BLI_listbase.h"
27#include "BLI_math_vector.h"
28#include "BLI_path_utils.hh"
29#include "BLI_string.h"
30#include "BLI_string_utils.hh"
31#include "BLI_utildefines.h"
32
33#include "BLT_translation.hh"
34
35#include "BKE_anim_data.hh"
36#include "BKE_animsys.h"
37#include "BKE_appdir.hh"
39#include "BKE_blendfile.hh"
40#include "BKE_brush.hh"
41#include "BKE_context.hh"
42#include "BKE_curve.hh"
43#include "BKE_editmesh.hh"
44#include "BKE_global.hh"
45#include "BKE_image.hh"
46#include "BKE_layer.hh"
47#include "BKE_lib_id.hh"
48#include "BKE_lib_query.hh"
49#include "BKE_lib_remap.hh"
50#include "BKE_library.hh"
51#include "BKE_lightprobe.h"
52#include "BKE_linestyle.h"
53#include "BKE_main.hh"
55#include "BKE_material.hh"
56#include "BKE_node.hh"
57#include "BKE_node_runtime.hh"
59#include "BKE_object.hh"
60#include "BKE_report.hh"
61#include "BKE_scene.hh"
62#include "BKE_texture.h"
63#include "BKE_vfont.hh"
64#include "BKE_workspace.hh"
65#include "BKE_world.h"
66
67#include "NOD_composite.hh"
68
69#include "DEG_depsgraph.hh"
72
73#ifdef WITH_FREESTYLE
74# include "BKE_freestyle.h"
75# include "FRS_freestyle.h"
76# include "RNA_enum_types.hh"
77#endif
78
79#include "RNA_access.hh"
80
81#include "WM_api.hh"
82#include "WM_types.hh"
83
84#include "ED_curve.hh"
85#include "ED_mesh.hh"
86#include "ED_node.hh"
87#include "ED_object.hh"
88#include "ED_paint.hh"
89#include "ED_render.hh"
90#include "ED_scene.hh"
91#include "ED_screen.hh"
92#include "ED_undo.hh"
93
94#include "RNA_define.hh"
95#include "RNA_prototypes.hh"
96
97#include "UI_interface.hh"
98
99#include "RE_engine.h"
100#include "RE_pipeline.h"
101
103
104#include "render_intern.hh" /* own include */
105
106using blender::Vector;
107
108static bool object_materials_supported_poll_ex(bContext *C, const Object *ob);
109
110/* -------------------------------------------------------------------- */
113
114static void material_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
115{
116 BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer_material.blend");
117}
118
119static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob, void *user_data)
120{
121 bContext *C = static_cast<bContext *>(user_data);
123 if (BKE_object_is_in_editmode(ob) == true) {
124 return true;
125 }
126 }
127 return false;
128}
129
135
136static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob, void *user_data)
137{
138 bContext *C = static_cast<bContext *>(user_data);
140 if (BKE_object_is_in_editmode(ob) == false) {
141 return true;
142 }
143 }
144 return false;
145}
146
152
154
155/* -------------------------------------------------------------------- */
158
160{
162 return false;
163 }
164 if (!OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
165 return false;
166 }
167
168 /* Material linked to object. */
169 if (ob->matbits && ob->actcol && ob->matbits[ob->actcol - 1]) {
170 return true;
171 }
172
173 /* Material linked to obdata. */
174 const ID *data = static_cast<ID *>(ob->data);
176}
177
183
185
186/* -------------------------------------------------------------------- */
189
191{
192 Main *bmain = CTX_data_main(C);
194
195 if (!ob) {
196 return OPERATOR_CANCELLED;
197 }
198
200
201 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
202 Scene *scene = CTX_data_scene(C);
203 ED_paint_proj_mesh_data_check(*scene, *ob, nullptr, nullptr, nullptr, nullptr);
205 }
206
210
211 return OPERATOR_FINISHED;
212}
213
215{
216 /* identifiers */
217 ot->name = "Add Material Slot";
218 ot->idname = "OBJECT_OT_material_slot_add";
219 ot->description = "Add a new material slot";
220
221 /* API callbacks. */
224
225 /* flags */
227}
228
230
231/* -------------------------------------------------------------------- */
234
236{
238
239 if (!ob) {
240 return OPERATOR_CANCELLED;
241 }
242
243 /* Removing material slots in edit mode screws things up, see bug #21822. */
245 BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode");
246 return OPERATOR_CANCELLED;
247 }
248
250
251 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
252 Scene *scene = CTX_data_scene(C);
253 ED_paint_proj_mesh_data_check(*scene, *ob, nullptr, nullptr, nullptr, nullptr);
255 }
256
261
262 return OPERATOR_FINISHED;
263}
264
266{
267 /* identifiers */
268 ot->name = "Remove Material Slot";
269 ot->idname = "OBJECT_OT_material_slot_remove";
270 ot->description = "Remove the selected material slot";
271
272 /* API callbacks. */
275
276 /* flags */
278}
279
281
282/* -------------------------------------------------------------------- */
285
287{
288 View3D *v3d = CTX_wm_view3d(C);
289 bool changed_multi = false;
290
292 const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
293
295 for (Object *ob : objects) {
296 short mat_nr_active = -1;
297
298 if (ob->totcol == 0) {
299 continue;
300 }
301 if (obact && (obact->actcol >= 1 && obact->actcol <= ob->totcol) &&
302 (mat_active == BKE_object_material_get(ob, obact->actcol)))
303 {
304 /* Avoid searching since there may be multiple slots with the same material.
305 * For the active object or duplicates: match the material slot index first. */
306 mat_nr_active = obact->actcol - 1;
307 }
308 else {
309 /* Find the first matching material.
310 * NOTE: there may be multiple but that's not a common use case. */
311 for (int i = 0; i < ob->totcol; i++) {
312 const Material *mat = BKE_object_material_get(ob, i + 1);
313 if (mat_active == mat) {
314 mat_nr_active = i;
315 break;
316 }
317 }
318 if (mat_nr_active == -1) {
319 continue;
320 }
321 }
322
323 bool changed = false;
324 if (ob->type == OB_MESH) {
326 BMFace *efa;
327 BMIter iter;
328
329 if (em) {
330 BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
332 changed = true;
333 efa->mat_nr = mat_nr_active;
334 }
335 }
336 }
337 }
338 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
339 ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data);
340
341 if (nurbs) {
342 LISTBASE_FOREACH (Nurb *, nu, nurbs) {
343 if (ED_curve_nurb_select_check(v3d, nu)) {
344 changed = true;
345 nu->mat_nr = mat_nr_active;
346 }
347 }
348 }
349 }
350 else if (ob->type == OB_FONT) {
351 const Curve *cu = static_cast<const Curve *>(ob->data);
352 EditFont *ef = cu->editfont;
353 int i, selstart, selend;
354
355 if (ef && BKE_vfont_select_get(cu, &selstart, &selend)) {
356 for (i = selstart; i <= selend; i++) {
357 changed = true;
358 ef->textbufinfo[i].mat_nr = mat_nr_active;
359 }
360 }
361 }
362
363 if (changed) {
364 changed_multi = true;
367 }
368 }
369
370 return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
371}
372
374{
375 /* identifiers */
376 ot->name = "Assign Material Slot";
377 ot->idname = "OBJECT_OT_material_slot_assign";
378 ot->description = "Assign active material slot to selection";
379
380 /* API callbacks. */
383
384 /* flags */
386}
387
389
390/* -------------------------------------------------------------------- */
393
395{
396 bool changed_multi = false;
398 const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
399
401 for (Object *ob : objects) {
402 if (ob->totcol == 0) {
403 continue;
404 }
405
406 const short mat_nr_active = BKE_object_material_index_get_with_hint(
407 ob, mat_active, obact ? obact->actcol - 1 : -1);
408
409 if (mat_nr_active == -1) {
410 continue;
411 }
412
413 bool changed = false;
414
415 if (ob->type == OB_MESH) {
417
418 if (em) {
419 changed = EDBM_deselect_by_material(em, mat_nr_active, select);
420 }
421 }
422 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
423 ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data);
424 BPoint *bp;
425 BezTriple *bezt;
426 int a;
427
428 if (nurbs) {
429 LISTBASE_FOREACH (Nurb *, nu, nurbs) {
430 if (nu->mat_nr == mat_nr_active) {
431 if (nu->bezt) {
432 a = nu->pntsu;
433 bezt = nu->bezt;
434 while (a--) {
435 if (bezt->hide == 0) {
436 changed = true;
437 if (select) {
438 bezt->f1 |= SELECT;
439 bezt->f2 |= SELECT;
440 bezt->f3 |= SELECT;
441 }
442 else {
443 bezt->f1 &= ~SELECT;
444 bezt->f2 &= ~SELECT;
445 bezt->f3 &= ~SELECT;
446 }
447 }
448 bezt++;
449 }
450 }
451 else if (nu->bp) {
452 a = nu->pntsu * nu->pntsv;
453 bp = nu->bp;
454 while (a--) {
455 if (bp->hide == 0) {
456 changed = true;
457 if (select) {
458 bp->f1 |= SELECT;
459 }
460 else {
461 bp->f1 &= ~SELECT;
462 }
463 }
464 bp++;
465 }
466 }
467 }
468 }
469 }
470 }
471
472 if (changed) {
473 changed_multi = true;
474 DEG_id_tag_update(static_cast<ID *>(ob->data), ID_RECALC_SELECT);
476 }
477 }
478
479 return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
480}
481
486
488{
489 /* identifiers */
490 ot->name = "Select Material Slot";
491 ot->idname = "OBJECT_OT_material_slot_select";
492 ot->description = "Select by active material slot";
493
494 /* API callbacks. */
496
497 /* flags */
499}
500
505
507{
508 /* identifiers */
509 ot->name = "Deselect Material Slot";
510 ot->idname = "OBJECT_OT_material_slot_deselect";
511 ot->description = "Deselect by active material slot";
512
513 /* API callbacks. */
515
516 /* flags */
518}
519
521
522/* -------------------------------------------------------------------- */
525
527{
528 Main *bmain = CTX_data_main(C);
530 Material ***matar_obdata;
531
532 if (!ob || !(matar_obdata = BKE_object_material_array_p(ob))) {
533 return OPERATOR_CANCELLED;
534 }
535
537
538 Material ***matar_object = &ob->mat;
539
540 Material **matar = static_cast<Material **>(
541 MEM_callocN(sizeof(*matar) * size_t(ob->totcol), __func__));
542 for (int i = ob->totcol; i--;) {
543 matar[i] = ob->matbits[i] ? (*matar_object)[i] : (*matar_obdata)[i];
544 }
545
546 CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) {
547 if (ob != ob_iter && BKE_object_material_array_p(ob_iter)) {
548 /* If we are using the same obdata, we only assign slots in ob_iter that are using object
549 * materials, and not obdata ones. */
550 const bool is_same_obdata = ob->data == ob_iter->data;
551
552 /* If we are using the same obdata, make the target object inherit the matbits of the active
553 * object. Without this, object material slots are not copied unless the target object
554 * already had its material slot link set to object. */
555 if (is_same_obdata) {
556 for (int i = ob->totcol; i--;) {
557 if (ob->matbits[i]) {
558 ob_iter->matbits[i] = ob->matbits[i];
559 }
560 }
561 }
562
563 BKE_object_material_array_assign(bmain, ob_iter, &matar, ob->totcol, is_same_obdata);
564
565 if (ob_iter->totcol == ob->totcol) {
566 ob_iter->actcol = ob->actcol;
569 }
570 }
571 }
573
574 MEM_freeN(matar);
575
576 return OPERATOR_FINISHED;
577}
578
580{
581 /* identifiers */
582 ot->name = "Copy Material to Selected";
583 ot->idname = "OBJECT_OT_material_slot_copy";
584 ot->description = "Copy material to selected objects";
585
586 /* API callbacks. */
588
589 /* flags */
591}
592
594
595/* -------------------------------------------------------------------- */
598
600{
602
603 uint *slot_remap;
604 int index_pair[2];
605
606 int dir = RNA_enum_get(op->ptr, "direction");
607
608 if (!ob || ob->totcol < 2) {
609 return OPERATOR_CANCELLED;
610 }
611
612 /* up */
613 if (dir == 1 && ob->actcol > 1) {
614 index_pair[0] = ob->actcol - 2;
615 index_pair[1] = ob->actcol - 1;
616 ob->actcol--;
617 }
618 /* down */
619 else if (dir == -1 && ob->actcol < ob->totcol) {
620 index_pair[0] = ob->actcol - 1;
621 index_pair[1] = ob->actcol - 0;
622 ob->actcol++;
623 }
624 else {
625 return OPERATOR_CANCELLED;
626 }
627
628 slot_remap = MEM_malloc_arrayN<uint>(ob->totcol, __func__);
629
630 range_vn_u(slot_remap, ob->totcol, 0);
631
632 slot_remap[index_pair[0]] = index_pair[1];
633 slot_remap[index_pair[1]] = index_pair[0];
634
635 BKE_object_material_remap(ob, slot_remap);
636
637 MEM_freeN(slot_remap);
638
642
643 return OPERATOR_FINISHED;
644}
645
647{
648 static const EnumPropertyItem material_slot_move[] = {
649 {1, "UP", 0, "Up", ""},
650 {-1, "DOWN", 0, "Down", ""},
651 {0, nullptr, 0, nullptr, nullptr},
652 };
653
654 /* identifiers */
655 ot->name = "Move Material";
656 ot->idname = "OBJECT_OT_material_slot_move";
657 ot->description = "Move the active material up/down in the list";
658
659 /* API callbacks. */
662
663 /* flags */
665
666 RNA_def_enum(ot->srna,
667 "direction",
668 material_slot_move,
669 0,
670 "Direction",
671 "Direction to move the active material towards");
672}
673
675
676/* -------------------------------------------------------------------- */
679
681{
682 /* Removing material slots in edit mode screws things up, see bug #21822. */
683 Object *ob_active = CTX_data_active_object(C);
684 if (ob_active && BKE_object_is_in_editmode(ob_active)) {
685 BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode");
686 return OPERATOR_CANCELLED;
687 }
688
689 Main *bmain = CTX_data_main(C);
690 int removed = 0;
691
693 for (Object *ob : objects) {
694 int actcol = ob->actcol;
695 for (int slot = 1; slot <= ob->totcol; slot++) {
696 while (slot <= ob->totcol && !BKE_object_material_slot_used(ob, slot)) {
697 ob->actcol = slot;
699
700 if (actcol >= slot) {
701 actcol--;
702 }
703
704 removed++;
705 }
706 }
707 ob->actcol = actcol;
708
710 }
711
712 if (!removed) {
713 return OPERATOR_CANCELLED;
714 }
715
716 BKE_reportf(op->reports, RPT_INFO, "Removed %d slots", removed);
717
718 if (ob_active->mode & OB_MODE_TEXTURE_PAINT) {
719 Scene *scene = CTX_data_scene(C);
720 ED_paint_proj_mesh_data_check(*scene, *ob_active, nullptr, nullptr, nullptr, nullptr);
722 }
723
727
728 return OPERATOR_FINISHED;
729}
730
732{
733 /* identifiers */
734 ot->name = "Remove Unused Slots";
735 ot->idname = "OBJECT_OT_material_slot_remove_unused";
736 ot->description = "Remove unused material slots";
737
738 /* API callbacks. */
741
742 /* flags */
744}
745
747{
748 /* Removing material slots in edit mode screws things up, see bug #21822. */
749 Object *ob_active = CTX_data_active_object(C);
750 if (ob_active && BKE_object_is_in_editmode(ob_active)) {
751 BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode");
752 return OPERATOR_CANCELLED;
753 }
754 Main *bmain = CTX_data_main(C);
755 int removed = 0;
756
758 for (Object *ob : objects) {
759 int actcol = ob->actcol;
760 for (int slot = 1; slot <= ob->totcol; slot++) {
761 while (slot <= ob->totcol) {
762 ob->actcol = slot;
764
765 if (actcol >= slot) {
766 actcol--;
767 }
768
769 removed++;
770 }
771 }
772 ob->actcol = actcol;
773
775 }
776
777 if (!removed) {
778 return OPERATOR_CANCELLED;
779 }
780
781 BKE_reportf(op->reports, RPT_INFO, "Removed %d materials", removed);
782
783 if (ob_active->mode == OB_MODE_TEXTURE_PAINT) {
784 Scene *scene = CTX_data_scene(C);
785 ED_paint_proj_mesh_data_check(*scene, *ob_active, nullptr, nullptr, nullptr, nullptr);
787 }
788
792
793 return OPERATOR_FINISHED;
794}
795
797{
798 /* identifiers */
799 ot->name = "Remove All Materials";
800 ot->idname = "OBJECT_OT_material_slot_remove_all";
801 ot->description = "Remove all materials";
802
803 /* API callbacks. */
806
807 /* flags */
809}
810
812
813/* -------------------------------------------------------------------- */
816
818{
819 Material *ma = static_cast<Material *>(
820 CTX_data_pointer_get_type(C, "material", &RNA_Material).data);
821 Main *bmain = CTX_data_main(C);
822 PointerRNA ptr;
823 PropertyRNA *prop;
824
825 /* hook into UI */
827
828 Object *ob = static_cast<Object *>((prop && RNA_struct_is_a(ptr.type, &RNA_Object)) ? ptr.data :
829 nullptr);
830
831 /* add or copy material */
832 if (ma) {
833 Material *new_ma = (Material *)BKE_id_copy_ex(
834 bmain, &ma->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS);
835 ma = new_ma;
836 }
837 else {
838 const char *name = DATA_("Material");
839 if (!(ob != nullptr && ob->type == OB_GREASE_PENCIL)) {
840 ma = BKE_material_add(bmain, name);
841 }
842 else {
843 ma = BKE_gpencil_material_add(bmain, name);
844 }
846 ma->use_nodes = true;
847 }
848
849 if (prop) {
850 if (ob != nullptr) {
851 /* Add slot follows user-preferences for creating new slots,
852 * RNA pointer assignment doesn't, see: #60014. */
853 if (BKE_object_material_get_p(ob, ob->actcol) == nullptr) {
855 }
856 }
857
858 /* when creating new ID blocks, use is already 1, but RNA
859 * pointer use also increases user, so this compensates it */
860 id_us_min(&ma->id);
861
862 if (ptr.owner_id) {
863 BKE_id_move_to_same_lib(*bmain, ma->id, *ptr.owner_id);
864 }
865
866 PointerRNA idptr = RNA_id_pointer_create(&ma->id);
867 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
868 RNA_property_update(C, &ptr, prop);
869 }
870
872
873 return OPERATOR_FINISHED;
874}
875
877{
878 /* identifiers */
879 ot->name = "New Material";
880 ot->idname = "MATERIAL_OT_new";
881 ot->description = "Add a new material";
882
883 /* API callbacks. */
886
887 /* flags */
889}
890
892
893/* -------------------------------------------------------------------- */
896
898{
899 Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data);
900 Main *bmain = CTX_data_main(C);
901 PointerRNA ptr;
902 PropertyRNA *prop;
903
904 /* add or copy texture */
905 if (tex) {
906 tex = (Tex *)BKE_id_copy(bmain, &tex->id);
907 }
908 else {
909 tex = BKE_texture_add(bmain, DATA_("Texture"));
910 }
911
912 /* hook into UI */
914
915 bool linked_id_created = false;
916 if (prop) {
917 /* when creating new ID blocks, use is already 1, but RNA
918 * pointer use also increases user, so this compensates it */
919 id_us_min(&tex->id);
920
921 if (ptr.owner_id) {
922 BKE_id_move_to_same_lib(*bmain, tex->id, *ptr.owner_id);
923 linked_id_created = ID_IS_LINKED(&tex->id);
924 }
925
926 PointerRNA idptr = RNA_id_pointer_create(&tex->id);
927 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
928 RNA_property_update(C, &ptr, prop);
929 }
930
931 if (!linked_id_created) {
932 ED_undo_push_op(C, op);
933 }
934
936
937 return OPERATOR_FINISHED;
938}
939
941{
942 /* identifiers */
943 ot->name = "New Texture";
944 ot->idname = "TEXTURE_OT_new";
945 ot->description = "Add a new texture";
946
947 /* API callbacks. */
949
950 /* flags */
952}
953
955
956/* -------------------------------------------------------------------- */
959
961{
962 World *wo = static_cast<World *>(CTX_data_pointer_get_type(C, "world", &RNA_World).data);
963 Main *bmain = CTX_data_main(C);
964 PointerRNA ptr;
965 PropertyRNA *prop;
966
967 /* add or copy world */
968 if (wo) {
969 World *new_wo = (World *)BKE_id_copy_ex(
970 bmain, &wo->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS);
971 wo = new_wo;
972 }
973 else {
974 wo = BKE_world_add(bmain, CTX_DATA_(BLT_I18NCONTEXT_ID_WORLD, "World"));
976 wo->use_nodes = true;
977 }
978
979 /* hook into UI */
981
982 if (prop) {
983 /* when creating new ID blocks, use is already 1, but RNA
984 * pointer use also increases user, so this compensates it */
985 id_us_min(&wo->id);
986
987 if (ptr.owner_id) {
988 BKE_id_move_to_same_lib(*bmain, wo->id, *ptr.owner_id);
989 }
990
991 PointerRNA idptr = RNA_id_pointer_create(&wo->id);
992 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
993 RNA_property_update(C, &ptr, prop);
994 }
995
997
998 return OPERATOR_FINISHED;
999}
1000
1002{
1003 /* identifiers */
1004 ot->name = "New World";
1005 ot->idname = "WORLD_OT_new";
1006 ot->description = "Create a new world Data-Block";
1007
1008 /* API callbacks. */
1009 ot->exec = new_world_exec;
1010
1011 /* flags */
1013}
1014
1016
1017/* -------------------------------------------------------------------- */
1020
1022{
1023 wmWindow *win = CTX_wm_window(C);
1024 Scene *scene = CTX_data_scene(C);
1025
1026 ViewLayer *view_layer_current = win ? WM_window_get_active_view_layer(win) : nullptr;
1027 int type = RNA_enum_get(op->ptr, "type");
1028 /* Copy requires a source. */
1029 if (type == VIEWLAYER_ADD_COPY) {
1030 if (view_layer_current == nullptr) {
1031 type = VIEWLAYER_ADD_NEW;
1032 }
1033 }
1034 ViewLayer *view_layer_new = BKE_view_layer_add(
1035 scene, view_layer_current ? view_layer_current->name : nullptr, view_layer_current, type);
1036
1037 if (win) {
1038 WM_window_set_active_view_layer(win, view_layer_new);
1039 }
1040
1044
1045 return OPERATOR_FINISHED;
1046}
1047
1049{
1050 static EnumPropertyItem type_items[] = {
1051 {VIEWLAYER_ADD_NEW, "NEW", 0, "New", "Add a new view layer"},
1052 {VIEWLAYER_ADD_COPY, "COPY", 0, "Copy Settings", "Copy settings of current view layer"},
1054 "EMPTY",
1055 0,
1056 "Blank",
1057 "Add a new view layer with all collections disabled"},
1058 {0, nullptr, 0, nullptr, nullptr},
1059 };
1060
1061 /* identifiers */
1062 ot->name = "Add View Layer";
1063 ot->idname = "SCENE_OT_view_layer_add";
1064 ot->description = "Add a view layer";
1065
1066 /* API callbacks. */
1068 ot->invoke = WM_menu_invoke;
1069
1070 /* flags */
1072
1073 /* properties */
1074 ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1075}
1076
1078
1079/* -------------------------------------------------------------------- */
1082
1084{
1085 Scene *scene = CTX_data_scene(C);
1086 return (scene->view_layers.first != scene->view_layers.last);
1087}
1088
1090{
1091 Main *bmain = CTX_data_main(C);
1092 Scene *scene = CTX_data_scene(C);
1093 ViewLayer *view_layer = CTX_data_view_layer(C);
1094
1095 if (!ED_scene_view_layer_delete(bmain, scene, view_layer, nullptr)) {
1096 return OPERATOR_CANCELLED;
1097 }
1098
1100
1101 return OPERATOR_FINISHED;
1102}
1103
1105{
1106 /* identifiers */
1107 ot->name = "Remove View Layer";
1108 ot->idname = "SCENE_OT_view_layer_remove";
1109 ot->description = "Remove the selected view layer";
1110
1111 /* API callbacks. */
1114
1115 /* flags */
1117}
1118
1120
1121/* -------------------------------------------------------------------- */
1124
1126{
1127 Scene *scene = CTX_data_scene(C);
1128 ViewLayer *view_layer = CTX_data_view_layer(C);
1129
1130 BKE_view_layer_add_aov(view_layer);
1131
1132 RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
1133 if (engine_type->update_render_passes) {
1134 RenderEngine *engine = RE_engine_create(engine_type);
1135 if (engine) {
1136 BKE_view_layer_verify_aov(engine, scene, view_layer);
1137 }
1138 RE_engine_free(engine);
1139 engine = nullptr;
1140 }
1141
1142 if (scene->nodetree) {
1144 }
1145
1149
1150 return OPERATOR_FINISHED;
1151}
1152
1154{
1155 /* identifiers */
1156 ot->name = "Add AOV";
1157 ot->idname = "SCENE_OT_view_layer_add_aov";
1158 ot->description = "Add a Shader AOV";
1159
1160 /* API callbacks. */
1162
1163 /* flags */
1165}
1166
1168
1169/* -------------------------------------------------------------------- */
1172
1174{
1175 Scene *scene = CTX_data_scene(C);
1176 ViewLayer *view_layer = CTX_data_view_layer(C);
1177
1178 if (view_layer->active_aov == nullptr) {
1179 return OPERATOR_FINISHED;
1180 }
1181
1182 BKE_view_layer_remove_aov(view_layer, view_layer->active_aov);
1183
1184 RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
1185 if (engine_type->update_render_passes) {
1186 RenderEngine *engine = RE_engine_create(engine_type);
1187 if (engine) {
1188 BKE_view_layer_verify_aov(engine, scene, view_layer);
1189 }
1190 RE_engine_free(engine);
1191 engine = nullptr;
1192 }
1193
1194 if (scene->nodetree) {
1196 }
1197
1201
1202 return OPERATOR_FINISHED;
1203}
1204
1206{
1207 /* identifiers */
1208 ot->name = "Remove AOV";
1209 ot->idname = "SCENE_OT_view_layer_remove_aov";
1210 ot->description = "Remove Active AOV";
1211
1212 /* API callbacks. */
1214
1215 /* flags */
1217}
1218
1220
1221/* -------------------------------------------------------------------- */
1224
1226{
1227 Scene *scene = CTX_data_scene(C);
1228 ViewLayer *view_layer = CTX_data_view_layer(C);
1229
1230 char name[MAX_NAME];
1231 name[0] = '\0';
1232 /* If a name is provided, ensure that it is unique. */
1233 if (RNA_struct_property_is_set(op->ptr, "name")) {
1234 RNA_string_get(op->ptr, "name", name);
1235 /* Ensure that there are no dots in the name. */
1236 BLI_string_replace_char(name, '.', '_');
1237 LISTBASE_FOREACH (ViewLayerLightgroup *, lightgroup, &view_layer->lightgroups) {
1238 if (STREQ(lightgroup->name, name)) {
1239 return OPERATOR_CANCELLED;
1240 }
1241 }
1242 }
1243
1244 BKE_view_layer_add_lightgroup(view_layer, name);
1245
1246 if (scene->nodetree) {
1248 }
1249
1253
1254 return OPERATOR_FINISHED;
1255}
1256
1258{
1259 /* identifiers */
1260 ot->name = "Add Lightgroup";
1261 ot->idname = "SCENE_OT_view_layer_add_lightgroup";
1262 ot->description = "Add a Light Group";
1263
1264 /* API callbacks. */
1266
1267 /* flags */
1269
1270 /* properties */
1271 ot->prop = RNA_def_string(ot->srna,
1272 "name",
1273 nullptr,
1275 "Name",
1276 "Name of newly created lightgroup");
1277}
1278
1280
1281/* -------------------------------------------------------------------- */
1284
1286{
1287 Scene *scene = CTX_data_scene(C);
1288 ViewLayer *view_layer = CTX_data_view_layer(C);
1289
1290 if (view_layer->active_lightgroup == nullptr) {
1291 return OPERATOR_FINISHED;
1292 }
1293
1294 BKE_view_layer_remove_lightgroup(view_layer, view_layer->active_lightgroup);
1295
1296 if (scene->nodetree) {
1298 }
1299
1303
1304 return OPERATOR_FINISHED;
1305}
1306
1308{
1309 /* identifiers */
1310 ot->name = "Remove Lightgroup";
1311 ot->idname = "SCENE_OT_view_layer_remove_lightgroup";
1312 ot->description = "Remove Active Lightgroup";
1313
1314 /* API callbacks. */
1316
1317 /* flags */
1319}
1320
1322
1323/* -------------------------------------------------------------------- */
1326
1328{
1329 blender::Set<blender::StringRefNull> used_lightgroups;
1330
1331 FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
1332 if (ob->lightgroup && ob->lightgroup->name[0]) {
1333 used_lightgroups.add_as(ob->lightgroup->name);
1334 }
1335 }
1337
1338 if (scene->world && scene->world->lightgroup && scene->world->lightgroup->name[0]) {
1339 used_lightgroups.add_as(scene->world->lightgroup->name);
1340 }
1341
1342 return used_lightgroups;
1343}
1344
1346{
1347 Scene *scene = CTX_data_scene(C);
1348 ViewLayer *view_layer = CTX_data_view_layer(C);
1349
1351 for (const blender::StringRefNull used_lightgroup : used_lightgroups) {
1352 if (!BLI_findstring(&view_layer->lightgroups,
1353 used_lightgroup.c_str(),
1355 {
1356 BKE_view_layer_add_lightgroup(view_layer, used_lightgroup.c_str());
1357 }
1358 }
1359
1360 if (scene->nodetree) {
1362 }
1363
1367
1368 return OPERATOR_FINISHED;
1369}
1370
1372{
1373 /* identifiers */
1374 ot->name = "Add Used Lightgroups";
1375 ot->idname = "SCENE_OT_view_layer_add_used_lightgroups";
1376 ot->description = "Add all used Light Groups";
1377
1378 /* API callbacks. */
1380
1381 /* flags */
1383}
1384
1386
1387/* -------------------------------------------------------------------- */
1390
1392{
1393 Scene *scene = CTX_data_scene(C);
1394 ViewLayer *view_layer = CTX_data_view_layer(C);
1395
1397 LISTBASE_FOREACH_MUTABLE (ViewLayerLightgroup *, lightgroup, &view_layer->lightgroups) {
1398 if (!used_lightgroups.contains_as(lightgroup->name)) {
1399 BKE_view_layer_remove_lightgroup(view_layer, lightgroup);
1400 }
1401 }
1402
1403 if (scene->nodetree) {
1405 }
1406
1410
1411 return OPERATOR_FINISHED;
1412}
1413
1415{
1416 /* identifiers */
1417 ot->name = "Remove Unused Lightgroups";
1418 ot->idname = "SCENE_OT_view_layer_remove_unused_lightgroups";
1419 ot->description = "Remove all unused Light Groups";
1420
1421 /* API callbacks. */
1423
1424 /* flags */
1426}
1427
1429
1430/* -------------------------------------------------------------------- */
1433
1434enum {
1438};
1439
1441 wmOperator *op)
1442{
1443 ViewLayer *view_layer = CTX_data_view_layer(C);
1444 Scene *scene = CTX_data_scene(C);
1445
1446 auto is_irradiance_volume = [](Object *ob) -> bool {
1447 return ob->type == OB_LIGHTPROBE &&
1448 static_cast<LightProbe *>(ob->data)->type == LIGHTPROBE_TYPE_VOLUME;
1449 };
1450
1452
1453 auto irradiance_volume_setup = [&](Object *ob) {
1457 probes.append(ob);
1458 };
1459
1460 int subset = RNA_enum_get(op->ptr, "subset");
1461 switch (subset) {
1462 case LIGHTCACHE_SUBSET_ALL: {
1463 FOREACH_OBJECT_BEGIN (scene, view_layer, ob) {
1464 if (is_irradiance_volume(ob)) {
1465 irradiance_volume_setup(ob);
1466 }
1467 }
1469 break;
1470 }
1472 ObjectsInViewLayerParams parameters;
1473 parameters.filter_fn = nullptr;
1474 parameters.no_dup_data = true;
1476 view_layer, nullptr, &parameters);
1477 for (Object *ob : objects) {
1478 if (is_irradiance_volume(ob)) {
1479 irradiance_volume_setup(ob);
1480 }
1481 }
1482 break;
1483 }
1485 Object *active_ob = CTX_data_active_object(C);
1486 if (is_irradiance_volume(active_ob)) {
1487 irradiance_volume_setup(active_ob);
1488 }
1489 break;
1490 }
1491 default:
1493 break;
1494 }
1495
1496 return probes;
1497}
1498
1500 /* Store actual owner of job, so modal operator could check for it,
1501 * the reason of this is that active scene could change when rendering
1502 * several layers from compositor #31800. */
1504
1505 std::string report;
1506};
1507
1509 wmOperator *op,
1510 const wmEvent * /*event*/)
1511{
1513 wmWindow *win = CTX_wm_window(C);
1514 ViewLayer *view_layer = CTX_data_view_layer(C);
1515 Main *bmain = CTX_data_main(C);
1516 Scene *scene = CTX_data_scene(C);
1517
1519
1520 if (probes.is_empty()) {
1521 return OPERATOR_CANCELLED;
1522 }
1523
1524 BakeOperatorData *data = MEM_new<BakeOperatorData>(__func__);
1525 data->scene = scene;
1526 data->report = "";
1527
1529 wm, win, bmain, view_layer, scene, probes, data->report, scene->r.cfra, 0);
1530 if (wm_job == nullptr) {
1531 MEM_delete(data);
1532 BKE_report(op->reports, RPT_WARNING, "Can't bake light probe while rendering");
1533 return OPERATOR_CANCELLED;
1534 }
1535
1537
1538 op->customdata = static_cast<void *>(data);
1539
1540 WM_jobs_start(wm, wm_job);
1541
1542 WM_cursor_wait(false);
1543
1545}
1546
1548 wmOperator *op,
1549 const wmEvent *event)
1550{
1551 BakeOperatorData *data = static_cast<BakeOperatorData *>(op->customdata);
1552 Scene *scene = data->scene;
1553
1554 /* No running bake, remove handler and pass through. */
1556 std::string report = data->report;
1557
1558 MEM_delete(data);
1559 op->customdata = nullptr;
1560
1561 if (!report.empty()) {
1562 BKE_report(op->reports, RPT_ERROR, report.c_str());
1563 return OPERATOR_CANCELLED;
1564 }
1566 }
1567
1568 /* Running bake. */
1569 switch (event->type) {
1570 case EVT_ESCKEY:
1572 default: {
1573 break;
1574 }
1575 }
1576 return OPERATOR_PASS_THROUGH;
1577}
1578
1580{
1582 Scene *scene = static_cast<BakeOperatorData *>(op->customdata)->scene;
1583
1584 /* Kill on cancel, because job is using op->reports. */
1586}
1587
1588/* Executes blocking bake. */
1590{
1591 ViewLayer *view_layer = CTX_data_view_layer(C);
1592 Main *bmain = CTX_data_main(C);
1593 Scene *scene = CTX_data_scene(C);
1594
1595 G.is_break = false;
1596
1598
1599 std::string report;
1601 bmain, view_layer, scene, probes, report, scene->r.cfra);
1602 /* Do the job. */
1603 wmJobWorkerStatus worker_status = {};
1604 EEVEE_lightbake_job(rj, &worker_status);
1605 /* Move baking data to original object and then free it. */
1608
1609 if (!report.empty()) {
1610 BKE_report(op->reports, RPT_ERROR, report.c_str());
1611 return OPERATOR_CANCELLED;
1612 }
1613
1614 return OPERATOR_FINISHED;
1615}
1616
1618{
1619 static const EnumPropertyItem light_cache_subset_items[] = {
1620 {LIGHTCACHE_SUBSET_ALL, "ALL", 0, "All Volumes", "Bake all light probe volumes"},
1622 "SELECTED",
1623 0,
1624 "Selected Only",
1625 "Only bake selected light probe volumes"},
1627 "ACTIVE",
1628 0,
1629 "Active Only",
1630 "Only bake the active light probe volume"},
1631 {0, nullptr, 0, nullptr, nullptr},
1632 };
1633
1634 /* identifiers */
1635 ot->name = "Bake Light Cache";
1636 ot->idname = "OBJECT_OT_lightprobe_cache_bake";
1637 ot->description = "Bake irradiance volume light cache";
1638
1639 /* API callbacks. */
1644
1645 ot->prop = RNA_def_enum(
1646 ot->srna, "subset", light_cache_subset_items, 0, "Subset", "Subset of probes to update");
1648}
1649
1651
1652/* -------------------------------------------------------------------- */
1655
1657{
1658 Scene *scene = CTX_data_scene(C);
1659
1660 /* Kill potential bake job first (see #57011). */
1663
1665
1666 for (Object *object : probes) {
1667 if (object->lightprobe_cache == nullptr) {
1668 continue;
1669 }
1672 }
1673
1675
1676 return OPERATOR_FINISHED;
1677}
1678
1680{
1681 static const EnumPropertyItem lightprobe_subset_items[] = {
1683 "ALL",
1684 0,
1685 "All Light Probes",
1686 "Delete all light probes' baked lighting data"},
1688 "SELECTED",
1689 0,
1690 "Selected Only",
1691 "Only delete selected light probes' baked lighting data"},
1693 "ACTIVE",
1694 0,
1695 "Active Only",
1696 "Only delete the active light probe's baked lighting data"},
1697 {0, nullptr, 0, nullptr, nullptr},
1698 };
1699
1700 /* identifiers */
1701 ot->name = "Delete Light Cache";
1702 ot->idname = "OBJECT_OT_lightprobe_cache_free";
1703 ot->description = "Delete cached indirect lighting";
1705
1706 /* API callbacks. */
1708
1709 ot->prop = RNA_def_enum(ot->srna,
1710 "subset",
1711 lightprobe_subset_items,
1713 "Subset",
1714 "Subset of probes to update");
1715}
1716
1718
1719/* -------------------------------------------------------------------- */
1722
1724{
1725 Scene *scene = CTX_data_scene(C);
1726
1727 /* don't allow user to remove "left" and "right" views */
1728 return scene->r.actview > 1;
1729}
1730
1732{
1733 Main *bmain = CTX_data_main(C);
1734 Scene *scene = CTX_data_scene(C);
1735
1736 BKE_scene_add_render_view(scene, nullptr);
1737 scene->r.actview = BLI_listbase_count(&scene->r.views) - 1;
1738
1740
1741 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1743
1744 return OPERATOR_FINISHED;
1745}
1746
1748{
1749 /* identifiers */
1750 ot->name = "Add Render View";
1751 ot->idname = "SCENE_OT_render_view_add";
1752 ot->description = "Add a render view";
1753
1754 /* API callbacks. */
1756
1757 /* flags */
1759}
1760
1762
1763/* -------------------------------------------------------------------- */
1766
1768{
1769 Main *bmain = CTX_data_main(C);
1770 Scene *scene = CTX_data_scene(C);
1771 SceneRenderView *rv = static_cast<SceneRenderView *>(
1772 BLI_findlink(&scene->r.views, scene->r.actview));
1773
1774 if (!BKE_scene_remove_render_view(scene, rv)) {
1775 return OPERATOR_CANCELLED;
1776 }
1777
1779
1780 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1782
1783 return OPERATOR_FINISHED;
1784}
1785
1787{
1788 /* identifiers */
1789 ot->name = "Remove Render View";
1790 ot->idname = "SCENE_OT_render_view_remove";
1791 ot->description = "Remove the selected render view";
1792
1793 /* API callbacks. */
1796
1797 /* flags */
1799}
1800
1802
1803#ifdef WITH_FREESTYLE
1804
1805/* -------------------------------------------------------------------- */
1808
1809static bool freestyle_linestyle_check_report(FreestyleLineSet *lineset, ReportList *reports)
1810{
1811 if (!lineset) {
1813 RPT_ERROR,
1814 "No active lineset and associated line style to manipulate the modifier");
1815 return false;
1816 }
1817 if (!lineset->linestyle) {
1819 RPT_ERROR,
1820 "The active lineset does not have a line style (indicating data corruption)");
1821 return false;
1822 }
1823
1824 return true;
1825}
1826
1827static bool freestyle_active_module_poll(bContext *C)
1828{
1829 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
1830 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1831
1832 return module != nullptr;
1833}
1834
1835static wmOperatorStatus freestyle_module_add_exec(bContext *C, wmOperator * /*op*/)
1836{
1837 Scene *scene = CTX_data_scene(C);
1838 ViewLayer *view_layer = CTX_data_view_layer(C);
1839
1841
1843
1844 return OPERATOR_FINISHED;
1845}
1846
1847void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
1848{
1849 /* identifiers */
1850 ot->name = "Add Freestyle Module";
1851 ot->idname = "SCENE_OT_freestyle_module_add";
1852 ot->description = "Add a style module into the list of modules";
1853
1854 /* API callbacks. */
1855 ot->exec = freestyle_module_add_exec;
1856
1857 /* flags */
1859}
1860
1862
1863/* -------------------------------------------------------------------- */
1866
1867static wmOperatorStatus freestyle_module_remove_exec(bContext *C, wmOperator * /*op*/)
1868{
1869 Scene *scene = CTX_data_scene(C);
1870 ViewLayer *view_layer = CTX_data_view_layer(C);
1871 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
1872 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1873
1874 BKE_freestyle_module_delete(&view_layer->freestyle_config, module);
1875
1878
1879 return OPERATOR_FINISHED;
1880}
1881
1882void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
1883{
1884 /* identifiers */
1885 ot->name = "Remove Freestyle Module";
1886 ot->idname = "SCENE_OT_freestyle_module_remove";
1887 ot->description = "Remove the style module from the stack";
1888
1889 /* API callbacks. */
1890 ot->poll = freestyle_active_module_poll;
1891 ot->exec = freestyle_module_remove_exec;
1892
1893 /* flags */
1895}
1896
1897static wmOperatorStatus freestyle_module_move_exec(bContext *C, wmOperator *op)
1898{
1899 Scene *scene = CTX_data_scene(C);
1900 ViewLayer *view_layer = CTX_data_view_layer(C);
1901 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
1902 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1903 int dir = RNA_enum_get(op->ptr, "direction");
1904
1905 if (BKE_freestyle_module_move(&view_layer->freestyle_config, module, dir)) {
1908 }
1909
1910 return OPERATOR_FINISHED;
1911}
1912
1914
1915/* -------------------------------------------------------------------- */
1918
1919void SCENE_OT_freestyle_module_move(wmOperatorType *ot)
1920{
1921 static const EnumPropertyItem direction_items[] = {
1922 {-1, "UP", 0, "Up", ""},
1923 {1, "DOWN", 0, "Down", ""},
1924 {0, nullptr, 0, nullptr, nullptr},
1925 };
1926
1927 /* identifiers */
1928 ot->name = "Move Freestyle Module";
1929 ot->idname = "SCENE_OT_freestyle_module_move";
1930 ot->description = "Change the position of the style module within in the list of style modules";
1931
1932 /* API callbacks. */
1933 ot->poll = freestyle_active_module_poll;
1934 ot->exec = freestyle_module_move_exec;
1935
1936 /* flags */
1938
1939 /* props */
1940 RNA_def_enum(ot->srna,
1941 "direction",
1942 direction_items,
1943 0,
1944 "Direction",
1945 "Direction to move the chosen style module towards");
1946}
1947
1949
1950/* -------------------------------------------------------------------- */
1953
1954static wmOperatorStatus freestyle_lineset_add_exec(bContext *C, wmOperator * /*op*/)
1955{
1956 Main *bmain = CTX_data_main(C);
1957 Scene *scene = CTX_data_scene(C);
1958 ViewLayer *view_layer = CTX_data_view_layer(C);
1959
1960 BKE_freestyle_lineset_add(bmain, &view_layer->freestyle_config, nullptr);
1961
1964
1965 return OPERATOR_FINISHED;
1966}
1967
1968void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
1969{
1970 /* identifiers */
1971 ot->name = "Add Line Set";
1972 ot->idname = "SCENE_OT_freestyle_lineset_add";
1973 ot->description = "Add a line set into the list of line sets";
1974
1975 /* API callbacks. */
1976 ot->exec = freestyle_lineset_add_exec;
1977
1978 /* flags */
1980}
1981
1983
1984/* -------------------------------------------------------------------- */
1987
1988static bool freestyle_active_lineset_poll(bContext *C)
1989{
1990 ViewLayer *view_layer = CTX_data_view_layer(C);
1991
1992 if (!view_layer) {
1993 return false;
1994 }
1995
1996 return BKE_freestyle_lineset_get_active(&view_layer->freestyle_config) != nullptr;
1997}
1998
1999static wmOperatorStatus freestyle_lineset_copy_exec(bContext *C, wmOperator * /*op*/)
2000{
2001 ViewLayer *view_layer = CTX_data_view_layer(C);
2002
2004
2005 return OPERATOR_FINISHED;
2006}
2007
2008void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot)
2009{
2010 /* identifiers */
2011 ot->name = "Copy Line Set";
2012 ot->idname = "SCENE_OT_freestyle_lineset_copy";
2013 ot->description = "Copy the active line set to the internal clipboard";
2014
2015 /* API callbacks. */
2016 ot->exec = freestyle_lineset_copy_exec;
2017 ot->poll = freestyle_active_lineset_poll;
2018
2019 /* flags */
2021}
2022
2024
2025/* -------------------------------------------------------------------- */
2028
2029static wmOperatorStatus freestyle_lineset_paste_exec(bContext *C, wmOperator * /*op*/)
2030{
2031 Scene *scene = CTX_data_scene(C);
2032 ViewLayer *view_layer = CTX_data_view_layer(C);
2033
2035
2038
2039 return OPERATOR_FINISHED;
2040}
2041
2042void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot)
2043{
2044 /* identifiers */
2045 ot->name = "Paste Line Set";
2046 ot->idname = "SCENE_OT_freestyle_lineset_paste";
2047 ot->description = "Paste the internal clipboard content to the active line set";
2048
2049 /* API callbacks. */
2050 ot->exec = freestyle_lineset_paste_exec;
2051 ot->poll = freestyle_active_lineset_poll;
2052
2053 /* flags */
2055}
2056
2058
2059/* -------------------------------------------------------------------- */
2062
2063static wmOperatorStatus freestyle_lineset_remove_exec(bContext *C, wmOperator * /*op*/)
2064{
2065 Scene *scene = CTX_data_scene(C);
2066 ViewLayer *view_layer = CTX_data_view_layer(C);
2067
2069
2072
2073 return OPERATOR_FINISHED;
2074}
2075
2076void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
2077{
2078 /* identifiers */
2079 ot->name = "Remove Line Set";
2080 ot->idname = "SCENE_OT_freestyle_lineset_remove";
2081 ot->description = "Remove the active line set from the list of line sets";
2082
2083 /* API callbacks. */
2084 ot->exec = freestyle_lineset_remove_exec;
2085 ot->poll = freestyle_active_lineset_poll;
2086
2087 /* flags */
2089}
2090
2092
2093/* -------------------------------------------------------------------- */
2096
2097static wmOperatorStatus freestyle_lineset_move_exec(bContext *C, wmOperator *op)
2098{
2099 Scene *scene = CTX_data_scene(C);
2100 ViewLayer *view_layer = CTX_data_view_layer(C);
2101 int dir = RNA_enum_get(op->ptr, "direction");
2102
2103 if (FRS_move_active_lineset(&view_layer->freestyle_config, dir)) {
2106 }
2107
2108 return OPERATOR_FINISHED;
2109}
2110
2111void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
2112{
2113 static const EnumPropertyItem direction_items[] = {
2114 {-1, "UP", 0, "Up", ""},
2115 {1, "DOWN", 0, "Down", ""},
2116 {0, nullptr, 0, nullptr, nullptr},
2117 };
2118
2119 /* identifiers */
2120 ot->name = "Move Line Set";
2121 ot->idname = "SCENE_OT_freestyle_lineset_move";
2122 ot->description = "Change the position of the active line set within the list of line sets";
2123
2124 /* API callbacks. */
2125 ot->exec = freestyle_lineset_move_exec;
2126 ot->poll = freestyle_active_lineset_poll;
2127
2128 /* flags */
2130
2131 /* props */
2132 RNA_def_enum(ot->srna,
2133 "direction",
2134 direction_items,
2135 0,
2136 "Direction",
2137 "Direction to move the active line set towards");
2138}
2139
2141
2142/* -------------------------------------------------------------------- */
2145
2146static wmOperatorStatus freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
2147{
2148 Main *bmain = CTX_data_main(C);
2149 ViewLayer *view_layer = CTX_data_view_layer(C);
2151
2152 if (!lineset) {
2153 BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to");
2154 return OPERATOR_CANCELLED;
2155 }
2156 if (lineset->linestyle) {
2157 id_us_min(&lineset->linestyle->id);
2158 lineset->linestyle = (FreestyleLineStyle *)BKE_id_copy(bmain, &lineset->linestyle->id);
2159 }
2160 else {
2161 lineset->linestyle = BKE_linestyle_new(bmain, DATA_("LineStyle"));
2162 }
2163 DEG_id_tag_update(&lineset->linestyle->id, 0);
2165
2166 return OPERATOR_FINISHED;
2167}
2168
2169void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot)
2170{
2171 /* identifiers */
2172 ot->name = "New Line Style";
2173 ot->idname = "SCENE_OT_freestyle_linestyle_new";
2174 ot->description = "Create a new line style, reusable by multiple line sets";
2175
2176 /* API callbacks. */
2177 ot->exec = freestyle_linestyle_new_exec;
2178 ot->poll = freestyle_active_lineset_poll;
2179
2180 /* flags */
2182}
2183
2185
2186/* -------------------------------------------------------------------- */
2189
2190static wmOperatorStatus freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
2191{
2192 ViewLayer *view_layer = CTX_data_view_layer(C);
2194 int type = RNA_enum_get(op->ptr, "type");
2195
2196 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2197 return OPERATOR_CANCELLED;
2198 }
2199
2200 if (BKE_linestyle_color_modifier_add(lineset->linestyle, nullptr, type) == nullptr) {
2201 BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type");
2202 return OPERATOR_CANCELLED;
2203 }
2204 DEG_id_tag_update(&lineset->linestyle->id, 0);
2206
2207 return OPERATOR_FINISHED;
2208}
2209
2210void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
2211{
2212 /* identifiers */
2213 ot->name = "Add Line Color Modifier";
2214 ot->idname = "SCENE_OT_freestyle_color_modifier_add";
2215 ot->description =
2216 "Add a line color modifier to the line style associated with the active lineset";
2217
2218 /* API callbacks. */
2219 ot->invoke = WM_menu_invoke;
2220 ot->exec = freestyle_color_modifier_add_exec;
2221 ot->poll = freestyle_active_lineset_poll;
2222
2223 /* flags */
2225
2226 /* properties */
2227 ot->prop = RNA_def_enum(
2228 ot->srna, "type", rna_enum_linestyle_color_modifier_type_items, 0, "Type", "");
2229}
2230
2232
2233/* -------------------------------------------------------------------- */
2236
2237static wmOperatorStatus freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
2238{
2239 ViewLayer *view_layer = CTX_data_view_layer(C);
2241 int type = RNA_enum_get(op->ptr, "type");
2242
2243 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2244 return OPERATOR_CANCELLED;
2245 }
2246
2247 if (BKE_linestyle_alpha_modifier_add(lineset->linestyle, nullptr, type) == nullptr) {
2248 BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type");
2249 return OPERATOR_CANCELLED;
2250 }
2251 DEG_id_tag_update(&lineset->linestyle->id, 0);
2253
2254 return OPERATOR_FINISHED;
2255}
2256
2257void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
2258{
2259 /* identifiers */
2260 ot->name = "Add Alpha Transparency Modifier";
2261 ot->idname = "SCENE_OT_freestyle_alpha_modifier_add";
2262 ot->description =
2263 "Add an alpha transparency modifier to the line style associated with the active lineset";
2264
2265 /* API callbacks. */
2266 ot->invoke = WM_menu_invoke;
2267 ot->exec = freestyle_alpha_modifier_add_exec;
2268 ot->poll = freestyle_active_lineset_poll;
2269
2270 /* flags */
2272
2273 /* properties */
2274 ot->prop = RNA_def_enum(
2275 ot->srna, "type", rna_enum_linestyle_alpha_modifier_type_items, 0, "Type", "");
2276}
2277
2279
2280/* -------------------------------------------------------------------- */
2283
2284static wmOperatorStatus freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
2285{
2286 ViewLayer *view_layer = CTX_data_view_layer(C);
2288 int type = RNA_enum_get(op->ptr, "type");
2289
2290 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2291 return OPERATOR_CANCELLED;
2292 }
2293
2294 if (BKE_linestyle_thickness_modifier_add(lineset->linestyle, nullptr, type) == nullptr) {
2295 BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type");
2296 return OPERATOR_CANCELLED;
2297 }
2298 DEG_id_tag_update(&lineset->linestyle->id, 0);
2300
2301 return OPERATOR_FINISHED;
2302}
2303
2304void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
2305{
2306 /* identifiers */
2307 ot->name = "Add Line Thickness Modifier";
2308 ot->idname = "SCENE_OT_freestyle_thickness_modifier_add";
2309 ot->description =
2310 "Add a line thickness modifier to the line style associated with the active lineset";
2311
2312 /* API callbacks. */
2313 ot->invoke = WM_menu_invoke;
2314 ot->exec = freestyle_thickness_modifier_add_exec;
2315 ot->poll = freestyle_active_lineset_poll;
2316
2317 /* flags */
2319
2320 /* properties */
2321 ot->prop = RNA_def_enum(
2322 ot->srna, "type", rna_enum_linestyle_thickness_modifier_type_items, 0, "Type", "");
2323}
2324
2326
2327/* -------------------------------------------------------------------- */
2330
2331static wmOperatorStatus freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
2332{
2333 ViewLayer *view_layer = CTX_data_view_layer(C);
2335 int type = RNA_enum_get(op->ptr, "type");
2336
2337 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2338 return OPERATOR_CANCELLED;
2339 }
2340
2341 if (BKE_linestyle_geometry_modifier_add(lineset->linestyle, nullptr, type) == nullptr) {
2342 BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type");
2343 return OPERATOR_CANCELLED;
2344 }
2345 DEG_id_tag_update(&lineset->linestyle->id, 0);
2347
2348 return OPERATOR_FINISHED;
2349}
2350
2351void SCENE_OT_freestyle_geometry_modifier_add(wmOperatorType *ot)
2352{
2353 /* identifiers */
2354 ot->name = "Add Stroke Geometry Modifier";
2355 ot->idname = "SCENE_OT_freestyle_geometry_modifier_add";
2356 ot->description =
2357 "Add a stroke geometry modifier to the line style associated with the active lineset";
2358
2359 /* API callbacks. */
2360 ot->invoke = WM_menu_invoke;
2361 ot->exec = freestyle_geometry_modifier_add_exec;
2362 ot->poll = freestyle_active_lineset_poll;
2363
2364 /* flags */
2366
2367 /* properties */
2368 ot->prop = RNA_def_enum(
2369 ot->srna, "type", rna_enum_linestyle_geometry_modifier_type_items, 0, "Type", "");
2370}
2371
2373
2374/* -------------------------------------------------------------------- */
2377
2378static int freestyle_get_modifier_type(PointerRNA *ptr)
2379{
2380 if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier)) {
2382 }
2383 if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier)) {
2385 }
2386 if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier)) {
2388 }
2389 if (RNA_struct_is_a(ptr->type, &RNA_LineStyleGeometryModifier)) {
2391 }
2392 return -1;
2393}
2394
2395static wmOperatorStatus freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
2396{
2397 ViewLayer *view_layer = CTX_data_view_layer(C);
2399 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
2400 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2401
2402 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2403 return OPERATOR_CANCELLED;
2404 }
2405
2406 switch (freestyle_get_modifier_type(&ptr)) {
2409 break;
2412 break;
2415 break;
2418 break;
2419 default:
2420 BKE_report(
2421 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2422 return OPERATOR_CANCELLED;
2423 }
2424 DEG_id_tag_update(&lineset->linestyle->id, 0);
2426
2427 return OPERATOR_FINISHED;
2428}
2429
2430void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
2431{
2432 /* identifiers */
2433 ot->name = "Remove Modifier";
2434 ot->idname = "SCENE_OT_freestyle_modifier_remove";
2435 ot->description = "Remove the modifier from the list of modifiers";
2436
2437 /* API callbacks. */
2438 ot->exec = freestyle_modifier_remove_exec;
2439 ot->poll = freestyle_active_lineset_poll;
2440
2441 /* flags */
2443}
2444
2446
2447/* -------------------------------------------------------------------- */
2450
2451static wmOperatorStatus freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
2452{
2453 ViewLayer *view_layer = CTX_data_view_layer(C);
2455 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
2456 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2457
2458 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2459 return OPERATOR_CANCELLED;
2460 }
2461
2462 switch (freestyle_get_modifier_type(&ptr)) {
2464 BKE_linestyle_color_modifier_copy(lineset->linestyle, modifier, 0);
2465 break;
2467 BKE_linestyle_alpha_modifier_copy(lineset->linestyle, modifier, 0);
2468 break;
2470 BKE_linestyle_thickness_modifier_copy(lineset->linestyle, modifier, 0);
2471 break;
2473 BKE_linestyle_geometry_modifier_copy(lineset->linestyle, modifier, 0);
2474 break;
2475 default:
2476 BKE_report(
2477 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2478 return OPERATOR_CANCELLED;
2479 }
2480 DEG_id_tag_update(&lineset->linestyle->id, 0);
2482
2483 return OPERATOR_FINISHED;
2484}
2485
2486void SCENE_OT_freestyle_modifier_copy(wmOperatorType *ot)
2487{
2488 /* identifiers */
2489 ot->name = "Copy Modifier";
2490 ot->idname = "SCENE_OT_freestyle_modifier_copy";
2491 ot->description = "Duplicate the modifier within the list of modifiers";
2492
2493 /* API callbacks. */
2494 ot->exec = freestyle_modifier_copy_exec;
2495 ot->poll = freestyle_active_lineset_poll;
2496
2497 /* flags */
2499}
2500
2502
2503/* -------------------------------------------------------------------- */
2506
2507static wmOperatorStatus freestyle_modifier_move_exec(bContext *C, wmOperator *op)
2508{
2509 ViewLayer *view_layer = CTX_data_view_layer(C);
2511 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
2512 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2513 int dir = RNA_enum_get(op->ptr, "direction");
2514 bool changed = false;
2515
2516 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2517 return OPERATOR_CANCELLED;
2518 }
2519
2520 switch (freestyle_get_modifier_type(&ptr)) {
2522 changed = BKE_linestyle_color_modifier_move(lineset->linestyle, modifier, dir);
2523 break;
2525 changed = BKE_linestyle_alpha_modifier_move(lineset->linestyle, modifier, dir);
2526 break;
2528 changed = BKE_linestyle_thickness_modifier_move(lineset->linestyle, modifier, dir);
2529 break;
2531 changed = BKE_linestyle_geometry_modifier_move(lineset->linestyle, modifier, dir);
2532 break;
2533 default:
2534 BKE_report(
2535 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2536 return OPERATOR_CANCELLED;
2537 }
2538
2539 if (changed) {
2540 DEG_id_tag_update(&lineset->linestyle->id, 0);
2542 }
2543
2544 return OPERATOR_FINISHED;
2545}
2546
2547void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
2548{
2549 static const EnumPropertyItem direction_items[] = {
2550 {-1, "UP", 0, "Up", ""},
2551 {1, "DOWN", 0, "Down", ""},
2552 {0, nullptr, 0, nullptr, nullptr},
2553 };
2554
2555 /* identifiers */
2556 ot->name = "Move Modifier";
2557 ot->idname = "SCENE_OT_freestyle_modifier_move";
2558 ot->description = "Move the modifier within the list of modifiers";
2559
2560 /* API callbacks. */
2561 ot->exec = freestyle_modifier_move_exec;
2562 ot->poll = freestyle_active_lineset_poll;
2563
2564 /* flags */
2566
2567 /* props */
2568 RNA_def_enum(ot->srna,
2569 "direction",
2570 direction_items,
2571 0,
2572 "Direction",
2573 "Direction to move the chosen modifier towards");
2574}
2575
2577
2578/* -------------------------------------------------------------------- */
2581
2582static wmOperatorStatus freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
2583{
2584 Main *bmain = CTX_data_main(C);
2585 ViewLayer *view_layer = CTX_data_view_layer(C);
2587
2588 if (!linestyle) {
2589 BKE_report(op->reports, RPT_ERROR, "No active line style in the current scene");
2590 return OPERATOR_CANCELLED;
2591 }
2592
2593 FRS_create_stroke_material(bmain, linestyle);
2594
2595 return OPERATOR_FINISHED;
2596}
2597
2598void SCENE_OT_freestyle_stroke_material_create(wmOperatorType *ot)
2599{
2600 /* identifiers */
2601 ot->name = "Create Freestyle Stroke Material";
2602 ot->idname = "SCENE_OT_freestyle_stroke_material_create";
2603 ot->description = "Create Freestyle stroke material for testing";
2604
2605 /* API callbacks. */
2606 ot->exec = freestyle_stroke_material_create_exec;
2607
2608 /* flags */
2610}
2611
2613
2614#endif /* WITH_FREESTYLE */
2615
2616/* -------------------------------------------------------------------- */
2619
2621{
2622 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).owner_id;
2623
2624 if (id) {
2625 MTex **mtex_ar, *mtexswap;
2626 short act;
2627 int type = RNA_enum_get(op->ptr, "type");
2628 AnimData *adt = BKE_animdata_from_id(id);
2629
2630 give_active_mtex(id, &mtex_ar, &act);
2631
2632 if (type == -1) { /* Up */
2633 if (act > 0) {
2634 mtexswap = mtex_ar[act];
2635 mtex_ar[act] = mtex_ar[act - 1];
2636 mtex_ar[act - 1] = mtexswap;
2637
2639 id, adt, nullptr, "texture_slots", nullptr, nullptr, act - 1, -1, false);
2641 id, adt, nullptr, "texture_slots", nullptr, nullptr, act, act - 1, false);
2643 id, adt, nullptr, "texture_slots", nullptr, nullptr, -1, act, false);
2644
2645 set_active_mtex(id, act - 1);
2646 }
2647 }
2648 else { /* Down */
2649 if (act < MAX_MTEX - 1) {
2650 mtexswap = mtex_ar[act];
2651 mtex_ar[act] = mtex_ar[act + 1];
2652 mtex_ar[act + 1] = mtexswap;
2653
2655 id, adt, nullptr, "texture_slots", nullptr, nullptr, act + 1, -1, false);
2657 id, adt, nullptr, "texture_slots", nullptr, nullptr, act, act + 1, false);
2659 id, adt, nullptr, "texture_slots", nullptr, nullptr, -1, act, false);
2660
2661 set_active_mtex(id, act + 1);
2662 }
2663 }
2664
2665 DEG_id_tag_update(id, 0);
2667 }
2668
2669 return OPERATOR_FINISHED;
2670}
2671
2673{
2674 static const EnumPropertyItem slot_move[] = {
2675 {-1, "UP", 0, "Up", ""},
2676 {1, "DOWN", 0, "Down", ""},
2677 {0, nullptr, 0, nullptr, nullptr},
2678 };
2679
2680 /* identifiers */
2681 ot->name = "Move Texture Slot";
2682 ot->idname = "TEXTURE_OT_slot_move";
2683 ot->description = "Move texture slots up and down";
2684
2685 /* API callbacks. */
2687
2688 /* flags */
2690
2691 RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
2692}
2693
2695
2696/* -------------------------------------------------------------------- */
2699
2701{
2702 using namespace blender::bke::blendfile;
2703
2704 Material *ma = static_cast<Material *>(
2705 CTX_data_pointer_get_type(C, "material", &RNA_Material).data);
2706
2707 if (ma == nullptr) {
2708 return OPERATOR_CANCELLED;
2709 }
2710
2711 Main *bmain = CTX_data_main(C);
2713
2714 /* Add the material to the copybuffer (and all of its dependencies). */
2715 copybuffer.id_add(
2716 &ma->id,
2717 PartialWriteContext::IDAddOptions{(PartialWriteContext::IDAddOperations::SET_FAKE_USER |
2718 PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK |
2719 PartialWriteContext::IDAddOperations::ADD_DEPENDENCIES)},
2720 nullptr);
2721
2722 char filepath[FILE_MAX];
2723 material_copybuffer_filepath_get(filepath, sizeof(filepath));
2724 copybuffer.write(filepath, *op->reports);
2725
2726 /* We are all done! */
2727 BKE_report(op->reports, RPT_INFO, "Copied material to internal clipboard");
2728
2729 return OPERATOR_FINISHED;
2730}
2731
2733{
2734 /* identifiers */
2735 ot->name = "Copy Material";
2736 ot->idname = "MATERIAL_OT_copy";
2737 ot->description = "Copy the material settings and nodes";
2738
2739 /* API callbacks. */
2741
2742 /* flags */
2743 /* no undo needed since no changes are made to the material */
2745}
2746
2748
2749/* -------------------------------------------------------------------- */
2752
2757{
2758 if (cb_data->cb_flag & IDWALK_CB_USER) {
2759 id_us_min(*cb_data->id_pointer);
2760 }
2761 *cb_data->id_pointer = nullptr;
2762 return IDWALK_RET_NOP;
2763}
2764
2769{
2770 Main *bmain = static_cast<Main *>(cb_data->user_data);
2771 ID **id_p = cb_data->id_pointer;
2772 if (*id_p) {
2773 if (cb_data->cb_flag & IDWALK_CB_USER) {
2774 id_us_min(*id_p);
2775 }
2776 ListBase *lb = which_libbase(bmain, GS((*id_p)->name));
2777 ID *id_local = static_cast<ID *>(
2778 BLI_findstring(lb, (*id_p)->name + 2, offsetof(ID, name) + 2));
2779 *id_p = id_local;
2780 if (cb_data->cb_flag & IDWALK_CB_USER) {
2781 id_us_plus(id_local);
2782 }
2783 else if (cb_data->cb_flag & IDWALK_CB_USER_ONE) {
2784 id_us_ensure_real(id_local);
2785 }
2786 id_lib_extern(id_local);
2787 }
2788 return IDWALK_RET_NOP;
2789}
2790
2792{
2793 Main *bmain = CTX_data_main(C);
2794 Material *ma = static_cast<Material *>(
2795 CTX_data_pointer_get_type(C, "material", &RNA_Material).data);
2796
2797 if (ma == nullptr) {
2798 BKE_report(op->reports, RPT_WARNING, "Cannot paste without a material");
2799 return OPERATOR_CANCELLED;
2800 }
2801
2802 /* Read copy buffer .blend file. */
2803 char filepath[FILE_MAX];
2804 Main *temp_bmain = BKE_main_new();
2805
2807
2808 material_copybuffer_filepath_get(filepath, sizeof(filepath));
2809
2810 /* NOTE(@ideasman42) The node tree might reference different kinds of ID types.
2811 * It's not clear-cut which ID types should be included, although it's unlikely
2812 * users would want an entire scene & it's objects to be included.
2813 * Filter a subset of ID types with some reasons for including them. */
2814 const uint64_t ntree_filter = (
2815 /* Material is necessary for reading the clipboard. */
2816 FILTER_ID_MA |
2817 /* Node-groups. */
2818 FILTER_ID_NT |
2819 /* Image textures. */
2820 FILTER_ID_IM |
2821 /* Internal text (scripts). */
2823 /* Texture coordinates may reference objects.
2824 * Note that object data is *not* included. */
2825 FILTER_ID_OB);
2826
2827 if (!BKE_copybuffer_read(temp_bmain, filepath, op->reports, ntree_filter)) {
2828 BKE_report(op->reports, RPT_ERROR, "Internal clipboard is empty");
2829 BKE_main_free(temp_bmain);
2830 return OPERATOR_CANCELLED;
2831 }
2832
2833 /* There may be multiple materials,
2834 * check for a property that marks this as the active material. */
2835 Material *ma_from = nullptr;
2836 LISTBASE_FOREACH (Material *, ma_iter, &temp_bmain->materials) {
2837 if (ma_iter->id.flag & ID_FLAG_CLIPBOARD_MARK) {
2838 ma_from = ma_iter;
2839 break;
2840 }
2841 }
2842
2843 /* Make sure data from this file is usable for material paste. */
2844 if (ma_from == nullptr) {
2845 BKE_report(op->reports, RPT_ERROR, "Internal clipboard is not from a material");
2846 BKE_main_free(temp_bmain);
2847 return OPERATOR_CANCELLED;
2848 }
2849
2850 /* Keep animation by moving local animation to the paste node-tree. */
2851 if (ma->nodetree && ma_from->nodetree) {
2852 BLI_assert(ma_from->nodetree->adt == nullptr);
2853 std::swap(ma->nodetree->adt, ma_from->nodetree->adt);
2854 }
2855
2856 /* Needed to update #SpaceNode::nodetree else a stale pointer is used. */
2857 if (ma->nodetree) {
2858 bNodeTree *nodetree = ma->nodetree;
2860
2861 /* Free & clear data here, so user counts are handled, otherwise it's
2862 * freed as part of #BKE_main_free which doesn't handle user-counts. */
2863 /* Walk over all the embedded nodes ID's (non-recursively). */
2865 bmain, &nodetree->id, paste_material_nodetree_ids_decref, nullptr, IDWALK_NOP);
2866
2868 MEM_freeN(nodetree);
2869 ma->nodetree = nullptr;
2870 }
2871
2872/* Swap data-block content, while swapping isn't always needed,
2873 * it means memory is properly freed in the case of allocations.. */
2874#define SWAP_MEMBER(member) std::swap(ma->member, ma_from->member)
2875
2876 /* Intentionally skip:
2877 * - Texture painting slots.
2878 * - Preview render.
2879 * - Grease pencil styles (we could although they reference many ID's themselves).
2880 */
2881 SWAP_MEMBER(flag);
2882 SWAP_MEMBER(r);
2883 SWAP_MEMBER(g);
2884 SWAP_MEMBER(b);
2885 SWAP_MEMBER(a);
2886 SWAP_MEMBER(specr);
2887 SWAP_MEMBER(specg);
2888 SWAP_MEMBER(specb);
2889 SWAP_MEMBER(spec);
2890 SWAP_MEMBER(roughness);
2891 SWAP_MEMBER(metallic);
2892 SWAP_MEMBER(use_nodes);
2893 SWAP_MEMBER(index);
2894 SWAP_MEMBER(nodetree);
2895 SWAP_MEMBER(line_col);
2896 SWAP_MEMBER(line_priority);
2897 SWAP_MEMBER(vcol_alpha);
2898
2899 SWAP_MEMBER(alpha_threshold);
2900 SWAP_MEMBER(refract_depth);
2901 SWAP_MEMBER(blend_method);
2902 SWAP_MEMBER(blend_shadow);
2903 SWAP_MEMBER(blend_flag);
2904
2905 SWAP_MEMBER(lineart);
2906
2907#undef SWAP_MEMBER
2908
2909 /* The node-tree from the clipboard is now assigned to the local material,
2910 * however the ID's it references are still part of `temp_bmain`.
2911 * These data-blocks references must be cleared or replaces with references to `bmain`.
2912 * TODO(@ideasman42): support merging indirectly referenced data-blocks besides the material,
2913 * this would be useful for pasting materials with node-groups between files. */
2914 if (ma->nodetree) {
2915 /* This implicitly points to local data, assign after remapping. */
2916 ma->nodetree->owner_id = nullptr;
2917
2918 /* Map remote ID's to local ones. */
2921
2922 ma->nodetree->owner_id = &ma->id;
2923 }
2924 BKE_main_free(temp_bmain);
2925
2926 /* Important to run this when the embedded tree if freed,
2927 * otherwise the depsgraph holds a reference to the (now freed) `ma->nodetree`.
2928 * Also run this when a new node-tree is set to ensure it's accounted for.
2929 * This also applies to animation data which is likely to be stored in the depsgraph.
2930 * Always call instead of checking when it *might* be needed. */
2932
2933 /* There are some custom updates to the node tree above, better do a full update pass. */
2936
2939
2940 return OPERATOR_FINISHED;
2941}
2942
2944{
2945 /* identifiers */
2946 ot->name = "Paste Material";
2947 ot->idname = "MATERIAL_OT_paste";
2948 ot->description = "Paste the material settings and nodes";
2949
2950 /* API callbacks. */
2953
2954 /* flags */
2956}
2957
2959
2960/* -------------------------------------------------------------------- */
2963
2964static short mtexcopied = 0; /* must be reset on file load */
2966
2968{ /* use for file reload */
2969 mtexcopied = 0;
2970}
2971
2972static void copy_mtex_copybuf(ID *id)
2973{
2974 MTex **mtex = nullptr;
2975
2976 switch (GS(id->name)) {
2977 case ID_PA:
2978 mtex = &(((ParticleSettings *)id)->mtex[int(((ParticleSettings *)id)->texact)]);
2979 break;
2980 case ID_LS:
2981 mtex = &(((FreestyleLineStyle *)id)->mtex[int(((FreestyleLineStyle *)id)->texact)]);
2982 break;
2983 default:
2984 break;
2985 }
2986
2987 if (mtex && *mtex) {
2988 mtexcopybuf = blender::dna::shallow_copy(**mtex);
2989 mtexcopied = 1;
2990 }
2991 else {
2992 mtexcopied = 0;
2993 }
2994}
2995
2996static void paste_mtex_copybuf(ID *id)
2997{
2998 MTex **mtex = nullptr;
2999
3000 if (mtexcopied == 0 || mtexcopybuf.tex == nullptr) {
3001 return;
3002 }
3003
3004 switch (GS(id->name)) {
3005 case ID_PA:
3006 mtex = &(((ParticleSettings *)id)->mtex[int(((ParticleSettings *)id)->texact)]);
3007 break;
3008 case ID_LS:
3009 mtex = &(((FreestyleLineStyle *)id)->mtex[int(((FreestyleLineStyle *)id)->texact)]);
3010 break;
3011 default:
3012 BLI_assert_msg(0, "invalid id type");
3013 return;
3014 }
3015
3016 if (mtex) {
3017 if (*mtex == nullptr) {
3018 *mtex = MEM_callocN<MTex>("mtex copy");
3019 }
3020 else if ((*mtex)->tex) {
3021 id_us_min(&(*mtex)->tex->id);
3022 }
3023
3024 **mtex = blender::dna::shallow_copy(mtexcopybuf);
3025
3026 /* NOTE(@ideasman42): the simple memory copy has no special handling for ID data-blocks.
3027 * Ideally this would use `BKE_copybuffer_*` API's, however for common using
3028 * copy-pasting between slots, the case a users expects to copy between files
3029 * seems quite niche. So, do primitive ID validation. */
3030
3031 /* WARNING: This isn't a fool-proof solution as it's possible memory locations are reused,
3032 * or that the ID was relocated in memory since it was copied.
3033 * it does however guard against references to dangling pointers. */
3034 if ((*mtex)->tex && (BLI_findindex(&G_MAIN->textures, (*mtex)->tex) == -1)) {
3035 (*mtex)->tex = nullptr;
3036 }
3037 if ((*mtex)->object && (BLI_findindex(&G_MAIN->objects, (*mtex)->object) == -1)) {
3038 (*mtex)->object = nullptr;
3039 }
3040 id_us_plus((ID *)(*mtex)->tex);
3041 id_lib_extern((ID *)(*mtex)->object);
3042 }
3043}
3044
3046
3047/* -------------------------------------------------------------------- */
3050
3052{
3053 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).owner_id;
3054
3055 if (id == nullptr) {
3056 /* copying empty slot */
3058 return OPERATOR_CANCELLED;
3059 }
3060
3062
3063 return OPERATOR_FINISHED;
3064}
3065
3067{
3068 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).owner_id;
3069
3070 return (id != nullptr);
3071}
3072
3074{
3075 /* identifiers */
3076 ot->name = "Copy Texture Slot Settings";
3077 ot->idname = "TEXTURE_OT_slot_copy";
3078 ot->description = "Copy the material texture settings and nodes";
3079
3080 /* API callbacks. */
3081 ot->exec = copy_mtex_exec;
3082 ot->poll = copy_mtex_poll;
3083
3084 /* flags */
3085 /* no undo needed since no changes are made to the mtex */
3087}
3088
3090
3091/* -------------------------------------------------------------------- */
3094
3096{
3097 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).owner_id;
3098
3099 if (id == nullptr) {
3100 Material *ma = static_cast<Material *>(
3101 CTX_data_pointer_get_type(C, "material", &RNA_Material).data);
3102 Light *la = static_cast<Light *>(CTX_data_pointer_get_type(C, "light", &RNA_Light).data);
3103 World *wo = static_cast<World *>(CTX_data_pointer_get_type(C, "world", &RNA_World).data);
3104 ParticleSystem *psys = static_cast<ParticleSystem *>(
3105 CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data);
3106 FreestyleLineStyle *linestyle = static_cast<FreestyleLineStyle *>(
3107 CTX_data_pointer_get_type(C, "line_style", &RNA_FreestyleLineStyle).data);
3108
3109 if (ma) {
3110 id = &ma->id;
3111 }
3112 else if (la) {
3113 id = &la->id;
3114 }
3115 else if (wo) {
3116 id = &wo->id;
3117 }
3118 else if (psys) {
3119 id = &psys->part->id;
3120 }
3121 else if (linestyle) {
3122 id = &linestyle->id;
3123 }
3124
3125 if (id == nullptr) {
3126 return OPERATOR_CANCELLED;
3127 }
3128 }
3129
3131
3133
3134 return OPERATOR_FINISHED;
3135}
3136
3138{
3139 /* identifiers */
3140 ot->name = "Paste Texture Slot Settings";
3141 ot->idname = "TEXTURE_OT_slot_paste";
3142 ot->description = "Copy the texture settings and nodes";
3143
3144 /* API callbacks. */
3145 ot->exec = paste_mtex_exec;
3146
3147 /* flags */
3149}
3150
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:82
void BKE_animdata_fix_paths_rename(struct ID *owner_id, struct AnimData *adt, struct ID *ref_id, const char *prefix, const char *oldName, const char *newName, int oldSubscript, int newSubscript, bool verify_paths)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1249
bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *reports, uint64_t id_types_mask)
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define CTX_DATA_BEGIN(C, Type, instance, member)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
wmWindow * CTX_wm_window(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
#define CTX_DATA_END
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
ListBase * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:423
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:61
struct FreestyleModuleConfig * BKE_freestyle_module_add(struct FreestyleConfig *config)
Definition freestyle.cc:116
struct FreestyleLineSet * BKE_freestyle_lineset_add(struct Main *bmain, struct FreestyleConfig *config, const char *name)
Definition freestyle.cc:163
struct FreestyleLineSet * BKE_freestyle_lineset_get_active(struct FreestyleConfig *config)
Definition freestyle.cc:212
bool BKE_freestyle_module_move(struct FreestyleConfig *config, struct FreestyleModuleConfig *module_conf, int direction)
Definition freestyle.cc:140
bool BKE_freestyle_module_delete(struct FreestyleConfig *config, struct FreestyleModuleConfig *module_conf)
Definition freestyle.cc:131
#define G_MAIN
ViewLayerLightgroup * BKE_view_layer_add_lightgroup(ViewLayer *view_layer, const char *name)
void BKE_view_layer_remove_aov(ViewLayer *view_layer, ViewLayerAOV *aov)
void BKE_view_layer_remove_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
#define FOREACH_OBJECT_END
Definition BKE_layer.hh:432
#define FOREACH_OBJECT_BEGIN(scene, view_layer, _instance)
Definition BKE_layer.hh:422
@ VIEWLAYER_ADD_NEW
Definition BKE_layer.hh:34
@ VIEWLAYER_ADD_EMPTY
Definition BKE_layer.hh:35
@ VIEWLAYER_ADD_COPY
Definition BKE_layer.hh:36
void BKE_view_layer_verify_aov(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
blender::Vector< Object * > BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer, const View3D *v3d, const ObjectsInViewLayerParams *params)
ViewLayer * BKE_view_layer_add(Scene *scene, const char *name, ViewLayer *view_layer_source, int type)
ViewLayerAOV * BKE_view_layer_add_aov(ViewLayer *view_layer)
void id_lib_extern(ID *id)
Definition lib_id.cc:285
void id_us_plus(ID *id)
Definition lib_id.cc:353
void BKE_id_move_to_same_lib(Main &bmain, ID &id, const ID &owner_id)
Definition lib_id.cc:869
void id_us_ensure_real(ID *id)
Definition lib_id.cc:308
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:767
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:772
void id_us_min(ID *id)
Definition lib_id.cc:361
@ LIB_ID_COPY_ACTIONS
@ LIB_ID_COPY_DEFAULT
@ IDWALK_CB_USER_ONE
@ IDWALK_CB_USER
void BKE_library_foreach_ID_link(Main *bmain, ID *id, blender::FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:431
@ IDWALK_RET_NOP
@ IDWALK_NOP
@ ID_REMAP_FORCE_UI_POINTERS
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
General operations for probes.
void BKE_lightprobe_cache_free(struct Object *object)
void BKE_lightprobe_cache_create(struct Object *object)
Blender kernel freestyle line style functionality.
FreestyleLineStyle * BKE_linestyle_new(struct Main *bmain, const char *name)
Definition linestyle.cc:710
int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
Definition linestyle.cc:934
LineStyleModifier * BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
LineStyleModifier * BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
LineStyleModifier * BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type)
#define LS_MODIFIER_TYPE_COLOR
#define LS_MODIFIER_TYPE_ALPHA
bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
LineStyleModifier * BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type)
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
Definition linestyle.cc:721
LineStyleModifier * BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type)
Definition linestyle.cc:784
int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
#define LS_MODIFIER_TYPE_GEOMETRY
bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
LineStyleModifier * BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
Definition linestyle.cc:842
#define LS_MODIFIER_TYPE_THICKNESS
LineStyleModifier * BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type)
LineStyleModifier * BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
ListBase * which_libbase(Main *bmain, short type)
Definition main.cc:887
Main * BKE_main_new()
Definition main.cc:48
void BKE_main_free(Main *bmain)
Definition main.cc:175
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:877
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:882
void BKE_main_ensure_invariants(Main &bmain, std::optional< blender::Span< ID * > > modified_ids=std::nullopt)
General operations, lookup, etc. for materials.
short * BKE_object_material_len_p(Object *ob)
Material ** BKE_object_material_get_p(Object *ob, short act)
void BKE_object_material_remap(Object *ob, const unsigned int *remap)
Material * BKE_gpencil_material_add(Main *bmain, const char *name)
bool BKE_object_material_slot_add(Main *bmain, Object *ob, bool set_active=true)
void BKE_object_material_array_assign(Main *bmain, Object *ob, Material ***matar, int totcol, bool to_object_only)
Material * BKE_material_add(Main *bmain, const char *name)
bool BKE_object_material_slot_used(Object *object, short actcol)
Material * BKE_object_material_get(Object *ob, short act)
int BKE_object_material_index_get_with_hint(Object *ob, const Material *ma, int hint_index)
Material *** BKE_object_material_array_p(Object *ob)
bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
void BKE_ntree_update_tag_all(bNodeTree *ntree)
void BKE_ntree_update_tag_id_changed(Main *bmain, ID *id)
General operations, lookup, etc. for blender objects.
bool BKE_object_is_in_editmode(const Object *ob)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
bool BKE_scene_remove_render_view(Scene *scene, SceneRenderView *srv)
Definition scene.cc:2728
SceneRenderView * BKE_scene_add_render_view(Scene *sce, const char *name)
Definition scene.cc:2709
bool give_active_mtex(struct ID *id, struct MTex ***mtex_ar, short *act)
Definition texture.cc:484
void set_active_mtex(struct ID *id, short act)
Definition texture.cc:510
struct Tex * BKE_texture_add(struct Main *bmain, const char *name)
Definition texture.cc:374
int BKE_vfont_select_get(const Curve *cu, int *r_start, int *r_end)
Definition vfont.cc:404
struct World * BKE_world_add(struct Main *bmain, const char *name)
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
void range_vn_u(unsigned int *array_tar, int size, unsigned int start)
#define FILE_MAX
#define BLI_path_join(...)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
unsigned int uint
#define ELEM(...)
#define STREQ(a, b)
#define BLT_I18NCONTEXT_ID_WORLD
#define CTX_DATA_(context, msgid)
#define DATA_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
ID and Library types, which are fundamental for SDNA.
@ ID_FLAG_CLIPBOARD_MARK
Definition DNA_ID.h:712
@ ID_RECALC_SHADING
Definition DNA_ID.h:1002
@ ID_RECALC_SELECT
Definition DNA_ID.h:1009
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1012
@ ID_LS
@ ID_PA
@ LIGHTPROBE_TYPE_VOLUME
@ OB_MODE_TEXTURE_PAINT
Object is a sort of wrapper for general info.
@ OB_SURF
@ OB_FONT
@ OB_GREASE_PENCIL
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_LIGHTPROBE
#define OB_TYPE_SUPPORT_MATERIAL(_type)
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_RUNNING_MODAL
@ OPERATOR_PASS_THROUGH
bool EDBM_deselect_by_material(BMEditMesh *em, short index, bool select)
void ED_node_shader_default(const bContext *C, ID *id)
Definition node_edit.cc:574
bool ED_paint_proj_mesh_data_check(Scene &scene, Object &ob, bool *r_has_uvs, bool *r_has_mat, bool *r_has_tex, bool *r_has_stencil)
void ED_render_clear_mtex_copybuf()
bool ED_scene_view_layer_delete(Main *bmain, Scene *scene, ViewLayer *layer, ReportList *reports) ATTR_NONNULL(1
bool ED_operator_object_active_local_editable_ex(bContext *C, const Object *ob)
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:358
bool FRS_move_active_lineset(struct FreestyleConfig *config, int direction)
void FRS_paste_active_lineset(struct FreestyleConfig *config)
struct Material * FRS_create_stroke_material(struct Main *bmain, struct FreestyleLineStyle *linestyle)
void FRS_copy_active_lineset(struct FreestyleConfig *config)
void FRS_delete_active_lineset(struct FreestyleConfig *config)
Read Guarded memory(de)allocation.
@ PROP_SKIP_SAVE
Definition RNA_types.hh:330
#define C
Definition RandGen.cpp:29
#define MAX_MTEX
Definition Stroke.h:31
void UI_context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
@ WM_JOB_TYPE_LIGHT_BAKE
Definition WM_api.hh:1752
#define NC_WORLD
Definition WM_types.hh:384
#define NC_GEOM
Definition WM_types.hh:390
#define ND_DRAW
Definition WM_types.hh:458
#define ND_DATA
Definition WM_types.hh:506
#define NC_LINESTYLE
Definition WM_types.hh:397
#define ND_RENDER_OPTIONS
Definition WM_types.hh:432
#define ND_SHADING_PREVIEW
Definition WM_types.hh:477
#define NC_SCENE
Definition WM_types.hh:375
#define NA_ADDED
Definition WM_types.hh:583
#define ND_TOOLSETTINGS
Definition WM_types.hh:446
ReportList * reports
Definition WM_types.hh:1025
#define NC_MATERIAL
Definition WM_types.hh:377
#define ND_SELECT
Definition WM_types.hh:505
#define NC_TEXTURE
Definition WM_types.hh:378
@ OPTYPE_INTERNAL
Definition WM_types.hh:202
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_LAYER
Definition WM_types.hh:447
#define ND_OB_SHADING
Definition WM_types.hh:454
#define NC_OBJECT
Definition WM_types.hh:376
#define ND_SHADING_LINKS
Definition WM_types.hh:476
@ BM_ELEM_SELECT
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
@ BM_FACES_OF_MESH
BMesh const char void * data
unsigned long long int uint64_t
bool add_as(ForwardKey &&key)
Definition BLI_set.hh:256
bool contains_as(const ForwardKey &key) const
Definition BLI_set.hh:314
void append(const T &value)
bool is_empty() const
ID * id_add(const ID *id, IDAddOptions options, blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports)
#define SELECT
#define offsetof(t, d)
bool ED_curve_nurb_select_check(const View3D *v3d, const Nurb *nu)
void * EEVEE_lightbake_job_data_alloc(Main *bmain, ViewLayer *view_layer, Scene *scene, blender::Vector< Object * > original_probes, std::string &report, int frame)
void EEVEE_lightbake_job(void *job_data, wmJobWorkerStatus *worker_status)
void EEVEE_lightbake_job_data_free(void *job_data)
wmJob * EEVEE_lightbake_job_create(wmWindowManager *wm, wmWindow *win, Main *bmain, ViewLayer *view_layer, Scene *scene, blender::Vector< Object * > original_probes, std::string &report, int delay_ms, int frame)
void EEVEE_lightbake_update(void *job_data)
#define select(A, B, C)
#define FILTER_ID_OB
#define FILTER_ID_MA
#define ID_IS_LINKED(_id)
#define ID_IS_EDITABLE(_id)
#define MAX_NAME
#define ID_IS_OVERRIDE_LIBRARY(_id)
#define FILTER_ID_IM
#define GS(a)
#define FILTER_ID_NT
#define FILTER_ID_TXT
RenderEngineType * RE_engines_find(const char *idname)
RenderEngine * RE_engine_create(RenderEngineType *type)
void RE_engine_free(RenderEngine *engine)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
#define G(x, y, z)
void node_tree_free_embedded_tree(bNodeTree *ntree)
Definition node.cc:4724
Object * context_object(const bContext *C)
blender::Vector< Object * > objects_in_mode_or_selected(bContext *C, bool(*filter_fn)(const Object *ob, void *user_data), void *filter_user_data)
void ntreeCompositUpdateRLayers(bNodeTree *ntree)
void OBJECT_OT_material_slot_remove_all(wmOperatorType *ot)
void OBJECT_OT_material_slot_add(wmOperatorType *ot)
void OBJECT_OT_material_slot_deselect(wmOperatorType *ot)
void OBJECT_OT_lightprobe_cache_free(wmOperatorType *ot)
void OBJECT_OT_material_slot_copy(wmOperatorType *ot)
void SCENE_OT_view_layer_remove_unused_lightgroups(wmOperatorType *ot)
void OBJECT_OT_lightprobe_cache_bake(wmOperatorType *ot)
void OBJECT_OT_material_slot_select(wmOperatorType *ot)
void WORLD_OT_new(wmOperatorType *ot)
void OBJECT_OT_material_slot_remove_unused(wmOperatorType *ot)
void OBJECT_OT_material_slot_assign(wmOperatorType *ot)
void MATERIAL_OT_paste(wmOperatorType *ot)
void MATERIAL_OT_new(wmOperatorType *ot)
void SCENE_OT_view_layer_add(wmOperatorType *ot)
void OBJECT_OT_material_slot_move(wmOperatorType *ot)
void SCENE_OT_view_layer_add_used_lightgroups(wmOperatorType *ot)
void TEXTURE_OT_new(wmOperatorType *ot)
void MATERIAL_OT_copy(wmOperatorType *ot)
void SCENE_OT_view_layer_remove_lightgroup(wmOperatorType *ot)
void TEXTURE_OT_slot_paste(wmOperatorType *ot)
void SCENE_OT_view_layer_add_aov(wmOperatorType *ot)
void TEXTURE_OT_slot_copy(wmOperatorType *ot)
void SCENE_OT_render_view_add(wmOperatorType *ot)
void SCENE_OT_view_layer_remove_aov(wmOperatorType *ot)
void OBJECT_OT_material_slot_remove(wmOperatorType *ot)
void TEXTURE_OT_slot_move(wmOperatorType *ot)
void SCENE_OT_view_layer_remove(wmOperatorType *ot)
void SCENE_OT_view_layer_add_lightgroup(wmOperatorType *ot)
void SCENE_OT_render_view_remove(wmOperatorType *ot)
static wmOperatorStatus material_slot_assign_exec(bContext *C, wmOperator *)
static wmOperatorStatus render_view_remove_exec(bContext *C, wmOperator *)
static wmOperatorStatus paste_mtex_exec(bContext *C, wmOperator *)
@ LIGHTCACHE_SUBSET_ACTIVE
@ LIGHTCACHE_SUBSET_SELECTED
@ LIGHTCACHE_SUBSET_ALL
static wmOperatorStatus copy_material_exec(bContext *C, wmOperator *op)
static wmOperatorStatus material_slot_remove_all_exec(bContext *C, wmOperator *op)
static wmOperatorStatus lightprobe_cache_bake_invoke(bContext *C, wmOperator *op, const wmEvent *)
static blender::Vector< Object * > lightprobe_cache_irradiance_volume_subset_get(bContext *C, wmOperator *op)
static wmOperatorStatus view_layer_remove_unused_lightgroups_exec(bContext *C, wmOperator *)
static wmOperatorStatus lightprobe_cache_bake_modal(bContext *C, wmOperator *op, const wmEvent *event)
static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob, void *user_data)
static wmOperatorStatus new_material_exec(bContext *C, wmOperator *)
static MTex mtexcopybuf
static bool view_layer_remove_poll(bContext *C)
static void paste_mtex_copybuf(ID *id)
static wmOperatorStatus material_slot_remove_unused_exec(bContext *C, wmOperator *op)
static wmOperatorStatus material_slot_copy_exec(bContext *C, wmOperator *)
static void copy_mtex_copybuf(ID *id)
static wmOperatorStatus material_slot_select_exec(bContext *C, wmOperator *)
static wmOperatorStatus lightprobe_cache_free_exec(bContext *C, wmOperator *op)
static wmOperatorStatus new_world_exec(bContext *C, wmOperator *)
static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob, void *user_data)
static wmOperatorStatus lightprobe_cache_bake_exec(bContext *C, wmOperator *op)
static wmOperatorStatus material_slot_deselect_exec(bContext *C, wmOperator *)
static wmOperatorStatus view_layer_add_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_layer_add_lightgroup_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_layer_add_aov_exec(bContext *C, wmOperator *)
static bool render_view_remove_poll(bContext *C)
static bool object_materials_supported_poll(bContext *C)
static wmOperatorStatus material_slot_move_exec(bContext *C, wmOperator *op)
static wmOperatorStatus material_slot_remove_exec(bContext *C, wmOperator *op)
static wmOperatorStatus new_texture_exec(bContext *C, wmOperator *op)
static int paste_material_nodetree_ids_decref(LibraryIDLinkCallbackData *cb_data)
static wmOperatorStatus render_view_add_exec(bContext *C, wmOperator *)
static Vector< Object * > object_array_for_shading_edit_mode_enabled(bContext *C)
static wmOperatorStatus view_layer_remove_lightgroup_exec(bContext *C, wmOperator *)
static wmOperatorStatus view_layer_remove_exec(bContext *C, wmOperator *)
static int paste_material_nodetree_ids_relink_or_clear(LibraryIDLinkCallbackData *cb_data)
static wmOperatorStatus view_layer_remove_aov_exec(bContext *C, wmOperator *)
static wmOperatorStatus paste_material_exec(bContext *C, wmOperator *op)
static wmOperatorStatus copy_mtex_exec(bContext *C, wmOperator *)
static wmOperatorStatus material_slot_add_exec(bContext *C, wmOperator *)
static blender::Set< blender::StringRefNull > get_used_lightgroups(Scene *scene)
static void material_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
static wmOperatorStatus material_slot_de_select(bContext *C, bool select)
static void lightprobe_cache_bake_cancel(bContext *C, wmOperator *op)
#define SWAP_MEMBER(member)
static wmOperatorStatus view_layer_add_used_lightgroups_exec(bContext *C, wmOperator *)
static bool object_materials_supported_poll_ex(bContext *C, const Object *ob)
static bool copy_mtex_poll(bContext *C)
static wmOperatorStatus texture_slot_move_exec(bContext *C, wmOperator *op)
static short mtexcopied
static Vector< Object * > object_array_for_shading_edit_mode_disabled(bContext *C)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
const EnumPropertyItem rna_enum_linestyle_thickness_modifier_type_items[]
const EnumPropertyItem rna_enum_linestyle_geometry_modifier_type_items[]
const EnumPropertyItem rna_enum_linestyle_color_modifier_type_items[]
const EnumPropertyItem rna_enum_linestyle_alpha_modifier_type_items[]
short mat_nr
uint8_t f1
struct EditFont * editfont
CharInfo * textbufinfo
Definition BKE_vfont.hh:42
struct FreestyleLineStyle * linestyle
Definition DNA_ID.h:404
LibraryForeachIDCallbackFlag cb_flag
void * last
void * first
struct Tex * tex
char filepath[1024]
Definition BKE_main.hh:155
ListBase materials
Definition BKE_main.hh:251
struct bNodeTree * nodetree
struct Material ** mat
char * matbits
bool(*) filter_fn(const Object *ob, void *user_data)
Definition BKE_layer.hh:487
ParticleSettings * part
ID * owner_id
Definition RNA_types.hh:51
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
char engine[32]
void(*) update_render_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer)
Definition RE_engine.h:111
struct bNodeTree * nodetree
struct RenderData r
ListBase view_layers
struct World * world
struct FreestyleConfig freestyle_config
ListBase lightgroups
ViewLayerLightgroup * active_lightgroup
ViewLayerAOV * active_aov
char name[64]
struct LightgroupMembership * lightgroup
short use_nodes
struct AnimData * adt
wmEventType type
Definition WM_types.hh:754
const char * name
Definition WM_types.hh:1030
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1062
const char * idname
Definition WM_types.hh:1032
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1046
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1086
const char * description
Definition WM_types.hh:1036
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1078
PropertyRNA * prop
Definition WM_types.hh:1136
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1070
StructRNA * srna
Definition WM_types.hh:1124
struct ReportList * reports
struct PointerRNA * ptr
i
Definition text_draw.cc:230
void WM_cursor_wait(bool val)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ EVT_ESCKEY
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition wm_jobs.cc:456
void WM_jobs_kill_type(wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:598
bool WM_jobs_test(const wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:224
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void WM_window_set_active_view_layer(wmWindow *win, ViewLayer *view_layer)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)