Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_edit.c
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | |||||
| #include "ED_view3d.h" | #include "ED_view3d.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "PIL_time.h" | #include "PIL_time.h" | ||||
| #include "view3d_intern.h" /* own include */ | #include "view3d_intern.h" /* own include */ | ||||
| #include "DEG_depsgraph_query.h" | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Generic View Operator Properties | /** \name Generic View Operator Properties | ||||
| * \{ */ | * \{ */ | ||||
| enum eV3D_OpPropFlag { | enum eV3D_OpPropFlag { | ||||
| V3D_OP_PROP_MOUSE_CO = (1 << 0), | V3D_OP_PROP_MOUSE_CO = (1 << 0), | ||||
| V3D_OP_PROP_DELTA = (1 << 1), | V3D_OP_PROP_DELTA = (1 << 1), | ||||
| V3D_OP_PROP_USE_ALL_REGIONS = (1 << 2), | V3D_OP_PROP_USE_ALL_REGIONS = (1 << 2), | ||||
| ▲ Show 20 Lines • Show All 2,680 Lines • ▼ Show 20 Lines | void VIEW3D_OT_view_all(wmOperatorType *ot) | ||||
| /* properties */ | /* properties */ | ||||
| view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); | view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); | ||||
| RNA_def_boolean(ot->srna, "center", 0, "Center", ""); | RNA_def_boolean(ot->srna, "center", 0, "Center", ""); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* TODO(sergey): Find a better name and place for this. */ | |||||
| #define TESTOBJECT(object) ( \ | |||||
| (((object)->base_flag & BASE_SELECTED) != 0) && \ | |||||
| (((object)->base_flag & BASE_VISIBLED) != 0)) | |||||
| #define TESTOBJECTLIB(object) ( \ | |||||
| (((object)->base_flag & BASE_SELECTED) != 0) && \ | |||||
| ((object)->id.lib == NULL) && \ | |||||
| (((object)->base_flag & BASE_VISIBLED) != 0)) | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name View Selected Operator | /** \name View Selected Operator | ||||
| * | * | ||||
| * Move & Zoom the view to fit selected contents. | * Move & Zoom the view to fit selected contents. | ||||
| * \{ */ | * \{ */ | ||||
| /* like a localview without local!, was centerview() in 2.4x */ | /* like a localview without local!, was centerview() in 2.4x */ | ||||
| static int viewselected_exec(bContext *C, wmOperator *op) | static int viewselected_exec(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_depsgraph(C); | Depsgraph *depsgraph = CTX_data_depsgraph(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| bGPdata *gpd = CTX_data_gpencil_data(C); | bGPdata *gpd = CTX_data_gpencil_data(C); | ||||
| const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); | const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)); | ||||
| const bool is_face_map = ((is_gp_edit == false) && ar->manipulator_map && | const bool is_face_map = ((is_gp_edit == false) && ar->manipulator_map && | ||||
| WM_manipulatormap_is_any_selected(ar->manipulator_map)); | WM_manipulatormap_is_any_selected(ar->manipulator_map)); | ||||
| Object *ob = OBACT(view_layer); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, OBACT(view_layer)); | ||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| float min[3], max[3]; | float min[3], max[3]; | ||||
| bool ok = false, ok_dist = true; | bool ok = false, ok_dist = true; | ||||
| const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); | const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); | ||||
| const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) || | const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) || | ||||
| /* any one of the regions may be locked */ | /* any one of the regions may be locked */ | ||||
| (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); | (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); | ||||
| const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); | ||||
| INIT_MINMAX(min, max); | INIT_MINMAX(min, max); | ||||
| if (is_gp_edit || is_face_map) { | if (is_gp_edit || is_face_map) { | ||||
| ob = NULL; | ob_eval = NULL; | ||||
| } | } | ||||
| if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) { | if (ob_eval && (ob_eval->mode & OB_MODE_WEIGHT_PAINT)) { | ||||
| /* hard-coded exception, we look for the one selected armature */ | /* hard-coded exception, we look for the one selected armature */ | ||||
| /* this is weak code this way, we should make a generic active/selection callback interface once... */ | /* this is weak code this way, we should make a generic active/selection callback interface once... */ | ||||
| Base *base; | DEG_OBJECT_ITER_FOR_OPERATOR_BEGIN(depsgraph, ob_iter_eval) | ||||
| for (base = view_layer->object_bases.first; base; base = base->next) { | { | ||||
| if (TESTBASELIB(base)) { | if (!TESTOBJECTLIB(ob_iter_eval)) { | ||||
| if (base->object->type == OB_ARMATURE) | continue; | ||||
| if (base->object->mode & OB_MODE_POSE) | } | ||||
| if (ob_iter_eval->type == OB_ARMATURE) { | |||||
| if (ob_iter_eval->mode & OB_MODE_POSE) { | |||||
| ob_eval = ob_iter_eval; | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (base) | } | ||||
| ob = base->object; | DEG_OBJECT_ITER_FOR_OPERATOR_END; | ||||
| } | } | ||||
| if (is_gp_edit) { | if (is_gp_edit) { | ||||
| CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) | CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes) | ||||
| { | { | ||||
| /* we're only interested in selected points here... */ | /* we're only interested in selected points here... */ | ||||
| if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) { | if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) { | ||||
| if (ED_gpencil_stroke_minmax(gps, true, min, max)) { | if (ED_gpencil_stroke_minmax(gps, true, min, max)) { | ||||
| ok = true; | ok = true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| } | } | ||||
| else if (is_face_map) { | else if (is_face_map) { | ||||
| ok = WM_manipulatormap_minmax(ar->manipulator_map, true, true, min, max); | ok = WM_manipulatormap_minmax(ar->manipulator_map, true, true, min, max); | ||||
| } | } | ||||
| else if (obedit) { | else if (obedit) { | ||||
| /* only selected */ | /* only selected */ | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, obedit->mode, ob_iter) { | DEG_FOREACH_OBJECT_IN_MODE_BEGIN(depsgraph, obedit->mode, ob_eval_iter) | ||||
| ok |= ED_view3d_minmax_verts(ob_iter, min, max); | { | ||||
| ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max); | |||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | DEG_FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| else if (ob && (ob->mode & OB_MODE_POSE)) { | else if (ob_eval && (ob_eval->mode & OB_MODE_POSE)) { | ||||
| FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, ob->mode, ob_iter) { | DEG_FOREACH_OBJECT_IN_MODE_BEGIN(depsgraph, ob_eval->mode, ob_eval_iter) | ||||
| ok |= BKE_pose_minmax(ob_iter, min, max, true, true); | { | ||||
| ok |= BKE_pose_minmax(ob_eval_iter, min, max, true, true); | |||||
| } | } | ||||
| FOREACH_OBJECT_IN_MODE_END; | DEG_FOREACH_OBJECT_IN_MODE_END; | ||||
| } | } | ||||
| else if (BKE_paint_select_face_test(ob)) { | else if (BKE_paint_select_face_test(ob_eval)) { | ||||
| ok = paintface_minmax(ob, min, max); | ok = paintface_minmax(ob_eval, min, max); | ||||
| } | } | ||||
| else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) { | else if (ob_eval && (ob_eval->mode & OB_MODE_PARTICLE_EDIT)) { | ||||
| ok = PE_minmax(scene, view_layer, min, max); | ok = PE_minmax(scene, view_layer, min, max); | ||||
| } | } | ||||
| else if (ob && | else if (ob_eval && | ||||
| (ob->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) | (ob_eval->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) | ||||
| { | { | ||||
| BKE_paint_stroke_get_average(scene, ob, min); | BKE_paint_stroke_get_average(scene, ob_eval, min); | ||||
| copy_v3_v3(max, min); | copy_v3_v3(max, min); | ||||
| ok = true; | ok = true; | ||||
| ok_dist = 0; /* don't zoom */ | ok_dist = 0; /* don't zoom */ | ||||
| } | } | ||||
| else { | else { | ||||
| Base *base; | DEG_OBJECT_ITER_FOR_OPERATOR_BEGIN(depsgraph, object_eval) | ||||
| for (base = FIRSTBASE(view_layer); base; base = base->next) { | { | ||||
| if (TESTBASE(base)) { | if (!TESTOBJECT(object_eval)) { | ||||
| continue; | |||||
| } | |||||
| if (skip_camera && base->object == v3d->camera) { | if (skip_camera && object_eval == v3d->camera) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| /* account for duplis */ | /* account for duplis */ | ||||
| if (BKE_object_minmax_dupli(depsgraph, scene, base->object, min, max, false) == 0) | if (BKE_object_minmax_dupli(depsgraph, scene, object_eval, min, max, false) == 0) { | ||||
| BKE_object_minmax(base->object, min, max, false); /* use if duplis not found */ | BKE_object_minmax(object_eval, min, max, false); /* use if duplis not found */ | ||||
| } | |||||
| ok = 1; | ok = 1; | ||||
| } | } | ||||
| } | DEG_OBJECT_ITER_FOR_OPERATOR_END; | ||||
| } | } | ||||
| if (ok == 0) { | if (ok == 0) { | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| if (use_all_regions) { | if (use_all_regions) { | ||||
| view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx); | view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx); | ||||
| ▲ Show 20 Lines • Show All 1,816 Lines • Show Last 20 Lines | |||||