Assets: Disable snap-dragging for linking object assets
The location of a linked object isn't editable, or at least it will be reset when reloading the file. So the drag & drop shouldn't even pretend like this would work, so disable the snapping of the object and the bounding-box to show the snapped object location while dragging.
This commit is contained in:
parent
18ace3b541
commit
f81c514bd2
@ -3617,6 +3617,13 @@ static int object_transform_to_mouse_exec(bContext *C, wmOperator *op)
|
||||
BKE_report(op->reports, RPT_ERROR, "Object not found");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* Don't transform a linked object. There's just nothing to do here in this case, so return
|
||||
* #OPERATOR_FINISHED. */
|
||||
if (ID_IS_LINKED(ob)) {
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
/* Ensure the locations are updated so snap reads the evaluated active location. */
|
||||
CTX_data_ensure_evaluated_depsgraph(C);
|
||||
|
||||
|
@ -526,6 +526,12 @@ static void view3d_ob_drop_draw_activate(struct wmDropBox *drop, wmDrag *drag)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Don't use the snap cursor when linking the object. Object transform isn't editable then and
|
||||
* would be reset on reload. */
|
||||
if (WM_drag_asset_will_import_linked(drag)) {
|
||||
return;
|
||||
}
|
||||
|
||||
state = drop->draw_data = ED_view3d_cursor_snap_active();
|
||||
state->draw_plane = true;
|
||||
|
||||
@ -552,8 +558,10 @@ static void view3d_ob_drop_draw_activate(struct wmDropBox *drop, wmDrag *drag)
|
||||
static void view3d_ob_drop_draw_deactivate(struct wmDropBox *drop, wmDrag *UNUSED(drag))
|
||||
{
|
||||
V3DSnapCursorState *state = drop->draw_data;
|
||||
ED_view3d_cursor_snap_deactive(state);
|
||||
drop->draw_data = NULL;
|
||||
if (state) {
|
||||
ED_view3d_cursor_snap_deactive(state);
|
||||
drop->draw_data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static bool view3d_ob_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
|
||||
@ -762,12 +770,14 @@ static void view3d_ob_drop_copy_external_asset(wmDrag *drag, wmDropBox *drop)
|
||||
DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
|
||||
ED_outliner_select_sync_from_object_tag(C);
|
||||
|
||||
V3DSnapCursorState *snap_state = ED_view3d_cursor_snap_state_get();
|
||||
float obmat_final[4][4];
|
||||
V3DSnapCursorState *snap_state = drop->draw_data;
|
||||
if (snap_state) {
|
||||
float obmat_final[4][4];
|
||||
|
||||
view3d_ob_drop_matrix_from_snap(snap_state, (Object *)id, obmat_final);
|
||||
view3d_ob_drop_matrix_from_snap(snap_state, (Object *)id, obmat_final);
|
||||
|
||||
RNA_float_set_array(drop->ptr, "matrix", &obmat_final[0][0]);
|
||||
RNA_float_set_array(drop->ptr, "matrix", &obmat_final[0][0]);
|
||||
}
|
||||
}
|
||||
|
||||
static void view3d_collection_drop_copy(wmDrag *drag, wmDropBox *drop)
|
||||
|
@ -752,6 +752,7 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
|
||||
|
||||
/* ID drag and drop */
|
||||
ID *WM_drag_asset_id_import(wmDragAsset *asset_drag, int flag_extra);
|
||||
bool WM_drag_asset_will_import_linked(const wmDrag *drag);
|
||||
void WM_drag_add_local_ID(struct wmDrag *drag, struct ID *id, struct ID *from_parent);
|
||||
struct ID *WM_drag_get_local_ID(const struct wmDrag *drag, short idcode);
|
||||
struct ID *WM_drag_get_local_ID_from_event(const struct wmEvent *event, short idcode);
|
||||
|
@ -577,6 +577,16 @@ ID *WM_drag_asset_id_import(wmDragAsset *asset_drag, const int flag_extra)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool WM_drag_asset_will_import_linked(const wmDrag *drag)
|
||||
{
|
||||
if (drag->type != WM_DRAG_ASSET) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
|
||||
return asset_drag->import_type == FILE_ASSET_IMPORT_LINK;
|
||||
}
|
||||
|
||||
/**
|
||||
* When dragging a local ID, return that. Otherwise, if dragging an asset-handle, link or append
|
||||
* that depending on what was chosen by the drag-box (currently append only in fact).
|
||||
|
Loading…
Reference in New Issue
Block a user