Index: source/blender/editors/space_outliner/outliner_ops.c =================================================================== --- source/blender/editors/space_outliner/outliner_ops.c (revision 43782) +++ source/blender/editors/space_outliner/outliner_ops.c (working copy) @@ -80,6 +80,7 @@ WM_operatortype_append(OUTLINER_OT_parent_drop); WM_operatortype_append(OUTLINER_OT_parent_clear); + WM_operatortype_append(OUTLINER_OT_drop_named_material); } void outliner_keymap(wmKeyConfig *keyconf) Index: source/blender/editors/space_outliner/outliner_intern.h =================================================================== --- source/blender/editors/space_outliner/outliner_intern.h (revision 43782) +++ source/blender/editors/space_outliner/outliner_intern.h (working copy) @@ -188,7 +188,7 @@ void item_rename_cb(struct bContext *C, struct Scene *scene, TreeElement *te, struct TreeStoreElem *tsep, struct TreeStoreElem *tselem); -TreeElement *outliner_dropzone_parent(struct bContext *C, struct wmEvent *event, struct TreeElement *te, float *fmval); +TreeElement *outliner_dropzone_object(struct bContext *C, struct wmEvent *event, struct TreeElement *te, float *fmval); int outliner_dropzone_parent_clear(struct bContext *C, struct wmEvent *event, struct TreeElement *te, float *fmval); /* ...................................................... */ @@ -220,6 +220,7 @@ void OUTLINER_OT_parent_drop(struct wmOperatorType *ot); void OUTLINER_OT_parent_clear(struct wmOperatorType *ot); +void OUTLINER_OT_drop_named_material(struct wmOperatorType *ot); /* outliner_tools.c ---------------------------------------------- */ Index: source/blender/editors/space_outliner/outliner_edit.c =================================================================== --- source/blender/editors/space_outliner/outliner_edit.c (revision 43782) +++ source/blender/editors/space_outliner/outliner_edit.c (working copy) @@ -75,6 +75,7 @@ #include "BKE_group.h" #include "BKE_library.h" #include "BKE_main.h" +#include "BKE_material.h" #include "BKE_modifier.h" #include "BKE_report.h" #include "BKE_scene.h" @@ -1447,8 +1448,9 @@ return OPERATOR_FINISHED; } -/* Used for drag and drop parenting */ -TreeElement *outliner_dropzone_parent(bContext *C, wmEvent *event, TreeElement *te, float *fmval) +/* Used for drag and drop parenting */ +/* Returns TreeElement under mouse if ID_OB */ +TreeElement *outliner_dropzone_object(bContext *C, wmEvent *event, TreeElement *te, float *fmval) { SpaceOops *soops= CTX_wm_space_outliner(C); TreeStoreElem *tselem= TREESTORE(te); @@ -1470,7 +1472,7 @@ if ((tselem->flag & TSE_CLOSED)==0 && (te->subtree.first)) { for (te = te->subtree.first; te; te = te->next) { TreeElement *te_valid; - te_valid= outliner_dropzone_parent(C, event, te, fmval); + te_valid= outliner_dropzone_object(C, event, te, fmval); if (te_valid) return te_valid; } } @@ -1495,7 +1497,7 @@ /* Find object hovered over */ for (te= soops->tree.first; te; te= te->next) { - te_found= outliner_dropzone_parent(C, event, te, fmval); + te_found= outliner_dropzone_object(C, event, te, fmval); if (te_found) break; } @@ -1704,3 +1706,60 @@ RNA_def_string(ot->srna, "dragged_obj", "Object", MAX_ID_NAME, "Child", "Child Object"); RNA_def_enum(ot->srna, "type", prop_clear_parent_types, 0, "Type", ""); } + +static int drop_named_material_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + SpaceOops *soops= CTX_wm_space_outliner(C); + Main *bmain= CTX_data_main(C); + ARegion *ar= CTX_wm_region(C); + TreeElement *te = NULL; + TreeElement *te_found = NULL; + Object *ob = NULL; + Material *ma = NULL; + float fmval[2]; + char name[MAX_ID_NAME-2]; + + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); + + /* Find object under mouse*/ + for (te= soops->tree.first; te; te= te->next) { + te_found= outliner_dropzone_object(C, event, te, fmval); + if (te_found) break; + } + + RNA_string_get(op->ptr, "name", name); + ma= (Material *)find_id("MA", name); + ob= (Object *)find_id("OB", te_found->name); + if(ob==NULL || ma==NULL) + return OPERATOR_CANCELLED; + + assign_material(ob, ma, 1); + + DAG_ids_flush_update(bmain, 0); + + WM_event_add_notifier(C, NC_OBJECT|ND_OB_SHADING, ob); + WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob); + WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL); + + return OPERATOR_FINISHED; +} + +/* assigns to object under cursor, only first material slot */ +void OUTLINER_OT_drop_named_material(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name= "Drop Named Material on Object"; + ot->description = ""; + ot->idname= "OUTLINER_OT_drop_named_material"; + + /* api callbacks */ + ot->invoke= drop_named_material_invoke; + ot->poll= ED_operator_outliner_active; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + /* properties */ + RNA_def_string(ot->srna, "name", "Material", MAX_ID_NAME-2, "Name", "Material name to assign"); +} Index: source/blender/editors/space_outliner/space_outliner.c =================================================================== --- source/blender/editors/space_outliner/space_outliner.c (revision 43782) +++ source/blender/editors/space_outliner/space_outliner.c (working copy) @@ -34,12 +34,15 @@ #include "MEM_guardedalloc.h" +#include "DNA_object_types.h" + #include "BLI_blenlib.h" #include "BLI_math.h" #include "BLI_rand.h" #include "BLI_utildefines.h" #include "BKE_context.h" +#include "BKE_library.h" #include "BKE_screen.h" #include "ED_space_api.h" @@ -90,7 +93,7 @@ /* Find object hovered over */ for(te= soops->tree.first; te; te= te->next) { TreeElement *te_valid; - te_valid= outliner_dropzone_parent(C, event, te, fmval); + te_valid= outliner_dropzone_object(C, event, te, fmval); if(te_valid) return 1; } } @@ -144,6 +147,38 @@ RNA_enum_set(drop->ptr, "type", 0); } +static int outliner_mat_drop_poll(bContext *C, wmDrag *drag, wmEvent *event) +{ + ARegion *ar= CTX_wm_region(C); + SpaceOops *soops= CTX_wm_space_outliner(C); + TreeElement *te= NULL; + float fmval[2]; + UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]); + + if(drag->type==WM_DRAG_ID) { + ID *id= (ID *)drag->poin; + if( GS(id->name)==ID_MA ) { + /* Ensure item under cursor is valid drop target */ + /* Find object under cursor*/ + for(te= soops->tree.first; te; te= te->next) { + TreeElement *te_valid; + te_valid= outliner_dropzone_object(C, event, te, fmval); + if(te_valid && OB_TYPE_SUPPORT_MATERIAL(((Object *)find_id("OB", te_valid->name))->type)) + return 1; + } + } + } + return 0; +} + +/* TODO: Merge outliner_parent_drop_copy with this to avoid duplication. */ +static void outliner_id_drop_copy(wmDrag *drag, wmDropBox *drop) +{ + ID *id= (ID *)drag->poin; + + RNA_string_set(drop->ptr, "name", id->name+2); +} + /* region dropbox definition */ static void outliner_dropboxes(void) { @@ -151,6 +186,7 @@ WM_dropbox_add(lb, "OUTLINER_OT_parent_drop", outliner_parent_drop_poll, outliner_parent_drop_copy); WM_dropbox_add(lb, "OUTLINER_OT_parent_clear", outliner_parent_clear_poll, outliner_parent_clear_copy); + WM_dropbox_add(lb, "OUTLINER_OT_drop_named_material", outliner_mat_drop_poll, outliner_id_drop_copy); } static void outliner_main_area_draw(const bContext *C, ARegion *ar)