forked from bartvdbraak/blender
copy icon in the material buttons list view so you can copy the current set of materials to other selected objects, (like Ctrl+L, Materials in 2.4x)
This commit is contained in:
parent
df63ccd904
commit
763358fe91
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user