copy icon in the material buttons list view so you can copy the current set of materi...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 7 Oct 2009 16:32:55 +0000 (16:32 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 7 Oct 2009 16:32:55 +0000 (16:32 +0000)
release/scripts/ui/buttons_material.py
source/blender/blenkernel/BKE_material.h
source/blender/blenkernel/intern/material.c
source/blender/editors/render/render_intern.h
source/blender/editors/render/render_ops.c
source/blender/editors/render/render_shading.c

index e91e324f49deb0c080a4cfb2ff60ff686ff73f92..03e11e003e20267ff028bcf7314b1025ed8e1b10 100644 (file)
@@ -59,6 +59,7 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel):
                        col = row.column(align=True)
                        col.itemO("object.material_slot_add", icon='ICON_ZOOMIN', text="")
                        col.itemO("object.material_slot_remove", icon='ICON_ZOOMOUT', text="")
+                       col.itemO("object.material_slot_copy", icon='ICON_COPYDOWN', text="")
 
                        if ob.mode == 'EDIT':
                                row = layout.row(align=True)
index 382754ee2b287545ee4e84b2356ab9d979ee6b1d..b6645ef873786ca192cbcfa7df436119d7ae71e1 100644 (file)
@@ -58,6 +58,7 @@ short *give_totcolp(struct Object *ob);
 struct Material *give_current_material(struct Object *ob, int act);
 struct ID *material_from(struct Object *ob, int act);
 void assign_material(struct Object *ob, struct Material *ma, int act);
+void assign_matarar(struct Object *ob, struct Material ***matar, int totcol);
 
 int find_material_index(struct Object *ob, struct Material *ma);
 
index 7e742dc56314de9b059f82a6054899b220f69cd7..b44c59baaca4081e2fd71bf87ae10b30bbf9bebf 100644 (file)
@@ -625,6 +625,25 @@ void assign_material(Object *ob, Material *ma, int act)
        test_object_materials(ob->data);
 }
 
+/* XXX - this calls many more update calls per object then are needed, could be optimized */
+void assign_matarar(struct Object *ob, struct Material ***matar, int totcol)
+{
+       int i, actcol_orig= ob->actcol;
+
+       while(ob->totcol)
+               object_remove_material_slot(ob);
+
+       /* now we have the right number of slots */
+       for(i=0; i<totcol; i++)
+               assign_material(ob, (*matar)[i], i+1);
+
+       if(actcol_orig > ob->totcol)
+               actcol_orig= ob->totcol;
+
+       ob->actcol= actcol_orig;
+}
+
+
 int find_material_index(Object *ob, Material *ma)
 {
        Material ***matarar;
index dccc2d360028ee78660ebb0bb89235dc5deeb690..d3ecbbc56e8c0cdbbbc86d3b2102b28519ac7083 100644 (file)
@@ -37,6 +37,7 @@ void OBJECT_OT_material_slot_remove(struct wmOperatorType *ot);
 void OBJECT_OT_material_slot_assign(struct wmOperatorType *ot);
 void OBJECT_OT_material_slot_select(struct wmOperatorType *ot);
 void OBJECT_OT_material_slot_deselect(struct wmOperatorType *ot);
+void OBJECT_OT_material_slot_copy(struct wmOperatorType *ot);
 
 void MATERIAL_OT_new(struct wmOperatorType *ot);
 void TEXTURE_OT_new(struct wmOperatorType *ot);
index 8b60582d4662ffe4fd68ac6969e994da1931b019..7d35dff74935f486dd3dcfd0b9b108596302113e 100644 (file)
@@ -43,6 +43,7 @@ void ED_operatortypes_render(void)
        WM_operatortype_append(OBJECT_OT_material_slot_assign);
        WM_operatortype_append(OBJECT_OT_material_slot_select);
        WM_operatortype_append(OBJECT_OT_material_slot_deselect);
+       WM_operatortype_append(OBJECT_OT_material_slot_copy);
 
        WM_operatortype_append(MATERIAL_OT_new);
        WM_operatortype_append(TEXTURE_OT_new);
index 56605ad097040acac6213516bcc527eaa062ff6d..26df0df935b9f8bf8835d3dbeb9644bd67f385fa 100644 (file)
@@ -431,6 +431,44 @@ void OBJECT_OT_material_slot_deselect(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
+
+static int material_slot_copy_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       Material ***matar;
+
+       if(!ob || !(matar= give_matarar(ob)))
+               return OPERATOR_CANCELLED;
+
+       CTX_DATA_BEGIN(C, Object*, ob_iter, selected_editable_objects) {
+               if(ob != ob_iter && give_matarar(ob_iter)) {
+                       assign_matarar(ob_iter, matar, ob->totcol);
+                       if(ob_iter->totcol==ob->totcol) {
+                               ob_iter->actcol= ob->actcol;
+                               WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob_iter);
+                       }
+               }
+       }
+       CTX_DATA_END;
+
+       return OPERATOR_FINISHED;
+}
+
+
+void OBJECT_OT_material_slot_copy(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Copy Material to Others";
+       ot->idname= "OBJECT_OT_material_slot_copy";
+       ot->description="Copies materials to other selected objects.";
+
+       /* api callbacks */
+       ot->exec= material_slot_copy_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
 /********************** new material operator *********************/
 
 static int new_material_exec(bContext *C, wmOperator *op)