Asset Browser: Allow World assets to be drag/dropped onto the viewport
While World data has always been able to be marked as an asset, there was no way to actually use them from the asset browser. This change allows users to drag-drop world assets onto the Viewport and have them appended/linked to their scene. Differential Revision: https://developer.blender.org/D12566
This commit is contained in:
parent
c53ffda8a4
commit
986d60490c
Notes:
blender-bot
2023-02-14 05:22:18 +01:00
Referenced by commit 685ceaa2f7
, Fix reference counting error for world drag & drop
Referenced by issue #90747, As a user I want to drop an environment to the 3d viewport to change the world of the scene.
|
@ -539,6 +539,11 @@ static char *view3d_mat_drop_tooltip(bContext *C,
|
|||
return ED_object_ot_drop_named_material_tooltip(C, drop->ptr, event);
|
||||
}
|
||||
|
||||
static bool view3d_world_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
{
|
||||
return view3d_drop_id_in_main_region_poll(C, drag, event, ID_WO);
|
||||
}
|
||||
|
||||
static bool view3d_object_data_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
{
|
||||
ID_Type id_type = view3d_drop_id_in_main_region_poll_get_id_type(C, drag, event);
|
||||
|
@ -732,6 +737,12 @@ static void view3d_dropboxes(void)
|
|||
view3d_id_drop_copy_with_type,
|
||||
WM_drag_free_imported_drag_ID,
|
||||
view3d_object_data_drop_tooltip);
|
||||
WM_dropbox_add(lb,
|
||||
"VIEW3D_OT_drop_world",
|
||||
view3d_world_drop_poll,
|
||||
view3d_id_drop_copy,
|
||||
WM_drag_free_imported_drag_ID,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void view3d_widgets(void)
|
||||
|
@ -1555,11 +1566,16 @@ static void space_view3d_listener(const wmSpaceTypeListenerParams *params)
|
|||
switch (wmn->category) {
|
||||
case NC_SCENE:
|
||||
switch (wmn->data) {
|
||||
case ND_WORLD:
|
||||
if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
|
||||
case ND_WORLD: {
|
||||
const bool use_scene_world = ((v3d->shading.type == OB_MATERIAL) &&
|
||||
(v3d->shading.flag & V3D_SHADING_SCENE_WORLD)) ||
|
||||
((v3d->shading.type == OB_RENDER) &&
|
||||
(v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER));
|
||||
if (v3d->flag2 & V3D_HIDE_OVERLAYS || use_scene_world) {
|
||||
ED_area_tag_redraw_regiontype(area, RGN_TYPE_WINDOW);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NC_WORLD:
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "DNA_gpencil_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_world_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
|
@ -4873,6 +4874,59 @@ void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
|
|||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Drop World Operator
|
||||
* \{ */
|
||||
|
||||
static int drop_world_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
|
||||
char name[MAX_ID_NAME - 2];
|
||||
|
||||
RNA_string_get(op->ptr, "name", name);
|
||||
World *world = (World *)BKE_libblock_find_name(bmain, ID_WO, name);
|
||||
if (world == NULL) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
id_us_plus(&world->id);
|
||||
scene->world = world;
|
||||
|
||||
DEG_id_tag_update(&scene->id, 0);
|
||||
DEG_relations_tag_update(bmain);
|
||||
|
||||
WM_event_add_notifier(C, NC_SCENE | ND_WORLD, scene);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static bool drop_world_poll(bContext *C)
|
||||
{
|
||||
return ED_operator_scene_editable(C);
|
||||
}
|
||||
|
||||
void VIEW3D_OT_drop_world(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Drop World";
|
||||
ot->description = "Drop a world into the scene";
|
||||
ot->idname = "VIEW3D_OT_drop_world";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = drop_world_exec;
|
||||
ot->poll = drop_world_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
|
||||
|
||||
/* properties */
|
||||
RNA_def_string(ot->srna, "name", "World", MAX_ID_NAME - 2, "Name", "World to assign");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name View Clipping Planes Operator
|
||||
*
|
||||
|
|
|
@ -80,6 +80,7 @@ void VIEW3D_OT_view_persportho(struct wmOperatorType *ot);
|
|||
void VIEW3D_OT_navigate(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_background_image_add(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_background_image_remove(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_drop_world(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_view_orbit(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_view_roll(struct wmOperatorType *ot);
|
||||
void VIEW3D_OT_clip_border(struct wmOperatorType *ot);
|
||||
|
|
|
@ -169,6 +169,7 @@ void view3d_operatortypes(void)
|
|||
WM_operatortype_append(VIEW3D_OT_view_persportho);
|
||||
WM_operatortype_append(VIEW3D_OT_background_image_add);
|
||||
WM_operatortype_append(VIEW3D_OT_background_image_remove);
|
||||
WM_operatortype_append(VIEW3D_OT_drop_world);
|
||||
WM_operatortype_append(VIEW3D_OT_view_selected);
|
||||
WM_operatortype_append(VIEW3D_OT_view_lock_clear);
|
||||
WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
|
||||
|
|
Loading…
Reference in New Issue