[Bf-blender-cvs] [a6896bda899] temp-collection-assets: Port to new operator with instancing option from master

Julian Eisel noreply at git.blender.org
Thu Apr 7 16:10:18 CEST 2022


Commit: a6896bda8999f61816dd8171225486dc3ee160be
Author: Julian Eisel
Date:   Thu Apr 7 16:08:40 2022 +0200
Branches: temp-collection-assets
https://developer.blender.org/rBa6896bda8999f61816dd8171225486dc3ee160be

Port to new operator with instancing option from master

===================================================================

M	source/blender/editors/space_view3d/space_view3d.c

===================================================================

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,33 +989,16 @@ 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,



More information about the Bf-blender-cvs mailing list