Blender V5.3
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_array_utils.hh"
27#include "BLI_listbase.hh"
28#include "BLI_math_vector_c.hh"
29#include "BLI_path_utils.hh"
30#include "BLI_string_utils.hh"
31#include "BLI_utildefines.hh"
32
33#include "BLT_translation.hh"
34
35#include "BKE_anim_data.hh"
36#include "BKE_animsys.hh"
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#include "NOD_defaults.hh"
69
70#include "DEG_depsgraph.hh"
73
74#ifdef WITH_FREESTYLE
75# include "BKE_freestyle.h"
76# include "FRS_freestyle.h"
77# include "RNA_enum_types.hh"
78#endif
79
80#include "RNA_access.hh"
81#include "RNA_path.hh"
82
83#include "WM_api.hh"
84#include "WM_types.hh"
85
86#include "ED_curve.hh"
87#include "ED_mesh.hh"
88#include "ED_node.hh"
89#include "ED_object.hh"
90#include "ED_paint.hh"
91#include "ED_render.hh"
92#include "ED_scene.hh"
93#include "ED_screen.hh"
94#include "ED_undo.hh"
95
96#include "RNA_define.hh"
97#include "RNA_prototypes.hh"
98
99#include "UI_interface.hh"
100
101#include "RE_engine.h"
102#include "RE_pipeline.h"
103
105
106#include "render_intern.hh" /* own include */
107
108namespace blender {
109
110static bool object_materials_supported_poll_ex(bContext *C, const Object *ob);
111
112/* -------------------------------------------------------------------- */
115
116static void material_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
117{
118 BLI_path_join(filepath, filepath_maxncpy, BKE_tempdir_base(), "copybuffer_material.blend");
119}
120
121static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob, void *user_data)
122{
123 bContext *C = static_cast<bContext *>(user_data);
125 if (BKE_object_is_in_editmode(ob) == true) {
126 return true;
127 }
128 }
129 return false;
130}
131
137
138static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob, void *user_data)
139{
140 bContext *C = static_cast<bContext *>(user_data);
142 if (BKE_object_is_in_editmode(ob) == false) {
143 return true;
144 }
145 }
146 return false;
147}
148
154
156
157/* -------------------------------------------------------------------- */
160
162{
164 return false;
165 }
166 if (!OB_TYPE_SUPPORT_MATERIAL(ob->type)) {
167 return false;
168 }
169
170 /* Material linked to object. */
171 if (ob->matbits && ob->actcol >= 1 && ob->actcol <= ob->totcol && ob->matbits[ob->actcol - 1]) {
172 return true;
173 }
174
175 /* Material linked to obdata. */
176 const ID *data = ob->data;
178}
179
185
187{
188 const Object *ob_active = CTX_data_active_object(C);
189 if (ob_active == nullptr) {
190 return false;
191 }
192 return ob_active->actcol > 0;
193}
194
195
196/* -------------------------------------------------------------------- */
199
201{
202 Main *bmain = CTX_data_main(C);
204
205 if (!ob) {
206 return OPERATOR_CANCELLED;
207 }
208
210
211 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
212 Scene *scene = CTX_data_scene(C);
213 ED_paint_proj_mesh_data_check(*scene, *ob, nullptr, nullptr, nullptr, nullptr);
215 }
216
220
221 return OPERATOR_FINISHED;
222}
223
225{
226 /* identifiers */
227 ot->name = "Add Material Slot";
228 ot->idname = "OBJECT_OT_material_slot_add";
229 ot->description = "Add a new material slot";
230
231 /* API callbacks. */
234
235 /* flags */
237}
238
240
241/* -------------------------------------------------------------------- */
244
246{
248
250 return false;
251 }
252
253 /* Removing material slots in edit mode screws things up, see bug #21822. */
255 CTX_wm_operator_poll_msg_set(C, "Unable to remove material slot in edit mode");
256 return false;
257 }
259 return false;
260 }
261
262 return true;
263}
264
266{
268
269 if (!ob) {
270 return OPERATOR_CANCELLED;
271 }
272
274
275 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
276 Scene *scene = CTX_data_scene(C);
277 ED_paint_proj_mesh_data_check(*scene, *ob, nullptr, nullptr, nullptr, nullptr);
279 }
280
285
286 return OPERATOR_FINISHED;
287}
288
290{
291 /* identifiers */
292 ot->name = "Remove Material Slot";
293 ot->idname = "OBJECT_OT_material_slot_remove";
294 ot->description = "Remove the selected material slot";
295
296 /* API callbacks. */
299
300 /* flags */
302}
303
305
306/* -------------------------------------------------------------------- */
309
311{
312 View3D *v3d = CTX_wm_view3d(C);
313 bool changed_multi = false;
314
316 const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
317
319 for (Object *ob : objects) {
320 short mat_nr_active = -1;
321
322 if (ob->totcol == 0) {
323 continue;
324 }
325 if (obact && (obact->actcol >= 1 && obact->actcol <= ob->totcol) &&
326 (mat_active == BKE_object_material_get(ob, obact->actcol)))
327 {
328 /* Avoid searching since there may be multiple slots with the same material.
329 * For the active object or duplicates: match the material slot index first. */
330 mat_nr_active = obact->actcol - 1;
331 }
332 else {
333 /* Find the first matching material.
334 * NOTE: there may be multiple but that's not a common use case. */
335 for (int i = 0; i < ob->totcol; i++) {
336 const Material *mat = BKE_object_material_get(ob, i + 1);
337 if (mat_active == mat) {
338 mat_nr_active = i;
339 break;
340 }
341 }
342 if (mat_nr_active == -1) {
343 continue;
344 }
345 }
346
347 bool changed = false;
348 if (ob->type == OB_MESH) {
349 BMFace *efa;
350 BMIter iter;
351
353 BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
355 changed = true;
356 efa->mat_nr = mat_nr_active;
357 }
358 }
359 }
360 }
361 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
362 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(id_cast<Curve *>(ob->data));
363
364 if (nurbs) {
365 for (Nurb &nu : *nurbs) {
366 if (ED_curve_nurb_select_check(v3d, &nu)) {
367 changed = true;
368 nu.mat_nr = mat_nr_active;
369 }
370 }
371 }
372 }
373 else if (ob->type == OB_FONT) {
374 const Curve *cu = id_cast<const Curve *>(ob->data);
375 EditFont *ef = cu->editfont;
376 int i, selstart, selend;
377
378 if (ef && BKE_vfont_select_get(cu, &selstart, &selend)) {
379 for (i = selstart; i <= selend; i++) {
380 changed = true;
381 ef->textbufinfo[i].mat_nr = mat_nr_active;
382 }
383 }
384 }
385
386 if (changed) {
387 changed_multi = true;
390 }
391 }
392
393 return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
394}
395
397{
398 /* identifiers */
399 ot->name = "Assign Material Slot";
400 ot->idname = "OBJECT_OT_material_slot_assign";
401 ot->description = "Assign active material slot to selection";
402
403 /* API callbacks. */
406
407 /* flags */
409}
410
412
413/* -------------------------------------------------------------------- */
416
418{
419 bool changed_multi = false;
421 const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
422
424 for (Object *ob : objects) {
425 if (ob->totcol == 0) {
426 continue;
427 }
428
429 const short mat_nr_active = BKE_object_material_index_get_with_hint(
430 ob, mat_active, obact ? obact->actcol - 1 : -1);
431
432 if (mat_nr_active == -1) {
433 continue;
434 }
435
436 bool changed = false;
437
438 if (ob->type == OB_MESH) {
440
441 if (em) {
443 changed = EDBM_deselect_by_material(bm, mat_nr_active, select);
444 }
445 }
446 else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
447 ListBaseT<Nurb> *nurbs = BKE_curve_editNurbs_get(id_cast<Curve *>(ob->data));
448 BPoint *bp;
449 BezTriple *bezt;
450 int a;
451
452 if (nurbs) {
453 for (Nurb &nu : *nurbs) {
454 if (nu.mat_nr == mat_nr_active) {
455 if (nu.bezt) {
456 a = nu.pntsu;
457 bezt = nu.bezt;
458 while (a--) {
459 if (bezt->hide == 0) {
460 changed = true;
461 if (select) {
462 bezt->f1 |= BEZT_FLAG_SELECT;
463 bezt->f2 |= BEZT_FLAG_SELECT;
464 bezt->f3 |= BEZT_FLAG_SELECT;
465 }
466 else {
467 bezt->f1 &= ~BEZT_FLAG_SELECT;
468 bezt->f2 &= ~BEZT_FLAG_SELECT;
469 bezt->f3 &= ~BEZT_FLAG_SELECT;
470 }
471 }
472 bezt++;
473 }
474 }
475 else if (nu.bp) {
476 a = nu.pntsu * nu.pntsv;
477 bp = nu.bp;
478 while (a--) {
479 if (bp->hide == 0) {
480 changed = true;
481 if (select) {
482 bp->f1 |= SELECT;
483 }
484 else {
485 bp->f1 &= ~SELECT;
486 }
487 }
488 bp++;
489 }
490 }
491 }
492 }
493 }
494 }
495
496 if (changed) {
497 changed_multi = true;
500 }
501 }
502
503 return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
504}
505
510
512{
513 /* identifiers */
514 ot->name = "Select Material Slot";
515 ot->idname = "OBJECT_OT_material_slot_select";
516 ot->description = "Select by active material slot";
517
518 /* API callbacks. */
520
521 /* flags */
523}
524
529
531{
532 /* identifiers */
533 ot->name = "Deselect Material Slot";
534 ot->idname = "OBJECT_OT_material_slot_deselect";
535 ot->description = "Deselect by active material slot";
536
537 /* API callbacks. */
539
540 /* flags */
542}
543
545
546/* -------------------------------------------------------------------- */
549
551{
552 Main *bmain = CTX_data_main(C);
554 Material ***matar_obdata;
555
556 if (!ob || !(matar_obdata = BKE_object_material_array_p(ob))) {
557 return OPERATOR_CANCELLED;
558 }
559
561
562 Material ***matar_object = &ob->mat;
563
564 Material **matar = MEM_new_array_zeroed<Material *>(size_t(ob->totcol), __func__);
565 for (int i = ob->totcol; i--;) {
566 matar[i] = ob->matbits[i] ? (*matar_object)[i] : (*matar_obdata)[i];
567 }
568
569 CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) {
570 if (ob != ob_iter && BKE_object_material_array_p(ob_iter)) {
571 /* If we are using the same obdata, we only assign slots in ob_iter that are using object
572 * materials, and not obdata ones. */
573 const bool is_same_obdata = ob->data == ob_iter->data;
574
575 /* If we are using the same obdata, make the target object inherit the matbits of the active
576 * object. Without this, object material slots are not copied unless the target object
577 * already had its material slot link set to object. */
578 if (is_same_obdata) {
579 for (int i = ob->totcol; i--;) {
580 if (ob->matbits[i]) {
581 ob_iter->matbits[i] = ob->matbits[i];
582 }
583 }
584 }
585
586 BKE_object_material_array_assign(bmain, ob_iter, &matar, ob->totcol, is_same_obdata);
587
588 if (ob_iter->totcol == ob->totcol) {
589 ob_iter->actcol = ob->actcol;
592 }
593 }
594 }
596
597 MEM_delete(matar);
598
599 return OPERATOR_FINISHED;
600}
601
603{
604 /* identifiers */
605 ot->name = "Copy Material to Selected";
606 ot->idname = "OBJECT_OT_material_slot_copy";
607 ot->description = "Copy material to selected objects";
608
609 /* API callbacks. */
612
613 /* flags */
615}
616
618
619/* -------------------------------------------------------------------- */
622
624{
626
627 uint *slot_remap;
628 int index_pair[2];
629
630 int dir = RNA_enum_get(op->ptr, "direction");
631
632 if (!ob || ob->totcol < 2) {
633 return OPERATOR_CANCELLED;
634 }
635
637
638 /* up */
639 if (dir == 1 && ob->actcol > 1) {
640 index_pair[0] = ob->actcol - 2;
641 index_pair[1] = ob->actcol - 1;
642 ob->actcol--;
643 }
644 /* down */
645 else if (dir == -1 && ob->actcol < ob->totcol) {
646 index_pair[0] = ob->actcol - 1;
647 index_pair[1] = ob->actcol - 0;
648 ob->actcol++;
649 }
650 else {
651 return OPERATOR_CANCELLED;
652 }
653
654 slot_remap = MEM_new_array_uninitialized<uint>(ob->totcol, __func__);
655
657
658 slot_remap[index_pair[0]] = index_pair[1];
659 slot_remap[index_pair[1]] = index_pair[0];
660
661 BKE_object_material_remap(ob, slot_remap);
662
663 MEM_delete(slot_remap);
664
668
669 return OPERATOR_FINISHED;
670}
671
673{
674 static const EnumPropertyItem material_slot_move[] = {
675 {1, "UP", 0, "Up", ""},
676 {-1, "DOWN", 0, "Down", ""},
677 {0, nullptr, 0, nullptr, nullptr},
678 };
679
680 /* identifiers */
681 ot->name = "Move Material";
682 ot->idname = "OBJECT_OT_material_slot_move";
683 ot->description = "Move the active material up/down in the list";
684
685 /* API callbacks. */
688
689 /* flags */
691
692 RNA_def_enum(ot->srna,
693 "direction",
694 material_slot_move,
695 0,
696 "Direction",
697 "Direction to move the active material towards");
698}
699
701
702/* -------------------------------------------------------------------- */
705
707{
708 Main *bmain = CTX_data_main(C);
709 int removed = 0;
710
712 for (Object *ob : objects) {
713 removed += BKE_object_material_remove_unused(bmain, ob);
715 }
716
717 if (!removed) {
718 return OPERATOR_CANCELLED;
719 }
720
721 BKE_reportf(op->reports, RPT_INFO, "Removed %d slots", removed);
722
723 Object *ob_active = CTX_data_active_object(C);
724 if (ob_active->mode & OB_MODE_TEXTURE_PAINT) {
725 Scene *scene = CTX_data_scene(C);
726 ED_paint_proj_mesh_data_check(*scene, *ob_active, nullptr, nullptr, nullptr, nullptr);
728 }
729
733
734 return OPERATOR_FINISHED;
735}
736
738{
739 /* identifiers */
740 ot->name = "Remove Unused Slots";
741 ot->idname = "OBJECT_OT_material_slot_remove_unused";
742 ot->description = "Remove unused material slots";
743
744 /* API callbacks. */
747
748 /* flags */
750}
751
753{
754 /* Removing material slots in edit mode screws things up, see bug #21822. */
755 Object *ob_active = CTX_data_active_object(C);
756 Main *bmain = CTX_data_main(C);
757 int removed = 0;
758
760 for (Object *ob : objects) {
761 removed += BKE_object_material_remove_all(bmain, ob);
763 }
764
765 if (!removed) {
766 return OPERATOR_CANCELLED;
767 }
768
769 BKE_reportf(op->reports, RPT_INFO, "Removed %d materials", removed);
770
771 if (ob_active->mode == OB_MODE_TEXTURE_PAINT) {
772 Scene *scene = CTX_data_scene(C);
773 ED_paint_proj_mesh_data_check(*scene, *ob_active, nullptr, nullptr, nullptr, nullptr);
775 }
776
780
781 return OPERATOR_FINISHED;
782}
783
785{
786 /* identifiers */
787 ot->name = "Remove All Materials";
788 ot->idname = "OBJECT_OT_material_slot_remove_all";
789 ot->description = "Remove all materials";
790
791 /* API callbacks. */
794
795 /* flags */
797}
798
800
801/* -------------------------------------------------------------------- */
804
806{
807 Material *ma = static_cast<Material *>(
808 CTX_data_pointer_get_type(C, "material", RNA_Material).data);
809 Main *bmain = CTX_data_main(C);
810 PointerRNA ptr;
811 PropertyRNA *prop;
812
813 /* hook into UI */
815
816 Object *ob = static_cast<Object *>((prop && RNA_struct_is_a(ptr.type, RNA_Object)) ? ptr.data :
817 nullptr);
818
819 /* add or copy material */
820 if (ma) {
821 Material *new_ma = id_cast<Material *>(
822 BKE_id_copy_ex(bmain, &ma->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
823 ma = new_ma;
824 }
825 else {
826 const char *name = DATA_("Material");
827 if (!(ob != nullptr && ob->type == OB_GREASE_PENCIL)) {
828 ma = BKE_material_add(bmain, name);
829 }
830 else {
831 ma = BKE_gpencil_material_add(bmain, name);
832 }
833 nodes::node_tree_shader_default(C, bmain, &ma->id);
834 }
835
836 if (prop) {
837 if (ob != nullptr) {
838 /* Add slot follows user-preferences for creating new slots,
839 * RNA pointer assignment doesn't, see: #60014. */
840 if (BKE_object_material_get_p(ob, ob->actcol) == nullptr) {
842 }
843 }
844
845 /* when creating new ID blocks, use is already 1, but RNA
846 * pointer use also increases user, so this compensates it */
847 id_us_min(&ma->id);
848
849 if (ptr.owner_id) {
850 BKE_id_move_to_same_lib(*bmain, ma->id, *ptr.owner_id);
851 }
852
853 PointerRNA idptr = RNA_id_pointer_create(&ma->id);
854 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
855 RNA_property_update(C, &ptr, prop);
856 }
857
859
860 return OPERATOR_FINISHED;
861}
862
864{
865 /* identifiers */
866 ot->name = "New Material";
867 ot->idname = "MATERIAL_OT_new";
868 ot->description = "Add a new material";
869
870 /* API callbacks. */
873
874 /* flags */
876}
877
879
880/* -------------------------------------------------------------------- */
883
885{
886 Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", RNA_Texture).data);
887 Main *bmain = CTX_data_main(C);
888 PointerRNA ptr;
889 PropertyRNA *prop;
890
891 /* add or copy texture */
892 if (tex) {
893 tex = id_cast<Tex *>(BKE_id_copy(bmain, &tex->id));
894 }
895 else {
896 tex = BKE_texture_add(bmain, DATA_("Texture"));
897 }
898
899 /* hook into UI */
901
902 bool linked_id_created = false;
903 if (prop) {
904 /* when creating new ID blocks, use is already 1, but RNA
905 * pointer use also increases user, so this compensates it */
906 id_us_min(&tex->id);
907
908 if (ptr.owner_id) {
909 BKE_id_move_to_same_lib(*bmain, tex->id, *ptr.owner_id);
910 linked_id_created = ID_IS_LINKED(&tex->id);
911 }
912
913 PointerRNA idptr = RNA_id_pointer_create(&tex->id);
914 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
915 RNA_property_update(C, &ptr, prop);
916 }
917
918 if (!linked_id_created) {
919 ED_undo_push_op(C, op);
920 }
921
923
924 return OPERATOR_FINISHED;
925}
926
928{
929 /* identifiers */
930 ot->name = "New Texture";
931 ot->idname = "TEXTURE_OT_new";
932 ot->description = "Add a new texture";
933
934 /* API callbacks. */
936
937 /* flags */
939}
940
942
943/* -------------------------------------------------------------------- */
946
948{
949 World *wo = static_cast<World *>(CTX_data_pointer_get_type(C, "world", RNA_World).data);
950 Main *bmain = CTX_data_main(C);
951 PointerRNA ptr;
952 PropertyRNA *prop;
953
954 /* add or copy world */
955 if (wo) {
956 World *new_wo = id_cast<World *>(
957 BKE_id_copy_ex(bmain, &wo->id, nullptr, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS));
958 wo = new_wo;
959 }
960 else {
961 wo = BKE_world_add(bmain, CTX_DATA_(BLT_I18NCONTEXT_ID_WORLD, "World"));
962 nodes::node_tree_shader_default(C, bmain, &wo->id);
963 }
964
965 /* hook into UI */
967
968 if (prop) {
969 /* when creating new ID blocks, use is already 1, but RNA
970 * pointer use also increases user, so this compensates it */
971 id_us_min(&wo->id);
972
973 if (ptr.owner_id) {
974 BKE_id_move_to_same_lib(*bmain, wo->id, *ptr.owner_id);
975 }
976
977 PointerRNA idptr = RNA_id_pointer_create(&wo->id);
978 RNA_property_pointer_set(&ptr, prop, idptr, nullptr);
979 RNA_property_update(C, &ptr, prop);
980 }
981
983
984 return OPERATOR_FINISHED;
985}
986
988{
989 /* identifiers */
990 ot->name = "New World";
991 ot->idname = "WORLD_OT_new";
992 ot->description = "Create a new world Data-Block";
993
994 /* API callbacks. */
995 ot->exec = new_world_exec;
996
997 /* flags */
999}
1000
1002
1003/* -------------------------------------------------------------------- */
1006
1008{
1009 wmWindow *win = CTX_wm_window(C);
1010 const Main *bmain = CTX_data_main(C);
1011 Scene *scene = CTX_data_scene(C);
1012
1013 /* Only make the view layer active if the windows scene matches the context. */
1014 if (win) {
1015 if (scene != WM_window_get_active_scene(win)) {
1016 win = nullptr;
1017 }
1018 }
1019
1020 ViewLayer *view_layer_current = win ? WM_window_get_active_view_layer(win) : nullptr;
1021 int type = RNA_enum_get(op->ptr, "type");
1022 /* Copy requires a source. */
1023 if (type == VIEWLAYER_ADD_COPY) {
1024 if (view_layer_current == nullptr) {
1025 type = VIEWLAYER_ADD_NEW;
1026 }
1027 }
1028 ViewLayer *view_layer_new = BKE_view_layer_add(bmain,
1029 scene,
1030 view_layer_current ? view_layer_current->name :
1031 nullptr,
1032 view_layer_current,
1033 type);
1034
1035 if (win) {
1036 WM_window_set_active_view_layer(win, view_layer_new);
1037 }
1038
1042
1043 return OPERATOR_FINISHED;
1044}
1045
1047{
1048 static EnumPropertyItem type_items[] = {
1049 {VIEWLAYER_ADD_NEW, "NEW", 0, "New", "Add a new view layer"},
1050 {VIEWLAYER_ADD_COPY, "COPY", 0, "Copy Settings", "Copy settings of current view layer"},
1052 "EMPTY",
1053 0,
1054 "Blank",
1055 "Add a new view layer with all collections disabled"},
1056 {0, nullptr, 0, nullptr, nullptr},
1057 };
1058
1059 /* identifiers */
1060 ot->name = "Add View Layer";
1061 ot->idname = "SCENE_OT_view_layer_add";
1062 ot->description = "Add a view layer";
1063
1064 /* API callbacks. */
1066 ot->invoke = WM_menu_invoke;
1067
1068 /* flags */
1070
1071 /* properties */
1072 ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
1073}
1074
1076
1077/* -------------------------------------------------------------------- */
1080
1082{
1083 Scene *scene = CTX_data_scene(C);
1084 return (scene->view_layers.first() != scene->view_layers.last());
1085}
1086
1088{
1089 Main *bmain = CTX_data_main(C);
1090 Scene *scene = CTX_data_scene(C);
1091 ViewLayer *view_layer = CTX_data_view_layer(C);
1092
1093 if (!ED_scene_view_layer_delete(bmain, scene, view_layer, nullptr)) {
1094 return OPERATOR_CANCELLED;
1095 }
1096
1098
1099 return OPERATOR_FINISHED;
1100}
1101
1103{
1104 /* identifiers */
1105 ot->name = "Remove View Layer";
1106 ot->idname = "SCENE_OT_view_layer_remove";
1107 ot->description = "Remove the selected view layer";
1108
1109 /* API callbacks. */
1112
1113 /* flags */
1115}
1116
1118
1119/* -------------------------------------------------------------------- */
1122
1124{
1125 Scene *scene = CTX_data_scene(C);
1126 ViewLayer *view_layer = CTX_data_view_layer(C);
1127
1128 BKE_view_layer_add_aov(view_layer);
1129
1130 RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
1131 if (engine_type->update_render_passes) {
1132 RenderEngine *engine = RE_engine_create(engine_type);
1133 if (engine) {
1134 BKE_view_layer_verify_aov(engine, scene, view_layer);
1135 }
1136 RE_engine_free(engine);
1137 engine = nullptr;
1138 }
1139
1140 Main *bmain = CTX_data_main(C);
1141 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1142 BKE_ntree_update(*bmain);
1143
1147
1148 return OPERATOR_FINISHED;
1149}
1150
1152{
1153 /* identifiers */
1154 ot->name = "Add AOV";
1155 ot->idname = "SCENE_OT_view_layer_add_aov";
1156 ot->description = "Add a Shader AOV";
1157
1158 /* API callbacks. */
1160
1161 /* flags */
1163}
1164
1166
1167/* -------------------------------------------------------------------- */
1170
1172{
1173 Scene *scene = CTX_data_scene(C);
1174 ViewLayer *view_layer = CTX_data_view_layer(C);
1175
1176 if (view_layer->active_aov == nullptr) {
1177 return OPERATOR_FINISHED;
1178 }
1179
1180 BKE_view_layer_remove_aov(view_layer, view_layer->active_aov);
1181
1182 RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
1183 if (engine_type->update_render_passes) {
1184 RenderEngine *engine = RE_engine_create(engine_type);
1185 if (engine) {
1186 BKE_view_layer_verify_aov(engine, scene, view_layer);
1187 }
1188 RE_engine_free(engine);
1189 engine = nullptr;
1190 }
1191
1192 Main *bmain = CTX_data_main(C);
1193 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1194 BKE_ntree_update(*bmain);
1195
1199
1200 return OPERATOR_FINISHED;
1201}
1202
1204{
1205 /* identifiers */
1206 ot->name = "Remove AOV";
1207 ot->idname = "SCENE_OT_view_layer_remove_aov";
1208 ot->description = "Remove Active AOV";
1209
1210 /* API callbacks. */
1212
1213 /* flags */
1215}
1216
1218
1219/* -------------------------------------------------------------------- */
1222
1224{
1225 Scene *scene = CTX_data_scene(C);
1226 ViewLayer *view_layer = CTX_data_view_layer(C);
1227
1228 char name[MAX_NAME];
1229 name[0] = '\0';
1230 /* If a name is provided, ensure that it is unique. */
1231 if (RNA_struct_property_is_set(op->ptr, "name")) {
1232 RNA_string_get(op->ptr, "name", name);
1233 /* Ensure that there are no dots in the name. */
1234 BLI_string_replace_char(name, '.', '_');
1235 for (ViewLayerLightgroup &lightgroup : view_layer->lightgroups) {
1236 if (STREQ(lightgroup.name, name)) {
1237 return OPERATOR_CANCELLED;
1238 }
1239 }
1240 }
1241
1242 BKE_view_layer_add_lightgroup(view_layer, name);
1243
1244 Main *bmain = CTX_data_main(C);
1245 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1246 BKE_ntree_update(*bmain);
1247
1251
1252 return OPERATOR_FINISHED;
1253}
1254
1256{
1257 /* identifiers */
1258 ot->name = "Add Lightgroup";
1259 ot->idname = "SCENE_OT_view_layer_add_lightgroup";
1260 ot->description = "Add a Light Group";
1261
1262 /* API callbacks. */
1264
1265 /* flags */
1267
1268 /* properties */
1269 ot->prop = RNA_def_string(ot->srna,
1270 "name",
1271 nullptr,
1273 "Name",
1274 "Name of newly created lightgroup");
1275}
1276
1278
1279/* -------------------------------------------------------------------- */
1282
1284{
1285 Scene *scene = CTX_data_scene(C);
1286 ViewLayer *view_layer = CTX_data_view_layer(C);
1287
1288 if (view_layer->active_lightgroup == nullptr) {
1289 return OPERATOR_FINISHED;
1290 }
1291
1292 BKE_view_layer_remove_lightgroup(view_layer, view_layer->active_lightgroup);
1293
1294 Main *bmain = CTX_data_main(C);
1295 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1296 BKE_ntree_update(*bmain);
1297
1301
1302 return OPERATOR_FINISHED;
1303}
1304
1306{
1307 /* identifiers */
1308 ot->name = "Remove Lightgroup";
1309 ot->idname = "SCENE_OT_view_layer_remove_lightgroup";
1310 ot->description = "Remove Active Lightgroup";
1311
1312 /* API callbacks. */
1314
1315 /* flags */
1317}
1318
1320
1321/* -------------------------------------------------------------------- */
1324
1326{
1327 Set<StringRefNull> used_lightgroups;
1328
1329 FOREACH_SCENE_OBJECT_BEGIN (scene, ob) {
1330 if (ob->lightgroup && ob->lightgroup->name[0]) {
1331 used_lightgroups.add_as(ob->lightgroup->name);
1332 }
1333 }
1335
1336 if (scene->world && scene->world->lightgroup && scene->world->lightgroup->name[0]) {
1337 used_lightgroups.add_as(scene->world->lightgroup->name);
1338 }
1339
1340 return used_lightgroups;
1341}
1342
1344{
1345 Scene *scene = CTX_data_scene(C);
1346 ViewLayer *view_layer = CTX_data_view_layer(C);
1347
1348 Set<StringRefNull> used_lightgroups = get_used_lightgroups(scene);
1349 for (const StringRefNull used_lightgroup : used_lightgroups) {
1350 if (!BLI_findstring(&view_layer->lightgroups,
1351 used_lightgroup.c_str(),
1353 {
1354 BKE_view_layer_add_lightgroup(view_layer, used_lightgroup.c_str());
1355 }
1356 }
1357
1358 Main *bmain = CTX_data_main(C);
1359 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1360 BKE_ntree_update(*bmain);
1361
1365
1366 return OPERATOR_FINISHED;
1367}
1368
1370{
1371 /* identifiers */
1372 ot->name = "Add Used Lightgroups";
1373 ot->idname = "SCENE_OT_view_layer_add_used_lightgroups";
1374 ot->description = "Add all used Light Groups";
1375
1376 /* API callbacks. */
1378
1379 /* flags */
1381}
1382
1384
1385/* -------------------------------------------------------------------- */
1388
1390{
1391 Scene *scene = CTX_data_scene(C);
1392 ViewLayer *view_layer = CTX_data_view_layer(C);
1393
1394 Set<StringRefNull> used_lightgroups = get_used_lightgroups(scene);
1395 for (ViewLayerLightgroup &lightgroup : view_layer->lightgroups.items_mutable()) {
1396 if (!used_lightgroups.contains_as(lightgroup.name)) {
1397 BKE_view_layer_remove_lightgroup(view_layer, &lightgroup);
1398 }
1399 }
1400
1401 Main *bmain = CTX_data_main(C);
1402 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1403 BKE_ntree_update(*bmain);
1404
1408
1409 return OPERATOR_FINISHED;
1410}
1411
1413{
1414 /* identifiers */
1415 ot->name = "Remove Unused Lightgroups";
1416 ot->idname = "SCENE_OT_view_layer_remove_unused_lightgroups";
1417 ot->description = "Remove all unused Light Groups";
1418
1419 /* API callbacks. */
1421
1422 /* flags */
1424}
1425
1427
1428/* -------------------------------------------------------------------- */
1431
1432enum {
1436};
1437
1439{
1440 const Main *bmain = CTX_data_main(C);
1441 ViewLayer *view_layer = CTX_data_view_layer(C);
1442 Scene *scene = CTX_data_scene(C);
1443
1444 auto is_irradiance_volume = [](Object *ob) -> bool {
1445 return ob->type == OB_LIGHTPROBE &&
1446 id_cast<LightProbe *>(ob->data)->type == LIGHTPROBE_TYPE_VOLUME;
1447 };
1448
1449 Vector<Object *> probes;
1450
1451 auto irradiance_volume_setup = [&](Object *ob) {
1455 probes.append(ob);
1456 };
1457
1458 int subset = RNA_enum_get(op->ptr, "subset");
1459 switch (subset) {
1460 case LIGHTCACHE_SUBSET_ALL: {
1461 FOREACH_OBJECT_BEGIN (bmain, scene, view_layer, ob) {
1462 if (is_irradiance_volume(ob)) {
1463 irradiance_volume_setup(ob);
1464 }
1465 }
1467 break;
1468 }
1470 ObjectsInViewLayerParams parameters;
1471 parameters.filter_fn = nullptr;
1472 parameters.no_dup_data = true;
1474 view_layer, nullptr, &parameters);
1475 for (Object *ob : objects) {
1476 if (is_irradiance_volume(ob)) {
1477 irradiance_volume_setup(ob);
1478 }
1479 }
1480 break;
1481 }
1483 if (Object *active_ob = CTX_data_active_object(C)) {
1484 if (is_irradiance_volume(active_ob)) {
1485 irradiance_volume_setup(active_ob);
1486 }
1487 }
1488 break;
1489 }
1490 default:
1492 break;
1493 }
1494
1495 return probes;
1496}
1497
1499 /* Store actual owner of job, so modal operator could check for it,
1500 * the reason of this is that active scene could change when rendering
1501 * several layers from compositor #31800. */
1503
1504 std::string report;
1505};
1506
1508 wmOperator *op,
1509 const wmEvent * /*event*/)
1510{
1512 wmWindow *win = CTX_wm_window(C);
1513 ViewLayer *view_layer = CTX_data_view_layer(C);
1514 Main *bmain = CTX_data_main(C);
1515 Scene *scene = CTX_data_scene(C);
1516
1518
1519 if (probes.is_empty()) {
1520 return OPERATOR_CANCELLED;
1521 }
1522
1523 BakeOperatorData *data = MEM_new<BakeOperatorData>(__func__);
1524 data->scene = scene;
1525 data->report = "";
1526
1528 wm, win, bmain, view_layer, scene, probes, data->report, scene->r.cfra, 0);
1529 if (wm_job == nullptr) {
1530 MEM_delete(data);
1531 BKE_report(op->reports, RPT_WARNING, "Cannot bake light probe while rendering");
1532 return OPERATOR_CANCELLED;
1533 }
1534
1536
1537 op->customdata = static_cast<void *>(data);
1538
1539 WM_jobs_start(wm, wm_job);
1540
1541 WM_cursor_wait(false);
1542
1544}
1545
1547 wmOperator *op,
1548 const wmEvent *event)
1549{
1550 BakeOperatorData *data = static_cast<BakeOperatorData *>(op->customdata);
1551 Scene *scene = data->scene;
1552
1553 /* No running bake, remove handler and pass through. */
1555 std::string report = data->report;
1556
1557 MEM_delete(data);
1558 op->customdata = nullptr;
1559
1560 if (!report.empty()) {
1561 BKE_report(op->reports, RPT_ERROR, report.c_str());
1562 return OPERATOR_CANCELLED;
1563 }
1565 }
1566
1567 /* Running bake. */
1568 switch (event->type) {
1569 case EVT_ESCKEY:
1571 default: {
1572 break;
1573 }
1574 }
1575 return OPERATOR_PASS_THROUGH;
1576}
1577
1579{
1581 Scene *scene = static_cast<BakeOperatorData *>(op->customdata)->scene;
1582
1583 /* Kill on cancel, because job is using op->reports. */
1585}
1586
1587/* Executes blocking bake. */
1589{
1590 ViewLayer *view_layer = CTX_data_view_layer(C);
1591 Main *bmain = CTX_data_main(C);
1592 Scene *scene = CTX_data_scene(C);
1593
1594 G.is_break = false;
1595
1597
1598 std::string report;
1600 bmain, view_layer, scene, probes, report, scene->r.cfra);
1601 /* Do the job. */
1602 wmJobWorkerStatus worker_status = {};
1603 EEVEE_lightbake_job(rj, &worker_status);
1604 /* Move baking data to original object and then free it. */
1607
1608 if (!report.empty()) {
1609 BKE_report(op->reports, RPT_ERROR, report.c_str());
1610 return OPERATOR_CANCELLED;
1611 }
1612
1613 return OPERATOR_FINISHED;
1614}
1615
1617{
1618 static const EnumPropertyItem light_cache_subset_items[] = {
1619 {LIGHTCACHE_SUBSET_ALL, "ALL", 0, "All Volumes", "Bake all light probe volumes"},
1621 "SELECTED",
1622 0,
1623 "Selected Only",
1624 "Only bake selected light probe volumes"},
1626 "ACTIVE",
1627 0,
1628 "Active Only",
1629 "Only bake the active light probe volume"},
1630 {0, nullptr, 0, nullptr, nullptr},
1631 };
1632
1633 /* identifiers */
1634 ot->name = "Bake Light Cache";
1635 ot->idname = "OBJECT_OT_lightprobe_cache_bake";
1636 ot->description = "Bake irradiance volume light cache";
1637
1638 /* API callbacks. */
1643
1644 ot->prop = RNA_def_enum(
1645 ot->srna, "subset", light_cache_subset_items, 0, "Subset", "Subset of probes to update");
1647}
1648
1650
1651/* -------------------------------------------------------------------- */
1654
1656{
1657 Scene *scene = CTX_data_scene(C);
1658
1659 /* Kill potential bake job first (see #57011). */
1662
1664
1665 for (Object *object : probes) {
1666 if (object->lightprobe_cache == nullptr) {
1667 continue;
1668 }
1671 }
1672
1674
1675 return OPERATOR_FINISHED;
1676}
1677
1679{
1680 static const EnumPropertyItem lightprobe_subset_items[] = {
1682 "ALL",
1683 0,
1684 "All Light Probes",
1685 "Delete all light probes' baked lighting data"},
1687 "SELECTED",
1688 0,
1689 "Selected Only",
1690 "Only delete selected light probes' baked lighting data"},
1692 "ACTIVE",
1693 0,
1694 "Active Only",
1695 "Only delete the active light probe's baked lighting data"},
1696 {0, nullptr, 0, nullptr, nullptr},
1697 };
1698
1699 /* identifiers */
1700 ot->name = "Delete Light Cache";
1701 ot->idname = "OBJECT_OT_lightprobe_cache_free";
1702 ot->description = "Delete cached indirect lighting";
1704
1705 /* API callbacks. */
1707
1708 ot->prop = RNA_def_enum(ot->srna,
1709 "subset",
1710 lightprobe_subset_items,
1712 "Subset",
1713 "Subset of probes to update");
1714}
1715
1717
1718/* -------------------------------------------------------------------- */
1721
1723{
1724 Scene *scene = CTX_data_scene(C);
1725
1726 /* don't allow user to remove "left" and "right" views */
1727 return scene->r.actview > 1;
1728}
1729
1731{
1732 Main *bmain = CTX_data_main(C);
1733 Scene *scene = CTX_data_scene(C);
1734
1735 BKE_scene_add_render_view(scene, nullptr);
1736 scene->r.actview = scene->r.views.count() - 1;
1737
1739
1740 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1742
1743 return OPERATOR_FINISHED;
1744}
1745
1747{
1748 /* identifiers */
1749 ot->name = "Add Render View";
1750 ot->idname = "SCENE_OT_render_view_add";
1751 ot->description = "Add a render view";
1752
1753 /* API callbacks. */
1755
1756 /* flags */
1758}
1759
1761
1762/* -------------------------------------------------------------------- */
1765
1767{
1768 Main *bmain = CTX_data_main(C);
1769 Scene *scene = CTX_data_scene(C);
1770 SceneRenderView *rv = static_cast<SceneRenderView *>(
1771 BLI_findlink(&scene->r.views, scene->r.actview));
1772
1773 if (!BKE_scene_remove_render_view(scene, rv)) {
1774 return OPERATOR_CANCELLED;
1775 }
1776
1778
1779 BKE_ntree_update_tag_id_changed(bmain, &scene->id);
1781
1782 return OPERATOR_FINISHED;
1783}
1784
1786{
1787 /* identifiers */
1788 ot->name = "Remove Render View";
1789 ot->idname = "SCENE_OT_render_view_remove";
1790 ot->description = "Remove the selected render view";
1791
1792 /* API callbacks. */
1795
1796 /* flags */
1798}
1799
1801
1802#ifdef WITH_FREESTYLE
1803
1804/* -------------------------------------------------------------------- */
1807
1808static bool freestyle_linestyle_check_report(FreestyleLineSet *lineset, ReportList *reports)
1809{
1810 if (!lineset) {
1811 BKE_report(reports,
1812 RPT_ERROR,
1813 "No active lineset and associated line style to manipulate the modifier");
1814 return false;
1815 }
1816 if (!lineset->linestyle) {
1817 BKE_report(reports,
1818 RPT_ERROR,
1819 "The active lineset does not have a line style (indicating data corruption)");
1820 return false;
1821 }
1822
1823 return true;
1824}
1825
1826static bool freestyle_active_module_poll(bContext *C)
1827{
1828 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", RNA_FreestyleModuleSettings);
1829 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1830
1831 return module != nullptr;
1832}
1833
1834static wmOperatorStatus freestyle_module_add_exec(bContext *C, wmOperator * /*op*/)
1835{
1836 Scene *scene = CTX_data_scene(C);
1837 ViewLayer *view_layer = CTX_data_view_layer(C);
1838
1839 BKE_freestyle_module_add(&view_layer->freestyle_config);
1840
1842
1843 return OPERATOR_FINISHED;
1844}
1845
1846void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
1847{
1848 /* identifiers */
1849 ot->name = "Add Freestyle Module";
1850 ot->idname = "SCENE_OT_freestyle_module_add";
1851 ot->description = "Add a style module into the list of modules";
1852
1853 /* API callbacks. */
1854 ot->exec = freestyle_module_add_exec;
1855
1856 /* flags */
1858}
1859
1861
1862/* -------------------------------------------------------------------- */
1865
1866static wmOperatorStatus freestyle_module_remove_exec(bContext *C, wmOperator * /*op*/)
1867{
1868 Scene *scene = CTX_data_scene(C);
1869 ViewLayer *view_layer = CTX_data_view_layer(C);
1870 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", RNA_FreestyleModuleSettings);
1871 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1872
1873 BKE_freestyle_module_delete(&view_layer->freestyle_config, module);
1874
1877
1878 return OPERATOR_FINISHED;
1879}
1880
1881void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
1882{
1883 /* identifiers */
1884 ot->name = "Remove Freestyle Module";
1885 ot->idname = "SCENE_OT_freestyle_module_remove";
1886 ot->description = "Remove the style module from the stack";
1887
1888 /* API callbacks. */
1889 ot->poll = freestyle_active_module_poll;
1890 ot->exec = freestyle_module_remove_exec;
1891
1892 /* flags */
1894}
1895
1896static wmOperatorStatus freestyle_module_move_exec(bContext *C, wmOperator *op)
1897{
1898 Scene *scene = CTX_data_scene(C);
1899 ViewLayer *view_layer = CTX_data_view_layer(C);
1900 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", RNA_FreestyleModuleSettings);
1901 FreestyleModuleConfig *module = static_cast<FreestyleModuleConfig *>(ptr.data);
1902 int dir = RNA_enum_get(op->ptr, "direction");
1903
1904 if (BKE_freestyle_module_move(&view_layer->freestyle_config, module, dir)) {
1907 }
1908
1909 return OPERATOR_FINISHED;
1910}
1911
1913
1914/* -------------------------------------------------------------------- */
1917
1918void SCENE_OT_freestyle_module_move(wmOperatorType *ot)
1919{
1920 static const EnumPropertyItem direction_items[] = {
1921 {-1, "UP", 0, "Up", ""},
1922 {1, "DOWN", 0, "Down", ""},
1923 {0, nullptr, 0, nullptr, nullptr},
1924 };
1925
1926 /* identifiers */
1927 ot->name = "Move Freestyle Module";
1928 ot->idname = "SCENE_OT_freestyle_module_move";
1929 ot->description = "Change the position of the style module within in the list of style modules";
1930
1931 /* API callbacks. */
1932 ot->poll = freestyle_active_module_poll;
1933 ot->exec = freestyle_module_move_exec;
1934
1935 /* flags */
1937
1938 /* props */
1939 RNA_def_enum(ot->srna,
1940 "direction",
1941 direction_items,
1942 0,
1943 "Direction",
1944 "Direction to move the chosen style module towards");
1945}
1946
1948
1949/* -------------------------------------------------------------------- */
1952
1953static wmOperatorStatus freestyle_lineset_add_exec(bContext *C, wmOperator * /*op*/)
1954{
1955 Main *bmain = CTX_data_main(C);
1956 Scene *scene = CTX_data_scene(C);
1957 ViewLayer *view_layer = CTX_data_view_layer(C);
1958
1959 BKE_freestyle_lineset_add(bmain, &view_layer->freestyle_config, nullptr);
1960
1963
1964 return OPERATOR_FINISHED;
1965}
1966
1967void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
1968{
1969 /* identifiers */
1970 ot->name = "Add Line Set";
1971 ot->idname = "SCENE_OT_freestyle_lineset_add";
1972 ot->description = "Add a line set into the list of line sets";
1973
1974 /* API callbacks. */
1975 ot->exec = freestyle_lineset_add_exec;
1976
1977 /* flags */
1979}
1980
1982
1983/* -------------------------------------------------------------------- */
1986
1987static bool freestyle_active_lineset_poll(bContext *C)
1988{
1989 ViewLayer *view_layer = CTX_data_view_layer(C);
1990
1991 if (!view_layer) {
1992 return false;
1993 }
1994
1995 return BKE_freestyle_lineset_get_active(&view_layer->freestyle_config) != nullptr;
1996}
1997
1998static wmOperatorStatus freestyle_lineset_copy_exec(bContext *C, wmOperator * /*op*/)
1999{
2000 ViewLayer *view_layer = CTX_data_view_layer(C);
2001
2002 FRS_copy_active_lineset(&view_layer->freestyle_config);
2003
2004 return OPERATOR_FINISHED;
2005}
2006
2007void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot)
2008{
2009 /* identifiers */
2010 ot->name = "Copy Line Set";
2011 ot->idname = "SCENE_OT_freestyle_lineset_copy";
2012 ot->description = "Copy the active line set to the internal clipboard";
2013
2014 /* API callbacks. */
2015 ot->exec = freestyle_lineset_copy_exec;
2016 ot->poll = freestyle_active_lineset_poll;
2017
2018 /* flags */
2020}
2021
2023
2024/* -------------------------------------------------------------------- */
2027
2028static wmOperatorStatus freestyle_lineset_paste_exec(bContext *C, wmOperator * /*op*/)
2029{
2030 Scene *scene = CTX_data_scene(C);
2031 ViewLayer *view_layer = CTX_data_view_layer(C);
2032
2033 FRS_paste_active_lineset(&view_layer->freestyle_config);
2034
2037
2038 return OPERATOR_FINISHED;
2039}
2040
2041void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot)
2042{
2043 /* identifiers */
2044 ot->name = "Paste Line Set";
2045 ot->idname = "SCENE_OT_freestyle_lineset_paste";
2046 ot->description = "Paste the internal clipboard content to the active line set";
2047
2048 /* API callbacks. */
2049 ot->exec = freestyle_lineset_paste_exec;
2050 ot->poll = freestyle_active_lineset_poll;
2051
2052 /* flags */
2054}
2055
2057
2058/* -------------------------------------------------------------------- */
2061
2062static wmOperatorStatus freestyle_lineset_remove_exec(bContext *C, wmOperator * /*op*/)
2063{
2064 Scene *scene = CTX_data_scene(C);
2065 ViewLayer *view_layer = CTX_data_view_layer(C);
2066
2067 FRS_delete_active_lineset(&view_layer->freestyle_config);
2068
2071
2072 return OPERATOR_FINISHED;
2073}
2074
2075void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
2076{
2077 /* identifiers */
2078 ot->name = "Remove Line Set";
2079 ot->idname = "SCENE_OT_freestyle_lineset_remove";
2080 ot->description = "Remove the active line set from the list of line sets";
2081
2082 /* API callbacks. */
2083 ot->exec = freestyle_lineset_remove_exec;
2084 ot->poll = freestyle_active_lineset_poll;
2085
2086 /* flags */
2088}
2089
2091
2092/* -------------------------------------------------------------------- */
2095
2096static wmOperatorStatus freestyle_lineset_move_exec(bContext *C, wmOperator *op)
2097{
2098 Scene *scene = CTX_data_scene(C);
2099 ViewLayer *view_layer = CTX_data_view_layer(C);
2100 int dir = RNA_enum_get(op->ptr, "direction");
2101
2102 if (FRS_move_active_lineset(&view_layer->freestyle_config, dir)) {
2105 }
2106
2107 return OPERATOR_FINISHED;
2108}
2109
2110void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
2111{
2112 static const EnumPropertyItem direction_items[] = {
2113 {-1, "UP", 0, "Up", ""},
2114 {1, "DOWN", 0, "Down", ""},
2115 {0, nullptr, 0, nullptr, nullptr},
2116 };
2117
2118 /* identifiers */
2119 ot->name = "Move Line Set";
2120 ot->idname = "SCENE_OT_freestyle_lineset_move";
2121 ot->description = "Change the position of the active line set within the list of line sets";
2122
2123 /* API callbacks. */
2124 ot->exec = freestyle_lineset_move_exec;
2125 ot->poll = freestyle_active_lineset_poll;
2126
2127 /* flags */
2129
2130 /* props */
2131 RNA_def_enum(ot->srna,
2132 "direction",
2133 direction_items,
2134 0,
2135 "Direction",
2136 "Direction to move the active line set towards");
2137}
2138
2140
2141/* -------------------------------------------------------------------- */
2144
2145static wmOperatorStatus freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
2146{
2147 Main *bmain = CTX_data_main(C);
2148 ViewLayer *view_layer = CTX_data_view_layer(C);
2149 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2150
2151 if (!lineset) {
2152 BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to");
2153 return OPERATOR_CANCELLED;
2154 }
2155 if (lineset->linestyle) {
2156 id_us_min(&lineset->linestyle->id);
2157 lineset->linestyle = id_cast<FreestyleLineStyle *>(
2158 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);
2164 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
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);
2193 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
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
2201 lineset->linestyle, nullptr, eLineStyleModifier_Type(type)) == nullptr)
2202 {
2203 BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type");
2204 return OPERATOR_CANCELLED;
2205 }
2206 DEG_id_tag_update(&lineset->linestyle->id, 0);
2207 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2208
2209 return OPERATOR_FINISHED;
2210}
2211
2212void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
2213{
2214 /* identifiers */
2215 ot->name = "Add Line Color Modifier";
2216 ot->idname = "SCENE_OT_freestyle_color_modifier_add";
2217 ot->description =
2218 "Add a line color modifier to the line style associated with the active lineset";
2219
2220 /* API callbacks. */
2221 ot->invoke = WM_menu_invoke;
2222 ot->exec = freestyle_color_modifier_add_exec;
2223 ot->poll = freestyle_active_lineset_poll;
2224
2225 /* flags */
2227
2228 /* properties */
2229 ot->prop = RNA_def_enum(
2230 ot->srna, "type", rna_enum_linestyle_color_modifier_type_items, 0, "Type", "");
2231}
2232
2234
2235/* -------------------------------------------------------------------- */
2238
2239static wmOperatorStatus freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
2240{
2241 ViewLayer *view_layer = CTX_data_view_layer(C);
2242 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2243 int type = RNA_enum_get(op->ptr, "type");
2244
2245 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2246 return OPERATOR_CANCELLED;
2247 }
2248
2250 lineset->linestyle, nullptr, eLineStyleModifier_Type(type)) == nullptr)
2251 {
2252 BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type");
2253 return OPERATOR_CANCELLED;
2254 }
2255 DEG_id_tag_update(&lineset->linestyle->id, 0);
2256 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2257
2258 return OPERATOR_FINISHED;
2259}
2260
2261void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
2262{
2263 /* identifiers */
2264 ot->name = "Add Alpha Transparency Modifier";
2265 ot->idname = "SCENE_OT_freestyle_alpha_modifier_add";
2266 ot->description =
2267 "Add an alpha transparency modifier to the line style associated with the active lineset";
2268
2269 /* API callbacks. */
2270 ot->invoke = WM_menu_invoke;
2271 ot->exec = freestyle_alpha_modifier_add_exec;
2272 ot->poll = freestyle_active_lineset_poll;
2273
2274 /* flags */
2276
2277 /* properties */
2278 ot->prop = RNA_def_enum(
2279 ot->srna, "type", rna_enum_linestyle_alpha_modifier_type_items, 0, "Type", "");
2280}
2281
2283
2284/* -------------------------------------------------------------------- */
2287
2288static wmOperatorStatus freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
2289{
2290 ViewLayer *view_layer = CTX_data_view_layer(C);
2291 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2292 int type = RNA_enum_get(op->ptr, "type");
2293
2294 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2295 return OPERATOR_CANCELLED;
2296 }
2297
2299 lineset->linestyle, nullptr, eLineStyleModifier_Type(type)) == nullptr)
2300 {
2301 BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type");
2302 return OPERATOR_CANCELLED;
2303 }
2304 DEG_id_tag_update(&lineset->linestyle->id, 0);
2305 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2306
2307 return OPERATOR_FINISHED;
2308}
2309
2310void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
2311{
2312 /* identifiers */
2313 ot->name = "Add Line Thickness Modifier";
2314 ot->idname = "SCENE_OT_freestyle_thickness_modifier_add";
2315 ot->description =
2316 "Add a line thickness modifier to the line style associated with the active lineset";
2317
2318 /* API callbacks. */
2319 ot->invoke = WM_menu_invoke;
2320 ot->exec = freestyle_thickness_modifier_add_exec;
2321 ot->poll = freestyle_active_lineset_poll;
2322
2323 /* flags */
2325
2326 /* properties */
2327 ot->prop = RNA_def_enum(
2328 ot->srna, "type", rna_enum_linestyle_thickness_modifier_type_items, 0, "Type", "");
2329}
2330
2332
2333/* -------------------------------------------------------------------- */
2336
2337static wmOperatorStatus freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
2338{
2339 ViewLayer *view_layer = CTX_data_view_layer(C);
2340 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2341 int type = RNA_enum_get(op->ptr, "type");
2342
2343 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2344 return OPERATOR_CANCELLED;
2345 }
2346
2348 lineset->linestyle, nullptr, eLineStyleModifier_Type(type)) == nullptr)
2349 {
2350 BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type");
2351 return OPERATOR_CANCELLED;
2352 }
2353 DEG_id_tag_update(&lineset->linestyle->id, 0);
2354 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2355
2356 return OPERATOR_FINISHED;
2357}
2358
2359void SCENE_OT_freestyle_geometry_modifier_add(wmOperatorType *ot)
2360{
2361 /* identifiers */
2362 ot->name = "Add Stroke Geometry Modifier";
2363 ot->idname = "SCENE_OT_freestyle_geometry_modifier_add";
2364 ot->description =
2365 "Add a stroke geometry modifier to the line style associated with the active lineset";
2366
2367 /* API callbacks. */
2368 ot->invoke = WM_menu_invoke;
2369 ot->exec = freestyle_geometry_modifier_add_exec;
2370 ot->poll = freestyle_active_lineset_poll;
2371
2372 /* flags */
2374
2375 /* properties */
2376 ot->prop = RNA_def_enum(
2377 ot->srna, "type", rna_enum_linestyle_geometry_modifier_type_items, 0, "Type", "");
2378}
2379
2381
2382/* -------------------------------------------------------------------- */
2385
2386static int freestyle_get_modifier_type(PointerRNA *ptr)
2387{
2388 if (RNA_struct_is_a(ptr->type, RNA_LineStyleColorModifier)) {
2390 }
2391 if (RNA_struct_is_a(ptr->type, RNA_LineStyleAlphaModifier)) {
2393 }
2394 if (RNA_struct_is_a(ptr->type, RNA_LineStyleThicknessModifier)) {
2396 }
2397 if (RNA_struct_is_a(ptr->type, RNA_LineStyleGeometryModifier)) {
2399 }
2400 return -1;
2401}
2402
2403static wmOperatorStatus freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
2404{
2405 ViewLayer *view_layer = CTX_data_view_layer(C);
2406 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2407 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_LineStyleModifier);
2408 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2409
2410 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2411 return OPERATOR_CANCELLED;
2412 }
2413
2414 switch (freestyle_get_modifier_type(&ptr)) {
2416 BKE_linestyle_color_modifier_remove(lineset->linestyle, modifier);
2417 break;
2419 BKE_linestyle_alpha_modifier_remove(lineset->linestyle, modifier);
2420 break;
2423 break;
2426 break;
2427 default:
2428 BKE_report(
2429 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2430 return OPERATOR_CANCELLED;
2431 }
2432 DEG_id_tag_update(&lineset->linestyle->id, 0);
2433 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2434
2435 return OPERATOR_FINISHED;
2436}
2437
2438void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
2439{
2440 /* identifiers */
2441 ot->name = "Remove Modifier";
2442 ot->idname = "SCENE_OT_freestyle_modifier_remove";
2443 ot->description = "Remove the modifier from the list of modifiers";
2444
2445 /* API callbacks. */
2446 ot->exec = freestyle_modifier_remove_exec;
2447 ot->poll = freestyle_active_lineset_poll;
2448
2449 /* flags */
2451}
2452
2454
2455/* -------------------------------------------------------------------- */
2458
2459static wmOperatorStatus freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
2460{
2461 ViewLayer *view_layer = CTX_data_view_layer(C);
2462 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2463 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_LineStyleModifier);
2464 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2465
2466 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2467 return OPERATOR_CANCELLED;
2468 }
2469
2470 switch (freestyle_get_modifier_type(&ptr)) {
2472 BKE_linestyle_color_modifier_copy(lineset->linestyle, modifier, 0);
2473 break;
2475 BKE_linestyle_alpha_modifier_copy(lineset->linestyle, modifier, 0);
2476 break;
2478 BKE_linestyle_thickness_modifier_copy(lineset->linestyle, modifier, 0);
2479 break;
2481 BKE_linestyle_geometry_modifier_copy(lineset->linestyle, modifier, 0);
2482 break;
2483 default:
2484 BKE_report(
2485 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2486 return OPERATOR_CANCELLED;
2487 }
2488 DEG_id_tag_update(&lineset->linestyle->id, 0);
2489 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2490
2491 return OPERATOR_FINISHED;
2492}
2493
2494void SCENE_OT_freestyle_modifier_copy(wmOperatorType *ot)
2495{
2496 /* identifiers */
2497 ot->name = "Copy Modifier";
2498 ot->idname = "SCENE_OT_freestyle_modifier_copy";
2499 ot->description = "Duplicate the modifier within the list of modifiers";
2500
2501 /* API callbacks. */
2502 ot->exec = freestyle_modifier_copy_exec;
2503 ot->poll = freestyle_active_lineset_poll;
2504
2505 /* flags */
2507}
2508
2510
2511/* -------------------------------------------------------------------- */
2514
2515static wmOperatorStatus freestyle_modifier_move_exec(bContext *C, wmOperator *op)
2516{
2517 ViewLayer *view_layer = CTX_data_view_layer(C);
2518 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
2519 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", RNA_LineStyleModifier);
2520 LineStyleModifier *modifier = static_cast<LineStyleModifier *>(ptr.data);
2521 int dir = RNA_enum_get(op->ptr, "direction");
2522 bool changed = false;
2523
2524 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
2525 return OPERATOR_CANCELLED;
2526 }
2527
2528 switch (freestyle_get_modifier_type(&ptr)) {
2530 changed = BKE_linestyle_color_modifier_move(lineset->linestyle, modifier, dir);
2531 break;
2533 changed = BKE_linestyle_alpha_modifier_move(lineset->linestyle, modifier, dir);
2534 break;
2536 changed = BKE_linestyle_thickness_modifier_move(lineset->linestyle, modifier, dir);
2537 break;
2539 changed = BKE_linestyle_geometry_modifier_move(lineset->linestyle, modifier, dir);
2540 break;
2541 default:
2542 BKE_report(
2543 op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
2544 return OPERATOR_CANCELLED;
2545 }
2546
2547 if (changed) {
2548 DEG_id_tag_update(&lineset->linestyle->id, 0);
2549 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
2550 }
2551
2552 return OPERATOR_FINISHED;
2553}
2554
2555void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
2556{
2557 static const EnumPropertyItem direction_items[] = {
2558 {-1, "UP", 0, "Up", ""},
2559 {1, "DOWN", 0, "Down", ""},
2560 {0, nullptr, 0, nullptr, nullptr},
2561 };
2562
2563 /* identifiers */
2564 ot->name = "Move Modifier";
2565 ot->idname = "SCENE_OT_freestyle_modifier_move";
2566 ot->description = "Move the modifier within the list of modifiers";
2567
2568 /* API callbacks. */
2569 ot->exec = freestyle_modifier_move_exec;
2570 ot->poll = freestyle_active_lineset_poll;
2571
2572 /* flags */
2574
2575 /* props */
2576 RNA_def_enum(ot->srna,
2577 "direction",
2578 direction_items,
2579 0,
2580 "Direction",
2581 "Direction to move the chosen modifier towards");
2582}
2583
2585
2586/* -------------------------------------------------------------------- */
2589
2590static wmOperatorStatus freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
2591{
2592 Main *bmain = CTX_data_main(C);
2593 ViewLayer *view_layer = CTX_data_view_layer(C);
2595
2596 if (!linestyle) {
2597 BKE_report(op->reports, RPT_ERROR, "No active line style in the current scene");
2598 return OPERATOR_CANCELLED;
2599 }
2600
2601 FRS_create_stroke_material(bmain, linestyle);
2602
2603 return OPERATOR_FINISHED;
2604}
2605
2606void SCENE_OT_freestyle_stroke_material_create(wmOperatorType *ot)
2607{
2608 /* identifiers */
2609 ot->name = "Create Freestyle Stroke Material";
2610 ot->idname = "SCENE_OT_freestyle_stroke_material_create";
2611 ot->description = "Create Freestyle stroke material for testing";
2612
2613 /* API callbacks. */
2614 ot->exec = freestyle_stroke_material_create_exec;
2615
2616 /* flags */
2617 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
2618}
2619
2621
2622#endif /* WITH_FREESTYLE */
2623
2624/* -------------------------------------------------------------------- */
2627
2629{
2630 ID *id = CTX_data_pointer_get_type(C, "texture_slot", RNA_TextureSlot).owner_id;
2631 if (id) {
2633 MTex **mtex_ar, *mtexswap;
2634 short act;
2635 int type = RNA_enum_get(op->ptr, "type");
2636
2637 give_active_mtex(id, &mtex_ar, &act);
2638
2639 if (type == -1) { /* Up */
2640 if (act > 0) {
2641 mtexswap = mtex_ar[act];
2642 mtex_ar[act] = mtex_ar[act - 1];
2643 mtex_ar[act - 1] = mtexswap;
2644
2646 "texture_slots",
2647 RNA_path_number_to_infix(act - 1),
2649 /*verify_paths=*/false,
2650 driver_map);
2652 "texture_slots",
2654 RNA_path_number_to_infix(act - 1),
2655 /*verify_paths=*/false,
2656 driver_map);
2658 "texture_slots",
2661 /*verify_paths=*/false,
2662 driver_map);
2663
2664 set_active_mtex(id, act - 1);
2665 }
2666 }
2667 else { /* Down */
2668 if (act < MAX_MTEX - 1) {
2669 mtexswap = mtex_ar[act];
2670 mtex_ar[act] = mtex_ar[act + 1];
2671 mtex_ar[act + 1] = mtexswap;
2672
2674 "texture_slots",
2675 RNA_path_number_to_infix(act + 1),
2677 /*verify_paths=*/false,
2678 driver_map);
2680 "texture_slots",
2682 RNA_path_number_to_infix(act + 1),
2683 /*verify_paths=*/false,
2684 driver_map);
2686 "texture_slots",
2689 /*verify_paths=*/false,
2690 driver_map);
2691
2692 set_active_mtex(id, act + 1);
2693 }
2694 }
2695
2696 DEG_id_tag_update(id, 0);
2698 }
2699
2700 return OPERATOR_FINISHED;
2701}
2702
2704{
2705 static const EnumPropertyItem slot_move[] = {
2706 {-1, "UP", 0, "Up", ""},
2707 {1, "DOWN", 0, "Down", ""},
2708 {0, nullptr, 0, nullptr, nullptr},
2709 };
2710
2711 /* identifiers */
2712 ot->name = "Move Texture Slot";
2713 ot->idname = "TEXTURE_OT_slot_move";
2714 ot->description = "Move texture slots up and down";
2715
2716 /* API callbacks. */
2718
2719 /* flags */
2721
2722 RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
2723}
2724
2726
2727/* -------------------------------------------------------------------- */
2730
2732{
2733 using namespace blender::bke::blendfile;
2734
2735 Material *ma = static_cast<Material *>(
2736 CTX_data_pointer_get_type(C, "material", RNA_Material).data);
2737
2738 if (ma == nullptr) {
2739 return OPERATOR_CANCELLED;
2740 }
2741 if (ID_IS_LINKED(&ma->id)) {
2742 /* Direct link/append of linked IDs is not supported currently, so neither is their
2743 * copy/pasting. */
2744 BKE_reportf(op->reports,
2745 RPT_INFO,
2746 "Cannot copy the linked material '%s' to the internal clipboard",
2747 BKE_id_name(ma->id));
2748 return OPERATOR_CANCELLED;
2749 }
2750 if (ID_IS_PACKED(&ma->id)) {
2751 /* Direct link/append of packed IDs is not supported currently, so neither is their
2752 * copy/pasting. */
2753 /* NOTE: In practice, always shadowed currently by the more general check on linked status
2754 * above. */
2755 BKE_reportf(op->reports,
2756 RPT_INFO,
2757 "Cannot copy the linked packed material '%s' to the internal clipboard",
2758 BKE_id_name(ma->id));
2759 return OPERATOR_CANCELLED;
2760 }
2761
2762 Main *bmain = CTX_data_main(C);
2763 PartialWriteContext copybuffer{*bmain};
2764
2765 /* Add the material to the copybuffer (and all of its dependencies). */
2766 copybuffer.id_add(
2767 &ma->id,
2768 PartialWriteContext::IDAddOptions{(PartialWriteContext::IDAddOperations::SET_FAKE_USER |
2769 PartialWriteContext::IDAddOperations::SET_CLIPBOARD_MARK |
2770 PartialWriteContext::IDAddOperations::ADD_DEPENDENCIES)},
2771 nullptr);
2772
2773 char filepath[FILE_MAX];
2774 material_copybuffer_filepath_get(filepath, sizeof(filepath));
2775 copybuffer.write_as_copypaste_buffer(filepath, *op->reports);
2776
2777 /* We are all done! */
2778 BKE_report(op->reports, RPT_INFO, "Copied material to internal clipboard");
2779
2780 return OPERATOR_FINISHED;
2781}
2782
2784{
2785 /* identifiers */
2786 ot->name = "Copy Material";
2787 ot->idname = "MATERIAL_OT_copy";
2788 ot->description = "Copy the material settings and nodes";
2789
2790 /* API callbacks. */
2793
2794 /* flags */
2795 /* no undo needed since no changes are made to the material */
2797}
2798
2800
2801/* -------------------------------------------------------------------- */
2804
2809{
2810 if (cb_data->cb_flag & IDWALK_CB_USER) {
2811 id_us_min(*cb_data->id_pointer);
2812 }
2813 *cb_data->id_pointer = nullptr;
2814 return IDWALK_RET_NOP;
2815}
2816
2821{
2822 Main *bmain = static_cast<Main *>(cb_data->user_data);
2823 ID **id_p = cb_data->id_pointer;
2824 if (*id_p) {
2825 if (cb_data->cb_flag & IDWALK_CB_USER) {
2826 id_us_min(*id_p);
2827 }
2828 ListBaseT<ID> *lb = which_libbase(bmain, (*id_p)->id_type());
2829 ID *id_local = static_cast<ID *>(
2830 BLI_findstring(lb, (*id_p)->name + 2, offsetof(ID, name) + 2));
2831 *id_p = id_local;
2832 if (cb_data->cb_flag & IDWALK_CB_USER) {
2833 id_us_plus(id_local);
2834 }
2835 else if (cb_data->cb_flag & IDWALK_CB_USER_ONE) {
2836 id_us_ensure_real(id_local);
2837 }
2838 id_lib_extern(id_local);
2839 }
2840 return IDWALK_RET_NOP;
2841}
2842
2844{
2845 Main *bmain = CTX_data_main(C);
2846 Material *ma = static_cast<Material *>(
2847 CTX_data_pointer_get_type(C, "material", RNA_Material).data);
2848
2849 if (ma == nullptr) {
2850 BKE_report(op->reports, RPT_WARNING, "Cannot paste without a material");
2851 return OPERATOR_CANCELLED;
2852 }
2853
2854 /* Read copy buffer .blend file. */
2855 char filepath[FILE_MAX];
2856 material_copybuffer_filepath_get(filepath, sizeof(filepath));
2857
2858 /* NOTE(@ideasman42) The node tree might reference different kinds of ID types.
2859 * It's not clear-cut which ID types should be included, although it's unlikely
2860 * users would want an entire scene & it's objects to be included.
2861 * Filter a subset of ID types with some reasons for including them. */
2862 const uint64_t ntree_filter = (
2863 /* Material is necessary for reading the clipboard. */
2864 FILTER_ID_MA |
2865 /* Node-groups. */
2866 FILTER_ID_NT |
2867 /* Image textures. */
2868 FILTER_ID_IM |
2869 /* Internal text (scripts). */
2871 /* Texture coordinates may reference objects.
2872 * Note that object data is *not* included. */
2873 FILTER_ID_OB);
2874
2875 Main *temp_bmain = BKE_copybuffer_read(*bmain, filepath, op->reports, ntree_filter);
2876 if (!temp_bmain) {
2877 BKE_report(op->reports, RPT_ERROR, "Internal clipboard is empty");
2878 return OPERATOR_CANCELLED;
2879 }
2880
2881 /* There may be multiple materials,
2882 * check for a property that marks this as the active material. */
2883 Material *ma_from = nullptr;
2884 for (Material &ma_iter : temp_bmain->materials) {
2885 if (ma_iter.id.flag & ID_FLAG_CLIPBOARD_MARK) {
2886 ma_from = &ma_iter;
2887 break;
2888 }
2889 }
2890
2891 /* Make sure data from this file is usable for material paste. */
2892 if (ma_from == nullptr) {
2893 BKE_report(op->reports, RPT_ERROR, "Internal clipboard is not from a material");
2894 BKE_main_free(temp_bmain);
2895 return OPERATOR_CANCELLED;
2896 }
2897
2898 /* Keep animation by moving local animation to the paste node-tree. */
2899 if (ma->nodetree && ma_from->nodetree) {
2900 BLI_assert(ma_from->nodetree->adt == nullptr);
2901 std::swap(ma->nodetree->adt, ma_from->nodetree->adt);
2902 }
2903
2904 /* Needed to update #SpaceNode::nodetree else a stale pointer is used. */
2905 if (ma->nodetree) {
2906 bNodeTree *nodetree = ma->nodetree;
2907 BKE_libblock_remap(bmain, ma->nodetree, ma_from->nodetree, ID_REMAP_FORCE_UI_POINTERS);
2908
2909 /* Free & clear data here, so user counts are handled, otherwise it's
2910 * freed as part of #BKE_main_free which doesn't handle user-counts. */
2911 /* Walk over all the embedded nodes ID's (non-recursively). */
2913 bmain, &nodetree->id, paste_material_nodetree_ids_decref, nullptr, IDWALK_NOP);
2914
2916 MEM_delete(nodetree);
2917 ma->nodetree = nullptr;
2918 }
2919
2920/* Swap data-block content, while swapping isn't always needed,
2921 * it means memory is properly freed in the case of allocations.. */
2922#define SWAP_MEMBER(member) std::swap(ma->member, ma_from->member)
2923
2924 /* Intentionally skip:
2925 * - Texture painting slots.
2926 * - Preview render.
2927 * - Grease pencil styles (we could although they reference many ID's themselves).
2928 */
2929 SWAP_MEMBER(flag);
2930 SWAP_MEMBER(r);
2931 SWAP_MEMBER(g);
2932 SWAP_MEMBER(b);
2933 SWAP_MEMBER(a);
2934 SWAP_MEMBER(specr);
2935 SWAP_MEMBER(specg);
2936 SWAP_MEMBER(specb);
2937 SWAP_MEMBER(spec);
2938 SWAP_MEMBER(roughness);
2939 SWAP_MEMBER(metallic);
2941 SWAP_MEMBER(nodetree);
2942 SWAP_MEMBER(line_col);
2943 SWAP_MEMBER(line_priority);
2944 SWAP_MEMBER(vcol_alpha);
2945
2946 SWAP_MEMBER(alpha_threshold);
2947 SWAP_MEMBER(refract_depth);
2948 SWAP_MEMBER(blend_method);
2949 SWAP_MEMBER(blend_shadow);
2950 SWAP_MEMBER(blend_flag);
2951
2952 SWAP_MEMBER(lineart);
2953
2954#undef SWAP_MEMBER
2955
2956 /* The node-tree from the clipboard is now assigned to the local material,
2957 * however the ID's it references are still part of `temp_bmain`.
2958 * These data-blocks references must be cleared or replaces with references to `bmain`.
2959 * TODO(@ideasman42): support merging indirectly referenced data-blocks besides the material,
2960 * this would be useful for pasting materials with node-groups between files. */
2961 if (ma->nodetree) {
2962 /* This implicitly points to local data, assign after remapping. */
2963 ma->nodetree->owner_id = nullptr;
2964
2965 /* Map remote ID's to local ones. */
2967 bmain, &ma->nodetree->id, paste_material_nodetree_ids_relink_or_clear, bmain, IDWALK_NOP);
2968
2969 ma->nodetree->owner_id = &ma->id;
2970 }
2971 BKE_main_free(temp_bmain);
2972
2973 /* Important to run this when the embedded tree if freed,
2974 * otherwise the depsgraph holds a reference to the (now freed) `ma->nodetree`.
2975 * Also run this when a new node-tree is set to ensure it's accounted for.
2976 * This also applies to animation data which is likely to be stored in the depsgraph.
2977 * Always call instead of checking when it *might* be needed. */
2979
2980 /* There are some custom updates to the node tree above, better do a full update pass. */
2981 BKE_ntree_update_tag_all(ma->nodetree);
2983
2986
2987 return OPERATOR_FINISHED;
2988}
2989
2991{
2992 /* identifiers */
2993 ot->name = "Paste Material";
2994 ot->idname = "MATERIAL_OT_paste";
2995 ot->description = "Paste the material settings and nodes";
2996
2997 /* API callbacks. */
3000
3001 /* flags */
3003}
3004
3006
3007/* -------------------------------------------------------------------- */
3010
3011static short mtexcopied = 0; /* must be reset on file load */
3013
3015{ /* use for file reload */
3016 mtexcopied = 0;
3017}
3018
3019static void copy_mtex_copybuf(ID *id)
3020{
3021 MTex **mtex = nullptr;
3022
3023 switch (id->id_type()) {
3024 case ID_PA:
3025 mtex = &(
3026 (id_cast<ParticleSettings *>(id))->mtex[int((id_cast<ParticleSettings *>(id))->texact)]);
3027 break;
3028 case ID_LS:
3029 mtex = &((id_cast<FreestyleLineStyle *>(id))
3030 ->mtex[int((id_cast<FreestyleLineStyle *>(id))->texact)]);
3031 break;
3032 default:
3033 break;
3034 }
3035
3036 if (mtex && *mtex) {
3038 mtexcopied = 1;
3039 }
3040 else {
3041 mtexcopied = 0;
3042 }
3043}
3044
3045static void paste_mtex_copybuf(ID *id)
3046{
3047 MTex **mtex = nullptr;
3048
3049 if (mtexcopied == 0 || mtexcopybuf.tex == nullptr) {
3050 return;
3051 }
3052
3053 switch (id->id_type()) {
3054 case ID_PA:
3055 mtex = &(
3056 (id_cast<ParticleSettings *>(id))->mtex[int((id_cast<ParticleSettings *>(id))->texact)]);
3057 break;
3058 case ID_LS:
3059 mtex = &((id_cast<FreestyleLineStyle *>(id))
3060 ->mtex[int((id_cast<FreestyleLineStyle *>(id))->texact)]);
3061 break;
3062 default:
3063 BLI_assert_msg(0, "invalid id type");
3064 return;
3065 }
3066
3067 if (mtex) {
3068 if (*mtex == nullptr) {
3069 *mtex = MEM_new<MTex>("mtex copy");
3070 }
3071 else if ((*mtex)->tex) {
3072 id_us_min(&(*mtex)->tex->id);
3073 }
3074
3076
3077 /* NOTE(@ideasman42): the simple memory copy has no special handling for ID data-blocks.
3078 * Ideally this would use `BKE_copybuffer_*` API's, however for common using
3079 * copy-pasting between slots, the case a users expects to copy between files
3080 * seems quite niche. So, do primitive ID validation. */
3081
3082 /* WARNING: This isn't a fool-proof solution as it's possible memory locations are reused,
3083 * or that the ID was relocated in memory since it was copied.
3084 * it does however guard against references to dangling pointers. */
3085 if ((*mtex)->tex && (BLI_findindex(&G_MAIN->textures, (*mtex)->tex) == -1)) {
3086 (*mtex)->tex = nullptr;
3087 }
3088 if ((*mtex)->object && (BLI_findindex(&G_MAIN->objects, (*mtex)->object) == -1)) {
3089 (*mtex)->object = nullptr;
3090 }
3091 id_us_plus(id_cast<ID *>((*mtex)->tex));
3092 id_lib_extern(id_cast<ID *>((*mtex)->object));
3093 }
3094}
3095
3097
3098/* -------------------------------------------------------------------- */
3101
3103{
3104 ID *id = CTX_data_pointer_get_type(C, "texture_slot", RNA_TextureSlot).owner_id;
3105
3106 if (id == nullptr) {
3107 /* copying empty slot */
3109 return OPERATOR_CANCELLED;
3110 }
3111
3113
3114 return OPERATOR_FINISHED;
3115}
3116
3118{
3119 ID *id = CTX_data_pointer_get_type(C, "texture_slot", RNA_TextureSlot).owner_id;
3120
3121 return (id != nullptr);
3122}
3123
3125{
3126 /* identifiers */
3127 ot->name = "Copy Texture Slot Settings";
3128 ot->idname = "TEXTURE_OT_slot_copy";
3129 ot->description = "Copy the material texture settings and nodes";
3130
3131 /* API callbacks. */
3132 ot->exec = copy_mtex_exec;
3133 ot->poll = copy_mtex_poll;
3134
3135 /* flags */
3136 /* no undo needed since no changes are made to the mtex */
3138}
3139
3141
3142/* -------------------------------------------------------------------- */
3145
3147{
3148 ID *id = CTX_data_pointer_get_type(C, "texture_slot", RNA_TextureSlot).owner_id;
3149
3150 if (id == nullptr) {
3151 Material *ma = static_cast<Material *>(
3152 CTX_data_pointer_get_type(C, "material", RNA_Material).data);
3153 Light *la = static_cast<Light *>(CTX_data_pointer_get_type(C, "light", RNA_Light).data);
3154 World *wo = static_cast<World *>(CTX_data_pointer_get_type(C, "world", RNA_World).data);
3155 ParticleSystem *psys = static_cast<ParticleSystem *>(
3156 CTX_data_pointer_get_type(C, "particle_system", RNA_ParticleSystem).data);
3157 FreestyleLineStyle *linestyle = static_cast<FreestyleLineStyle *>(
3158 CTX_data_pointer_get_type(C, "line_style", RNA_FreestyleLineStyle).data);
3159
3160 if (ma) {
3161 id = &ma->id;
3162 }
3163 else if (la) {
3164 id = &la->id;
3165 }
3166 else if (wo) {
3167 id = &wo->id;
3168 }
3169 else if (psys) {
3170 id = &psys->part->id;
3171 }
3172 else if (linestyle) {
3173 id = &linestyle->id;
3174 }
3175
3176 if (id == nullptr) {
3177 return OPERATOR_CANCELLED;
3178 }
3179 }
3180
3182
3184
3185 return OPERATOR_FINISHED;
3186}
3187
3189{
3190 /* identifiers */
3191 ot->name = "Paste Texture Slot Settings";
3192 ot->idname = "TEXTURE_OT_slot_paste";
3193 ot->description = "Paste the texture settings and nodes";
3194
3195 /* API callbacks. */
3196 ot->exec = paste_mtex_exec;
3197
3198 /* flags */
3200}
3201
3203
3204} // namespace blender
#define FOREACH_SCENE_OBJECT_END
#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance)
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
#define G_MAIN
#define FOREACH_OBJECT_END
Definition BKE_layer.hh:533
#define FOREACH_OBJECT_BEGIN(_bmain, _scene, _view_layer, _instance)
Definition BKE_layer.hh:523
General operations for probes.
Blender kernel freestyle line style functionality.
#define LS_MODIFIER_TYPE_COLOR
#define LS_MODIFIER_TYPE_ALPHA
#define LS_MODIFIER_TYPE_GEOMETRY
#define LS_MODIFIER_TYPE_THICKNESS
#define SELECT
Definition BKE_mask.hh:19
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define FILE_MAX
#define BLI_path_join(...)
#define BLT_I18NCONTEXT_ID_WORLD
#define CTX_DATA_(context, msgid)
#define DATA_(msgid)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
Definition DNA_ID.h:703
#define FILTER_ID_OB
Definition DNA_ID.h:1216
#define FILTER_ID_MA
Definition DNA_ID.h:1210
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define FILTER_ID_IM
Definition DNA_ID.h:1206
#define FILTER_ID_NT
Definition DNA_ID.h:1215
#define FILTER_ID_TXT
Definition DNA_ID.h:1223
#define MAX_NAME
Definition DNA_defs.h:63
Object is a sort of wrapper for general info.
#define OB_TYPE_SUPPORT_MATERIAL(_type)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define MAX_MTEX
Definition Stroke.h:31
#define NC_WORLD
Definition WM_types.hh:400
#define NC_GEOM
Definition WM_types.hh:406
#define ND_DRAW
Definition WM_types.hh:502
#define ND_DATA
Definition WM_types.hh:552
#define NC_LINESTYLE
Definition WM_types.hh:413
#define ND_RENDER_OPTIONS
Definition WM_types.hh:454
#define ND_SHADING_PREVIEW
Definition WM_types.hh:523
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define ND_TOOLSETTINGS
Definition WM_types.hh:468
#define NC_MATERIAL
Definition WM_types.hh:393
#define ND_SELECT
Definition WM_types.hh:551
#define NC_TEXTURE
Definition WM_types.hh:394
#define ND_LAYER
Definition WM_types.hh:469
#define ND_OB_SHADING
Definition WM_types.hh:476
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_SHADING_LINKS
Definition WM_types.hh:522
#define BLI_assert_unreachable()
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_MESH(ele, iter, bm, itype)
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, FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
bool write_as_copypaste_buffer(const char *write_filepath, ReportList &reports)
#define offsetof(t, d)
void fill_index_range(MutableSpan< T > span, const T start=0)
void node_tree_free_embedded_tree(bNodeTree *ntree)
Definition node.cc:5231
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
Definition DNA_defs.h:147
Object * context_object(const bContext *C)
Vector< Object * > objects_in_mode_or_selected(bContext *C, bool(*filter_fn)(const Object *ob, void *user_data), void *filter_user_data)
void node_tree_shader_default(const bContext *C, Main *bmain, ID *id)
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
BMesh Iterators.
void SCENE_OT_view_layer_remove_lightgroup(wmOperatorType *ot)
LineStyleModifier * BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle, const char *name, eLineStyleModifier_Type type)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static bool copy_mtex_poll(bContext *C)
void id_lib_extern(ID *id, bool enforce_fix=false)
Definition lib_id.cc:328
bool EDBM_deselect_by_material(BMesh *bm, short index, bool select)
void FRS_delete_active_lineset(struct FreestyleConfig *config)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
unsigned __int64 uint64_t
Definition BKE_text.h:91
void OBJECT_OT_material_slot_remove(wmOperatorType *ot)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus material_slot_de_select(bContext *C, bool select)
void BKE_object_material_remap(Object *ob, const unsigned int *remap)
LineStyleModifier * BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
void BKE_ntree_update(Main &bmain, std::optional< Span< bNodeTree * > > modified_trees=std::nullopt, const NodeTreeUpdateExtraParams &params={})
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
Main * BKE_copybuffer_read(Main &reference_bmain, const char *libname, ReportList *reports, uint64_t id_types_mask)
static wmOperatorStatus view_layer_remove_lightgroup_exec(bContext *C, wmOperator *)
void EEVEE_lightbake_update(void *job_data)
@ RPT_WARNING
Definition BKE_report.hh:40
static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob, void *user_data)
static wmOperatorStatus new_texture_exec(bContext *C, wmOperator *op)
void OBJECT_OT_material_slot_move(wmOperatorType *ot)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
BMesh * BKE_editmesh_bmesh_get_for_write(Mesh *mesh)
Definition editmesh.cc:79
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
static wmOperatorStatus lightprobe_cache_bake_exec(bContext *C, wmOperator *op)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
static void paste_mtex_copybuf(ID *id)
unsigned int uint
Definition BKE_text.h:55
int BKE_object_material_remove_unused(Main *bmain, Object *ob)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
short * BKE_object_material_len_p(Object *ob)
void BKE_ntree_update_tag_id_changed(Main *bmain, ID *id)
static bool view_layer_remove_poll(bContext *C)
static bool object_materials_supported_poll_ex(bContext *C, const Object *ob)
Material *** BKE_object_material_array_p(Object *ob)
bool ED_operator_object_active_local_editable_ex(bContext *C, const Object *ob)
ViewLayerLightgroup * BKE_view_layer_add_lightgroup(ViewLayer *view_layer, const char *name)
void id_us_plus(ID *id)
Definition lib_id.cc:433
static Set< StringRefNull > get_used_lightgroups(Scene *scene)
Material * BKE_gpencil_material_add(Main *bmain, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
static wmOperatorStatus view_layer_add_aov_exec(bContext *C, wmOperator *)
@ VIEWLAYER_ADD_COPY
Definition BKE_layer.hh:42
@ VIEWLAYER_ADD_NEW
Definition BKE_layer.hh:40
@ VIEWLAYER_ADD_EMPTY
Definition BKE_layer.hh:41
static wmOperatorStatus paste_mtex_exec(bContext *C, wmOperator *)
bool BKE_object_material_slot_add(Main *bmain, Object *ob, bool set_active=true)
static Vector< Object * > object_array_for_shading_edit_mode_enabled(bContext *C)
Material * BKE_object_material_get(Object *ob, short act)
std::string RNA_path_number_to_infix(const int number)
Definition rna_path.cc:1425
static wmOperatorStatus view_layer_remove_aov_exec(bContext *C, wmOperator *)
int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
@ WM_JOB_TYPE_LIGHT_BAKE
Definition WM_api.hh:2042
void BLI_string_replace_char(char *str, char src, char dst) ATTR_NONNULL(1)
void void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, int remap_flags) ATTR_NONNULL(1
Definition lib_remap.cc:701
static wmOperatorStatus lightprobe_cache_free_exec(bContext *C, wmOperator *op)
void MATERIAL_OT_paste(wmOperatorType *ot)
void OBJECT_OT_lightprobe_cache_bake(wmOperatorType *ot)
bool FRS_move_active_lineset(struct FreestyleConfig *config, int direction)
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 * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
static wmOperatorStatus view_layer_remove_exec(bContext *C, wmOperator *)
int BKE_object_material_index_get_with_hint(Object *ob, const Material *ma, int hint_index)
const EnumPropertyItem rna_enum_linestyle_thickness_modifier_type_items[]
static wmOperatorStatus material_slot_assign_exec(bContext *C, wmOperator *)
void SCENE_OT_render_view_remove(wmOperatorType *ot)
static wmOperatorStatus new_material_exec(bContext *C, wmOperator *)
wmWindow * CTX_wm_window(const bContext *C)
void BKE_object_material_active_index_sanitize(Object *ob)
@ ID_REMAP_FORCE_UI_POINTERS
void MATERIAL_OT_copy(wmOperatorType *ot)
const EnumPropertyItem rna_enum_linestyle_geometry_modifier_type_items[]
void SCENE_OT_view_layer_remove_aov(wmOperatorType *ot)
void BKE_view_layer_remove_aov(ViewLayer *view_layer, ViewLayerAOV *aov)
static bool render_view_remove_poll(bContext *C)
void TEXTURE_OT_new(wmOperatorType *ot)
bool ED_scene_view_layer_delete(Main *bmain, Scene *scene, ViewLayer *layer, ReportList *reports) ATTR_NONNULL(1
const char * BKE_id_name(const ID &id)
struct FreestyleLineSet * BKE_freestyle_lineset_add(struct Main *bmain, struct FreestyleConfig *config, const char *name)
Definition freestyle.cc:165
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:553
static wmOperatorStatus lightprobe_cache_bake_invoke(bContext *C, wmOperator *op, const wmEvent *)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
static wmOperatorStatus lightprobe_cache_bake_modal(bContext *C, wmOperator *op, const wmEvent *event)
void SCENE_OT_view_layer_remove(wmOperatorType *ot)
static bool material_slot_populated_poll(bContext *C)
int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
static bool material_slot_remove_poll(bContext *C)
static wmOperatorStatus texture_slot_move_exec(bContext *C, wmOperator *op)
@ LIB_ID_COPY_DEFAULT
@ LIB_ID_COPY_ACTIONS
ViewLayer * CTX_data_view_layer(const bContext *C)
@ LIGHTCACHE_SUBSET_SELECTED
@ LIGHTCACHE_SUBSET_ACTIVE
void WM_jobs_start(wmWindowManager *wm, wmJob *wm_job)
Definition wm_jobs.cc:498
static short mtexcopied
void BKE_animdata_fix_paths(ID &id, StringRef prefix, StringRef old_infix, StringRef new_infix, bool verify_paths, const DriverMap &driver_map)
static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob, void *user_data)
void RE_engine_free(RenderEngine *engine)
Global G
Definition blender.cc:57
ViewLayerAOV * BKE_view_layer_add_aov(ViewLayer *view_layer)
static wmOperatorStatus material_slot_select_exec(bContext *C, wmOperator *)
LineStyleModifier * BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
Definition linestyle.cc:902
bool BKE_linestyle_color_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
static int paste_material_nodetree_ids_relink_or_clear(LibraryIDLinkCallbackData *cb_data)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
bool ED_curve_nurb_select_check(const View3D *v3d, const Nurb *nu)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Scene * WM_window_get_active_scene(const wmWindow *win)
static wmOperatorStatus material_slot_add_exec(bContext *C, wmOperator *)
void SCENE_OT_view_layer_remove_unused_lightgroups(wmOperatorType *ot)
static wmOperatorStatus material_slot_remove_all_exec(bContext *C, wmOperator *op)
void OBJECT_OT_material_slot_add(wmOperatorType *ot)
const EnumPropertyItem rna_enum_linestyle_alpha_modifier_type_items[]
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
bool give_active_mtex(struct ID *id, struct MTex ***mtex_ar, short *act)
Definition texture.cc:480
@ OB_MODE_TEXTURE_PAINT
BMesh const char void * data
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
bool BKE_freestyle_module_move(struct FreestyleConfig *config, struct FreestyleModuleConfig *module_conf, int direction)
Definition freestyle.cc:142
struct FreestyleLineSet * BKE_freestyle_lineset_get_active(struct FreestyleConfig *config)
Definition freestyle.cc:214
wmWindowManager * CTX_wm_manager(const bContext *C)
static wmOperatorStatus material_slot_remove_exec(bContext *C, wmOperator *)
bool BKE_freestyle_module_delete(struct FreestyleConfig *config, struct FreestyleModuleConfig *module_conf)
Definition freestyle.cc:133
static wmOperatorStatus paste_material_exec(bContext *C, wmOperator *op)
static void copy_mtex_copybuf(ID *id)
void BKE_view_layer_verify_aov(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
static wmOperatorStatus material_slot_copy_exec(bContext *C, wmOperator *)
static wmOperatorStatus copy_material_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_layer_add_lightgroup_exec(bContext *C, wmOperator *op)
void MATERIAL_OT_new(wmOperatorType *ot)
static wmOperatorStatus render_view_add_exec(bContext *C, wmOperator *)
static wmOperatorStatus new_world_exec(bContext *C, wmOperator *)
wmJob * EEVEE_lightbake_job_create(wmWindowManager *wm, wmWindow *win, Main *bmain, ViewLayer *view_layer, Scene *scene, Vector< Object * > original_probes, std::string &report, int delay_ms, int frame)
void TEXTURE_OT_slot_paste(wmOperatorType *ot)
DriverMap BKE_animdata_build_driver_target_map(Main &bmain)
Definition anim_data.cc:980
void OBJECT_OT_material_slot_remove_unused(wmOperatorType *ot)
FreestyleLineStyle * BKE_linestyle_new(struct Main *bmain, const char *name)
Definition linestyle.cc:762
static Vector< Object * > object_array_for_shading_edit_mode_disabled(bContext *C)
static wmOperatorStatus copy_mtex_exec(bContext *C, wmOperator *)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
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)
static wmOperatorStatus render_view_remove_exec(bContext *C, wmOperator *)
void EEVEE_lightbake_job_data_free(void *job_data)
void BKE_lightprobe_cache_free(struct Object *object)
static void lightprobe_cache_bake_cancel(bContext *C, wmOperator *op)
void OBJECT_OT_material_slot_assign(wmOperatorType *ot)
void OBJECT_OT_material_slot_copy(wmOperatorType *ot)
void BKE_ntree_update_tag_all(bNodeTree *ntree)
const char * BKE_tempdir_base() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1288
LineStyleModifier * BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, const char *name, eLineStyleModifier_Type type)
void TEXTURE_OT_slot_copy(wmOperatorType *ot)
static wmOperatorStatus material_slot_move_exec(bContext *C, wmOperator *op)
int BKE_vfont_select_get(const Curve *cu, int *r_start, int *r_end)
Definition vfont.cc:424
void ED_render_clear_mtex_copybuf()
void BKE_object_material_array_assign(Main *bmain, Object *ob, Material ***matar, int totcol, bool to_object_only)
void SCENE_OT_view_layer_add_lightgroup(wmOperatorType *ot)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
RenderEngineType * RE_engines_find(const char *idname)
Vector< Object * > BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer, const View3D *v3d, const ObjectsInViewLayerParams *params)
void BKE_main_free(Main *bmain)
Definition main.cc:202
BMEditMesh * BKE_editmesh_from_object(Object *ob)
Return the BMEditMesh for a given object.
Definition editmesh.cc:59
struct World * BKE_world_add(struct Main *bmain, const char *name)
bool BKE_object_is_in_editmode(const Object *ob)
Definition object.cc:1898
static void material_copybuffer_filepath_get(char filepath[FILE_MAX], size_t filepath_maxncpy)
void BKE_view_layer_remove_lightgroup(ViewLayer *view_layer, ViewLayerLightgroup *lightgroup)
SceneRenderView * BKE_scene_add_render_view(Scene *sce, const char *name)
Definition scene.cc:2965
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
int BKE_object_material_remove_all(Main *bmain, Object *ob)
void WM_jobs_kill_type(wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:642
void OBJECT_OT_material_slot_select(wmOperatorType *ot)
RenderEngine * RE_engine_create(RenderEngineType *type)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void WORLD_OT_new(wmOperatorType *ot)
Main * CTX_data_main(const bContext *C)
void * EEVEE_lightbake_job_data_alloc(Main *bmain, ViewLayer *view_layer, Scene *scene, Vector< Object * > original_probes, std::string &report, int frame)
static MTex mtexcopybuf
bool BKE_linestyle_thickness_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
void set_active_mtex(struct ID *id, short act)
Definition texture.cc:506
Material ** BKE_object_material_get_p(Object *ob, short act)
LineStyleModifier * BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle, const char *name, eLineStyleModifier_Type type)
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
Definition linestyle.cc:773
void SCENE_OT_view_layer_add(wmOperatorType *ot)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1104
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
struct FreestyleModuleConfig * BKE_freestyle_module_add(struct FreestyleConfig *config)
Definition freestyle.cc:118
bool BKE_scene_remove_render_view(Scene *scene, SceneRenderView *srv)
Definition scene.cc:2984
struct Tex * BKE_texture_add(struct Main *bmain, const char *name)
Definition texture.cc:370
const EnumPropertyItem rna_enum_linestyle_color_modifier_type_items[]
void SCENE_OT_view_layer_add_used_lightgroups(wmOperatorType *ot)
void BKE_id_move_to_same_lib(Main &bmain, ID &id, const ID &owner_id)
Definition lib_id.cc:953
static int paste_material_nodetree_ids_decref(LibraryIDLinkCallbackData *cb_data)
ListBaseT< Nurb > * BKE_curve_editNurbs_get(Curve *cu)
Definition curve.cc:441
void DEG_relations_tag_update(Main *bmain)
static wmOperatorStatus material_slot_deselect_exec(bContext *C, wmOperator *)
ViewLayer * BKE_view_layer_add(const Main *bmain, Scene *scene, const char *name, ViewLayer *view_layer_source, int type)
Scene * CTX_data_scene(const bContext *C)
Map< ID *, Vector< DriverTarget * > > DriverMap
@ ID_FLAG_CLIPBOARD_MARK
Definition DNA_ID.h:801
bool BKE_linestyle_geometry_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
void OBJECT_OT_material_slot_remove_all(wmOperatorType *ot)
void OBJECT_OT_material_slot_deselect(wmOperatorType *ot)
void SCENE_OT_view_layer_add_aov(wmOperatorType *ot)
void FRS_copy_active_lineset(struct FreestyleConfig *config)
bool BKE_linestyle_alpha_modifier_move(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
void FRS_paste_active_lineset(struct FreestyleConfig *config)
void SCENE_OT_render_view_add(wmOperatorType *ot)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
LineStyleModifier * BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, const char *name, eLineStyleModifier_Type type)
Definition linestyle.cc:836
Material * BKE_material_add(Main *bmain, const char *name)
static wmOperatorStatus view_layer_add_exec(bContext *C, wmOperator *op)
void TEXTURE_OT_slot_move(wmOperatorType *ot)
int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
static wmOperatorStatus material_slot_remove_unused_exec(bContext *C, wmOperator *op)
static wmOperatorStatus view_layer_add_used_lightgroups_exec(bContext *C, wmOperator *)
struct Material * FRS_create_stroke_material(struct Main *bmain, struct FreestyleLineStyle *linestyle)
LineStyleModifier * BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
void EEVEE_lightbake_job(void *job_data, wmJobWorkerStatus *worker_status)
void WM_cursor_wait(bool val)
ID * BKE_id_copy(Main *bmain, const ID *id)
Definition lib_id.cc:856
static wmOperatorStatus view_layer_remove_unused_lightgroups_exec(bContext *C, wmOperator *)
void OBJECT_OT_lightprobe_cache_free(wmOperatorType *ot)
Object * CTX_data_active_object(const bContext *C)
void id_us_min(ID *id)
Definition lib_id.cc:441
LineStyleModifier * BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle, const LineStyleModifier *m, int flag)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
View3D * CTX_wm_view3d(const bContext *C)
void BKE_lightprobe_cache_create(struct Object *object)
void WM_window_set_active_view_layer(wmWindow *win, ViewLayer *view_layer)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
ListBaseT< ID > * which_libbase(Main *bmain, short type)
Definition main.cc:1073
int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *modifier)
static bool object_materials_supported_poll(bContext *C)
static Vector< Object * > lightprobe_cache_irradiance_volume_subset_get(bContext *C, wmOperator *op)
#define SWAP_MEMBER(member)
eBezTriple_Flag f2
eBezTriple_Flag f3
eBezTriple_Flag f1
struct EditFont * editfont
CharInfo * textbufinfo
Definition BKE_vfont.hh:48
LibraryForeachIDCallbackFlag cb_flag
ListBaseT< Material > materials
Definition BKE_main.hh:392
struct Material ** mat
bool(*) filter_fn(const Object *ob, void *user_data)
Definition BKE_layer.hh:593
StructRNA * type
Definition RNA_types.hh:63
ListBaseT< SceneRenderView > views
void(*) update_render_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer)
Definition RE_engine.h:123
ListBaseT< ViewLayer > view_layers
struct World * world
struct RenderData r
ListBaseT< ViewLayerLightgroup > lightgroups
ViewLayerAOV * active_aov
ViewLayerLightgroup * active_lightgroup
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports