diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-09-06 11:35:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-09-06 11:42:16 +0300 |
commit | e56ff76db5b44ae6784a26ff6daf9864b2387712 (patch) | |
tree | 03ffd243bb948574d95556f593c8770730b24e9a /source/blender/editors/space_view3d | |
parent | 5faf72bb719b075e8ef4bf4371cc13c35557eba9 (diff) |
Viewport: support dropping object-data to create instances
This allows orphan object data for example (meshes, curves, etc)
to be dropped into the 3D View from the outliner,
creating a new object instance.
Previously the only way to do this was to add the same type of object
then swap it's data through the ID selector drop-down.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/space_view3d.c | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index de0b420a3b5..4fdfc18c9ff 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -37,6 +37,8 @@ #include "BLI_math.h" #include "BLI_utildefines.h" +#include "BLT_translation.h" + #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_global.h" @@ -459,16 +461,24 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *region) ED_view3d_stop_render_preview(wm, region); } -static bool view3d_drop_id_in_main_region_poll(bContext *C, - wmDrag *drag, - const wmEvent *event, - ID_Type id_type) +static ID *view3d_drop_id_in_main_region_poll_id(bContext *C, + wmDrag *drag, + const wmEvent *event, + ID_Type id_type) { ScrArea *area = CTX_wm_area(C); if (ED_region_overlap_isect_any_xy(area, &event->x)) { return false; } - return WM_drag_ID(drag, id_type) != NULL; + return WM_drag_ID(drag, id_type); +} + +static bool view3d_drop_id_in_main_region_poll(bContext *C, + wmDrag *drag, + const wmEvent *event, + ID_Type id_type) +{ + return (view3d_drop_id_in_main_region_poll_id(C, drag, event, id_type) != NULL); } static bool view3d_ob_drop_poll(bContext *C, @@ -495,6 +505,21 @@ static bool view3d_mat_drop_poll(bContext *C, return view3d_drop_id_in_main_region_poll(C, drag, event, ID_MA); } +static bool view3d_object_data_drop_poll(bContext *C, + wmDrag *drag, + const wmEvent *event, + const char **r_tooltip) +{ + ID *id = view3d_drop_id_in_main_region_poll_id(C, drag, event, 0); + if (id != NULL) { + if (BKE_object_obdata_to_type(id) != -1) { + *r_tooltip = TIP_("Create object instance from object-data"); + return true; + } + } + return false; +} + static bool view3d_ima_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event, @@ -591,6 +616,14 @@ static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop) RNA_string_set(drop->ptr, "name", id->name + 2); } +static void view3d_id_drop_copy_with_type(wmDrag *drag, wmDropBox *drop) +{ + ID *id = WM_drag_ID(drag, 0); + + RNA_string_set(drop->ptr, "name", id->name + 2); + RNA_enum_set(drop->ptr, "type", GS(id->name)); +} + static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop) { ID *id = WM_drag_ID(drag, 0); @@ -642,6 +675,10 @@ static void view3d_dropboxes(void) "OBJECT_OT_collection_instance_add", view3d_collection_drop_poll, view3d_collection_drop_copy); + WM_dropbox_add(lb, + "OBJECT_OT_data_instance_add", + view3d_object_data_drop_poll, + view3d_id_drop_copy_with_type); } static void view3d_widgets(void) |