Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-04-07 17:08:40 +0300
committerJulian Eisel <julian@blender.org>2022-04-07 17:08:40 +0300
commita6896bda8999f61816dd8171225486dc3ee160be (patch)
treefa8571597c44fabb427e74109c8fe8d126d66b7d
parent22e102efae70cd50f5f49d93c8df22185cb4dc76 (diff)
Port to new operator with instancing option from mastertemp-collection-assets
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c97
1 files changed, 34 insertions, 63 deletions
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 4ae39440a12..bbe96ae7b76 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -834,46 +834,6 @@ static void view3d_collection_drop_matrix_get(const Collection *collection,
view3d_drop_matrix_from_snap(snap_state, &boundbox, unit_mat, r_mat_final);
}
-static void view3d_collection_instance_drop_copy_external_asset(wmDrag *drag, wmDropBox *drop)
-{
- wmDragAsset *asset_drag = WM_drag_get_asset_data(drag, 0);
- bContext *C = asset_drag->evil_C;
- Scene *scene = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
-
- BKE_view_layer_base_deselect_all(view_layer);
-
- ID *id = WM_drag_asset_id_import_ex(asset_drag, FILE_AUTOSELECT, true);
- /* `FILE_AUTOSELECT` causes the collection instance to be both selected and active. */
-
- /* TODO(sergey): Only update relations for the current scene. */
- DEG_relations_tag_update(CTX_data_main(C));
- DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
- WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
- ED_outliner_select_sync_from_object_tag(C);
-
- float mat[4][4];
- view3d_collection_drop_matrix_get((Collection *)id, mat);
- RNA_float_set_array(drop->ptr, "matrix", &mat[0][0]);
-}
-
-static void view3d_collection_drop_copy_local_id(wmDrag *drag, wmDropBox *drop)
-{
- ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR);
-
- float mat[4][4];
- view3d_collection_drop_matrix_get((Collection *)id, mat);
-
- float loc[3], rot_quat[4], rot_eul[3], scale[3];
- mat4_decompose(loc, rot_quat, scale, mat);
- quat_to_eul(rot_eul, rot_quat);
- RNA_float_set_array(drop->ptr, "location", loc);
- RNA_float_set_array(drop->ptr, "rotation", rot_eul);
- RNA_float_set_array(drop->ptr, "scale", scale);
-
- RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid);
-}
-
/* Mostly the same logic as #view3d_ob_drop_copy_external_asset(), just different enough to make
* sharing code a bit difficult. */
static void view3d_collection_drop_copy_external_asset(wmDrag *drag, wmDropBox *drop)
@@ -907,11 +867,39 @@ static void view3d_collection_drop_copy_external_asset(wmDrag *drag, wmDropBox *
DEG_id_tag_update(&scene->id, ID_RECALC_SELECT);
ED_outliner_select_sync_from_object_tag(C);
+ float mat[4][4];
+ view3d_collection_drop_matrix_get(collection, mat);
+
+ float loc[3], rot_quat[4], rot_eul[3], scale[3];
+ mat4_decompose(loc, rot_quat, scale, mat);
+ add_v3_v3(loc, collection->instance_offset);
+ quat_to_eul(rot_eul, rot_quat);
+ RNA_float_set_array(drop->ptr, "location", loc);
+ RNA_float_set_array(drop->ptr, "rotation", rot_eul);
+ RNA_float_set_array(drop->ptr, "scale", scale);
+
/* XXX Without an undo push here, there will be a crash when the user modifies operator
* properties. The stuff we do in these drop callbacks just isn't safe over undo/redo. */
ED_undo_push(C, "Collection_Drop");
}
+static void view3d_collection_drop_copy_local_id(wmDrag *drag, wmDropBox *drop)
+{
+ ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, ID_GR);
+
+ float mat[4][4];
+ view3d_collection_drop_matrix_get((Collection *)id, mat);
+
+ float loc[3], rot_quat[4], rot_eul[3], scale[3];
+ mat4_decompose(loc, rot_quat, scale, mat);
+ quat_to_eul(rot_eul, rot_quat);
+ RNA_float_set_array(drop->ptr, "location", loc);
+ RNA_float_set_array(drop->ptr, "rotation", rot_eul);
+ RNA_float_set_array(drop->ptr, "scale", scale);
+
+ RNA_int_set(drop->ptr, "session_uuid", (int)id->session_uuid);
+}
+
static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
{
ID *id = WM_drag_get_local_ID_or_import_from_asset(drag, 0);
@@ -1001,34 +989,17 @@ static void view3d_dropboxes(void)
drop->draw_activate = view3d_boundbox_drop_draw_activate_collection;
drop->draw_deactivate = view3d_boundbox_drop_draw_deactivate;
- /* Collection asset from external file (adds collection instance). */
- drop = WM_dropbox_add(
- lb,
- /* Use OBJECT_OT_transform_to_mouse for collection instances as well, to transform the
- * instance empty. Just needs different callbacks than objects. */
- "OBJECT_OT_transform_to_mouse",
- view3d_collection_drop_poll_external_asset,
- view3d_collection_instance_drop_copy_external_asset,
- WM_drag_free_imported_drag_ID,
- NULL);
+ drop = WM_dropbox_add(lb,
+ "OBJECT_OT_collection_external_asset_drop",
+ view3d_collection_drop_poll_external_asset,
+ view3d_collection_drop_copy_external_asset,
+ WM_drag_free_imported_drag_ID,
+ NULL);
drop->draw = WM_drag_draw_item_name_fn;
drop->draw_activate = view3d_boundbox_drop_draw_activate_collection;
drop->draw_deactivate = view3d_boundbox_drop_draw_deactivate;
WM_dropbox_add(lb,
- "OBJECT_OT_collection_external_asset_drop",
- view3d_collection_drop_poll_external_asset,
- view3d_collection_drop_copy_external_asset,
- WM_drag_free_imported_drag_ID,
- NULL);
- WM_dropbox_add(lb,
- "OBJECT_OT_collection_instance_add",
- view3d_collection_drop_poll_local_id,
- view3d_collection_drop_copy_local_id,
- WM_drag_free_imported_drag_ID,
- NULL);
-
- WM_dropbox_add(lb,
"OBJECT_OT_drop_named_material",
view3d_mat_drop_poll,
view3d_id_drop_copy,