Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 3,476 Lines • ▼ Show 20 Lines | if (!base) { | ||||
| LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer); | LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer); | ||||
| BKE_collection_object_add(bmain, layer_collection->collection, ob); | BKE_collection_object_add(bmain, layer_collection->collection, ob); | ||||
| base = BKE_view_layer_base_find(view_layer, ob); | base = BKE_view_layer_base_find(view_layer, ob); | ||||
| } | } | ||||
| return base; | return base; | ||||
| } | } | ||||
| /** | |||||
| * Alternate behavior for dropping an asset that positions the appended object(s). | |||||
| */ | |||||
| static int object_add_named_exec_for_only_place(bContext *C, wmOperator *op) | |||||
| { | |||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | |||||
| Object *ob = OBACT(view_layer); | |||||
| if (ob == NULL) { | |||||
| BKE_report(op->reports, RPT_ERROR, "Object not found"); | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
| /* Ensure the locations are updated so snap reads the evaluated active location. */ | |||||
| CTX_data_ensure_evaluated_depsgraph(C); | |||||
| int mval[2]; | |||||
| if (object_add_drop_xy_get(C, op, &mval)) { | |||||
| float cursor[3]; | |||||
| ED_object_location_from_view(C, cursor); | |||||
| ED_view3d_cursor3d_position(C, mval, false, cursor); | |||||
| /* Use the active objects location since this is the ID which the user selected to drop. */ | |||||
| ED_view3d_snap_selected_to_location(C, cursor, V3D_AROUND_ACTIVE); | |||||
| } | |||||
| return OPERATOR_FINISHED; | |||||
| } | |||||
| static int object_add_named_exec(bContext *C, wmOperator *op) | static int object_add_named_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| if (RNA_boolean_get(op->ptr, "only_place")) { | |||||
| return object_add_named_exec_for_only_place(C, op); | |||||
| } | |||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| Base *basen; | Base *basen; | ||||
| Object *ob; | Object *ob; | ||||
| const bool duplicate = RNA_boolean_get(op->ptr, "duplicate"); | const bool duplicate = RNA_boolean_get(op->ptr, "duplicate"); | ||||
| const bool linked = duplicate && RNA_boolean_get(op->ptr, "linked"); | const bool linked = duplicate && RNA_boolean_get(op->ptr, "linked"); | ||||
| const eDupli_ID_Flags dupflag = (linked) ? 0 : (eDupli_ID_Flags)U.dupflag; | const eDupli_ID_Flags dupflag = (linked) ? 0 : (eDupli_ID_Flags)U.dupflag; | ||||
| ▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | RNA_def_boolean(ot->srna, | ||||
| "linked", | "linked", | ||||
| false, | false, | ||||
| "Linked", | "Linked", | ||||
| "Duplicate object but not object data, linking to the original data (ignored if " | "Duplicate object but not object data, linking to the original data (ignored if " | ||||
| "'duplicate' is false)"); | "'duplicate' is false)"); | ||||
| RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Object name to add"); | RNA_def_string(ot->srna, "name", NULL, MAX_ID_NAME - 2, "Name", "Object name to add"); | ||||
| /* Use for asset manager to place the linked/appended ID. */ | |||||
| RNA_def_boolean(ot->srna, | |||||
| "only_place", | |||||
| true, | |||||
| "Only Place", | |||||
| "Place the active object (and other selected objects)"); | |||||
| object_add_drop_xy_props(ot); | object_add_drop_xy_props(ot); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Join Object Operator | /** \name Join Object Operator | ||||
| * \{ */ | * \{ */ | ||||
| Show All 25 Lines | if (BKE_object_obdata_is_libdata(ob)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data"); | BKE_report(op->reports, RPT_ERROR, "Cannot edit external library data"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| if (ob->type == OB_GPENCIL) { | if (ob->type == OB_GPENCIL) { | ||||
| bGPdata *gpd = (bGPdata *)ob->data; | bGPdata *gpd = (bGPdata *)ob->data; | ||||
| if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { | if ((!gpd) || GPENCIL_ANY_MODE(gpd)) { | ||||
| BKE_report(op->reports, RPT_ERROR, "This data does not support joining in this mode"); | BKE_report(op->reports, RPT_ERROR, "This data does not support joining in this mode"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
Severin: This mention clearly this transforms the entire selection, so that delta transforms with… | |||||
| } | } | ||||
Not Done Inline ActionsWhat's that hyphen doing there, looks wrong? :) Severin: What's that hyphen doing there, looks wrong? :)
I'd also mention child-parent and boolean… | |||||
| int ret = OPERATOR_CANCELLED; | int ret = OPERATOR_CANCELLED; | ||||
| if (ob->type == OB_MESH) { | if (ob->type == OB_MESH) { | ||||
| ret = ED_mesh_join_objects_exec(C, op); | ret = ED_mesh_join_objects_exec(C, op); | ||||
Not Done Inline Actionss/do/does? Severin: `s/do/does`? | |||||
| } | } | ||||
| else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { | ||||
| ret = ED_curve_join_objects_exec(C, op); | ret = ED_curve_join_objects_exec(C, op); | ||||
| } | } | ||||
| else if (ob->type == OB_ARMATURE) { | else if (ob->type == OB_ARMATURE) { | ||||
| ret = ED_armature_join_objects_exec(C, op); | ret = ED_armature_join_objects_exec(C, op); | ||||
| } | } | ||||
| else if (ob->type == OB_GPENCIL) { | else if (ob->type == OB_GPENCIL) { | ||||
Not Done Inline ActionsWith D12912: Assets: Snapping with visual feedback while dragging, the name transform_to_mouse doesn't make much sense anymore, since it would transform to a given matrix. Maybe rename it to drop_transform? Severin: With {D12912}, the name `transform_to_mouse` doesn't make much sense anymore, since it would… | |||||
| ret = ED_gpencil_join_objects_exec(C, op); | ret = ED_gpencil_join_objects_exec(C, op); | ||||
| } | } | ||||
| if (ret & OPERATOR_FINISHED) { | if (ret & OPERATOR_FINISHED) { | ||||
| /* Even though internally failure to invert is accounted for with a fallback, | /* Even though internally failure to invert is accounted for with a fallback, | ||||
| * show a warning since the result may not be what the user expects. See T80077. | * show a warning since the result may not be what the user expects. See T80077. | ||||
| * | * | ||||
| * Failure to invert the matrix is typically caused by zero scaled axes | * Failure to invert the matrix is typically caused by zero scaled axes | ||||
| ▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines | |||||
This mention clearly this transforms the entire selection, so that delta transforms with parents, boolean-objects, etc. are preserved.