Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/object/object_add.c
| Show First 20 Lines • Show All 3,524 Lines • ▼ Show 20 Lines | BKE_report(op->reports, | ||||
| RPT_ERROR, | RPT_ERROR, | ||||
| duplicate ? "Object could not be duplicated" : | duplicate ? "Object could not be duplicated" : | ||||
| "Object could not be linked to the view layer"); | "Object could not be linked to the view layer"); | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; | basen->object->visibility_flag &= ~OB_HIDE_VIEWPORT; | ||||
| int mval[2]; | |||||
| if (object_add_drop_xy_get(C, op, &mval)) { | |||||
| ED_object_location_from_view(C, basen->object->loc); | |||||
| ED_view3d_cursor3d_position(C, mval, false, basen->object->loc); | |||||
| } | |||||
| /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or | /* object_add_duplicate_internal() doesn't deselect other objects, unlike object_add_common() or | ||||
| * BKE_view_layer_base_deselect_all(). */ | * BKE_view_layer_base_deselect_all(). */ | ||||
| ED_object_base_deselect_all(view_layer, NULL, SEL_DESELECT); | ED_object_base_deselect_all(view_layer, NULL, SEL_DESELECT); | ||||
| ED_object_base_select(basen, BA_SELECT); | ED_object_base_select(basen, BA_SELECT); | ||||
| ED_object_base_activate(C, basen); | ED_object_base_activate(C, basen); | ||||
| copy_object_set_idnew(C); | copy_object_set_idnew(C); | ||||
| /* TODO(sergey): Only update relations for the current scene. */ | /* TODO(sergey): Only update relations for the current scene. */ | ||||
| DEG_relations_tag_update(bmain); | DEG_relations_tag_update(bmain); | ||||
| DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | DEG_id_tag_update(&scene->id, ID_RECALC_SELECT); | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene); | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); | WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene); | ||||
| WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); | WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene); | ||||
| ED_outliner_select_sync_from_object_tag(C); | ED_outliner_select_sync_from_object_tag(C); | ||||
| /* For the placement based on the bounding box to work, the object/object-data has to be | |||||
| * evaulated first. */ | |||||
| int mval[2]; | |||||
| if (object_add_drop_xy_get(C, op, &mval)) { | |||||
| Object *ob_eval = DEG_get_evaluated_object(CTX_data_ensure_evaluated_depsgraph(C), | |||||
| basen->object); | |||||
| BoundBox *boundbox = BKE_object_boundbox_get(ob_eval); | |||||
| float rotmat[3][3]; | |||||
| float scale[3]; | |||||
| BKE_object_scale_to_vec3(basen->object, scale); | |||||
| ED_view3d_placement_plane_boundbox_calc( | |||||
| C, mval, boundbox, PLACE_DIRECTION_NEG, scale, basen->object->loc, rotmat); | |||||
| BLI_assert(basen->object->rotmode == ROT_MODE_XYZ); | |||||
| mat3_to_eul(basen->object->rot, rotmat); | |||||
| DEG_id_tag_update(&basen->object->id, ID_RECALC_TRANSFORM); | |||||
| } | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void OBJECT_OT_add_named(wmOperatorType *ot) | void OBJECT_OT_add_named(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Add Named Object"; | ot->name = "Add Object"; | ||||
| ot->description = "Add named object"; | ot->description = "Add named object"; | ||||
| ot->idname = "OBJECT_OT_add_named"; | ot->idname = "OBJECT_OT_add_named"; | ||||
| /* api callbacks */ | /* api callbacks */ | ||||
| ot->invoke = object_add_drop_xy_generic_invoke; | ot->invoke = object_add_drop_xy_generic_invoke; | ||||
| ot->exec = object_add_named_exec; | ot->exec = object_add_named_exec; | ||||
| ot->poll = ED_operator_objectmode; | ot->poll = ED_operator_objectmode; | ||||
| ▲ Show 20 Lines • Show All 181 Lines • Show Last 20 Lines | |||||