2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * The Original Code is Copyright (C) 2009 Blender Foundation.
18 * All rights reserved.
20 * Contributor(s): Blender Foundation
22 * ***** END GPL LICENSE BLOCK *****
25 /** \file blender/editors/render/render_shading.c
32 #include "MEM_guardedalloc.h"
34 #include "DNA_curve_types.h"
35 #include "DNA_lamp_types.h"
36 #include "DNA_material_types.h"
37 #include "DNA_node_types.h"
38 #include "DNA_object_types.h"
39 #include "DNA_particle_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_world_types.h"
44 #include "BLI_blenlib.h"
45 #include "BLI_utildefines.h"
47 #include "BLF_translation.h"
49 #include "BKE_animsys.h"
50 #include "BKE_context.h"
51 #include "BKE_curve.h"
52 #include "BKE_depsgraph.h"
54 #include "BKE_global.h"
55 #include "BKE_image.h"
56 #include "BKE_library.h"
57 #include "BKE_linestyle.h"
59 #include "BKE_material.h"
60 #include "BKE_paint.h"
61 #include "BKE_report.h"
62 #include "BKE_scene.h"
63 #include "BKE_texture.h"
64 #include "BKE_world.h"
65 #include "BKE_editmesh.h"
70 # include "BKE_freestyle.h"
71 # include "FRS_freestyle.h"
72 # include "RNA_enum_types.h"
75 #include "RNA_access.h"
80 #include "ED_object.h"
84 #include "ED_render.h"
85 #include "ED_screen.h"
87 #include "RNA_define.h"
89 #include "UI_interface.h"
91 #include "RE_pipeline.h"
93 #include "render_intern.h" // own include
95 /********************** material slot operators *********************/
97 static int material_slot_add_exec(bContext *C, wmOperator *UNUSED(op))
99 Object *ob = ED_object_context(C);
102 return OPERATOR_CANCELLED;
104 object_add_material_slot(ob);
106 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
107 Scene *scene = CTX_data_scene(C);
108 BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
109 WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
112 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
113 WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
114 WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_PREVIEW, ob);
116 return OPERATOR_FINISHED;
119 void OBJECT_OT_material_slot_add(wmOperatorType *ot)
122 ot->name = "Add Material Slot";
123 ot->idname = "OBJECT_OT_material_slot_add";
124 ot->description = "Add a new material slot";
127 ot->exec = material_slot_add_exec;
128 ot->poll = ED_operator_object_active_editable;
131 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
134 static int material_slot_remove_exec(bContext *C, wmOperator *op)
136 Object *ob = ED_object_context(C);
139 return OPERATOR_CANCELLED;
141 /* Removing material slots in edit mode screws things up, see bug #21822.*/
142 if (ob == CTX_data_edit_object(C)) {
143 BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode");
144 return OPERATOR_CANCELLED;
147 object_remove_material_slot(ob);
149 if (ob->mode & OB_MODE_TEXTURE_PAINT) {
150 Scene *scene = CTX_data_scene(C);
151 BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
152 WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
155 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
156 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
157 WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
158 WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_PREVIEW, ob);
160 return OPERATOR_FINISHED;
163 void OBJECT_OT_material_slot_remove(wmOperatorType *ot)
166 ot->name = "Remove Material Slot";
167 ot->idname = "OBJECT_OT_material_slot_remove";
168 ot->description = "Remove the selected material slot";
171 ot->exec = material_slot_remove_exec;
172 ot->poll = ED_operator_object_active_editable;
175 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
178 static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
180 Object *ob = ED_object_context(C);
183 return OPERATOR_CANCELLED;
185 if (ob && ob->actcol > 0) {
186 if (ob->type == OB_MESH) {
187 BMEditMesh *em = BKE_editmesh_from_object(ob);
192 BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
193 if (BM_elem_flag_test(efa, BM_ELEM_SELECT))
194 efa->mat_nr = ob->actcol - 1;
198 else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
200 ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data);
203 for (nu = nurbs->first; nu; nu = nu->next)
205 nu->mat_nr = nu->charidx = ob->actcol - 1;
208 else if (ob->type == OB_FONT) {
209 EditFont *ef = ((Curve *)ob->data)->editfont;
210 int i, selstart, selend;
212 if (ef && BKE_vfont_select_get(ob, &selstart, &selend)) {
213 for (i = selstart; i <= selend; i++)
214 ef->textbufinfo[i].mat_nr = ob->actcol;
219 DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
220 WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
222 return OPERATOR_FINISHED;
225 void OBJECT_OT_material_slot_assign(wmOperatorType *ot)
228 ot->name = "Assign Material Slot";
229 ot->idname = "OBJECT_OT_material_slot_assign";
230 ot->description = "Assign active material slot to selection";
233 ot->exec = material_slot_assign_exec;
234 ot->poll = ED_operator_object_active_editable;
237 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
240 static int material_slot_de_select(bContext *C, bool select)
242 Object *ob = ED_object_context(C);
245 return OPERATOR_CANCELLED;
247 if (ob->type == OB_MESH) {
248 BMEditMesh *em = BKE_editmesh_from_object(ob);
251 EDBM_deselect_by_material(em, ob->actcol - 1, select);
254 else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
255 ListBase *nurbs = BKE_curve_editNurbs_get((Curve *)ob->data);
262 for (nu = nurbs->first; nu; nu = nu->next) {
263 if (nu->mat_nr == ob->actcol - 1) {
268 if (bezt->hide == 0) {
284 a = nu->pntsu * nu->pntsv;
288 if (select) bp->f1 |= SELECT;
289 else bp->f1 &= ~SELECT;
299 WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
301 return OPERATOR_FINISHED;
304 static int material_slot_select_exec(bContext *C, wmOperator *UNUSED(op))
306 return material_slot_de_select(C, true);
309 void OBJECT_OT_material_slot_select(wmOperatorType *ot)
312 ot->name = "Select Material Slot";
313 ot->idname = "OBJECT_OT_material_slot_select";
314 ot->description = "Select by active material slot";
317 ot->exec = material_slot_select_exec;
320 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
323 static int material_slot_deselect_exec(bContext *C, wmOperator *UNUSED(op))
325 return material_slot_de_select(C, false);
328 void OBJECT_OT_material_slot_deselect(wmOperatorType *ot)
331 ot->name = "Deselect Material Slot";
332 ot->idname = "OBJECT_OT_material_slot_deselect";
333 ot->description = "Deselect by active material slot";
336 ot->exec = material_slot_deselect_exec;
339 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
343 static int material_slot_copy_exec(bContext *C, wmOperator *UNUSED(op))
345 Object *ob = ED_object_context(C);
348 if (!ob || !(matar = give_matarar(ob)))
349 return OPERATOR_CANCELLED;
351 CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects)
353 if (ob != ob_iter && give_matarar(ob_iter)) {
354 if (ob->data != ob_iter->data)
355 assign_matarar(ob_iter, matar, ob->totcol);
357 if (ob_iter->totcol == ob->totcol) {
358 ob_iter->actcol = ob->actcol;
359 DAG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
360 WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
366 return OPERATOR_FINISHED;
370 void OBJECT_OT_material_slot_copy(wmOperatorType *ot)
373 ot->name = "Copy Material to Others";
374 ot->idname = "OBJECT_OT_material_slot_copy";
375 ot->description = "Copies materials to other selected objects";
378 ot->exec = material_slot_copy_exec;
381 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
384 /********************** new material operator *********************/
386 static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
388 Scene *scene = CTX_data_scene(C);
389 Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
390 Main *bmain = CTX_data_main(C);
391 PointerRNA ptr, idptr;
394 /* add or copy material */
396 ma = BKE_material_copy(ma);
399 ma = BKE_material_add(bmain, DATA_("Material"));
401 if (BKE_scene_use_new_shading_nodes(scene)) {
402 ED_node_shader_default(C, &ma->id);
403 ma->use_nodes = true;
408 UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
411 /* when creating new ID blocks, use is already 1, but RNA
412 * pointer se also increases user, so this compensates it */
415 RNA_id_pointer_create(&ma->id, &idptr);
416 RNA_property_pointer_set(&ptr, prop, idptr);
417 RNA_property_update(C, &ptr, prop);
420 WM_event_add_notifier(C, NC_MATERIAL | NA_ADDED, ma);
422 return OPERATOR_FINISHED;
425 void MATERIAL_OT_new(wmOperatorType *ot)
428 ot->name = "New Material";
429 ot->idname = "MATERIAL_OT_new";
430 ot->description = "Add a new material";
433 ot->exec = new_material_exec;
436 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
439 /********************** new texture operator *********************/
441 static int new_texture_exec(bContext *C, wmOperator *UNUSED(op))
443 Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
444 Main *bmain = CTX_data_main(C);
445 PointerRNA ptr, idptr;
448 /* add or copy texture */
450 tex = BKE_texture_copy(tex);
453 tex = BKE_texture_add(bmain, DATA_("Texture"));
457 UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
460 /* when creating new ID blocks, use is already 1, but RNA
461 * pointer se also increases user, so this compensates it */
464 if (ptr.id.data && GS(((ID *)ptr.id.data)->name) == ID_MA &&
465 RNA_property_pointer_get(&ptr, prop).id.data == NULL)
467 /* In case we are assigning new texture to a material, and active slot was empty, reset 'use' flag. */
468 Material *ma = (Material *)ptr.id.data;
469 ma->septex &= ~(1 << ma->texact);
472 RNA_id_pointer_create(&tex->id, &idptr);
473 RNA_property_pointer_set(&ptr, prop, idptr);
474 RNA_property_update(C, &ptr, prop);
477 WM_event_add_notifier(C, NC_TEXTURE | NA_ADDED, tex);
479 return OPERATOR_FINISHED;
482 void TEXTURE_OT_new(wmOperatorType *ot)
485 ot->name = "New Texture";
486 ot->idname = "TEXTURE_OT_new";
487 ot->description = "Add a new texture";
490 ot->exec = new_texture_exec;
493 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
496 /********************** new world operator *********************/
498 static int new_world_exec(bContext *C, wmOperator *UNUSED(op))
500 Scene *scene = CTX_data_scene(C);
501 World *wo = CTX_data_pointer_get_type(C, "world", &RNA_World).data;
502 Main *bmain = CTX_data_main(C);
503 PointerRNA ptr, idptr;
506 /* add or copy world */
508 wo = BKE_world_copy(wo);
511 wo = add_world(bmain, DATA_("World"));
513 if (BKE_scene_use_new_shading_nodes(scene)) {
514 ED_node_shader_default(C, &wo->id);
515 wo->use_nodes = true;
520 UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
523 /* when creating new ID blocks, use is already 1, but RNA
524 * pointer se also increases user, so this compensates it */
527 RNA_id_pointer_create(&wo->id, &idptr);
528 RNA_property_pointer_set(&ptr, prop, idptr);
529 RNA_property_update(C, &ptr, prop);
532 WM_event_add_notifier(C, NC_WORLD | NA_ADDED, wo);
534 return OPERATOR_FINISHED;
537 void WORLD_OT_new(wmOperatorType *ot)
540 ot->name = "New World";
541 ot->idname = "WORLD_OT_new";
542 ot->description = "Add a new world";
545 ot->exec = new_world_exec;
548 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
551 /********************** render layer operators *********************/
553 static int render_layer_add_exec(bContext *C, wmOperator *UNUSED(op))
555 Scene *scene = CTX_data_scene(C);
557 BKE_scene_add_render_layer(scene, NULL);
558 scene->r.actlay = BLI_listbase_count(&scene->r.layers) - 1;
560 DAG_id_tag_update(&scene->id, 0);
561 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
563 return OPERATOR_FINISHED;
566 void SCENE_OT_render_layer_add(wmOperatorType *ot)
569 ot->name = "Add Render Layer";
570 ot->idname = "SCENE_OT_render_layer_add";
571 ot->description = "Add a render layer";
574 ot->exec = render_layer_add_exec;
577 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
580 static int render_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
582 Scene *scene = CTX_data_scene(C);
583 SceneRenderLayer *rl = BLI_findlink(&scene->r.layers, scene->r.actlay);
585 if (!BKE_scene_remove_render_layer(CTX_data_main(C), scene, rl))
586 return OPERATOR_CANCELLED;
588 DAG_id_tag_update(&scene->id, 0);
589 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
591 return OPERATOR_FINISHED;
594 void SCENE_OT_render_layer_remove(wmOperatorType *ot)
597 ot->name = "Remove Render Layer";
598 ot->idname = "SCENE_OT_render_layer_remove";
599 ot->description = "Remove the selected render layer";
602 ot->exec = render_layer_remove_exec;
605 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
608 /********************** render view operators *********************/
610 static int render_view_remove_poll(bContext *C)
612 Scene *scene = CTX_data_scene(C);
614 /* don't allow user to remove "left" and "right" views */
615 return scene->r.actview > 1;
618 static int render_view_add_exec(bContext *C, wmOperator *UNUSED(op))
620 Scene *scene = CTX_data_scene(C);
622 BKE_scene_add_render_view(scene, NULL);
623 scene->r.actview = BLI_listbase_count(&scene->r.views) - 1;
625 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
627 return OPERATOR_FINISHED;
630 void SCENE_OT_render_view_add(wmOperatorType *ot)
633 ot->name = "Add Render View";
634 ot->idname = "SCENE_OT_render_view_add";
635 ot->description = "Add a render view";
638 ot->exec = render_view_add_exec;
641 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
644 static int render_view_remove_exec(bContext *C, wmOperator *UNUSED(op))
646 Scene *scene = CTX_data_scene(C);
647 SceneRenderView *rv = BLI_findlink(&scene->r.views, scene->r.actview);
649 if (!BKE_scene_remove_render_view(scene, rv))
650 return OPERATOR_CANCELLED;
652 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
654 return OPERATOR_FINISHED;
657 void SCENE_OT_render_view_remove(wmOperatorType *ot)
660 ot->name = "Remove Render View";
661 ot->idname = "SCENE_OT_render_view_remove";
662 ot->description = "Remove the selected render view";
665 ot->exec = render_view_remove_exec;
666 ot->poll = render_view_remove_poll;
669 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
672 #ifdef WITH_FREESTYLE
674 static bool freestyle_linestyle_check_report(FreestyleLineSet *lineset, ReportList *reports)
677 BKE_report(reports, RPT_ERROR, "No active lineset and associated line style to manipulate the modifier");
680 if (!lineset->linestyle) {
681 BKE_report(reports, RPT_ERROR, "The active lineset does not have a line style (indicating data corruption)");
688 static int freestyle_active_module_poll(bContext *C)
690 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
691 FreestyleModuleConfig *module = ptr.data;
693 return module != NULL;
696 static int freestyle_module_add_exec(bContext *C, wmOperator *UNUSED(op))
698 Scene *scene = CTX_data_scene(C);
699 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
701 BKE_freestyle_module_add(&srl->freestyleConfig);
703 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
705 return OPERATOR_FINISHED;
708 void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
711 ot->name = "Add Freestyle Module";
712 ot->idname = "SCENE_OT_freestyle_module_add";
713 ot->description = "Add a style module into the list of modules";
716 ot->exec = freestyle_module_add_exec;
719 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
722 static int freestyle_module_remove_exec(bContext *C, wmOperator *UNUSED(op))
724 Scene *scene = CTX_data_scene(C);
725 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
726 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
727 FreestyleModuleConfig *module = ptr.data;
729 BKE_freestyle_module_delete(&srl->freestyleConfig, module);
731 DAG_id_tag_update(&scene->id, 0);
732 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
734 return OPERATOR_FINISHED;
737 void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
740 ot->name = "Remove Freestyle Module";
741 ot->idname = "SCENE_OT_freestyle_module_remove";
742 ot->description = "Remove the style module from the stack";
745 ot->poll = freestyle_active_module_poll;
746 ot->exec = freestyle_module_remove_exec;
749 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
752 static int freestyle_module_move_exec(bContext *C, wmOperator *op)
754 Scene *scene = CTX_data_scene(C);
755 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
756 PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
757 FreestyleModuleConfig *module = ptr.data;
758 int dir = RNA_enum_get(op->ptr, "direction");
761 BKE_freestyle_module_move_up(&srl->freestyleConfig, module);
764 BKE_freestyle_module_move_down(&srl->freestyleConfig, module);
766 DAG_id_tag_update(&scene->id, 0);
767 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
769 return OPERATOR_FINISHED;
772 void SCENE_OT_freestyle_module_move(wmOperatorType *ot)
774 static EnumPropertyItem direction_items[] = {
775 {1, "UP", 0, "Up", ""},
776 {-1, "DOWN", 0, "Down", ""},
777 {0, NULL, 0, NULL, NULL}
781 ot->name = "Move Freestyle Module";
782 ot->idname = "SCENE_OT_freestyle_module_move";
783 ot->description = "Change the position of the style module within in the list of style modules";
786 ot->poll = freestyle_active_module_poll;
787 ot->exec = freestyle_module_move_exec;
790 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
793 RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
796 static int freestyle_lineset_add_exec(bContext *C, wmOperator *UNUSED(op))
798 Main *bmain = CTX_data_main(C);
799 Scene *scene = CTX_data_scene(C);
800 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
802 BKE_freestyle_lineset_add(bmain, &srl->freestyleConfig, NULL);
804 DAG_id_tag_update(&scene->id, 0);
805 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
807 return OPERATOR_FINISHED;
810 void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
813 ot->name = "Add Line Set";
814 ot->idname = "SCENE_OT_freestyle_lineset_add";
815 ot->description = "Add a line set into the list of line sets";
818 ot->exec = freestyle_lineset_add_exec;
821 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
824 static int freestyle_active_lineset_poll(bContext *C)
826 Scene *scene = CTX_data_scene(C);
827 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
833 return BKE_freestyle_lineset_get_active(&srl->freestyleConfig) != NULL;
836 static int freestyle_lineset_copy_exec(bContext *C, wmOperator *UNUSED(op))
838 Scene *scene = CTX_data_scene(C);
839 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
841 FRS_copy_active_lineset(&srl->freestyleConfig);
843 return OPERATOR_FINISHED;
846 void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot)
849 ot->name = "Copy Line Set";
850 ot->idname = "SCENE_OT_freestyle_lineset_copy";
851 ot->description = "Copy the active line set to a buffer";
854 ot->exec = freestyle_lineset_copy_exec;
855 ot->poll = freestyle_active_lineset_poll;
858 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
861 static int freestyle_lineset_paste_exec(bContext *C, wmOperator *UNUSED(op))
863 Scene *scene = CTX_data_scene(C);
864 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
866 FRS_paste_active_lineset(&srl->freestyleConfig);
868 DAG_id_tag_update(&scene->id, 0);
869 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
871 return OPERATOR_FINISHED;
874 void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot)
877 ot->name = "Paste Line Set";
878 ot->idname = "SCENE_OT_freestyle_lineset_paste";
879 ot->description = "Paste the buffer content to the active line set";
882 ot->exec = freestyle_lineset_paste_exec;
883 ot->poll = freestyle_active_lineset_poll;
886 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
889 static int freestyle_lineset_remove_exec(bContext *C, wmOperator *UNUSED(op))
891 Scene *scene = CTX_data_scene(C);
892 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
894 FRS_delete_active_lineset(&srl->freestyleConfig);
896 DAG_id_tag_update(&scene->id, 0);
897 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
899 return OPERATOR_FINISHED;
902 void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
905 ot->name = "Remove Line Set";
906 ot->idname = "SCENE_OT_freestyle_lineset_remove";
907 ot->description = "Remove the active line set from the list of line sets";
910 ot->exec = freestyle_lineset_remove_exec;
911 ot->poll = freestyle_active_lineset_poll;
914 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
917 static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
919 Scene *scene = CTX_data_scene(C);
920 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
921 int dir = RNA_enum_get(op->ptr, "direction");
924 FRS_move_active_lineset_up(&srl->freestyleConfig);
927 FRS_move_active_lineset_down(&srl->freestyleConfig);
929 DAG_id_tag_update(&scene->id, 0);
930 WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
932 return OPERATOR_FINISHED;
935 void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
937 static EnumPropertyItem direction_items[] = {
938 {1, "UP", 0, "Up", ""},
939 {-1, "DOWN", 0, "Down", ""},
940 {0, NULL, 0, NULL, NULL}
944 ot->name = "Move Line Set";
945 ot->idname = "SCENE_OT_freestyle_lineset_move";
946 ot->description = "Change the position of the active line set within the list of line sets";
949 ot->exec = freestyle_lineset_move_exec;
950 ot->poll = freestyle_active_lineset_poll;
953 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
956 RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
959 static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
961 Main *bmain = CTX_data_main(C);
962 Scene *scene = CTX_data_scene(C);
963 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
964 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
967 BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to");
968 return OPERATOR_CANCELLED;
970 if (lineset->linestyle) {
971 lineset->linestyle->id.us--;
972 lineset->linestyle = BKE_linestyle_copy(bmain, lineset->linestyle);
975 lineset->linestyle = BKE_linestyle_new(bmain, "LineStyle");
977 DAG_id_tag_update(&lineset->linestyle->id, 0);
978 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
980 return OPERATOR_FINISHED;
983 void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot)
986 ot->name = "New Line Style";
987 ot->idname = "SCENE_OT_freestyle_linestyle_new";
988 ot->description = "Create a new line style, reusable by multiple line sets";
991 ot->exec = freestyle_linestyle_new_exec;
992 ot->poll = freestyle_active_lineset_poll;
995 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
998 static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
1000 Scene *scene = CTX_data_scene(C);
1001 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1002 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1003 int type = RNA_enum_get(op->ptr, "type");
1005 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1006 return OPERATOR_CANCELLED;
1009 if (BKE_linestyle_color_modifier_add(lineset->linestyle, NULL, type) == NULL) {
1010 BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type");
1011 return OPERATOR_CANCELLED;
1013 DAG_id_tag_update(&lineset->linestyle->id, 0);
1014 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1016 return OPERATOR_FINISHED;
1019 void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
1022 ot->name = "Add Line Color Modifier";
1023 ot->idname = "SCENE_OT_freestyle_color_modifier_add";
1024 ot->description = "Add a line color modifier to the line style associated with the active lineset";
1027 ot->invoke = WM_menu_invoke;
1028 ot->exec = freestyle_color_modifier_add_exec;
1029 ot->poll = freestyle_active_lineset_poll;
1032 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1035 ot->prop = RNA_def_enum(ot->srna, "type", linestyle_color_modifier_type_items, 0, "Type", "");
1038 static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
1040 Scene *scene = CTX_data_scene(C);
1041 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1042 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1043 int type = RNA_enum_get(op->ptr, "type");
1045 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1046 return OPERATOR_CANCELLED;
1049 if (BKE_linestyle_alpha_modifier_add(lineset->linestyle, NULL, type) == NULL) {
1050 BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type");
1051 return OPERATOR_CANCELLED;
1053 DAG_id_tag_update(&lineset->linestyle->id, 0);
1054 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1056 return OPERATOR_FINISHED;
1059 void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
1062 ot->name = "Add Alpha Transparency Modifier";
1063 ot->idname = "SCENE_OT_freestyle_alpha_modifier_add";
1064 ot->description = "Add an alpha transparency modifier to the line style associated with the active lineset";
1067 ot->invoke = WM_menu_invoke;
1068 ot->exec = freestyle_alpha_modifier_add_exec;
1069 ot->poll = freestyle_active_lineset_poll;
1072 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1075 ot->prop = RNA_def_enum(ot->srna, "type", linestyle_alpha_modifier_type_items, 0, "Type", "");
1078 static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
1080 Scene *scene = CTX_data_scene(C);
1081 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1082 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1083 int type = RNA_enum_get(op->ptr, "type");
1085 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1086 return OPERATOR_CANCELLED;
1089 if (BKE_linestyle_thickness_modifier_add(lineset->linestyle, NULL, type) == NULL) {
1090 BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type");
1091 return OPERATOR_CANCELLED;
1093 DAG_id_tag_update(&lineset->linestyle->id, 0);
1094 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1096 return OPERATOR_FINISHED;
1099 void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
1102 ot->name = "Add Line Thickness Modifier";
1103 ot->idname = "SCENE_OT_freestyle_thickness_modifier_add";
1104 ot->description = "Add a line thickness modifier to the line style associated with the active lineset";
1107 ot->invoke = WM_menu_invoke;
1108 ot->exec = freestyle_thickness_modifier_add_exec;
1109 ot->poll = freestyle_active_lineset_poll;
1112 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1115 ot->prop = RNA_def_enum(ot->srna, "type", linestyle_thickness_modifier_type_items, 0, "Type", "");
1118 static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
1120 Scene *scene = CTX_data_scene(C);
1121 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1122 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1123 int type = RNA_enum_get(op->ptr, "type");
1125 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1126 return OPERATOR_CANCELLED;
1129 if (BKE_linestyle_geometry_modifier_add(lineset->linestyle, NULL, type) == NULL) {
1130 BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type");
1131 return OPERATOR_CANCELLED;
1133 DAG_id_tag_update(&lineset->linestyle->id, 0);
1134 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1136 return OPERATOR_FINISHED;
1139 void SCENE_OT_freestyle_geometry_modifier_add(wmOperatorType *ot)
1142 ot->name = "Add Stroke Geometry Modifier";
1143 ot->idname = "SCENE_OT_freestyle_geometry_modifier_add";
1144 ot->description = "Add a stroke geometry modifier to the line style associated with the active lineset";
1147 ot->invoke = WM_menu_invoke;
1148 ot->exec = freestyle_geometry_modifier_add_exec;
1149 ot->poll = freestyle_active_lineset_poll;
1152 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1155 ot->prop = RNA_def_enum(ot->srna, "type", linestyle_geometry_modifier_type_items, 0, "Type", "");
1158 static int freestyle_get_modifier_type(PointerRNA *ptr)
1160 if (RNA_struct_is_a(ptr->type, &RNA_LineStyleColorModifier))
1161 return LS_MODIFIER_TYPE_COLOR;
1162 else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleAlphaModifier))
1163 return LS_MODIFIER_TYPE_ALPHA;
1164 else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleThicknessModifier))
1165 return LS_MODIFIER_TYPE_THICKNESS;
1166 else if (RNA_struct_is_a(ptr->type, &RNA_LineStyleGeometryModifier))
1167 return LS_MODIFIER_TYPE_GEOMETRY;
1171 static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
1173 Scene *scene = CTX_data_scene(C);
1174 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1175 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1176 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
1177 LineStyleModifier *modifier = ptr.data;
1179 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1180 return OPERATOR_CANCELLED;
1183 switch (freestyle_get_modifier_type(&ptr)) {
1184 case LS_MODIFIER_TYPE_COLOR:
1185 BKE_linestyle_color_modifier_remove(lineset->linestyle, modifier);
1187 case LS_MODIFIER_TYPE_ALPHA:
1188 BKE_linestyle_alpha_modifier_remove(lineset->linestyle, modifier);
1190 case LS_MODIFIER_TYPE_THICKNESS:
1191 BKE_linestyle_thickness_modifier_remove(lineset->linestyle, modifier);
1193 case LS_MODIFIER_TYPE_GEOMETRY:
1194 BKE_linestyle_geometry_modifier_remove(lineset->linestyle, modifier);
1197 BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
1198 return OPERATOR_CANCELLED;
1200 DAG_id_tag_update(&lineset->linestyle->id, 0);
1201 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1203 return OPERATOR_FINISHED;
1206 void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
1209 ot->name = "Remove Modifier";
1210 ot->idname = "SCENE_OT_freestyle_modifier_remove";
1211 ot->description = "Remove the modifier from the list of modifiers";
1214 ot->exec = freestyle_modifier_remove_exec;
1215 ot->poll = freestyle_active_lineset_poll;
1218 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1221 static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
1223 Scene *scene = CTX_data_scene(C);
1224 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1225 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1226 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
1227 LineStyleModifier *modifier = ptr.data;
1229 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1230 return OPERATOR_CANCELLED;
1233 switch (freestyle_get_modifier_type(&ptr)) {
1234 case LS_MODIFIER_TYPE_COLOR:
1235 BKE_linestyle_color_modifier_copy(lineset->linestyle, modifier);
1237 case LS_MODIFIER_TYPE_ALPHA:
1238 BKE_linestyle_alpha_modifier_copy(lineset->linestyle, modifier);
1240 case LS_MODIFIER_TYPE_THICKNESS:
1241 BKE_linestyle_thickness_modifier_copy(lineset->linestyle, modifier);
1243 case LS_MODIFIER_TYPE_GEOMETRY:
1244 BKE_linestyle_geometry_modifier_copy(lineset->linestyle, modifier);
1247 BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
1248 return OPERATOR_CANCELLED;
1250 DAG_id_tag_update(&lineset->linestyle->id, 0);
1251 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1253 return OPERATOR_FINISHED;
1256 void SCENE_OT_freestyle_modifier_copy(wmOperatorType *ot)
1259 ot->name = "Copy Modifier";
1260 ot->idname = "SCENE_OT_freestyle_modifier_copy";
1261 ot->description = "Duplicate the modifier within the list of modifiers";
1264 ot->exec = freestyle_modifier_copy_exec;
1265 ot->poll = freestyle_active_lineset_poll;
1268 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1271 static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
1273 Scene *scene = CTX_data_scene(C);
1274 SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
1275 FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
1276 PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
1277 LineStyleModifier *modifier = ptr.data;
1278 int dir = RNA_enum_get(op->ptr, "direction");
1280 if (!freestyle_linestyle_check_report(lineset, op->reports)) {
1281 return OPERATOR_CANCELLED;
1284 switch (freestyle_get_modifier_type(&ptr)) {
1285 case LS_MODIFIER_TYPE_COLOR:
1286 BKE_linestyle_color_modifier_move(lineset->linestyle, modifier, dir);
1288 case LS_MODIFIER_TYPE_ALPHA:
1289 BKE_linestyle_alpha_modifier_move(lineset->linestyle, modifier, dir);
1291 case LS_MODIFIER_TYPE_THICKNESS:
1292 BKE_linestyle_thickness_modifier_move(lineset->linestyle, modifier, dir);
1294 case LS_MODIFIER_TYPE_GEOMETRY:
1295 BKE_linestyle_geometry_modifier_move(lineset->linestyle, modifier, dir);
1298 BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
1299 return OPERATOR_CANCELLED;
1301 DAG_id_tag_update(&lineset->linestyle->id, 0);
1302 WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
1304 return OPERATOR_FINISHED;
1307 void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
1309 static EnumPropertyItem direction_items[] = {
1310 {1, "UP", 0, "Up", ""},
1311 {-1, "DOWN", 0, "Down", ""},
1312 {0, NULL, 0, NULL, NULL}
1316 ot->name = "Move Modifier";
1317 ot->idname = "SCENE_OT_freestyle_modifier_move";
1318 ot->description = "Move the modifier within the list of modifiers";
1321 ot->exec = freestyle_modifier_move_exec;
1322 ot->poll = freestyle_active_lineset_poll;
1325 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1328 RNA_def_enum(ot->srna, "direction", direction_items, 0, "Direction", "Direction to move, UP or DOWN");
1331 static int freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
1333 Main *bmain = CTX_data_main(C);
1334 Scene *scene = CTX_data_scene(C);
1335 FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
1338 BKE_report(op->reports, RPT_ERROR, "No active line style in the current scene");
1339 return OPERATOR_CANCELLED;
1342 FRS_create_stroke_material(bmain, linestyle);
1344 return OPERATOR_FINISHED;
1347 void SCENE_OT_freestyle_stroke_material_create(wmOperatorType *ot)
1350 ot->name = "Create Freestyle Stroke Material";
1351 ot->idname = "SCENE_OT_freestyle_stroke_material_create";
1352 ot->description = "Create Freestyle stroke material for testing";
1355 ot->exec = freestyle_stroke_material_create_exec;
1358 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1361 #endif /* WITH_FREESTYLE */
1363 static int texture_slot_move_exec(bContext *C, wmOperator *op)
1365 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
1368 MTex **mtex_ar, *mtexswap;
1370 int type = RNA_enum_get(op->ptr, "type");
1371 struct AnimData *adt = BKE_animdata_from_id(id);
1373 give_active_mtex(id, &mtex_ar, &act);
1375 if (type == -1) { /* Up */
1377 mtexswap = mtex_ar[act];
1378 mtex_ar[act] = mtex_ar[act - 1];
1379 mtex_ar[act - 1] = mtexswap;
1381 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act - 1, -1, 0);
1382 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act, act - 1, 0);
1383 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, -1, act, 0);
1385 if (GS(id->name) == ID_MA) {
1386 Material *ma = (Material *)id;
1387 int mtexuse = ma->septex & (1 << act);
1388 ma->septex &= ~(1 << act);
1389 ma->septex |= (ma->septex & (1 << (act - 1))) << 1;
1390 ma->septex &= ~(1 << (act - 1));
1391 ma->septex |= mtexuse >> 1;
1394 set_active_mtex(id, act - 1);
1398 if (act < MAX_MTEX - 1) {
1399 mtexswap = mtex_ar[act];
1400 mtex_ar[act] = mtex_ar[act + 1];
1401 mtex_ar[act + 1] = mtexswap;
1403 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act + 1, -1, 0);
1404 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act, act + 1, 0);
1405 BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, -1, act, 0);
1407 if (GS(id->name) == ID_MA) {
1408 Material *ma = (Material *)id;
1409 int mtexuse = ma->septex & (1 << act);
1410 ma->septex &= ~(1 << act);
1411 ma->septex |= (ma->septex & (1 << (act + 1))) >> 1;
1412 ma->septex &= ~(1 << (act + 1));
1413 ma->septex |= mtexuse << 1;
1416 set_active_mtex(id, act + 1);
1420 DAG_id_tag_update(id, 0);
1421 WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
1424 return OPERATOR_FINISHED;
1427 void TEXTURE_OT_slot_move(wmOperatorType *ot)
1429 static EnumPropertyItem slot_move[] = {
1430 {-1, "UP", 0, "Up", ""},
1431 {1, "DOWN", 0, "Down", ""},
1432 {0, NULL, 0, NULL, NULL}
1436 ot->name = "Move Texture Slot";
1437 ot->idname = "TEXTURE_OT_slot_move";
1438 ot->description = "Move texture slots up and down";
1441 ot->exec = texture_slot_move_exec;
1444 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1446 RNA_def_enum(ot->srna, "type", slot_move, 0, "Type", "");
1451 /********************** environment map operators *********************/
1453 static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
1458 if ((prop = RNA_struct_find_property(op->ptr, "layout"))) {
1459 RNA_property_float_get_array(op->ptr, prop, layout);
1462 memcpy(layout, default_envmap_layout, sizeof(layout));
1465 if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) {
1466 return OPERATOR_FINISHED;
1469 return OPERATOR_CANCELLED;
1474 static int envmap_save_exec(bContext *C, wmOperator *op)
1476 Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
1477 Scene *scene = CTX_data_scene(C);
1478 //int imtype = RNA_enum_get(op->ptr, "file_type");
1479 char imtype = scene->r.im_format.imtype;
1480 char path[FILE_MAX];
1482 RNA_string_get(op->ptr, "filepath", path);
1484 if (scene->r.scemode & R_EXTENSION) {
1485 BKE_image_path_ensure_ext_from_imformat(path, &scene->r.im_format);
1490 save_envmap(op, scene, tex->env, path, imtype);
1494 WM_event_add_notifier(C, NC_TEXTURE, tex);
1496 return OPERATOR_FINISHED;
1499 static int envmap_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
1501 //Scene *scene= CTX_data_scene(C);
1503 if (RNA_struct_property_is_set(op->ptr, "filepath"))
1504 return envmap_save_exec(C, op);
1506 //RNA_enum_set(op->ptr, "file_type", scene->r.im_format.imtype);
1507 RNA_string_set(op->ptr, "filepath", G.main->name);
1508 WM_event_add_fileselect(C, op);
1510 return OPERATOR_RUNNING_MODAL;
1513 static int envmap_save_poll(bContext *C)
1515 Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
1519 if (!tex->env || !tex->env->ok)
1521 if (tex->env->cube[1] == NULL)
1527 void TEXTURE_OT_envmap_save(wmOperatorType *ot)
1531 ot->name = "Save Environment Map";
1532 ot->idname = "TEXTURE_OT_envmap_save";
1533 ot->description = "Save the current generated Environment map to an image file";
1536 ot->exec = envmap_save_exec;
1537 ot->invoke = envmap_save_invoke;
1538 ot->poll = envmap_save_poll;
1541 ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL; /* no undo since this doesnt modify the env-map */
1544 prop = RNA_def_float_array(ot->srna, "layout", 12, default_envmap_layout, 0.0f, 0.0f,
1546 "Flat array describing the X,Y position of each cube face in the output image, "
1547 "where 1 is the size of a face - order is [+Z -Z +Y -X -Y +X] "
1548 "(use -1 to skip a face)", 0.0f, 0.0f);
1549 RNA_def_property_flag(prop, PROP_HIDDEN);
1551 WM_operator_properties_filesel(ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_SAVE,
1552 WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
1555 static int envmap_clear_exec(bContext *C, wmOperator *UNUSED(op))
1557 Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
1559 BKE_texture_envmap_free_data(tex->env);
1561 WM_event_add_notifier(C, NC_TEXTURE | NA_EDITED, tex);
1563 return OPERATOR_FINISHED;
1566 static int envmap_clear_poll(bContext *C)
1568 Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
1572 if (!tex->env || !tex->env->ok)
1574 if (tex->env->cube[1] == NULL)
1580 void TEXTURE_OT_envmap_clear(wmOperatorType *ot)
1583 ot->name = "Clear Environment Map";
1584 ot->idname = "TEXTURE_OT_envmap_clear";
1585 ot->description = "Discard the environment map and free it from memory";
1588 ot->exec = envmap_clear_exec;
1589 ot->poll = envmap_clear_poll;
1592 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1595 static int envmap_clear_all_exec(bContext *C, wmOperator *UNUSED(op))
1597 Main *bmain = CTX_data_main(C);
1600 for (tex = bmain->tex.first; tex; tex = tex->id.next)
1602 BKE_texture_envmap_free_data(tex->env);
1604 WM_event_add_notifier(C, NC_TEXTURE | NA_EDITED, tex);
1606 return OPERATOR_FINISHED;
1609 void TEXTURE_OT_envmap_clear_all(wmOperatorType *ot)
1612 ot->name = "Clear All Environment Maps";
1613 ot->idname = "TEXTURE_OT_envmap_clear_all";
1614 ot->description = "Discard all environment maps in the .blend file and free them from memory";
1617 ot->exec = envmap_clear_all_exec;
1618 ot->poll = envmap_clear_poll;
1621 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
1624 /********************** material operators *********************/
1626 /* material copy/paste */
1627 static int copy_material_exec(bContext *C, wmOperator *UNUSED(op))
1629 Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
1632 return OPERATOR_CANCELLED;
1634 copy_matcopybuf(ma);
1636 return OPERATOR_FINISHED;
1639 void MATERIAL_OT_copy(wmOperatorType *ot)
1642 ot->name = "Copy Material";
1643 ot->idname = "MATERIAL_OT_copy";
1644 ot->description = "Copy the material settings and nodes";
1647 ot->exec = copy_material_exec;
1650 ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL; /* no undo needed since no changes are made to the material */
1653 static int paste_material_exec(bContext *C, wmOperator *UNUSED(op))
1655 Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
1658 return OPERATOR_CANCELLED;
1660 paste_matcopybuf(ma);
1662 WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, ma);
1664 return OPERATOR_FINISHED;
1667 void MATERIAL_OT_paste(wmOperatorType *ot)
1670 ot->name = "Paste Material";
1671 ot->idname = "MATERIAL_OT_paste";
1672 ot->description = "Paste the material settings and nodes";
1675 ot->exec = paste_material_exec;
1678 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
1682 static short mtexcopied = 0; /* must be reset on file load */
1683 static MTex mtexcopybuf;
1685 void ED_render_clear_mtex_copybuf(void)
1686 { /* use for file reload */
1690 static void copy_mtex_copybuf(ID *id)
1694 switch (GS(id->name)) {
1696 mtex = &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
1699 mtex = &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
1700 // la->mtex[(int)la->texact] // TODO
1703 mtex = &(((World *)id)->mtex[(int)((World *)id)->texact]);
1704 // mtex= wrld->mtex[(int)wrld->texact]; // TODO
1707 mtex = &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
1710 mtex = &(((FreestyleLineStyle *)id)->mtex[(int)((FreestyleLineStyle *)id)->texact]);
1714 if (mtex && *mtex) {
1715 memcpy(&mtexcopybuf, *mtex, sizeof(MTex));
1723 static void paste_mtex_copybuf(ID *id)
1727 if (mtexcopied == 0 || mtexcopybuf.tex == NULL)
1730 switch (GS(id->name)) {
1732 mtex = &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
1735 mtex = &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
1736 // la->mtex[(int)la->texact] // TODO
1739 mtex = &(((World *)id)->mtex[(int)((World *)id)->texact]);
1740 // mtex= wrld->mtex[(int)wrld->texact]; // TODO
1743 mtex = &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
1746 mtex = &(((FreestyleLineStyle *)id)->mtex[(int)((FreestyleLineStyle *)id)->texact]);
1749 BLI_assert("invalid id type");
1754 if (*mtex == NULL) {
1755 *mtex = MEM_mallocN(sizeof(MTex), "mtex copy");
1757 else if ((*mtex)->tex) {
1758 (*mtex)->tex->id.us--;
1761 memcpy(*mtex, &mtexcopybuf, sizeof(MTex));
1763 id_us_plus((ID *)mtexcopybuf.tex);
1768 static int copy_mtex_exec(bContext *C, wmOperator *UNUSED(op))
1770 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
1773 /* copying empty slot */
1774 ED_render_clear_mtex_copybuf();
1775 return OPERATOR_CANCELLED;
1778 copy_mtex_copybuf(id);
1780 return OPERATOR_FINISHED;
1783 static int copy_mtex_poll(bContext *C)
1785 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
1787 return (id != NULL);
1790 void TEXTURE_OT_slot_copy(wmOperatorType *ot)
1793 ot->name = "Copy Texture Slot Settings";
1794 ot->idname = "TEXTURE_OT_slot_copy";
1795 ot->description = "Copy the material texture settings and nodes";
1798 ot->exec = copy_mtex_exec;
1799 ot->poll = copy_mtex_poll;
1802 ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL; /* no undo needed since no changes are made to the mtex */
1805 static int paste_mtex_exec(bContext *C, wmOperator *UNUSED(op))
1807 ID *id = CTX_data_pointer_get_type(C, "texture_slot", &RNA_TextureSlot).id.data;
1810 Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
1811 Lamp *la = CTX_data_pointer_get_type(C, "lamp", &RNA_Lamp).data;
1812 World *wo = CTX_data_pointer_get_type(C, "world", &RNA_World).data;
1813 ParticleSystem *psys = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data;
1814 FreestyleLineStyle *linestyle = CTX_data_pointer_get_type(C, "line_style", &RNA_FreestyleLineStyle).data;
1823 id = &psys->part->id;
1825 id = &linestyle->id;
1828 return OPERATOR_CANCELLED;
1831 paste_mtex_copybuf(id);
1833 WM_event_add_notifier(C, NC_TEXTURE | ND_SHADING_LINKS, NULL);
1835 return OPERATOR_FINISHED;
1838 void TEXTURE_OT_slot_paste(wmOperatorType *ot)
1841 ot->name = "Paste Texture Slot Settings";
1842 ot->idname = "TEXTURE_OT_slot_paste";
1843 ot->description = "Copy the texture settings and nodes";
1846 ot->exec = paste_mtex_exec;
1849 ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;