diff options
Diffstat (limited to 'source/blender/editors')
148 files changed, 5919 insertions, 5760 deletions
diff --git a/source/blender/editors/animation/CMakeLists.txt b/source/blender/editors/animation/CMakeLists.txt index 6fa4d94df3a..0baac40660d 100644 --- a/source/blender/editors/animation/CMakeLists.txt +++ b/source/blender/editors/animation/CMakeLists.txt @@ -60,10 +60,6 @@ set(LIB bf_blenlib ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 2eaa42ee578..a697fd2fc96 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -35,8 +35,8 @@ #include "DNA_armature_types.h" #include "DNA_cachefile_types.h" #include "DNA_camera_types.h" +#include "DNA_curves_types.h" #include "DNA_gpencil_types.h" -#include "DNA_hair_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_light_types.h" @@ -700,8 +700,8 @@ static int acf_object_icon(bAnimListElem *ale) return ICON_OUTLINER_OB_FONT; case OB_SURF: return ICON_OUTLINER_OB_SURFACE; - case OB_HAIR: - return ICON_OUTLINER_OB_HAIR; + case OB_CURVES: + return ICON_OUTLINER_OB_CURVES; case OB_POINTCLOUD: return ICON_OUTLINER_OB_POINTCLOUD; case OB_VOLUME: @@ -2813,15 +2813,15 @@ static bAnimChannelType ACF_DSSPK = { /* Hair Expander ------------------------------------------- */ /* TODO: just get this from RNA? */ -static int acf_dshair_icon(bAnimListElem *UNUSED(ale)) +static int acf_dscurves_icon(bAnimListElem *UNUSED(ale)) { - return ICON_HAIR_DATA; + return ICON_CURVES_DATA; } /* Get the appropriate flag(s) for the setting when it is valid. */ -static int acf_dshair_setting_flag(bAnimContext *UNUSED(ac), - eAnimChannel_Settings setting, - bool *neg) +static int acf_dscurves_setting_flag(bAnimContext *UNUSED(ac), + eAnimChannel_Settings setting, + bool *neg) { /* clear extra return data first */ *neg = false; @@ -2846,22 +2846,24 @@ static int acf_dshair_setting_flag(bAnimContext *UNUSED(ac), } /* get pointer to the setting */ -static void *acf_dshair_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings setting, short *type) +static void *acf_dscurves_setting_ptr(bAnimListElem *ale, + eAnimChannel_Settings setting, + short *type) { - Hair *hair = (Hair *)ale->data; + Curves *curves = (Curves *)ale->data; /* clear extra return data first */ *type = 0; switch (setting) { case ACHANNEL_SETTING_EXPAND: /* expanded */ - return GET_ACF_FLAG_PTR(hair->flag, type); + return GET_ACF_FLAG_PTR(curves->flag, type); case ACHANNEL_SETTING_SELECT: /* selected */ case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */ case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */ - if (hair->adt) { - return GET_ACF_FLAG_PTR(hair->adt->flag, type); + if (curves->adt) { + return GET_ACF_FLAG_PTR(curves->adt->flag, type); } return NULL; @@ -2870,9 +2872,9 @@ static void *acf_dshair_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings se } } -/* hair expander type define */ +/* Curves expander type define */ static bAnimChannelType ACF_DSHAIR = { - "Hair Expander", /* type name */ + "Curves Expander", /* type name */ ACHANNEL_ROLE_EXPANDER, /* role */ acf_generic_dataexpand_color, /* backdrop color */ @@ -2882,11 +2884,11 @@ static bAnimChannelType ACF_DSHAIR = { acf_generic_idblock_name, /* name */ acf_generic_idblock_name_prop, /* name prop */ - acf_dshair_icon, /* icon */ + acf_dscurves_icon, /* icon */ acf_generic_dataexpand_setting_valid, /* has setting */ - acf_dshair_setting_flag, /* flag for setting */ - acf_dshair_setting_ptr /* pointer for setting */ + acf_dscurves_setting_flag, /* flag for setting */ + acf_dscurves_setting_ptr /* pointer for setting */ }; /* PointCloud Expander ------------------------------------------- */ @@ -3418,7 +3420,7 @@ static void acf_gpd_color(bAnimContext *UNUSED(ac), bAnimListElem *UNUSED(ale), /* TODO: just get this from RNA? */ static int acf_gpd_icon(bAnimListElem *UNUSED(ale)) { - return ICON_GREASEPENCIL; + return ICON_OUTLINER_OB_GREASEPENCIL; } /* check if some setting exists for this channel */ diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index c1a09b9d21f..3307385b84a 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -47,8 +47,8 @@ #include "DNA_brush_types.h" #include "DNA_cachefile_types.h" #include "DNA_camera_types.h" +#include "DNA_curves_types.h" #include "DNA_gpencil_types.h" -#include "DNA_hair_types.h" #include "DNA_key_types.h" #include "DNA_lattice_types.h" #include "DNA_layer_types.h" @@ -791,10 +791,10 @@ static bAnimListElem *make_new_animlistelem(void *data, break; } case ANIMTYPE_DSHAIR: { - Hair *hair = (Hair *)data; - AnimData *adt = hair->adt; + Curves *curves = (Curves *)data; + AnimData *adt = curves->adt; - ale->flag = FILTER_HAIR_OBJD(hair); + ale->flag = FILTER_CURVES_OBJD(curves); ale->key_data = (adt) ? adt->action : NULL; ale->datatype = ALE_ACT; @@ -2616,16 +2616,16 @@ static size_t animdata_filter_ds_obdata( expanded = FILTER_SPK_OBJD(spk); break; } - case OB_HAIR: /* ---------- Hair ----------- */ + case OB_CURVES: /* ---------- Curves ----------- */ { - Hair *hair = (Hair *)ob->data; + Curves *curves = (Curves *)ob->data; if (ads->filterflag2 & ADS_FILTER_NOHAIR) { return 0; } type = ANIMTYPE_DSHAIR; - expanded = FILTER_HAIR_OBJD(hair); + expanded = FILTER_CURVES_OBJD(curves); break; } case OB_POINTCLOUD: /* ---------- PointCloud ----------- */ diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt index aff5803f037..c8ca27c64a3 100644 --- a/source/blender/editors/armature/CMakeLists.txt +++ b/source/blender/editors/armature/CMakeLists.txt @@ -63,9 +63,5 @@ set(LIB bf_blenlib ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_armature "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c index 02ecfdb4ea6..e1d4b5fec73 100644 --- a/source/blender/editors/armature/armature_add.c +++ b/source/blender/editors/armature/armature_add.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Operators and API's for creating bones */ /** \file * \ingroup edarmature + * Operators and API's for creating bones. */ #include "DNA_anim_types.h" @@ -581,8 +581,6 @@ static void updateDuplicateLocRotConstraintSettings(Object *ob, { /* This code assumes that bRotLimitConstraint and bLocLimitConstraint have the same fields in * the same memory locations. */ - BLI_assert(sizeof(bLocLimitConstraint) == sizeof(bRotLimitConstraint)); - bRotLimitConstraint *limit = (bRotLimitConstraint *)curcon->data; float local_mat[4][4], imat[4][4]; @@ -798,6 +796,13 @@ static void updateDuplicateTransformConstraintSettings(Object *ob, trans->to_min_rot[i] = temp_vec[i]; } } + + if (trans->from == TRANS_ROTATION && trans->map[1] == Y) { + /* Y Rot to Y Rot: Flip and invert */ + trans->to_max_rot[1] = -trans->to_min_rot[1]; + trans->to_min_rot[1] = -temp_vec[1]; + } + break; } /* convert back to the settings space */ @@ -854,14 +859,28 @@ static void updateDuplicateCustomBoneShapes(bContext *C, EditBone *dup_bone, Obj Main *bmain = CTX_data_main(C); char name_flip[MAX_ID_NAME - 2]; + /* Invert the X location */ + pchan->custom_translation[0] *= -1; + /* Invert the Y rotation */ + pchan->custom_rotation_euler[1] *= -1; + /* Invert the Z rotation */ + pchan->custom_rotation_euler[2] *= -1; + /* Skip the first two chars in the object name as those are used to store object type */ BLI_string_flip_side_name(name_flip, pchan->custom->id.name + 2, false, sizeof(name_flip)); Object *shape_ob = (Object *)BKE_libblock_find_name(bmain, ID_OB, name_flip); + /* If name_flip doesn't exist, BKE_libblock_find_name() returns pchan->custom (best match) */ + shape_ob = shape_ob == pchan->custom ? NULL : shape_ob; + if (shape_ob != NULL) { /* A flipped shape object exists, use it! */ pchan->custom = shape_ob; } + else { + /* Flip shape */ + pchan->custom_scale_xyz[0] *= -1; + } } } diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index b709980cabe..0094783e50f 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Armature EditMode tools - transforms, chain based editing, and other settings */ /** \file * \ingroup edarmature + * Armature EditMode tools - transforms, chain based editing, and other settings. */ #include "DNA_armature_types.h" diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index 252cf806e34..aaeac29b7d0 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -27,6 +27,7 @@ struct wmOperatorType; struct Base; +struct GPUSelectResult; struct Object; struct Scene; struct bContext; @@ -323,21 +324,21 @@ struct Bone *ED_armature_pick_bone(struct bContext *C, struct EditBone *ED_armature_pick_ebone_from_selectbuffer(struct Base **bases, uint bases_len, - const uint *buffer, + const struct GPUSelectResult *buffer, short hits, bool findunsel, bool do_nearest, struct Base **r_base); struct bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(struct Base **bases, uint bases_len, - const uint *buffer, + const struct GPUSelectResult *buffer, short hits, bool findunsel, bool do_nearest, struct Base **r_base); struct Bone *ED_armature_pick_bone_from_selectbuffer(struct Base **bases, uint bases_len, - const uint *buffer, + const struct GPUSelectResult *buffer, short hits, bool findunsel, bool do_nearest, diff --git a/source/blender/editors/armature/armature_naming.c b/source/blender/editors/armature/armature_naming.c index 750c64d74a7..c45c6297d86 100644 --- a/source/blender/editors/armature/armature_naming.c +++ b/source/blender/editors/armature/armature_naming.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Operators and API's for renaming bones both in and out of Edit Mode */ /** \file * \ingroup edarmature + * Operators and API's for renaming bones both in and out of Edit Mode. * * This file contains functions/API's for renaming bones and/or working with them. */ diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c index eebe8a447f7..17d25aec198 100644 --- a/source/blender/editors/armature/armature_relations.c +++ b/source/blender/editors/armature/armature_relations.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Operators for relations between bones and for transferring bones between armature objects */ /** \file * \ingroup edarmature + * Operators for relations between bones and for transferring bones between armature objects. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c index 5e4cb813064..111989f1d86 100644 --- a/source/blender/editors/armature/armature_select.c +++ b/source/blender/editors/armature/armature_select.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * API's and Operators for selecting armature bones in EditMode */ /** \file * \ingroup edarmature + * API's and Operators for selecting armature bones in EditMode. */ #include "MEM_guardedalloc.h" @@ -55,6 +55,8 @@ #include "DEG_depsgraph.h" +#include "GPU_select.h" + #include "armature_intern.h" /* utility macros for storing a temp int in the bone (selection flag) */ @@ -67,10 +69,10 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases, uint bases_len, - int hit, + const uint select_id, EditBone **r_ebone) { - const uint hit_object = hit & 0xFFFF; + const uint hit_object = select_id & 0xFFFF; Base *base = NULL; EditBone *ebone = NULL; /* TODO(campbell): optimize, eg: sort & binary search. */ @@ -81,7 +83,7 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases, } } if (base != NULL) { - const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16; bArmature *arm = base->object->data; ebone = BLI_findlink(arm->edbo, hit_bone); } @@ -91,10 +93,10 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases, Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects, uint objects_len, - int hit, + const uint select_id, EditBone **r_ebone) { - const uint hit_object = hit & 0xFFFF; + const uint hit_object = select_id & 0xFFFF; Object *ob = NULL; EditBone *ebone = NULL; /* TODO(campbell): optimize, eg: sort & binary search. */ @@ -105,7 +107,7 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects, } } if (ob != NULL) { - const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16; bArmature *arm = ob->data; ebone = BLI_findlink(arm->edbo, hit_bone); } @@ -115,10 +117,10 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects, Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases, uint bases_len, - int hit, + const uint select_id, bPoseChannel **r_pchan) { - const uint hit_object = hit & 0xFFFF; + const uint hit_object = select_id & 0xFFFF; Base *base = NULL; bPoseChannel *pchan = NULL; /* TODO(campbell): optimize, eg: sort & binary search. */ @@ -130,7 +132,7 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases, } if (base != NULL) { if (base->object->pose != NULL) { - const uint hit_bone = (hit & ~BONESEL_ANY) >> 16; + const uint hit_bone = (select_id & ~BONESEL_ANY) >> 16; /* pchan may be NULL. */ pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone); } @@ -141,11 +143,11 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases, Base *ED_armature_base_and_bone_from_select_buffer(Base **bases, uint bases_len, - int hit, + const uint select_id, Bone **r_bone) { bPoseChannel *pchan = NULL; - Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, hit, &pchan); + Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, select_id, &pchan); *r_bone = pchan ? pchan->bone : NULL; return base; } @@ -166,8 +168,8 @@ Base *ED_armature_base_and_bone_from_select_buffer(Base **bases, static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode, Base **bases, uint bases_len, - const uint *buffer, - short hits, + const GPUSelectResult *buffer, + const short hits, bool findunsel, bool do_nearest, Base **r_base) @@ -181,7 +183,7 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode int minsel = 0xffffffff, minunsel = 0xffffffff; for (short i = 0; i < hits; i++) { - hitresult = buffer[3 + (i * 4)]; + hitresult = buffer[i].id; if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */ Base *base = NULL; @@ -221,10 +223,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode if (data) { if (sel) { if (do_nearest) { - if (minsel > buffer[4 * i + 1]) { + if (minsel > buffer[i].depth) { firstSel = data; firstSel_base = base; - minsel = buffer[4 * i + 1]; + minsel = buffer[i].depth; } } else { @@ -237,10 +239,10 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode } else { if (do_nearest) { - if (minunsel > buffer[4 * i + 1]) { + if (minunsel > buffer[i].depth) { firstunSel = data; firstunSel_base = base; - minunsel = buffer[4 * i + 1]; + minunsel = buffer[i].depth; } } else { @@ -268,8 +270,8 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases, uint bases_len, - const uint *buffer, - short hits, + const GPUSelectResult *buffer, + const short hits, bool findunsel, bool do_nearest, Base **r_base) @@ -281,8 +283,8 @@ EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases, bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases, uint bases_len, - const uint *buffer, - short hits, + const GPUSelectResult *buffer, + const short hits, bool findunsel, bool do_nearest, Base **r_base) @@ -294,8 +296,8 @@ bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases, Bone *ED_armature_pick_bone_from_selectbuffer(Base **bases, uint bases_len, - const uint *buffer, - short hits, + const GPUSelectResult *buffer, + const short hits, bool findunsel, bool do_nearest, Base **r_base) @@ -327,7 +329,7 @@ static void *ed_armature_pick_bone_impl( Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; rcti rect; - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; short hits; ED_view3d_viewcontext_init(C, &vc, depsgraph); @@ -340,7 +342,7 @@ static void *ed_armature_pick_bone_impl( hits = view3d_opengl_select_with_id_filter(&vc, buffer, - MAXPICKBUF, + ARRAY_SIZE(buffer), &rect, VIEW3D_SELECT_PICK_NEAREST, VIEW3D_SELECT_FILTER_NOP, @@ -636,15 +638,15 @@ void ARMATURE_OT_select_linked_pick(wmOperatorType *ot) * \{ */ /* utility function for get_nearest_editbonepoint */ -static int selectbuffer_ret_hits_12(uint *UNUSED(buffer), const int hits12) +static int selectbuffer_ret_hits_12(GPUSelectResult *UNUSED(buffer), const int hits12) { return hits12; } -static int selectbuffer_ret_hits_5(uint *buffer, const int hits12, const int hits5) +static int selectbuffer_ret_hits_5(GPUSelectResult *buffer, const int hits12, const int hits5) { - const int ofs = 4 * hits12; - memcpy(buffer, buffer + ofs, 4 * hits5 * sizeof(uint)); + const int ofs = hits12; + memcpy(buffer, buffer + ofs, hits5 * sizeof(*buffer)); return hits5; } @@ -653,7 +655,7 @@ static int selectbuffer_ret_hits_5(uint *buffer, const int hits12, const int hit static EditBone *get_nearest_editbonepoint( ViewContext *vc, bool findunsel, bool use_cycle, Base **r_base, int *r_selmask) { - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; struct { uint hitresult; Base *base; @@ -692,7 +694,7 @@ static EditBone *get_nearest_editbonepoint( rcti rect; BLI_rcti_init_pt_radius(&rect, vc->mval, 12); const int hits12 = view3d_opengl_select_with_id_filter( - vc, buffer, MAXPICKBUF, &rect, select_mode, select_filter, select_id_ignore); + vc, buffer, ARRAY_SIZE(buffer), &rect, select_mode, select_filter, select_id_ignore); if (hits12 == 1) { hits = selectbuffer_ret_hits_12(buffer, hits12); @@ -701,10 +703,15 @@ static EditBone *get_nearest_editbonepoint( else if (hits12 > 0) { int ofs; - ofs = 4 * hits12; + ofs = hits12; BLI_rcti_init_pt_radius(&rect, vc->mval, 5); - const int hits5 = view3d_opengl_select_with_id_filter( - vc, buffer + ofs, MAXPICKBUF - ofs, &rect, select_mode, select_filter, select_id_ignore); + const int hits5 = view3d_opengl_select_with_id_filter(vc, + buffer + ofs, + ARRAY_SIZE(buffer) - ofs, + &rect, + select_mode, + select_filter, + select_id_ignore); if (hits5 == 1) { hits = selectbuffer_ret_hits_5(buffer, hits12, hits5); @@ -732,7 +739,7 @@ cache_end: /* See if there are any selected bones in this group */ if (hits > 0) { if (hits == 1) { - result_bias.hitresult = buffer[3]; + result_bias.hitresult = buffer->id; result_bias.base = ED_armature_base_and_ebone_from_select_buffer( bases, bases_len, result_bias.hitresult, &result_bias.ebone); } @@ -771,7 +778,7 @@ cache_end: } for (int i = 0; i < hits; i++) { - const uint hitresult = buffer[3 + (i * 4)]; + const uint hitresult = buffer[i].id; Base *base = NULL; EditBone *ebone; diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c index ec5c665402b..9ef198f442c 100644 --- a/source/blender/editors/armature/armature_skinning.c +++ b/source/blender/editors/armature/armature_skinning.c @@ -15,12 +15,12 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * API's for creating vertex groups from bones - * - Interfaces with heat weighting in meshlaplacian */ /** \file * \ingroup edarmature + * API's for creating vertex groups from bones + * - Interfaces with heat weighting in meshlaplacian. */ #include "DNA_armature_types.h" diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 8bd6c9f54fd..5db4a4b6eaa 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Pose Mode API's and Operators for Pose Mode armatures */ /** \file * \ingroup edarmature + * Pose Mode API's and Operators for Pose Mode armatures. */ #include "MEM_guardedalloc.h" @@ -149,36 +149,6 @@ bool ED_object_posemode_exit(bContext *C, Object *ob) return ok; } -/* if a selected or active bone is protected, throw error (only if warn == 1) and return 1 */ -/* only_selected == 1: the active bone is allowed to be protected */ -#if 0 /* UNUSED 2.5 */ -static bool pose_has_protected_selected(Object *ob, short warn) -{ - /* check protection */ - if (ob->proxy) { - bPoseChannel *pchan; - bArmature *arm = ob->data; - - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - if (pchan->bone && BKE_pose_is_layer_visible(arm, pchan)) { - if (pchan->bone->layer & arm->layer_protected) { - if (pchan->bone->flag & BONE_SELECTED) { - break; - } - } - } - } - if (pchan) { - if (warn) { - error("Cannot change Proxy protected bones"); - } - return 1; - } - } - return 0; -} -#endif - /* ********************************************** */ /* Motion Paths */ @@ -1056,10 +1026,6 @@ static int pose_hide_exec(bContext *C, wmOperator *op) Object *ob_iter = objects[ob_index]; bArmature *arm = ob_iter->data; - if (ob_iter->proxy != NULL) { - BKE_report(op->reports, RPT_INFO, "Undo of hiding can only be done with Reveal Selected"); - } - bool changed = bone_looper(ob_iter, arm->bonebase.first, hide_select_p, hide_pose_bone_fn) != 0; if (changed) { diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c index 38d15d8b880..10ffa3fcae2 100644 --- a/source/blender/editors/armature/pose_group.c +++ b/source/blender/editors/armature/pose_group.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2008 Blender Foundation * All rights reserved. - * Implementation of Bone Groups operators and editing API's */ /** \file * \ingroup edarmature + * Implementation of Bone Groups operators and editing API's. */ #include <string.h> @@ -62,8 +62,8 @@ static bool pose_group_poll(bContext *C) } Object *obpose = ED_pose_object_from_context(C); - if ((obpose->proxy != NULL) || (obpose->proxy_group != NULL) || ID_IS_OVERRIDE_LIBRARY(obpose)) { - CTX_wm_operator_poll_msg_set(C, "Cannot edit bone groups for proxies or library overrides"); + if (ID_IS_OVERRIDE_LIBRARY(obpose)) { + CTX_wm_operator_poll_msg_set(C, "Cannot edit bone groups for library overrides"); return false; } diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c index 0b889149f9d..f41c3657431 100644 --- a/source/blender/editors/armature/pose_select.c +++ b/source/blender/editors/armature/pose_select.c @@ -240,8 +240,8 @@ void ED_armature_pose_select_pick_bone(ViewLayer *view_layer, bool ED_armature_pose_select_pick_with_buffer(ViewLayer *view_layer, View3D *v3d, Base *base, - const uint *buffer, - short hits, + const struct GPUSelectResult *buffer, + const short hits, bool extend, bool deselect, bool toggle, diff --git a/source/blender/editors/asset/CMakeLists.txt b/source/blender/editors/asset/CMakeLists.txt index 086fab4ab47..d91102528e5 100644 --- a/source/blender/editors/asset/CMakeLists.txt +++ b/source/blender/editors/asset/CMakeLists.txt @@ -21,6 +21,7 @@ set(INC ../../blenkernel ../../blenlib ../../blenloader + ../../blentranslation ../../makesdna ../../makesrna ../../windowmanager diff --git a/source/blender/editors/asset/intern/asset_list.cc b/source/blender/editors/asset/intern/asset_list.cc index c075ae390d9..fa0946ffe3d 100644 --- a/source/blender/editors/asset/intern/asset_list.cc +++ b/source/blender/editors/asset/intern/asset_list.cc @@ -41,6 +41,7 @@ #include "WM_api.h" /* XXX uses private header of file-space. */ +#include "../space_file/file_indexer.h" #include "../space_file/filelist.h" #include "ED_asset_handle.h" @@ -170,7 +171,8 @@ void AssetList::setup() "", ""); - filelist_setindexer(files, &file_indexer_asset); + const bool use_asset_indexer = !USER_EXPERIMENTAL_TEST(&U, no_asset_indexing); + filelist_setindexer(files, use_asset_indexer ? &file_indexer_asset : &file_indexer_noop); char path[FILE_MAXDIR] = ""; if (user_library) { diff --git a/source/blender/editors/asset/intern/asset_ops.cc b/source/blender/editors/asset/intern/asset_ops.cc index f7755aa9fea..0469f14487d 100644 --- a/source/blender/editors/asset/intern/asset_ops.cc +++ b/source/blender/editors/asset/intern/asset_ops.cc @@ -39,6 +39,8 @@ /* XXX needs access to the file list, should all be done via the asset system in future. */ #include "ED_fileselect.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -342,8 +344,8 @@ static bool asset_clear_poll(bContext *C) IDVecStats ctx_stats = asset_operation_get_id_vec_stats_from_context(C); if (!ctx_stats.has_asset) { - const char *msg_single = "Data-block is not marked as asset"; - const char *msg_multiple = "No data-block selected that is marked as asset"; + const char *msg_single = TIP_("Data-block is not marked as asset"); + const char *msg_multiple = TIP_("No data-block selected that is marked as asset"); CTX_wm_operator_poll_msg_set(C, ctx_stats.is_single ? msg_single : msg_multiple); return false; } @@ -365,8 +367,8 @@ static char *asset_clear_get_description(struct bContext *UNUSED(C), } return BLI_strdup( - "Delete all asset metadata, turning the selected asset data-blocks back into normal " - "data-blocks, and set Fake User to ensure the data-blocks will still be saved"); + TIP_("Delete all asset metadata, turning the selected asset data-blocks back into normal " + "data-blocks, and set Fake User to ensure the data-blocks will still be saved")); } static void ASSET_OT_clear(wmOperatorType *ot) diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt index 877c2d99102..0ac572c0422 100644 --- a/source/blender/editors/curve/CMakeLists.txt +++ b/source/blender/editors/curve/CMakeLists.txt @@ -51,9 +51,5 @@ set(LIB extern_curve_fit_nd ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_curve "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c index 3635ceb8f13..3871c1de77a 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/cage3d_gizmo.c @@ -91,7 +91,7 @@ static void gizmo_calc_rect_view_scale(const wmGizmo *gz, const float dims[3], f static void gizmo_calc_rect_view_margin(const wmGizmo *gz, const float dims[3], float margin[3]) { - const float handle_size = 0.15f; + const float handle_size = 9.0f; /* XXX, the scale isn't taking offset into account, we need to calculate scale per handle! */ // handle_size *= gz->scale_final; @@ -178,7 +178,7 @@ static void cage3d_draw_box_interaction(const RegionView3D *rv3d, float co_test[3]; mul_v3_m4v3(co_test, matrix_final, co); float rad_scale[3]; - mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * 60); + mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test)); { uint pos = GPU_vertformat_attr_add( @@ -255,7 +255,7 @@ static void cage3d_draw_circle_handles(const RegionView3D *rv3d, const float margin[3], const float color[3], bool solid, - float scale) + const float handle_scale) { uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3}; @@ -274,7 +274,7 @@ static void cage3d_draw_circle_handles(const RegionView3D *rv3d, float co_test[3]; mul_v3_m4v3(co_test, matrix_final, co); float rad_scale[3]; - mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * scale); + mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * handle_scale); imm_draw_point_aspect_3d(pos, co, rad_scale, solid); } } @@ -381,7 +381,8 @@ static void gizmo_cage3d_draw_intern( } if (show) { - cage3d_draw_box_interaction(rv3d, matrix_final, gz->color, gz->highlight_part, size_real, margin); + cage3d_draw_box_interaction( + rv3d, matrix_final, gz->color, gz->highlight_part, size_real, margin); } } else if (draw_style == ED_GIZMO_CAGE2D_STYLE_CIRCLE) { @@ -395,10 +396,10 @@ static void gizmo_cage3d_draw_intern( cage3d_draw_circle_wire( size_real, margin, color, transform_flag, draw_options, gz->line_width); - /* corner gizmos */ + /* Corner gizmos (draw the outer & inner so there is a visible outline). */ GPU_polygon_smooth(true); - cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, black, true, 60); - cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 40); + cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, black, true, 1.0f); + cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 1.0f / 1.5f); GPU_polygon_smooth(false); GPU_blend(GPU_BLEND_NONE); diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt index bff7310e9f7..93d17598181 100644 --- a/source/blender/editors/gpencil/CMakeLists.txt +++ b/source/blender/editors/gpencil/CMakeLists.txt @@ -86,9 +86,5 @@ if(WITH_POTRACE) add_definitions(-DWITH_POTRACE) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_gpencil "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index bf414851aed..8e7a0083ded 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2008, Blender Foundation * This is a new part of Blender - * Operator for converting Grease Pencil data to geometry */ /** \file * \ingroup edgpencil + * Operator for converting Grease Pencil data to geometry. */ #include <math.h> diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index afb786da8c6..dda36cf78d9 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2008, Blender Foundation * This is a new part of Blender - * Operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Operators for editing Grease Pencil strokes. */ #include <math.h> @@ -4635,7 +4635,7 @@ static int gpencil_stroke_separate_exec(bContext *C, wmOperator *op) } } - /* Separate the entrie stroke. */ + /* Separate the entire stroke. */ if (all_points_selected) { /* deselect old stroke */ gps->flag &= ~GP_STROKE_SELECT; diff --git a/source/blender/editors/gpencil/gpencil_edit_curve.c b/source/blender/editors/gpencil/gpencil_edit_curve.c index 2d7497357f2..5002623fbb1 100644 --- a/source/blender/editors/gpencil/gpencil_edit_curve.c +++ b/source/blender/editors/gpencil/gpencil_edit_curve.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2008, Blender Foundation * This is a new part of Blender - * Operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Operators for editing Grease Pencil strokes. */ #include <math.h> diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c index 2023ae5fe27..2d88461fb15 100644 --- a/source/blender/editors/gpencil/gpencil_interpolate.c +++ b/source/blender/editors/gpencil/gpencil_interpolate.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2016, Blender Foundation * This is a new part of Blender - * Operators for interpolating new Grease Pencil frames from existing strokes */ /** \file * \ingroup edgpencil + * Operators for interpolating new Grease Pencil frames from existing strokes. */ #include <math.h> diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 925c2e1cd7f..884167d7496 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2019, Blender Foundation. * This is a new part of Blender - * Operators for merge Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Operators for merge Grease Pencil strokes. */ #include <stdio.h> diff --git a/source/blender/editors/gpencil/gpencil_mesh.c b/source/blender/editors/gpencil/gpencil_mesh.c index efe29e852f2..adf76e79c2a 100644 --- a/source/blender/editors/gpencil/gpencil_mesh.c +++ b/source/blender/editors/gpencil/gpencil_mesh.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2008, Blender Foundation * This is a new part of Blender - * Operator for converting Grease Pencil data to geometry */ /** \file * \ingroup edgpencil + * Operator for converting Grease Pencil data to geometry. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/gpencil/gpencil_ops_versioning.c b/source/blender/editors/gpencil/gpencil_ops_versioning.c index 45842c28dff..d9706c281ca 100644 --- a/source/blender/editors/gpencil/gpencil_ops_versioning.c +++ b/source/blender/editors/gpencil/gpencil_ops_versioning.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2018, Blender Foundation, * This is a new part of Blender - * Use deprecated data to convert old 2.7x files */ /** \file * \ingroup edgpencil + * Use deprecated data to convert old 2.7x files. */ /* Allow using deprecated functionality. */ diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index 2715491414a..fa31dfffbc1 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2017, Blender Foundation * This is a new part of Blender - * Operators for creating new Grease Pencil primitives (boxes, circles, ...) */ /** \file * \ingroup edgpencil + * Operators for creating new Grease Pencil primitives (boxes, circles, ...). */ #include <math.h> diff --git a/source/blender/editors/gpencil/gpencil_sculpt_paint.c b/source/blender/editors/gpencil/gpencil_sculpt_paint.c index 50c7202599a..0cd4efb10d6 100644 --- a/source/blender/editors/gpencil/gpencil_sculpt_paint.c +++ b/source/blender/editors/gpencil/gpencil_sculpt_paint.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2015, Blender Foundation * This is a new part of Blender - * Brush based operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Brush based operators for editing Grease Pencil strokes. */ #include <math.h> diff --git a/source/blender/editors/gpencil/gpencil_vertex_ops.c b/source/blender/editors/gpencil/gpencil_vertex_ops.c index 891bd3ca5ec..d9f4cc87afc 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_ops.c +++ b/source/blender/editors/gpencil/gpencil_vertex_ops.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2015, Blender Foundation * This is a new part of Blender - * Brush based operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Brush based operators for editing Grease Pencil strokes. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/gpencil/gpencil_vertex_paint.c b/source/blender/editors/gpencil/gpencil_vertex_paint.c index 05304f9914f..2c16894354e 100644 --- a/source/blender/editors/gpencil/gpencil_vertex_paint.c +++ b/source/blender/editors/gpencil/gpencil_vertex_paint.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2015, Blender Foundation * This is a new part of Blender - * Brush based operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Brush based operators for editing Grease Pencil strokes. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/gpencil/gpencil_weight_paint.c b/source/blender/editors/gpencil/gpencil_weight_paint.c index 15f99d83f6d..fe4ab648581 100644 --- a/source/blender/editors/gpencil/gpencil_weight_paint.c +++ b/source/blender/editors/gpencil/gpencil_weight_paint.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2015, Blender Foundation * This is a new part of Blender - * Brush based operators for editing Grease Pencil strokes */ /** \file * \ingroup edgpencil + * Brush based operators for editing Grease Pencil strokes. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 3294316f880..04a892ab411 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -378,7 +378,7 @@ typedef enum eAnimFilter_Flags { #define FILTER_MESH_OBJD(me) (CHECK_TYPE_INLINE(me, Mesh *), ((me->flag & ME_DS_EXPAND))) #define FILTER_LATTICE_OBJD(lt) (CHECK_TYPE_INLINE(lt, Lattice *), ((lt->flag & LT_DS_EXPAND))) #define FILTER_SPK_OBJD(spk) (CHECK_TYPE_INLINE(spk, Speaker *), ((spk->flag & SPK_DS_EXPAND))) -#define FILTER_HAIR_OBJD(ha) (CHECK_TYPE_INLINE(ha, Hair *), ((ha->flag & HA_DS_EXPAND))) +#define FILTER_CURVES_OBJD(ha) (CHECK_TYPE_INLINE(ha, Curves *), ((ha->flag & HA_DS_EXPAND))) #define FILTER_POINTS_OBJD(pt) (CHECK_TYPE_INLINE(pt, PointCloud *), ((pt->flag & PT_DS_EXPAND))) #define FILTER_VOLUME_OBJD(vo) (CHECK_TYPE_INLINE(vo, Volume *), ((vo->flag & VO_DS_EXPAND))) #define FILTER_SIMULATION_OBJD(sim) \ diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h index 11b7c85ec58..0521b39ca1a 100644 --- a/source/blender/editors/include/ED_armature.h +++ b/source/blender/editors/include/ED_armature.h @@ -35,6 +35,7 @@ struct Base; struct Bone; struct Depsgraph; struct EditBone; +struct GPUSelectResult; struct ListBase; struct Main; struct Mesh; @@ -157,22 +158,22 @@ int ED_armature_join_objects_exec(struct bContext *C, struct wmOperator *op); struct Base *ED_armature_base_and_ebone_from_select_buffer(struct Base **bases, uint bases_len, - int hit, + unsigned int select_id, struct EditBone **r_ebone); struct Object *ED_armature_object_and_ebone_from_select_buffer(struct Object **objects, uint objects_len, - int hit, + unsigned int select_id, struct EditBone **r_ebone); struct Base *ED_armature_base_and_pchan_from_select_buffer(struct Base **bases, uint bases_len, - int hit, + unsigned int select_id, struct bPoseChannel **r_pchan); /** * For callers that don't need the pose channel. */ struct Base *ED_armature_base_and_bone_from_select_buffer(struct Base **bases, uint bases_len, - int hit, + unsigned int select_id, struct Bone **r_bone); bool ED_armature_edit_deselect_all(struct Object *obedit); bool ED_armature_edit_deselect_all_visible(struct Object *obedit); @@ -334,7 +335,7 @@ void ED_armature_pose_select_pick_bone(struct ViewLayer *view_layer, bool ED_armature_pose_select_pick_with_buffer(struct ViewLayer *view_layer, struct View3D *v3d, struct Base *base, - const unsigned int *buffer, + const struct GPUSelectResult *buffer, short hits, bool extend, bool deselect, diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h index 181b6848ac7..08f4648d02b 100644 --- a/source/blender/editors/include/ED_node.h +++ b/source/blender/editors/include/ED_node.h @@ -57,7 +57,7 @@ typedef enum { #define NODE_EDGE_PAN_DELAY 0.5f #define NODE_EDGE_PAN_ZOOM_INFLUENCE 0.5f -/* space_node.c */ +/* space_node.cc */ void ED_node_cursor_location_get(const struct SpaceNode *snode, float value[2]); void ED_node_cursor_location_set(struct SpaceNode *snode, const float value[2]); @@ -76,7 +76,7 @@ struct bNodeTree *ED_node_tree_get(struct SpaceNode *snode, int level); void ED_node_set_active_viewer_key(struct SpaceNode *snode); -/* drawnode.c */ +/* drawnode.cc */ void ED_node_init_butfuncs(void); void ED_init_custom_node_type(struct bNodeType *ntype); @@ -103,7 +103,7 @@ void ED_node_tag_update_id(struct ID *id); float ED_node_grid_size(void); -/* node_relationships.c */ +/* node_relationships.cc */ /** * Test == 0, clear all intersect flags. @@ -114,7 +114,7 @@ void ED_node_link_intersect_test(struct ScrArea *area, int test); */ void ED_node_link_insert(struct Main *bmain, struct ScrArea *area); -/* node_edit.c */ +/* node_edit.cc */ void ED_node_set_tree_type(struct SpaceNode *snode, struct bNodeTreeType *typeinfo); bool ED_node_is_compositor(struct SpaceNode *snode); @@ -175,11 +175,12 @@ void ED_node_composite_job(const struct bContext *C, struct bNodeTree *nodetree, struct Scene *scene_owner); -/* node_ops.c */ +/* node_ops.cc */ void ED_operatormacros_node(void); -/* node_view.c */ +/* node_view.cc */ + /** * Returns mouse position in image space. */ diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 0398c209c68..3bbffc3b7c9 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -41,6 +41,7 @@ struct Camera; struct CustomData_MeshMasks; struct Depsgraph; struct EditBone; +struct GPUSelectResult; struct ID; struct MVert; struct Main; @@ -871,9 +872,14 @@ bool ED_view3d_autodist_simple(struct ARegion *region, bool ED_view3d_depth_read_cached_seg( const ViewDepths *vd, const int mval_sta[2], const int mval_end[2], int margin, float *depth); -/* select */ +/** + * The default value for the maximum number of elements that can be selected at once + * using view-port selection. + * + * \note in many cases this defines the size of fixed-size stack buffers, + * so take care increasing this value. + */ #define MAXPICKELEMS 2500 -#define MAXPICKBUF (4 * MAXPICKELEMS) typedef enum { /* all elements in the region, ignore depth */ @@ -912,21 +918,21 @@ void view3d_opengl_select_cache_end(void); * \note (vc->obedit == NULL) can be set to explicitly skip edit-object selection. */ int view3d_opengl_select_ex(struct ViewContext *vc, - unsigned int *buffer, - unsigned int bufsize, + struct GPUSelectResult *buffer, + unsigned int buffer_len, const struct rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, bool do_material_slot_selection); int view3d_opengl_select(struct ViewContext *vc, - unsigned int *buffer, - unsigned int bufsize, + struct GPUSelectResult *buffer, + unsigned int buffer_len, const struct rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter); int view3d_opengl_select_with_id_filter(struct ViewContext *vc, - unsigned int *buffer, - unsigned int bufsize, + struct GPUSelectResult *buffer, + unsigned int buffer_len, const struct rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h index 4cf606bf98d..05353de2f92 100644 --- a/source/blender/editors/include/UI_icons.h +++ b/source/blender/editors/include/UI_icons.h @@ -752,9 +752,9 @@ DEF_ICON_BLANK(257) DEF_ICON_BLANK(257b) /* ADDITIONAL OBJECT TYPES */ -DEF_ICON_OBJECT(OUTLINER_OB_HAIR) -DEF_ICON_OBJECT_DATA(OUTLINER_DATA_HAIR) -DEF_ICON_OBJECT_DATA(HAIR_DATA) +DEF_ICON_OBJECT(OUTLINER_OB_CURVES) +DEF_ICON_OBJECT_DATA(OUTLINER_DATA_CURVES) +DEF_ICON_OBJECT_DATA(CURVES_DATA) DEF_ICON_OBJECT(OUTLINER_OB_POINTCLOUD) DEF_ICON_OBJECT_DATA(OUTLINER_DATA_POINTCLOUD) DEF_ICON_OBJECT_DATA(POINTCLOUD_DATA) @@ -840,7 +840,7 @@ DEF_ICON(MATPLANE) DEF_ICON(MATSPHERE) DEF_ICON(MATCUBE) DEF_ICON(MONKEY) -DEF_ICON(HAIR) +DEF_ICON(CURVES) DEF_ICON(ALIASED) DEF_ICON(ANTIALIASED) DEF_ICON(MAT_SPHERE_SKY) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 3796fa51499..ae4c2ff16fd 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1370,6 +1370,8 @@ uiBut *uiDefIconTextButO_ptr(uiBlock *block, /* for passing inputs to ButO buttons */ struct PointerRNA *UI_but_operator_ptr_get(uiBut *but); +struct bContextStore *UI_but_context_get(const uiBut *but); + void UI_but_unit_type_set(uiBut *but, int unit_type); int UI_but_unit_type_get(const uiBut *but); diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index a3f39e1286e..0a28b1cafe1 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -15,12 +15,12 @@ * * The Original Code is Copyright (C) 2008 Blender Foundation. * All rights reserved. - * Generic 2d view with should allow drawing grids, - * panning, zooming, scrolling, .. */ /** \file * \ingroup editorui + * Generic 2D view with should allow drawing grids, + * panning, zooming, scrolling, .. etc. */ #pragma once diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 636281ba373..2292bf759b7 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -5928,6 +5928,11 @@ PointerRNA *UI_but_operator_ptr_get(uiBut *but) return but->opptr; } +bContextStore *UI_but_context_get(const uiBut *but) +{ + return but->context; +} + void UI_but_unit_type_set(uiBut *but, const int unit_type) { but->unit_type = (uchar)(RNA_SUBTYPE_UNIT_VALUE(unit_type)); diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index fd03cc5e12c..6fa94730365 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -25,6 +25,7 @@ #include "DNA_space_types.h" #include "BLI_math_color.h" +#include "BLI_math_vector.h" #include "BKE_context.h" #include "BKE_screen.h" @@ -107,7 +108,7 @@ wmKeyMap *eyedropper_colorband_modal_keymap(wmKeyConfig *keyconf) /** \name Generic Shared Functions * \{ */ -static void eyedropper_draw_cursor_text_ex(const int x, const int y, const char *name) +static void eyedropper_draw_cursor_text_ex(const int xy[2], const char *name) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; @@ -119,7 +120,7 @@ static void eyedropper_draw_cursor_text_ex(const int x, const int y, const char rgba_uchar_to_float(col_fg, wcol->text); rgba_uchar_to_float(col_bg, wcol->inner); - UI_fontstyle_draw_simple_backdrop(fstyle, x, y + U.widget_unit, name, col_fg, col_bg); + UI_fontstyle_draw_simple_backdrop(fstyle, xy[0], xy[1] + U.widget_unit, name, col_fg, col_bg); } void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name) @@ -128,19 +129,16 @@ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const cha return; } - const int x = window->eventstate->xy[0]; - const int y = window->eventstate->xy[1]; - - eyedropper_draw_cursor_text_ex(x, y, name); + eyedropper_draw_cursor_text_ex(window->eventstate->xy, name); } -void eyedropper_draw_cursor_text_region(const int x, const int y, const char *name) +void eyedropper_draw_cursor_text_region(const int xy[2], const char *name) { if (name[0] == '\0') { return; } - eyedropper_draw_cursor_text_ex(x, y, name); + eyedropper_draw_cursor_text_ex(xy, name); } uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event) @@ -173,8 +171,7 @@ void datadropper_win_area_find( } } else if (mval != r_mval) { - r_mval[0] = mval[0]; - r_mval[1] = mval[1]; + copy_v2_v2_int(r_mval, mval); } } diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c index 05840175fab..b5eed2534a3 100644 --- a/source/blender/editors/interface/interface_eyedropper_color.c +++ b/source/blender/editors/interface/interface_eyedropper_color.c @@ -254,8 +254,10 @@ static bool eyedropper_cryptomatte_sample_image_fl(const bNode *node, return success; } -static bool eyedropper_cryptomatte_sample_fl( - bContext *C, Eyedropper *eye, int mx, int my, float r_col[3]) +static bool eyedropper_cryptomatte_sample_fl(bContext *C, + Eyedropper *eye, + const int m_xy[2], + float r_col[3]) { bNode *node = eye->crypto_node; NodeCryptomatte *crypto = node ? ((NodeCryptomatte *)node->storage) : NULL; @@ -265,17 +267,17 @@ static bool eyedropper_cryptomatte_sample_fl( } bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, (const int[2]){mx, my}); + ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, m_xy); if (!area || !ELEM(area->spacetype, SPACE_IMAGE, SPACE_NODE, SPACE_CLIP)) { return false; } - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, (const int[2]){mx, my}); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, m_xy); if (!region) { return false; } - int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + int mval[2] = {m_xy[0] - region->winrct.xmin, m_xy[1] - region->winrct.ymin}; float fpos[2] = {-1.0f, -1.0}; switch (area->spacetype) { case SPACE_IMAGE: { @@ -324,7 +326,7 @@ static bool eyedropper_cryptomatte_sample_fl( return false; } -void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]) +void eyedropper_color_sample_fl(bContext *C, const int m_xy[2], float r_col[3]) { /* we could use some clever */ Main *bmain = CTX_data_main(C); @@ -332,10 +334,10 @@ void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]) const char *display_device = CTX_data_scene(C)->display_settings.display_device; struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device); + int mval[2]; wmWindow *win; ScrArea *area; - int mval[2] = {mx, my}; - datadropper_win_area_find(C, mval, mval, &win, &area); + datadropper_win_area_find(C, m_xy, mval, &win, &area); if (area) { if (area->spacetype == SPACE_IMAGE) { @@ -406,17 +408,17 @@ static void eyedropper_color_set(bContext *C, Eyedropper *eye, const float col[3 RNA_property_update(C, &eye->ptr, eye->prop); } -static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my) +static void eyedropper_color_sample(bContext *C, Eyedropper *eye, const int m_xy[2]) { /* Accumulate color. */ float col[3]; if (eye->crypto_node) { - if (!eyedropper_cryptomatte_sample_fl(C, eye, mx, my, col)) { + if (!eyedropper_cryptomatte_sample_fl(C, eye, m_xy, col)) { return; } } else { - eyedropper_color_sample_fl(C, mx, my, col); + eyedropper_color_sample_fl(C, m_xy, col); } if (!eye->crypto_node) { @@ -439,13 +441,13 @@ static void eyedropper_color_sample(bContext *C, Eyedropper *eye, int mx, int my eyedropper_color_set(C, eye, accum_col); } -static void eyedropper_color_sample_text_update(bContext *C, Eyedropper *eye, int mx, int my) +static void eyedropper_color_sample_text_update(bContext *C, Eyedropper *eye, const int m_xy[2]) { float col[3]; eye->sample_text[0] = '\0'; if (eye->cryptomatte_session) { - if (eyedropper_cryptomatte_sample_fl(C, eye, mx, my, col)) { + if (eyedropper_cryptomatte_sample_fl(C, eye, m_xy, col)) { BKE_cryptomatte_find_name( eye->cryptomatte_session, col[0], eye->sample_text, sizeof(eye->sample_text)); eye->sample_text[sizeof(eye->sample_text) - 1] = '\0'; @@ -476,7 +478,7 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) case EYE_MODAL_SAMPLE_CONFIRM: { const bool is_undo = eye->is_undo; if (eye->accum_tot == 0) { - eyedropper_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_color_sample(C, eye, event->xy); } eyedropper_exit(C, op); /* Could support finished & undo-skip. */ @@ -485,23 +487,23 @@ static int eyedropper_modal(bContext *C, wmOperator *op, const wmEvent *event) case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ eye->accum_start = true; - eyedropper_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_color_sample(C, eye, event->xy); break; case EYE_MODAL_SAMPLE_RESET: eye->accum_tot = 0; zero_v3(eye->accum_col); - eyedropper_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_color_sample(C, eye, event->xy); break; } } else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { if (eye->accum_start) { /* button is pressed so keep sampling */ - eyedropper_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_color_sample(C, eye, event->xy); } if (eye->draw_handle_sample_text) { - eyedropper_color_sample_text_update(C, eye, event->xy[0], event->xy[1]); + eyedropper_color_sample_text_update(C, eye, event->xy); ED_region_tag_redraw(CTX_wm_region(C)); } } diff --git a/source/blender/editors/interface/interface_eyedropper_colorband.c b/source/blender/editors/interface/interface_eyedropper_colorband.c index 22320282766..05ed4ecf601 100644 --- a/source/blender/editors/interface/interface_eyedropper_colorband.c +++ b/source/blender/editors/interface/interface_eyedropper_colorband.c @@ -58,7 +58,7 @@ typedef struct Colorband_RNAUpdateCb { } Colorband_RNAUpdateCb; typedef struct EyedropperColorband { - int last_x, last_y; + int event_xy_last[2]; /* Alpha is currently fixed at 1.0, may support in future. */ float (*color_buffer)[4]; int color_buffer_alloc; @@ -142,13 +142,12 @@ static bool eyedropper_colorband_init(bContext *C, wmOperator *op) static void eyedropper_colorband_sample_point(bContext *C, EyedropperColorband *eye, - int mx, - int my) + const int m_xy[2]) { - if (eye->last_x != mx || eye->last_y != my) { + if (eye->event_xy_last[0] != m_xy[0] || eye->event_xy_last[1] != m_xy[1]) { float col[4]; col[3] = 1.0f; /* TODO: sample alpha */ - eyedropper_color_sample_fl(C, mx, my, col); + eyedropper_color_sample_fl(C, m_xy, col); if (eye->color_buffer_len + 1 == eye->color_buffer_alloc) { eye->color_buffer_alloc *= 2; eye->color_buffer = MEM_reallocN(eye->color_buffer, @@ -156,8 +155,7 @@ static void eyedropper_colorband_sample_point(bContext *C, } copy_v4_v4(eye->color_buffer[eye->color_buffer_len], col); eye->color_buffer_len += 1; - eye->last_x = mx; - eye->last_y = my; + copy_v2_v2_int(eye->event_xy_last, m_xy); eye->is_set = true; } } @@ -167,21 +165,20 @@ static bool eyedropper_colorband_sample_callback(int mx, int my, void *userdata) struct EyedropperColorband_Context *data = userdata; bContext *C = data->context; EyedropperColorband *eye = data->eye; - eyedropper_colorband_sample_point(C, eye, mx, my); + const int cursor[2] = {mx, my}; + eyedropper_colorband_sample_point(C, eye, cursor); return true; } static void eyedropper_colorband_sample_segment(bContext *C, EyedropperColorband *eye, - int mx, - int my) + const int m_xy[2]) { /* Since the mouse tends to move rather rapidly we use #BLI_bitmap_draw_2d_line_v2v2i * to interpolate between the reported coordinates */ struct EyedropperColorband_Context userdata = {C, eye}; - const int p1[2] = {eye->last_x, eye->last_y}; - const int p2[2] = {mx, my}; - BLI_bitmap_draw_2d_line_v2v2i(p1, p2, eyedropper_colorband_sample_callback, &userdata); + BLI_bitmap_draw_2d_line_v2v2i( + eye->event_xy_last, m_xy, eyedropper_colorband_sample_callback, &userdata); } static void eyedropper_colorband_exit(bContext *C, wmOperator *op) @@ -233,7 +230,7 @@ static int eyedropper_colorband_modal(bContext *C, wmOperator *op, const wmEvent return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: { const bool is_undo = eye->is_undo; - eyedropper_colorband_sample_segment(C, eye, event->xy[0], event->xy[1]); + eyedropper_colorband_sample_segment(C, eye, event->xy); eyedropper_colorband_apply(C, op); eyedropper_colorband_exit(C, op); /* Could support finished & undo-skip. */ @@ -242,10 +239,9 @@ static int eyedropper_colorband_modal(bContext *C, wmOperator *op, const wmEvent case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ eye->sample_start = true; - eyedropper_colorband_sample_point(C, eye, event->xy[0], event->xy[1]); + eyedropper_colorband_sample_point(C, eye, event->xy); eyedropper_colorband_apply(C, op); - eye->last_x = event->xy[0]; - eye->last_y = event->xy[1]; + copy_v2_v2_int(eye->event_xy_last, event->xy); break; case EYE_MODAL_SAMPLE_RESET: break; @@ -253,7 +249,7 @@ static int eyedropper_colorband_modal(bContext *C, wmOperator *op, const wmEvent } else if (event->type == MOUSEMOVE) { if (eye->sample_start) { - eyedropper_colorband_sample_segment(C, eye, event->xy[0], event->xy[1]); + eyedropper_colorband_sample_segment(C, eye, event->xy); eyedropper_colorband_apply(C, op); } } @@ -280,7 +276,7 @@ static int eyedropper_colorband_point_modal(bContext *C, wmOperator *op, const w } break; case EYE_MODAL_POINT_SAMPLE: - eyedropper_colorband_sample_point(C, eye, event->xy[0], event->xy[1]); + eyedropper_colorband_sample_point(C, eye, event->xy); eyedropper_colorband_apply(C, op); if (eye->color_buffer_len == MAXCOLORBAND) { eyedropper_colorband_exit(C, op); diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c index cf53ef0ec75..812011101e8 100644 --- a/source/blender/editors/interface/interface_eyedropper_datablock.c +++ b/source/blender/editors/interface/interface_eyedropper_datablock.c @@ -32,6 +32,7 @@ #include "DNA_screen_types.h" #include "DNA_space_types.h" +#include "BLI_math_vector.h" #include "BLI_string.h" #include "BLT_translation.h" @@ -80,7 +81,7 @@ static void datadropper_draw_cb(const struct bContext *UNUSED(C), void *arg) { DataDropper *ddr = arg; - eyedropper_draw_cursor_text_region(UNPACK2(ddr->name_pos), ddr->name); + eyedropper_draw_cursor_text_region(ddr->name_pos, ddr->name); } static int datadropper_init(bContext *C, wmOperator *op) @@ -152,7 +153,7 @@ static void datadropper_exit(bContext *C, wmOperator *op) * \brief get the ID from the 3D view or outliner. */ static void datadropper_id_sample_pt( - bContext *C, wmWindow *win, ScrArea *area, DataDropper *ddr, int mx, int my, ID **r_id) + bContext *C, wmWindow *win, ScrArea *area, DataDropper *ddr, const int m_xy[2], ID **r_id) { wmWindow *win_prev = CTX_wm_window(C); ScrArea *area_prev = CTX_wm_area(C); @@ -162,9 +163,9 @@ static void datadropper_id_sample_pt( if (area) { if (ELEM(area->spacetype, SPACE_VIEW3D, SPACE_OUTLINER)) { - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, (const int[2]){mx, my}); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, m_xy); if (region) { - const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + const int mval[2] = {m_xy[0] - region->winrct.xmin, m_xy[1] - region->winrct.ymin}; Base *base; CTX_wm_window_set(C, win); @@ -205,8 +206,7 @@ static void datadropper_id_sample_pt( *r_id = id; } - ddr->name_pos[0] = mval[0]; - ddr->name_pos[1] = mval[1]; + copy_v2_v2_int(ddr->name_pos, mval); } } } @@ -234,17 +234,16 @@ static bool datadropper_id_set(bContext *C, DataDropper *ddr, ID *id) } /* single point sample & set */ -static bool datadropper_id_sample(bContext *C, DataDropper *ddr, int mx, int my) +static bool datadropper_id_sample(bContext *C, DataDropper *ddr, const int m_xy[2]) { ID *id = NULL; + int mval[2]; wmWindow *win; ScrArea *area; + datadropper_win_area_find(C, m_xy, mval, &win, &area); - int mval[] = {mx, my}; - datadropper_win_area_find(C, mval, mval, &win, &area); - - datadropper_id_sample_pt(C, win, area, ddr, mval[0], mval[1], &id); + datadropper_id_sample_pt(C, win, area, ddr, mval, &id); return datadropper_id_set(C, ddr, id); } @@ -292,7 +291,7 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; case EYE_MODAL_SAMPLE_CONFIRM: { const bool is_undo = ddr->is_undo; - const bool success = datadropper_id_sample(C, ddr, event->xy[0], event->xy[1]); + const bool success = datadropper_id_sample(C, ddr, event->xy); datadropper_exit(C, op); if (success) { /* Could support finished & undo-skip. */ @@ -306,16 +305,15 @@ static int datadropper_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (event->type == MOUSEMOVE) { ID *id = NULL; + int mval[2]; wmWindow *win; ScrArea *area; - - int mval[] = {event->xy[0], event->xy[1]}; - datadropper_win_area_find(C, mval, mval, &win, &area); + datadropper_win_area_find(C, event->xy, mval, &win, &area); /* Set the region for eyedropper cursor text drawing */ datadropper_set_draw_callback_region(area, ddr); - datadropper_id_sample_pt(C, win, area, ddr, mval[0], mval[1], &id); + datadropper_id_sample_pt(C, win, area, ddr, mval, &id); } return OPERATOR_RUNNING_MODAL; diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index 8c6b0ac9cfe..b11001c4bf2 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -81,7 +81,7 @@ static void depthdropper_draw_cb(const struct bContext *UNUSED(C), void *arg) { DepthDropper *ddr = arg; - eyedropper_draw_cursor_text_region(UNPACK2(ddr->name_pos), ddr->name); + eyedropper_draw_cursor_text_region(ddr->name_pos, ddr->name); } static int depthdropper_init(bContext *C, wmOperator *op) @@ -152,12 +152,14 @@ static void depthdropper_exit(bContext *C, wmOperator *op) /** * \brief get the ID from the screen. */ -static void depthdropper_depth_sample_pt( - bContext *C, DepthDropper *ddr, int mx, int my, float *r_depth) +static void depthdropper_depth_sample_pt(bContext *C, + DepthDropper *ddr, + const int m_xy[2], + float *r_depth) { /* we could use some clever */ bScreen *screen = CTX_wm_screen(C); - ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, (const int[2]){mx, my}); + ScrArea *area = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, m_xy); Scene *scene = CTX_data_scene(C); ScrArea *area_prev = CTX_wm_area(C); @@ -167,14 +169,14 @@ static void depthdropper_depth_sample_pt( if (area) { if (area->spacetype == SPACE_VIEW3D) { - ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, (const int[2]){mx, my}); + ARegion *region = BKE_area_find_region_xy(area, RGN_TYPE_WINDOW, m_xy); if (region) { struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); View3D *v3d = area->spacedata.first; RegionView3D *rv3d = region->regiondata; /* weak, we could pass in some reference point */ const float *view_co = v3d->camera ? v3d->camera->obmat[3] : rv3d->viewinv[3]; - const int mval[2] = {mx - region->winrct.xmin, my - region->winrct.ymin}; + const int mval[2] = {m_xy[0] - region->winrct.xmin, m_xy[1] - region->winrct.ymin}; copy_v2_v2_int(ddr->name_pos, mval); float co[3]; @@ -234,19 +236,19 @@ static void depthdropper_depth_set_accum(bContext *C, DepthDropper *ddr) } /* single point sample & set */ -static void depthdropper_depth_sample(bContext *C, DepthDropper *ddr, int mx, int my) +static void depthdropper_depth_sample(bContext *C, DepthDropper *ddr, const int m_xy[2]) { float depth = -1.0f; if (depth != -1.0f) { - depthdropper_depth_sample_pt(C, ddr, mx, my, &depth); + depthdropper_depth_sample_pt(C, ddr, m_xy, &depth); depthdropper_depth_set(C, ddr, depth); } } -static void depthdropper_depth_sample_accum(bContext *C, DepthDropper *ddr, int mx, int my) +static void depthdropper_depth_sample_accum(bContext *C, DepthDropper *ddr, const int m_xy[2]) { float depth = -1.0f; - depthdropper_depth_sample_pt(C, ddr, mx, my, &depth); + depthdropper_depth_sample_pt(C, ddr, m_xy, &depth); if (depth != -1.0f) { ddr->accum_depth += depth; ddr->accum_tot++; @@ -276,7 +278,7 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) case EYE_MODAL_SAMPLE_CONFIRM: { const bool is_undo = ddr->is_undo; if (ddr->accum_tot == 0) { - depthdropper_depth_sample(C, ddr, event->xy[0], event->xy[1]); + depthdropper_depth_sample(C, ddr, event->xy); } else { depthdropper_depth_set_accum(C, ddr); @@ -288,12 +290,12 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) case EYE_MODAL_SAMPLE_BEGIN: /* enable accum and make first sample */ ddr->accum_start = true; - depthdropper_depth_sample_accum(C, ddr, event->xy[0], event->xy[1]); + depthdropper_depth_sample_accum(C, ddr, event->xy); break; case EYE_MODAL_SAMPLE_RESET: ddr->accum_tot = 0; ddr->accum_depth = 0.0f; - depthdropper_depth_sample_accum(C, ddr, event->xy[0], event->xy[1]); + depthdropper_depth_sample_accum(C, ddr, event->xy); depthdropper_depth_set_accum(C, ddr); break; } @@ -301,7 +303,7 @@ static int depthdropper_modal(bContext *C, wmOperator *op, const wmEvent *event) else if (event->type == MOUSEMOVE) { if (ddr->accum_start) { /* button is pressed so keep sampling */ - depthdropper_depth_sample_accum(C, ddr, event->xy[0], event->xy[1]); + depthdropper_depth_sample_accum(C, ddr, event->xy); depthdropper_depth_set_accum(C, ddr); } } diff --git a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c index d76ff84bcad..c1d49406818 100644 --- a/source/blender/editors/interface/interface_eyedropper_gpencil_color.c +++ b/source/blender/editors/interface/interface_eyedropper_gpencil_color.c @@ -265,9 +265,9 @@ static void eyedropper_gpencil_color_set(bContext *C, const wmEvent *event, Eyed } /* Sample the color below cursor. */ -static void eyedropper_gpencil_color_sample(bContext *C, EyedropperGPencil *eye, int mx, int my) +static void eyedropper_gpencil_color_sample(bContext *C, EyedropperGPencil *eye, const int m_xy[2]) { - eyedropper_color_sample_fl(C, mx, my, eye->color); + eyedropper_color_sample_fl(C, m_xy, eye->color); } /* Cancel operator. */ @@ -292,7 +292,7 @@ static int eyedropper_gpencil_modal(bContext *C, wmOperator *op, const wmEvent * return OPERATOR_CANCELLED; } case EYE_MODAL_SAMPLE_CONFIRM: { - eyedropper_gpencil_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_gpencil_color_sample(C, eye, event->xy); /* Create material. */ eyedropper_gpencil_color_set(C, event, eye); @@ -309,7 +309,7 @@ static int eyedropper_gpencil_modal(bContext *C, wmOperator *op, const wmEvent * } case MOUSEMOVE: case INBETWEEN_MOUSEMOVE: { - eyedropper_gpencil_color_sample(C, eye, event->xy[0], event->xy[1]); + eyedropper_gpencil_color_sample(C, eye, event->xy); break; } default: { diff --git a/source/blender/editors/interface/interface_eyedropper_intern.h b/source/blender/editors/interface/interface_eyedropper_intern.h index ec448ef9b9f..335ee520791 100644 --- a/source/blender/editors/interface/interface_eyedropper_intern.h +++ b/source/blender/editors/interface/interface_eyedropper_intern.h @@ -25,7 +25,7 @@ /* interface_eyedropper.c */ void eyedropper_draw_cursor_text_window(const struct wmWindow *window, const char *name); -void eyedropper_draw_cursor_text_region(int x, int y, const char *name); +void eyedropper_draw_cursor_text_region(const int xy[2], const char *name); /** * Utility to retrieve a button representing a RNA property that is currently under the cursor. * @@ -51,7 +51,7 @@ void datadropper_win_area_find(const struct bContext *C, * * \note Exposed by 'interface_eyedropper_intern.h' for use with color band picking. */ -void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3]); +void eyedropper_color_sample_fl(bContext *C, const int m_xy[2], float r_col[3]); /* Used for most eye-dropper operators. */ enum { diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 905fd452b6c..a171160d020 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -3957,7 +3957,14 @@ static void ui_do_but_textedit( ui_textedit_delete_selection(but, data); } if (event->type == WM_IME_COMPOSITE_EVENT && ime_data->result_len) { - ui_textedit_insert_buf(but, data, ime_data->str_result, ime_data->result_len); + if (ELEM(but->type, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER) && + strcmp(ime_data->str_result, "\xE3\x80\x82") == 0) { + /* Convert Ideographic Full Stop (U+3002) to decimal point when entering numbers. */ + ui_textedit_insert_ascii(but, data, '.'); + } + else { + ui_textedit_insert_buf(but, data, ime_data->str_result, ime_data->result_len); + } } } else if (event->type == WM_IME_COMPOSITE_END) { diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index c0d6b8a1a6c..d7d3288a68d 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -2335,8 +2335,8 @@ int UI_icon_from_idcode(const int idcode) return ICON_TEXT; case ID_VF: return ICON_FONT_DATA; - case ID_HA: - return ICON_HAIR_DATA; + case ID_CV: + return ICON_CURVES_DATA; case ID_PT: return ICON_POINTCLOUD_DATA; case ID_VO: diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index 33c6e382f50..260e3dabc25 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -2073,8 +2073,9 @@ static void UI_OT_tree_view_drop(wmOperatorType *ot) /** \name UI Tree-View Item Rename Operator * * General purpose renaming operator for tree-views. Thanks to this, to add a rename button to - * context menus for example, tree-view API users don't have to implement own renaming operators - * with the same logic as they already have for their #ui::AbstractTreeViewItem::rename() override. + * context menus for example, tree-view API users don't have to implement their own renaming + * operators with the same logic as they already have for their #ui::AbstractTreeViewItem::rename() + * override. * * \{ */ diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 44942d508ca..bf3fa6e62d4 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -39,9 +39,8 @@ #include "BKE_global.h" #include "BLF_api.h" -#ifdef WITH_INTERNATIONAL -# include "BLT_translation.h" -#endif + +#include "BLT_translation.h" #include "UI_interface.h" @@ -454,15 +453,6 @@ void uiStyleInit(void) printf("%s: error, no fonts available\n", __func__); } } - else { - /* ? just for speed to initialize? - * Yes, this build the glyph cache and create - * the texture. - */ - BLF_size(font->blf_id, 11.0f * U.pixelsize, U.dpi); - BLF_size(font->blf_id, 12.0f * U.pixelsize, U.dpi); - BLF_size(font->blf_id, 14.0f * U.pixelsize, U.dpi); - } } if (style == NULL) { @@ -486,8 +476,6 @@ void uiStyleInit(void) blf_mono_font = BLF_load_mono_default(unique); } - BLF_size(blf_mono_font, 12.0f * U.pixelsize, 72); - /* Set default flags based on UI preferences (not render fonts) */ { const int flag_disable = (BLF_MONOCHROME | BLF_HINTING_NONE | BLF_HINTING_SLIGHT | @@ -530,8 +518,6 @@ void uiStyleInit(void) const bool unique = true; blf_mono_font_render = BLF_load_mono_default(unique); } - - BLF_size(blf_mono_font_render, 12.0f * U.pixelsize, 72); } void UI_fontstyle_set(const uiFontStyle *fs) diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 8330f8c0db7..03d0cba5ec8 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -667,6 +667,13 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event) /* Assign new pointer, takes care of updates/notifiers */ RNA_id_pointer_create(override_id, &idptr); + /* Insert into override hierarchy if possible. */ + ID *owner_id = template_ui->ptr.owner_id; + if (owner_id != NULL && ID_IS_OVERRIDE_LIBRARY_REAL(owner_id)) { + override_id->override_library->hierarchy_root = + owner_id->override_library->hierarchy_root; + owner_id->override_library->flag &= ~IDOVERRIDE_LIBRARY_FLAG_NO_HIERARCHY; + } } undo_push_label = "Make Library Override"; } @@ -792,8 +799,8 @@ static const char *template_id_browse_tip(const StructRNA *type) return N_("Browse Workspace to be linked"); case ID_LP: return N_("Browse LightProbe to be linked"); - case ID_HA: - return N_("Browse Hair Data to be linked"); + case ID_CV: + return N_("Browse Hair Curves Data to be linked"); case ID_PT: return N_("Browse Point Cloud Data to be linked"); case ID_VO: @@ -874,7 +881,7 @@ static uiBut *template_id_def_new_but(uiBlock *block, BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, BLT_I18NCONTEXT_ID_WORKSPACE, BLT_I18NCONTEXT_ID_LIGHTPROBE, - BLT_I18NCONTEXT_ID_HAIR, + BLT_I18NCONTEXT_ID_CURVES, BLT_I18NCONTEXT_ID_POINTCLOUD, BLT_I18NCONTEXT_ID_VOLUME, BLT_I18NCONTEXT_ID_SIMULATION, ); @@ -2672,18 +2679,6 @@ static void constraint_ops_extra_draw(bContext *C, uiLayout *layout, void *con_v static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *con) { - bPoseChannel *pchan = BKE_pose_channel_active_if_layer_visible(ob); - short proxy_protected, xco = 0, yco = 0; - // int rb_col; // UNUSED - - /* determine whether constraint is proxy protected or not */ - if (BKE_constraints_proxylocked_owner(ob, pchan)) { - proxy_protected = (con->flag & CONSTRAINT_PROXY_LOCAL) == 0; - } - else { - proxy_protected = 0; - } - /* unless button has own callback, it adds this callback to button */ uiBlock *block = uiLayoutGetBlock(layout); UI_block_func_set(block, constraint_active_func, ob, con); @@ -2708,72 +2703,23 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co uiLayout *row = uiLayoutRow(layout, true); - if (proxy_protected == 0) { - uiItemR(row, &ptr, "name", 0, "", ICON_NONE); - } - else { - uiItemL(row, IFACE_(con->name), ICON_NONE); - } + uiItemR(row, &ptr, "name", 0, "", ICON_NONE); - /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */ - if (proxy_protected) { - UI_block_emboss_set(block, UI_EMBOSS_NONE); + /* Enabled eye icon. */ + uiItemR(row, &ptr, "enabled", 0, "", ICON_NONE); - /* draw a ghost icon (for proxy) and also a lock beside it, - * to show that constraint is "proxy locked" */ - uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_GHOST_ENABLED, - xco + 12.2f * UI_UNIT_X, - yco, - 0.95f * UI_UNIT_X, - 0.95f * UI_UNIT_Y, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - TIP_("Proxy Protected")); - uiDefIconBut(block, - UI_BTYPE_BUT, - 0, - ICON_LOCKED, - xco + 13.1f * UI_UNIT_X, - yco, - 0.95f * UI_UNIT_X, - 0.95f * UI_UNIT_Y, - NULL, - 0.0, - 0.0, - 0.0, - 0.0, - TIP_("Proxy Protected")); - - UI_block_emboss_set(block, UI_EMBOSS); - } - else { - /* Enabled eye icon. */ - uiItemR(row, &ptr, "enabled", 0, "", ICON_NONE); - - /* Extra operators menu. */ - uiItemMenuF(row, "", ICON_DOWNARROW_HLT, constraint_ops_extra_draw, con); + /* Extra operators menu. */ + uiItemMenuF(row, "", ICON_DOWNARROW_HLT, constraint_ops_extra_draw, con); - /* Close 'button' - emboss calls here disable drawing of 'button' behind X */ - sub = uiLayoutRow(row, false); - uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); - uiLayoutSetOperatorContext(sub, WM_OP_INVOKE_DEFAULT); - uiItemO(sub, "", ICON_X, "CONSTRAINT_OT_delete"); - } + /* Close 'button' - emboss calls here disable drawing of 'button' behind X */ + sub = uiLayoutRow(row, false); + uiLayoutSetEmboss(sub, UI_EMBOSS_NONE); + uiLayoutSetOperatorContext(sub, WM_OP_INVOKE_DEFAULT); + uiItemO(sub, "", ICON_X, "CONSTRAINT_OT_delete"); /* Some extra padding at the end, so the 'x' icon isn't too close to drag button. */ uiItemS(layout); - /* Set but-locks for protected settings (magic numbers are used here!) */ - if (proxy_protected) { - UI_block_lock_set(block, true, TIP_("Cannot edit Proxy-Protected Constraint")); - } - /* clear any locks set up for proxies/lib-linking */ UI_block_lock_clear(block); } diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index cb1c3cedf8e..5db16354124 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -84,10 +84,6 @@ if(WITH_USD) add_definitions(-DWITH_USD) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_PUGIXML) add_definitions(-DWITH_PUGIXML) endif() diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 4ad2e57d266..0fb64c8a46b 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -78,10 +78,6 @@ set(LIB bf_windowmanager ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 7e05209f79e..8383492e459 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -32,6 +32,7 @@ #include "BLI_math.h" #include "BLI_math_bits.h" #include "BLI_rand.h" +#include "BLI_string.h" #include "BLI_utildefines_stack.h" #include "BKE_context.h" @@ -55,6 +56,8 @@ #include "ED_transform.h" #include "ED_view3d.h" +#include "BLT_translation.h" + #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" #include "DNA_object_types.h" @@ -1389,6 +1392,37 @@ static int edbm_select_mode_invoke(bContext *C, wmOperator *op, const wmEvent *e return edbm_select_mode_exec(C, op); } +static char *edbm_select_mode_get_description(struct bContext *UNUSED(C), + struct wmOperatorType *UNUSED(op), + struct PointerRNA *values) +{ + const int type = RNA_enum_get(values, "type"); + + /* Because the special behavior for shift and ctrl click depend on user input, they may be + * incorrect if the operator is used from a script or from a special button. So only return the + * specialized descriptions if only the "type" is set, which conveys that the operator is meant + * to be used with the logic in the `invoke` method. */ + if (RNA_struct_property_is_set(values, "type") && + !RNA_struct_property_is_set(values, "use_extend") && + !RNA_struct_property_is_set(values, "use_expand") && + !RNA_struct_property_is_set(values, "action")) { + switch (type) { + case SCE_SELECT_VERTEX: + return BLI_strdup(TIP_( + "Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection")); + case SCE_SELECT_EDGE: + return BLI_strdup( + TIP_("Edge select - Shift-Click for multiple modes, " + "Ctrl-Click expands/contracts selection depending on the current mode")); + case SCE_SELECT_FACE: + return BLI_strdup( + TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection")); + } + } + + return NULL; +} + void MESH_OT_select_mode(wmOperatorType *ot) { PropertyRNA *prop; @@ -1409,6 +1443,7 @@ void MESH_OT_select_mode(wmOperatorType *ot) ot->invoke = edbm_select_mode_invoke; ot->exec = edbm_select_mode_exec; ot->poll = ED_operator_editmesh; + ot->get_description = edbm_select_mode_get_description; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; diff --git a/source/blender/editors/mesh/editmesh_select_similar.c b/source/blender/editors/mesh/editmesh_select_similar.c index 949b12f9a65..5ea3c0d7b32 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.c +++ b/source/blender/editors/mesh/editmesh_select_similar.c @@ -68,6 +68,7 @@ static const EnumPropertyItem prop_similar_types[] = { {SIMVERT_FACE, "FACE", 0, "Amount of Adjacent Faces", ""}, {SIMVERT_VGROUP, "VGROUP", 0, "Vertex Groups", ""}, {SIMVERT_EDGE, "EDGE", 0, "Amount of Connecting Edges", ""}, + {SIMVERT_CREASE, "VCREASE", 0, "Vertex Crease", ""}, {SIMEDGE_LENGTH, "LENGTH", 0, "Length", ""}, {SIMEDGE_DIR, "DIR", 0, "Direction", ""}, @@ -1009,12 +1010,16 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } KDTree_3d *tree_3d = NULL; + KDTree_1d *tree_1d = NULL; GSet *gset = NULL; switch (type) { case SIMVERT_NORMAL: tree_3d = BLI_kdtree_3d_new(tot_verts_selected_all); break; + case SIMVERT_CREASE: + tree_1d = BLI_kdtree_1d_new(tot_verts_selected_all); + break; case SIMVERT_EDGE: case SIMVERT_FACE: gset = BLI_gset_ptr_new("Select similar vertex: edge/face"); @@ -1025,6 +1030,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } int normal_tree_index = 0; + int tree_1d_index = 0; for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob = objects[ob_index]; BMEditMesh *em = BKE_editmesh_from_object(ob); @@ -1050,6 +1056,12 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } defbase_selected = BLI_BITMAP_NEW(defbase_len, __func__); } + else if (type == SIMVERT_CREASE) { + if (!CustomData_has_layer(&bm->vdata, CD_CREASE)) { + BLI_kdtree_1d_insert(tree_1d, tree_1d_index++, (float[1]){0.0f}); + continue; + } + } BMVert *vert; /* Mesh vertex. */ BMIter iter; /* Selected verts iterator. */ @@ -1085,6 +1097,11 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } break; } + case SIMVERT_CREASE: { + const float *value = CustomData_bmesh_get(&bm->vdata, vert->head.data, CD_CREASE); + BLI_kdtree_1d_insert(tree_1d, tree_1d_index++, value); + break; + } } } } @@ -1113,6 +1130,10 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } /* Remove duplicated entries. */ + if (tree_1d != NULL) { + BLI_kdtree_1d_deduplicate(tree_1d); + BLI_kdtree_1d_balance(tree_1d); + } if (tree_3d != NULL) { BLI_kdtree_3d_deduplicate(tree_3d); BLI_kdtree_3d_balance(tree_3d); @@ -1124,6 +1145,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) BMEditMesh *em = BKE_editmesh_from_object(ob); BMesh *bm = em->bm; bool changed = false; + bool has_crease_layer = false; int cd_dvert_offset = -1; BLI_bitmap *defbase_selected = NULL; int defbase_len = 0; @@ -1158,6 +1180,17 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) continue; } } + else if (type == SIMVERT_CREASE) { + has_crease_layer = CustomData_has_layer(&bm->vdata, CD_CREASE); + if (!has_crease_layer) { + /* Proceed only if we have to select all the vertices that have custom data value of 0.0f. + * In this case we will just select all the vertices. + * Otherwise continue the for loop. */ + if (!ED_select_similar_compare_float_tree(tree_1d, 0.0f, thresh, compare)) { + continue; + } + } + } BMVert *vert; /* Mesh vertex. */ BMIter iter; /* Selected verts iterator. */ @@ -1224,6 +1257,17 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } break; } + case SIMVERT_CREASE: { + if (!has_crease_layer) { + select = true; + break; + } + const float *value = CustomData_bmesh_get(&bm->vdata, vert->head.data, CD_CREASE); + if (ED_select_similar_compare_float_tree(tree_1d, *value, thresh, compare)) { + select = true; + } + break; + } } if (select) { @@ -1249,6 +1293,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op) } MEM_freeN(objects); + BLI_kdtree_1d_free(tree_1d); BLI_kdtree_3d_free(tree_3d); if (gset != NULL) { BLI_gset_free(gset, NULL); diff --git a/source/blender/editors/metaball/CMakeLists.txt b/source/blender/editors/metaball/CMakeLists.txt index 4e600dc0277..a247920c305 100644 --- a/source/blender/editors/metaball/CMakeLists.txt +++ b/source/blender/editors/metaball/CMakeLists.txt @@ -20,6 +20,7 @@ set(INC ../../blenkernel ../../blenlib ../../depsgraph + ../../gpu ../../makesdna ../../makesrna ../../render diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index bedb9d4f4f4..51cfc920d1d 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -47,6 +47,8 @@ #include "DEG_depsgraph.h" +#include "GPU_select.h" + #include "ED_mball.h" #include "ED_object.h" #include "ED_screen.h" @@ -756,15 +758,19 @@ bool ED_mball_select_pick(bContext *C, const int mval[2], bool extend, bool dese static MetaElem *startelem = NULL; ViewContext vc; int a, hits; - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; rcti rect; ED_view3d_viewcontext_init(C, &vc, depsgraph); BLI_rcti_init_pt_radius(&rect, mval, 12); - hits = view3d_opengl_select( - &vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST, VIEW3D_SELECT_FILTER_NOP); + hits = view3d_opengl_select(&vc, + buffer, + ARRAY_SIZE(buffer), + &rect, + VIEW3D_SELECT_PICK_NEAREST, + VIEW3D_SELECT_FILTER_NOP); FOREACH_BASE_IN_EDIT_MODE_BEGIN (vc.view_layer, vc.v3d, base) { ED_view3d_viewcontext_init_object(&vc, base->object); @@ -789,7 +795,7 @@ bool ED_mball_select_pick(bContext *C, const int mval[2], bool extend, bool dese ml = startelem; while (ml) { for (a = 0; a < hits; a++) { - int hitresult = buffer[(4 * a) + 3]; + const int hitresult = buffer[a].id; if (hitresult == -1) { continue; } diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt index 040b5cd5066..df76e605ebb 100644 --- a/source/blender/editors/object/CMakeLists.txt +++ b/source/blender/editors/object/CMakeLists.txt @@ -85,14 +85,10 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_EXPERIMENTAL_FEATURES) add_definitions(-DWITH_SIMULATION_DATABLOCK) add_definitions(-DWITH_POINT_CLOUD) - add_definitions(-DWITH_HAIR_NODES) + add_definitions(-DWITH_NEW_CURVES_TYPE) endif() blender_add_lib(bf_editor_object "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index 8a493eb0743..d1deb6824ea 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -62,6 +62,7 @@ #include "BKE_constraint.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_curves.h" #include "BKE_displist.h" #include "BKE_duplilist.h" #include "BKE_effect.h" @@ -69,7 +70,6 @@ #include "BKE_gpencil_curve.h" #include "BKE_gpencil_geom.h" #include "BKE_gpencil_modifier.h" -#include "BKE_hair.h" #include "BKE_key.h" #include "BKE_lattice.h" #include "BKE_layer.h" @@ -1894,18 +1894,18 @@ void OBJECT_OT_speaker_add(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Add Hair Operator +/** \name Add Hair Curves Operator * \{ */ -static bool object_hair_add_poll(bContext *C) +static bool object_hair_curves_add_poll(bContext *C) { - if (!U.experimental.use_new_hair_type) { + if (!U.experimental.use_new_curves_type) { return false; } return ED_operator_objectmode(C); } -static int object_hair_add_exec(bContext *C, wmOperator *op) +static int object_hair_curves_add_exec(bContext *C, wmOperator *op) { ushort local_view_bits; float loc[3], rot[3]; @@ -1913,22 +1913,22 @@ static int object_hair_add_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - Object *object = ED_object_add_type(C, OB_HAIR, NULL, loc, rot, false, local_view_bits); + Object *object = ED_object_add_type(C, OB_CURVES, NULL, loc, rot, false, local_view_bits); object->dtx |= OB_DRAWBOUNDOX; /* TODO: remove once there is actual drawing. */ return OPERATOR_FINISHED; } -void OBJECT_OT_hair_add(wmOperatorType *ot) +void OBJECT_OT_hair_curves_add(wmOperatorType *ot) { /* identifiers */ - ot->name = "Add Hair"; - ot->description = "Add a hair object to the scene"; - ot->idname = "OBJECT_OT_hair_add"; + ot->name = "Add Hair Curves"; + ot->description = "Add a hair curves object to the scene"; + ot->idname = "OBJECT_OT_hair_curves_add"; /* api callbacks */ - ot->exec = object_hair_add_exec; - ot->poll = object_hair_add_poll; + ot->exec = object_hair_curves_add_exec; + ot->poll = object_hair_curves_add_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -2347,11 +2347,6 @@ static void make_object_duplilist_real(bContext *C, BKE_animdata_free(&ob_dst->id, true); ob_dst->adt = NULL; - /* Proxies are not to be copied. */ - ob_dst->proxy_from = NULL; - ob_dst->proxy_group = NULL; - ob_dst->proxy = NULL; - ob_dst->parent = NULL; BKE_constraints_free(&ob_dst->constraints); ob_dst->runtime.curve_cache = NULL; @@ -2466,13 +2461,6 @@ static void make_object_duplilist_real(bContext *C, } if (base->object->transflag & OB_DUPLICOLLECTION && base->object->instance_collection) { - LISTBASE_FOREACH (Object *, ob, &bmain->objects) { - if (ob->proxy_group == base->object) { - ob->proxy = NULL; - ob->proxy_from = NULL; - DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); - } - } base->object->instance_collection = NULL; } diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 91a512ae8e9..7ef17689912 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -1356,15 +1356,6 @@ void ED_object_constraint_update(Main *bmain, Object *ob) static void object_pose_tag_update(Main *bmain, Object *ob) { BKE_pose_tag_recalc(bmain, ob->pose); /* Checks & sort pose channels. */ - if (ob->proxy && ob->adt) { - /* We need to make use of ugly #POSE_ANIMATION_WORKAROUND here too, - * else anim data are not reloaded after calling `BKE_pose_rebuild()`, - * which causes T43872. - * Note that this is a bit wide here, since we cannot be sure whether there are some locked - * proxy bones or not. - * XXX Temp hack until new depsgraph hopefully solves this. */ - DEG_id_tag_update(&ob->id, ID_RECALC_ANIMATION); - } } void ED_object_constraint_dependency_update(Main *bmain, Object *ob) @@ -2453,12 +2444,6 @@ static int constraint_add_exec( if ((ob->type == OB_ARMATURE) && (pchan)) { BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */ - if (BKE_constraints_proxylocked_owner(ob, pchan) && ob->adt) { - /* We need to make use of ugly POSE_ANIMATION_WORKAROUND here too, - * else anim data are not reloaded after calling `BKE_pose_rebuild()`, which causes T43872. - * XXX Temp hack until new depsgraph hopefully solves this. */ - DEG_id_tag_update(&ob->id, ID_RECALC_ANIMATION); - } DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY | ID_RECALC_TRANSFORM); } else { diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 595822de1e7..3744cbee3a4 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -43,6 +43,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" #include "RNA_enum_types.h" @@ -610,8 +612,8 @@ static char *data_transfer_get_description(bContext *UNUSED(C), const bool reverse_transfer = RNA_boolean_get(ptr, "use_reverse_transfer"); if (reverse_transfer) { - return BLI_strdup( - "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one"); + return BLI_strdup(TIP_( + "Transfer data layer(s) (weights, edge sharp, etc.) from selected meshes to active one")); } return NULL; diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index d517d68f1fc..ddd44fb9ded 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -65,7 +65,6 @@ void OBJECT_OT_track_set(struct wmOperatorType *ot); void OBJECT_OT_track_clear(struct wmOperatorType *ot); void OBJECT_OT_make_local(struct wmOperatorType *ot); void OBJECT_OT_make_override_library(struct wmOperatorType *ot); -void OBJECT_OT_convert_proxy_to_override(struct wmOperatorType *ot); void OBJECT_OT_make_single_user(struct wmOperatorType *ot); void OBJECT_OT_make_links_scene(struct wmOperatorType *ot); void OBJECT_OT_make_links_data(struct wmOperatorType *ot); @@ -130,7 +129,7 @@ void OBJECT_OT_light_add(struct wmOperatorType *ot); void OBJECT_OT_effector_add(struct wmOperatorType *ot); void OBJECT_OT_camera_add(struct wmOperatorType *ot); void OBJECT_OT_speaker_add(struct wmOperatorType *ot); -void OBJECT_OT_hair_add(struct wmOperatorType *ot); +void OBJECT_OT_hair_curves_add(struct wmOperatorType *ot); void OBJECT_OT_pointcloud_add(struct wmOperatorType *ot); /** * Only used as menu. diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 4ac2a9dca62..af428512cfd 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -53,12 +53,12 @@ #include "BKE_armature.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_curves.h" #include "BKE_displist.h" #include "BKE_editmesh.h" #include "BKE_effect.h" #include "BKE_global.h" #include "BKE_gpencil_modifier.h" -#include "BKE_hair.h" #include "BKE_key.h" #include "BKE_lattice.h" #include "BKE_lib_id.h" @@ -84,6 +84,8 @@ #include "DEG_depsgraph_build.h" #include "DEG_depsgraph_query.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" #include "RNA_enum_types.h" @@ -130,8 +132,8 @@ static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Object * else if (ob->type == OB_GPENCIL) { BKE_gpencil_modifiers_calc(depsgraph, scene_eval, ob_eval); } - else if (ob->type == OB_HAIR) { - BKE_hair_data_update(depsgraph, scene_eval, ob); + else if (ob->type == OB_CURVES) { + BKE_curves_data_update(depsgraph, scene_eval, ob); } else if (ob->type == OB_POINTCLOUD) { BKE_pointcloud_data_update(depsgraph, scene_eval, ob); @@ -1521,7 +1523,7 @@ static char *modifier_apply_as_shapekey_get_description(struct bContext *UNUSED( bool keep = RNA_boolean_get(values, "keep_modifier"); if (keep) { - return BLI_strdup("Apply modifier as a new shapekey and keep it in the stack"); + return BLI_strdup(TIP_("Apply modifier as a new shapekey and keep it in the stack")); } return NULL; diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index b171da42522..a9a429e7e6f 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -75,7 +75,6 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_track_clear); WM_operatortype_append(OBJECT_OT_make_local); WM_operatortype_append(OBJECT_OT_make_override_library); - WM_operatortype_append(OBJECT_OT_convert_proxy_to_override); WM_operatortype_append(OBJECT_OT_make_single_user); WM_operatortype_append(OBJECT_OT_make_links_scene); WM_operatortype_append(OBJECT_OT_make_links_data); @@ -106,7 +105,7 @@ void ED_operatortypes_object(void) WM_operatortype_append(OBJECT_OT_light_add); WM_operatortype_append(OBJECT_OT_camera_add); WM_operatortype_append(OBJECT_OT_speaker_add); - WM_operatortype_append(OBJECT_OT_hair_add); + WM_operatortype_append(OBJECT_OT_hair_curves_add); WM_operatortype_append(OBJECT_OT_pointcloud_add); WM_operatortype_append(OBJECT_OT_volume_add); WM_operatortype_append(OBJECT_OT_volume_import); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index a6eb35d49b9..8678bf9bd92 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -63,11 +63,11 @@ #include "BKE_constraint.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_curves.h" #include "BKE_displist.h" #include "BKE_editmesh.h" #include "BKE_fcurve.h" #include "BKE_gpencil.h" -#include "BKE_hair.h" #include "BKE_idprop.h" #include "BKE_idtype.h" #include "BKE_lattice.h" @@ -1872,7 +1872,7 @@ static void single_obdata_users( ob->data, BKE_id_copy_ex(bmain, ob->data, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS)); break; - case OB_HAIR: + case OB_CURVES: ob->data = ID_NEW_SET( ob->data, BKE_id_copy_ex(bmain, ob->data, NULL, LIB_ID_COPY_DEFAULT | LIB_ID_COPY_ACTIONS)); @@ -2334,7 +2334,7 @@ static int make_override_library_exec(bContext *C, wmOperator *op) BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); const bool success = BKE_lib_override_library_create( - bmain, scene, view_layer, id_root, &obact->id, NULL); + bmain, scene, view_layer, NULL, id_root, &obact->id, NULL); /* Remove the instance empty from this scene, the items now have an overridden collection * instead. */ @@ -2419,63 +2419,6 @@ void OBJECT_OT_make_override_library(wmOperatorType *ot) ot->prop = prop; } -static bool convert_proxy_to_override_poll(bContext *C) -{ - Object *obact = CTX_data_active_object(C); - - return obact != NULL && obact->proxy != NULL; -} - -static int convert_proxy_to_override_exec(bContext *C, wmOperator *op) -{ - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - - BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); - - Object *ob_proxy = CTX_data_active_object(C); - Object *ob_proxy_group = ob_proxy->proxy_group; - const bool is_override_instancing_object = ob_proxy_group != NULL; - - const bool success = BKE_lib_override_library_proxy_convert(bmain, scene, view_layer, ob_proxy); - - if (!success) { - BKE_reportf( - op->reports, - RPT_ERROR_INVALID_INPUT, - "Could not create a library override from proxy '%s' (might use already local data?)", - ob_proxy->id.name + 2); - return OPERATOR_CANCELLED; - } - - /* Remove the instance empty from this scene, the items now have an overridden collection - * instead. */ - if (is_override_instancing_object) { - ED_object_base_free_and_unlink(bmain, scene, ob_proxy_group); - } - - DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS | ID_RECALC_COPY_ON_WRITE); - WM_event_add_notifier(C, NC_WINDOW, NULL); - - return OPERATOR_FINISHED; -} - -void OBJECT_OT_convert_proxy_to_override(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Convert Proxy to Override"; - ot->description = "Convert a proxy to a local library override"; - ot->idname = "OBJECT_OT_convert_proxy_to_override"; - - /* api callbacks */ - ot->exec = convert_proxy_to_override_exec; - ot->poll = convert_proxy_to_override_poll; - - /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -} - /** \} */ /* ------------------------------------------------------------------- */ diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 3e74aaeeb10..ed0f7b2fad0 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -39,6 +39,7 @@ #include "BLI_alloca.h" #include "BLI_array.h" +#include "BLI_bitmap.h" #include "BLI_blenlib.h" #include "BLI_listbase.h" #include "BLI_math.h" @@ -63,6 +64,8 @@ #include "DEG_depsgraph_build.h" #include "DEG_depsgraph_query.h" +#include "BLT_translation.h" + #include "DNA_armature_types.h" #include "RNA_access.h" #include "RNA_define.h" @@ -2464,17 +2467,14 @@ void ED_vgroup_mirror(Object *ob, sel = sel_mirr = true; } - /* tag verts we have used */ - for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) { - mv->flag &= ~ME_VERT_TMP_TAG; - } + BLI_bitmap *vert_tag = BLI_BITMAP_NEW(me->totvert, __func__); for (vidx = 0, mv = me->mvert; vidx < me->totvert; vidx++, mv++) { - if ((mv->flag & ME_VERT_TMP_TAG) == 0) { + if (!BLI_BITMAP_TEST(vert_tag, vidx)) { if ((vidx_mirr = mesh_get_x_mirror_vert(ob, NULL, vidx, use_topology)) != -1) { if (vidx != vidx_mirr) { mv_mirr = &me->mvert[vidx_mirr]; - if ((mv_mirr->flag & ME_VERT_TMP_TAG) == 0) { + if (!BLI_BITMAP_TEST(vert_tag, vidx_mirr)) { if (use_vert_sel) { sel = mv->flag & SELECT; @@ -2489,8 +2489,8 @@ void ED_vgroup_mirror(Object *ob, totmirr++; } - mv->flag |= ME_VERT_TMP_TAG; - mv_mirr->flag |= ME_VERT_TMP_TAG; + BLI_BITMAP_ENABLE(vert_tag, vidx); + BLI_BITMAP_ENABLE(vert_tag, vidx_mirr); } } } @@ -2499,6 +2499,8 @@ void ED_vgroup_mirror(Object *ob, } } } + + MEM_freeN(vert_tag); } } else if (ob->type == OB_LATTICE) { @@ -3427,16 +3429,16 @@ static char *vertex_group_lock_description(struct bContext *UNUSED(C), switch (action) { case VGROUP_LOCK: - action_str = "Lock"; + action_str = TIP_("Lock"); break; case VGROUP_UNLOCK: - action_str = "Unlock"; + action_str = TIP_("Unlock"); break; case VGROUP_TOGGLE: - action_str = "Toggle locks of"; + action_str = TIP_("Toggle locks of"); break; case VGROUP_INVERT: - action_str = "Invert locks of"; + action_str = TIP_("Invert locks of"); break; default: return NULL; @@ -3444,34 +3446,34 @@ static char *vertex_group_lock_description(struct bContext *UNUSED(C), switch (mask) { case VGROUP_MASK_ALL: - target_str = "all"; + target_str = TIP_("all"); break; case VGROUP_MASK_SELECTED: - target_str = "selected"; + target_str = TIP_("selected"); break; case VGROUP_MASK_UNSELECTED: - target_str = "unselected"; + target_str = TIP_("unselected"); break; case VGROUP_MASK_INVERT_UNSELECTED: switch (action) { case VGROUP_INVERT: - target_str = "selected"; + target_str = TIP_("selected"); break; case VGROUP_LOCK: - target_str = "selected and unlock unselected"; + target_str = TIP_("selected and unlock unselected"); break; case VGROUP_UNLOCK: - target_str = "selected and lock unselected"; + target_str = TIP_("selected and lock unselected"); break; default: - target_str = "all and invert unselected"; + target_str = TIP_("all and invert unselected"); } break; default: return NULL; } - return BLI_sprintfN("%s %s vertex groups of the active object", action_str, target_str); + return BLI_sprintfN(TIP_("%s %s vertex groups of the active object"), action_str, target_str); } void OBJECT_OT_vertex_group_lock(wmOperatorType *ot) diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt index a607663763e..7c32a2dcf1d 100644 --- a/source/blender/editors/physics/CMakeLists.txt +++ b/source/blender/editors/physics/CMakeLists.txt @@ -60,10 +60,6 @@ if(WITH_MOD_FLUID) add_definitions(-DWITH_FLUID) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_BULLET) list(APPEND INC ../../../../intern/rigidbody diff --git a/source/blender/editors/render/CMakeLists.txt b/source/blender/editors/render/CMakeLists.txt index 1f867c6f1f7..934badd3b6f 100644 --- a/source/blender/editors/render/CMakeLists.txt +++ b/source/blender/editors/render/CMakeLists.txt @@ -67,8 +67,4 @@ if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_render "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/render/render_internal.cc b/source/blender/editors/render/render_internal.cc index 8e9a052381c..d04e45e4ccb 100644 --- a/source/blender/editors/render/render_internal.cc +++ b/source/blender/editors/render/render_internal.cc @@ -90,7 +90,7 @@ struct RenderJob { Scene *scene; ViewLayer *single_layer; Scene *current_scene; - /* TODO(sergey): Should not be needed once engine will have own + /* TODO(sergey): Should not be needed once engine will have its own * depsgraph and copy-on-write will be implemented. */ Depsgraph *depsgraph; @@ -981,7 +981,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj->scene = scene; rj->current_scene = rj->scene; rj->single_layer = single_layer; - /* TODO(sergey): Render engine should be using own depsgraph. + /* TODO(sergey): Render engine should be using its own depsgraph. * * NOTE: Currently is only used by ED_update_for_newframe() at the end of the render, so no * need to ensure evaluation here. */ diff --git a/source/blender/editors/render/render_opengl.cc b/source/blender/editors/render/render_opengl.cc index 8bd0244c899..fb6742c9fd5 100644 --- a/source/blender/editors/render/render_opengl.cc +++ b/source/blender/editors/render/render_opengl.cc @@ -72,8 +72,11 @@ #include "IMB_colormanagement.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" + #include "RE_pipeline.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -632,7 +635,7 @@ static int gather_frames_to_render_for_id(LibraryIDLinkCallbackData *cb_data) case ID_MC: /* MovieClip */ case ID_MSK: /* Mask */ case ID_LP: /* LightProbe */ - case ID_HA: /* Hair */ + case ID_CV: /* Curves */ case ID_PT: /* PointCloud */ case ID_VO: /* Volume */ case ID_SIM: /* Simulation */ @@ -1326,12 +1329,12 @@ static char *screen_opengl_render_description(struct bContext *UNUSED(C), } if (RNA_boolean_get(ptr, "render_keyed_only")) { - return BLI_strdup( + return BLI_strdup(TIP_( "Render the viewport for the animation range of this scene, but only render keyframes of " - "selected objects"); + "selected objects")); } - return BLI_strdup("Render the viewport for the animation range of this scene"); + return BLI_strdup(TIP_("Render the viewport for the animation range of this scene")); } void RENDER_OT_opengl(wmOperatorType *ot) diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index df078bbd890..c1c75e485f7 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -767,7 +767,7 @@ struct ObjectPreviewData { /* The main for the preview, not of the current file. */ Main *pr_main; /* Copy of the object to create the preview for. The copy is for thread safety (and to insert - * it into an own main). */ + * it into its own main). */ Object *object; /* Current frame. */ int cfra; diff --git a/source/blender/editors/scene/CMakeLists.txt b/source/blender/editors/scene/CMakeLists.txt index cd59f06c6e3..ce0c2062766 100644 --- a/source/blender/editors/scene/CMakeLists.txt +++ b/source/blender/editors/scene/CMakeLists.txt @@ -39,8 +39,5 @@ set(LIB bf_blenlib ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() blender_add_lib(bf_editor_scene "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/screen/CMakeLists.txt b/source/blender/editors/screen/CMakeLists.txt index d194d0cdbb6..7c5ae4dcd5e 100644 --- a/source/blender/editors/screen/CMakeLists.txt +++ b/source/blender/editors/screen/CMakeLists.txt @@ -57,9 +57,5 @@ set(LIB bf_editor_space_sequencer ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_screen "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 152a5c87c78..4af965621e3 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2608,7 +2608,7 @@ typedef struct RegionMoveData { ARegion *region; ScrArea *area; int bigger, smaller, origval; - int origx, origy; + int orig_xy[2]; int maxsize; AZEdge edge; @@ -2716,8 +2716,7 @@ static int region_scale_invoke(bContext *C, wmOperator *op, const wmEvent *event } rmd->area = sad->sa1; rmd->edge = az->edge; - rmd->origx = event->xy[0]; - rmd->origy = event->xy[1]; + copy_v2_v2_int(rmd->orig_xy, event->xy); rmd->maxsize = area_max_regionsize(rmd->area, rmd->region, rmd->edge); /* if not set we do now, otherwise it uses type */ @@ -2804,7 +2803,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) (BLI_rcti_size_x(&rmd->region->v2d.mask) + 1); const int snap_size_threshold = (U.widget_unit * 2) / aspect; if (ELEM(rmd->edge, AE_LEFT_TO_TOPRIGHT, AE_RIGHT_TO_TOPLEFT)) { - delta = event->xy[0] - rmd->origx; + delta = event->xy[0] - rmd->orig_xy[0]; if (rmd->edge == AE_LEFT_TO_TOPRIGHT) { delta = -delta; } @@ -2837,7 +2836,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) } } else { - delta = event->xy[1] - rmd->origy; + delta = event->xy[1] - rmd->orig_xy[1]; if (rmd->edge == AE_BOTTOM_TO_TOPLEFT) { delta = -delta; } @@ -2879,7 +2878,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event) } case LEFTMOUSE: if (event->val == KM_RELEASE) { - if (len_manhattan_v2v2_int(event->xy, &rmd->origx) <= WM_EVENT_CURSOR_MOTION_THRESHOLD) { + if (len_manhattan_v2v2_int(event->xy, rmd->orig_xy) <= WM_EVENT_CURSOR_MOTION_THRESHOLD) { if (rmd->region->flag & RGN_FLAG_HIDDEN) { region_scale_toggle_hidden(C, rmd); } diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c index 4bc9f1e2565..2b16b70d1ef 100644 --- a/source/blender/editors/screen/screendump.c +++ b/source/blender/editors/screen/screendump.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * Making screendumps. */ /** \file * \ingroup edscr + * Making screenshots of the entire window or sub-regions. */ #include <errno.h> diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index b15b6784d34..907080626e0 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -90,9 +90,5 @@ set(LIB bf_blenlib ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_sculpt_paint "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index da627c6b7db..805d2221f6f 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2010 by Nicholas Bishop * All rights reserved. - * Implements the PBVH node hiding operator */ /** \file * \ingroup edsculpt + * Implements the PBVH node hiding operator. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index a912bb5cf3b..d5aa7647603 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -14,8 +14,6 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * - * The Original Code is: some of this file. */ /** \file diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index ca012f20f01..4d23119dd5f 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -14,8 +14,6 @@ * * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. * All rights reserved. - * - * The Original Code is: some of this file. */ /** \file @@ -1730,17 +1728,12 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps, normalize_v3(no); } else { -#if 1 /* In case the normalizing per pixel isn't optimal, * we could cache or access from evaluated mesh. */ normal_tri_v3(no, ps->mvert_eval[lt_vtri[0]].co, ps->mvert_eval[lt_vtri[1]].co, ps->mvert_eval[lt_vtri[2]].co); -#else - /* Don't use because some modifiers don't have normal data (subsurf for eg). */ - copy_v3_v3(no, (float *)ps->dm->getTessFaceData(ps->dm, tri_index, CD_NORMAL)); -#endif } if (UNLIKELY(ps->is_flip_object)) { diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index 46c2acf112a..1234a56853c 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -430,7 +430,7 @@ void PAINT_OT_weight_sample_group(wmOperatorType *ot) /* Group to use (dynamic enum). */ prop = RNA_def_enum( - ot->srna, "group", DummyRNA_DEFAULT_items, 0, "Group", "Vertex group to set as active"); + ot->srna, "group", DummyRNA_NULL_items, 0, "Group", "Vertex group to set as active"); RNA_def_enum_funcs(prop, weight_paint_sample_enum_itemf); RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE); ot->prop = prop; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 07e26a3d931..ea3d694542c 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2006 by Nicholas Bishop * All rights reserved. - * Implements the Sculpt Mode tools */ /** \file * \ingroup edsculpt + * Implements the Sculpt Mode tools. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_brush_types.c b/source/blender/editors/sculpt_paint/sculpt_brush_types.c index c2acc361a79..0d2c5641183 100644 --- a/source/blender/editors/sculpt_paint/sculpt_brush_types.c +++ b/source/blender/editors/sculpt_paint/sculpt_brush_types.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2006 by Nicholas Bishop * All rights reserved. - * Implements the Sculpt Mode tools */ /** \file * \ingroup edsculpt + * Implements the Sculpt Mode tools. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.c b/source/blender/editors/sculpt_paint/sculpt_ops.c index 119d246a770..f50775f8a32 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.c +++ b/source/blender/editors/sculpt_paint/sculpt_ops.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2006 by Nicholas Bishop * All rights reserved. - * Implements the Sculpt Mode tools */ /** \file * \ingroup edsculpt + * Implements the Sculpt Mode tools. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 8819496c168..0b64d1f8a35 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) 2006 by Nicholas Bishop * All rights reserved. - * Implements the Sculpt Mode tools */ /** \file * \ingroup edsculpt + * Implements the Sculpt Mode tools. */ #include <stddef.h> diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c index e5ca5e4defd..3e05b8d7a7f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.c +++ b/source/blender/editors/sculpt_paint/sculpt_uv.c @@ -15,11 +15,11 @@ * * The Original Code is Copyright (C) Blender Foundation, 2002-2009 * All rights reserved. - * UV Sculpt tools */ /** \file * \ingroup edsculpt + * UV Sculpt tools. */ #include "MEM_guardedalloc.h" diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 184d715a347..ba4ba04d548 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -658,7 +658,7 @@ static char *actkeys_paste_description(bContext *UNUSED(C), { /* Custom description if the 'flipped' option is used. */ if (RNA_boolean_get(ptr, "flipped")) { - return BLI_strdup("Paste keyframes from mirrored bones if they exist"); + return BLI_strdup(TIP_("Paste keyframes from mirrored bones if they exist")); } /* Use the default description in the other cases. */ diff --git a/source/blender/editors/space_buttons/CMakeLists.txt b/source/blender/editors/space_buttons/CMakeLists.txt index b5f6874fcfc..14cc03e3120 100644 --- a/source/blender/editors/space_buttons/CMakeLists.txt +++ b/source/blender/editors/space_buttons/CMakeLists.txt @@ -40,10 +40,6 @@ set(SRC set(LIB ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) @@ -52,7 +48,7 @@ endif() if(WITH_EXPERIMENTAL_FEATURES) add_definitions(-DWITH_SIMULATION_DATABLOCK) add_definitions(-DWITH_POINT_CLOUD) - add_definitions(-DWITH_HAIR_NODES) + add_definitions(-DWITH_NEW_CURVES_TYPE) endif() blender_add_lib(bf_editor_space_buttons "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c index f5107cb13fd..b83396b10d9 100644 --- a/source/blender/editors/space_buttons/buttons_context.c +++ b/source/blender/editors/space_buttons/buttons_context.c @@ -273,8 +273,8 @@ static bool buttons_context_path_data(ButsContextPath *path, int type) if (RNA_struct_is_a(ptr->type, &RNA_GreasePencil) && (ELEM(type, -1, OB_GPENCIL))) { return true; } -#ifdef WITH_HAIR_NODES - if (RNA_struct_is_a(ptr->type, &RNA_Hair) && (ELEM(type, -1, OB_HAIR))) { +#ifdef WITH_NEW_CURVES_TYPE + if (RNA_struct_is_a(ptr->type, &RNA_Curves) && (ELEM(type, -1, OB_CURVES))) { return true; } #endif @@ -314,7 +314,7 @@ static bool buttons_context_path_modifier(ButsContextPath *path) OB_SURF, OB_LATTICE, OB_GPENCIL, - OB_HAIR, + OB_CURVES, OB_POINTCLOUD, OB_VOLUME)) { ModifierData *md = BKE_object_active_modifier(ob); @@ -845,8 +845,8 @@ const char *buttons_context_dir[] = { "line_style", "collection", "gpencil", -#ifdef WITH_HAIR_NODES - "hair", +#ifdef WITH_NEW_CURVES_TYPE + "curves", #endif #ifdef WITH_POINT_CLOUD "pointcloud", @@ -941,9 +941,9 @@ int /*eContextResult*/ buttons_context(const bContext *C, set_pointer_type(path, result, &RNA_LightProbe); return CTX_RESULT_OK; } -#ifdef WITH_HAIR_NODES - if (CTX_data_equals(member, "hair")) { - set_pointer_type(path, result, &RNA_Hair); +#ifdef WITH_NEW_CURVES_TYPE + if (CTX_data_equals(member, "curves")) { + set_pointer_type(path, result, &RNA_Curves); return CTX_RESULT_OK; } #endif diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt index db881dafa6b..8f1a2c3c81e 100644 --- a/source/blender/editors/space_clip/CMakeLists.txt +++ b/source/blender/editors/space_clip/CMakeLists.txt @@ -68,11 +68,6 @@ set(LIB ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - - blender_add_lib(bf_editor_space_clip "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") # Needed so we can use dna_type_offsets.h for defaults initialization. diff --git a/source/blender/editors/space_file/CMakeLists.txt b/source/blender/editors/space_file/CMakeLists.txt index cbeb2e6f529..1df0c9c4409 100644 --- a/source/blender/editors/space_file/CMakeLists.txt +++ b/source/blender/editors/space_file/CMakeLists.txt @@ -92,10 +92,6 @@ if(WITH_IMAGE_HDR) add_definitions(-DWITH_HDR) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 2d31e8030a4..6be17bbd355 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -524,7 +524,7 @@ static int compare_apply_inverted(int val, const struct FileSortData *sort_data) * 2) If not possible (file names match) and both represent local IDs, sort by ID-type. * 3) If not possible and only one is a local ID, place files representing local IDs first. * - * TODO (not actually implemented, but should be): + * TODO: (not actually implemented, but should be): * 4) If no file represents a local ID, sort by file path, so that files higher up the file system * hierarchy are placed first. */ @@ -2783,7 +2783,8 @@ int ED_path_extension_type(const char *path) NULL)) { return FILE_TYPE_TEXT; } - if (BLI_path_extension_check_n(path, ".ttf", ".ttc", ".pfb", ".otf", ".otc", NULL)) { + if (BLI_path_extension_check_n( + path, ".ttf", ".ttc", ".pfb", ".otf", ".otc", ".woff", ".woff2", NULL)) { return FILE_TYPE_FTFONT; } if (BLI_path_extension_check(path, ".btx")) { diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c index 14f596ae7bf..0a69d0f9b39 100644 --- a/source/blender/editors/space_file/fsmenu.c +++ b/source/blender/editors/space_file/fsmenu.c @@ -745,14 +745,17 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks) N_("Fonts"), ICON_FILE_FONT, FS_INSERT_LAST); + fsmenu_add_windows_folder(fsmenu, + FS_CATEGORY_SYSTEM_BOOKMARKS, + &FOLDERID_SkyDrive, + N_("OneDrive"), + ICON_URL, + FS_INSERT_LAST); /* These items are just put in path cache for thumbnail views and if bookmarked. */ fsmenu_add_windows_folder( fsmenu, FS_CATEGORY_OTHER, &FOLDERID_UserProfiles, NULL, ICON_COMMUNITY, FS_INSERT_LAST); - - fsmenu_add_windows_folder( - fsmenu, FS_CATEGORY_OTHER, &FOLDERID_SkyDrive, NULL, ICON_URL, FS_INSERT_LAST); } } #elif defined(__APPLE__) diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt index 2a795dd954c..2e6e6971ce9 100644 --- a/source/blender/editors/space_graph/CMakeLists.txt +++ b/source/blender/editors/space_graph/CMakeLists.txt @@ -61,9 +61,5 @@ if(WITH_AUDASPACE) add_definitions(-DWITH_AUDASPACE) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_space_graph "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index 9675901ead3..63de7fb570e 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -586,7 +586,7 @@ static char *graphkeys_paste_description(bContext *UNUSED(C), { /* Custom description if the 'flipped' option is used. */ if (RNA_boolean_get(ptr, "flipped")) { - return BLI_strdup("Paste keyframes from mirrored bones if they exist"); + return BLI_strdup(TIP_("Paste keyframes from mirrored bones if they exist")); } /* Use the default description in the other cases. */ diff --git a/source/blender/editors/space_graph/graph_slider_ops.c b/source/blender/editors/space_graph/graph_slider_ops.c index 4b8c983a761..cfaea33605a 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.c +++ b/source/blender/editors/space_graph/graph_slider_ops.c @@ -483,7 +483,7 @@ static char *decimate_desc(bContext *UNUSED(C), wmOperatorType *UNUSED(op), Poin if (RNA_enum_get(ptr, "mode") == DECIM_ERROR) { return BLI_strdup( - "Decimate F-Curves by specifying how much it can deviate from the original curve"); + TIP_("Decimate F-Curves by specifying how much they can deviate from the original curve")); } /* Use default description. */ diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt index 7a1bab0ef14..25d0e02ecc0 100644 --- a/source/blender/editors/space_image/CMakeLists.txt +++ b/source/blender/editors/space_image/CMakeLists.txt @@ -53,10 +53,6 @@ set(LIB bf_editor_uvedit ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_OPENIMAGEIO) add_definitions(-DWITH_OPENIMAGEIO) endif() diff --git a/source/blender/editors/space_image/image_undo.c b/source/blender/editors/space_image/image_undo.c index e81f3b6a490..73993606a14 100644 --- a/source/blender/editors/space_image/image_undo.c +++ b/source/blender/editors/space_image/image_undo.c @@ -1000,7 +1000,7 @@ void ED_image_undosys_type(UndoType *ut) ut->step_foreach_ID_ref = image_undosys_foreach_ID_ref; - /* NOTE this is actually a confusing case, since it expects a valid context, but only in a + /* NOTE: this is actually a confusing case, since it expects a valid context, but only in a * specific case, see `image_undosys_step_encode` code. We cannot specify * `UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE` though, as it can be called with a NULL context by * current code. */ diff --git a/source/blender/editors/space_info/CMakeLists.txt b/source/blender/editors/space_info/CMakeLists.txt index 144b21fb9b8..fb17a6c9709 100644 --- a/source/blender/editors/space_info/CMakeLists.txt +++ b/source/blender/editors/space_info/CMakeLists.txt @@ -48,9 +48,5 @@ set(SRC set(LIB ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_space_info "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_info/info_stats.cc b/source/blender/editors/space_info/info_stats.cc index 005ae0214cd..a1eacc2bc3a 100644 --- a/source/blender/editors/space_info/info_stats.cc +++ b/source/blender/editors/space_info/info_stats.cc @@ -219,7 +219,7 @@ static void stats_object(Object *ob, } break; } - case OB_HAIR: + case OB_CURVES: case OB_POINTCLOUD: case OB_VOLUME: { break; diff --git a/source/blender/editors/space_nla/CMakeLists.txt b/source/blender/editors/space_nla/CMakeLists.txt index 9a94d28c604..5326f1cce2b 100644 --- a/source/blender/editors/space_nla/CMakeLists.txt +++ b/source/blender/editors/space_nla/CMakeLists.txt @@ -47,9 +47,5 @@ set(LIB bf_blenlib ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_space_nla "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt index 41d6388c947..15e0d04c8fa 100644 --- a/source/blender/editors/space_node/CMakeLists.txt +++ b/source/blender/editors/space_node/CMakeLists.txt @@ -63,10 +63,6 @@ set(LIB bf_editor_screen ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_COMPOSITOR) add_definitions(-DWITH_COMPOSITOR) endif() diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 2c47883d831..e290316af1f 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -397,7 +397,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node, /* Round the socket location to stop it from jiggling. */ nsock->locx = round(loc.x + NODE_WIDTH(node)); - nsock->locy = round(0.5f * (dy + buty)); + nsock->locy = round(dy - NODE_DYS); dy = buty; if (nsock->next) { @@ -527,7 +527,7 @@ static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node, nsock->locx = loc.x; /* Round the socket vertical position to stop it from jiggling. */ - nsock->locy = round(0.5f * (dy + buty)); + nsock->locy = round(dy - NODE_DYS); dy = buty - multi_input_socket_offset * 0.5; if (nsock->next) { @@ -626,7 +626,9 @@ static void node_update_hidden(bNode &node, uiBlock &block) static int node_get_colorid(const bNode &node) { - switch (node.typeinfo->nclass) { + const int nclass = (node.typeinfo->ui_class == nullptr) ? node.typeinfo->nclass : + node.typeinfo->ui_class(&node); + switch (nclass) { case NODE_CLASS_INPUT: return TH_NODE_INPUT; case NODE_CLASS_OUTPUT: diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index 95f771cc00b..51825f5bd39 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -109,20 +109,30 @@ enum NodeResizeDirection { }; ENUM_OPERATORS(NodeResizeDirection, NODE_RESIZE_LEFT); +/* Nodes draw without dpi - the view zoom is flexible. */ +#define HIDDEN_RAD (0.75f * U.widget_unit) +#define BASIS_RAD (0.2f * U.widget_unit) +#define NODE_DYS (U.widget_unit / 2) +#define NODE_DY U.widget_unit +#define NODE_SOCKDY (0.1f * U.widget_unit) +#define NODE_WIDTH(node) (node.width * UI_DPI_FAC) +#define NODE_HEIGHT(node) (node.height * UI_DPI_FAC) +#define NODE_MARGIN_X (1.2f * U.widget_unit) +#define NODE_SOCKSIZE (0.25f * U.widget_unit) +#define NODE_MULTI_INPUT_LINK_GAP (0.25f * U.widget_unit) +#define NODE_RESIZE_MARGIN (0.20f * U.widget_unit) +#define NODE_LINK_RESOL 12 + +/* space_node.cc */ + /** * Transform between View2Ds in the tree path. */ float2 space_node_group_offset(const SpaceNode &snode); -float node_socket_calculate_height(const bNodeSocket &socket); -float2 node_link_calculate_multi_input_position(const float2 &socket_position, - int index, - int total_inputs); - rctf node_frame_rect_inside(const bNode &node); int node_get_resize_cursor(NodeResizeDirection directions); -NodeResizeDirection node_get_resize_direction(const bNode *node, int x, int y); /** * Usual convention here would be #node_socket_get_color(), * but that's already used (for setting a color property socket). @@ -132,6 +142,9 @@ void node_socket_color_get(const bContext &C, PointerRNA &node_ptr, const bNodeSocket &sock, float r_color[4]); + +/* node_draw.cc */ + void node_draw_space(const bContext &C, ARegion ®ion); /** @@ -146,9 +159,13 @@ float2 node_to_view(const bNode &node, const float2 &co); void node_to_updated_rect(const bNode &node, rctf &r_rect); float2 node_from_view(const bNode &node, const float2 &co); +/* node_ops.cc */ + void node_operatortypes(); void node_keymap(wmKeyConfig *keyconf); +/* node_select.cc */ + void node_deselect_all(SpaceNode &snode); void node_socket_select(bNode *node, bNodeSocket &sock); void node_socket_deselect(bNode *node, bNodeSocket &sock, bool deselect_node); @@ -167,6 +184,8 @@ void NODE_OT_select_grouped(wmOperatorType *ot); void NODE_OT_select_same_type_step(wmOperatorType *ot); void NODE_OT_find_node(wmOperatorType *ot); +/* node_view.cc */ + bool space_node_view_flag( bContext &C, SpaceNode &snode, ARegion ®ion, int node_flag, int smooth_viewtx); @@ -179,6 +198,10 @@ void NODE_OT_backimage_zoom(wmOperatorType *ot); void NODE_OT_backimage_fit(wmOperatorType *ot); void NODE_OT_backimage_sample(wmOperatorType *ot); +/* drawnode.cc */ + +NodeResizeDirection node_get_resize_direction(const bNode *node, int x, int y); + void nodelink_batch_start(SpaceNode &snode); void nodelink_batch_end(SpaceNode &snode); @@ -217,7 +240,7 @@ void draw_nodespace_back_pix(const bContext &C, SpaceNode &snode, bNodeInstanceKey parent_key); -void node_select_all(ListBase *lb, int action); +/* node_add.cc */ /** * XXX Does some additional initialization on top of #nodeAddNode @@ -234,6 +257,8 @@ void NODE_OT_add_file(wmOperatorType *ot); void NODE_OT_add_mask(wmOperatorType *ot); void NODE_OT_new_node_tree(wmOperatorType *ot); +/* node_group.cc */ + const char *node_group_idname(bContext *C); void NODE_OT_group_make(wmOperatorType *ot); void NODE_OT_group_insert(wmOperatorType *ot); @@ -241,6 +266,8 @@ void NODE_OT_group_ungroup(wmOperatorType *ot); void NODE_OT_group_separate(wmOperatorType *ot); void NODE_OT_group_edit(wmOperatorType *ot); +/* node_relationships.cc */ + void sort_multi_input_socket_links(SpaceNode &snode, bNode &node, bNodeLink *drag_link, @@ -261,6 +288,16 @@ void NODE_OT_link_viewer(wmOperatorType *ot); void NODE_OT_insert_offset(wmOperatorType *ot); +/* node_edit.cc */ + +float2 node_link_calculate_multi_input_position(const float2 &socket_position, + int index, + int total_inputs); + +void node_select_all(ListBase *lb, int action); + +float node_socket_calculate_height(const bNodeSocket &socket); + void snode_set_context(const bContext &C); bool composite_node_active(bContext *C); @@ -316,13 +353,17 @@ void NODE_OT_shader_script_update(wmOperatorType *ot); void NODE_OT_viewer_border(wmOperatorType *ot); void NODE_OT_clear_viewer_border(wmOperatorType *ot); +void NODE_OT_cryptomatte_layer_add(wmOperatorType *ot); +void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot); + +/* node_gizmo.cc */ + void NODE_GGT_backdrop_transform(wmGizmoGroupType *gzgt); void NODE_GGT_backdrop_crop(wmGizmoGroupType *gzgt); void NODE_GGT_backdrop_sun_beams(wmGizmoGroupType *gzgt); void NODE_GGT_backdrop_corner_pin(wmGizmoGroupType *gzgt); -void NODE_OT_cryptomatte_layer_add(wmOperatorType *ot); -void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot); +/* node_geometry_attribute_search.cc */ void node_geometry_add_attribute_search_button(const bContext &C, const bNodeTree &node_tree, @@ -330,22 +371,12 @@ void node_geometry_add_attribute_search_button(const bContext &C, PointerRNA &socket_ptr, uiLayout &layout); -/* Nodes draw without dpi - the view zoom is flexible. */ -#define HIDDEN_RAD (0.75f * U.widget_unit) -#define BASIS_RAD (0.2f * U.widget_unit) -#define NODE_DYS (U.widget_unit / 2) -#define NODE_DY U.widget_unit -#define NODE_SOCKDY (0.1f * U.widget_unit) -#define NODE_WIDTH(node) (node.width * UI_DPI_FAC) -#define NODE_HEIGHT(node) (node.height * UI_DPI_FAC) -#define NODE_MARGIN_X (1.2f * U.widget_unit) -#define NODE_SOCKSIZE (0.25f * U.widget_unit) -#define NODE_MULTI_INPUT_LINK_GAP (0.25f * U.widget_unit) -#define NODE_RESIZE_MARGIN (0.20f * U.widget_unit) -#define NODE_LINK_RESOL 12 +/* node_context_path.c */ Vector<ui::ContextPathItem> context_path_for_space_node(const bContext &C); +/* link_drag_search.cc */ + void invoke_node_link_drag_add_menu(bContext &C, bNode &node, bNodeSocket &socket, diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt index bc6db978a4f..d97f48bcb68 100644 --- a/source/blender/editors/space_outliner/CMakeLists.txt +++ b/source/blender/editors/space_outliner/CMakeLists.txt @@ -95,9 +95,5 @@ set(LIB bf_editor_undo ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_space_outliner "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc index 5fd7559370f..13c273d1ec9 100644 --- a/source/blender/editors/space_outliner/outliner_draw.cc +++ b/source/blender/editors/space_outliner/outliner_draw.cc @@ -2480,9 +2480,6 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te) case TSE_POSE_CHANNEL: data.icon = ICON_BONE_DATA; break; - case TSE_PROXY: - data.icon = ICON_GHOST_ENABLED; - break; case TSE_R_LAYER_BASE: data.icon = ICON_RENDERLAYERS; break; @@ -2635,8 +2632,8 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te) case OB_LIGHTPROBE: data.icon = ICON_OUTLINER_OB_LIGHTPROBE; break; - case OB_HAIR: - data.icon = ICON_OUTLINER_OB_HAIR; + case OB_CURVES: + data.icon = ICON_OUTLINER_OB_CURVES; break; case OB_POINTCLOUD: data.icon = ICON_OUTLINER_OB_POINTCLOUD; @@ -2749,8 +2746,8 @@ TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te) case ID_GR: data.icon = ICON_OUTLINER_COLLECTION; break; - case ID_HA: - data.icon = ICON_OUTLINER_DATA_HAIR; + case ID_CV: + data.icon = ICON_OUTLINER_DATA_CURVES; break; case ID_PT: data.icon = ICON_OUTLINER_DATA_POINTCLOUD; diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh index 9db1d73dc76..efbd8a32716 100644 --- a/source/blender/editors/space_outliner/outliner_intern.hh +++ b/source/blender/editors/space_outliner/outliner_intern.hh @@ -57,10 +57,12 @@ class AbstractTreeDisplay; class AbstractTreeElement; } // namespace blender::ed::outliner +namespace outliner = blender::ed::outliner; + struct SpaceOutliner_Runtime { /** Object to create and manage the tree for a specific display type (View Layers, Scenes, * Blender File, etc.). */ - std::unique_ptr<blender::ed::outliner::AbstractTreeDisplay> tree_display; + std::unique_ptr<outliner::AbstractTreeDisplay> tree_display; /** Pointers to tree-store elements, grouped by `(id, type, nr)` * in hash-table for faster searching. */ @@ -93,11 +95,12 @@ typedef struct TreeElement { struct TreeElement *next, *prev, *parent; /** - * Handle to the new C++ object (a derived type of base #AbstractTreeElement) that should replace - * #TreeElement. Step by step, data should be moved to it and operations based on the type should - * become virtual methods of the class hierarchy. + * The new inheritance based representation of the element (a derived type of base + * #AbstractTreeElement) that should eventually replace #TreeElement. Step by step, data should + * be moved to it and operations based on the type should become virtual methods of the class + * hierarchy. */ - std::unique_ptr<blender::ed::outliner::AbstractTreeElement> type; + std::unique_ptr<outliner::AbstractTreeElement> abstract_element; ListBase subtree; int xs, ys; /* Do selection. */ @@ -142,7 +145,7 @@ typedef struct TreeElementIcon { ID_GD, \ ID_LS, \ ID_LP, \ - ID_HA, \ + ID_CV, \ ID_PT, \ ID_VO, \ ID_SIM) || /* Only in 'blendfile' mode ... :/ */ \ @@ -700,7 +703,7 @@ template<typename TreeElementT> TreeElementT *tree_element_cast(const TreeElemen { static_assert(std::is_base_of_v<AbstractTreeElement, TreeElementT>, "Requested tree-element type must be an AbstractTreeElement"); - return dynamic_cast<TreeElementT *>(te->type.get()); + return dynamic_cast<TreeElementT *>(te->abstract_element.get()); } } // namespace blender::ed::outliner diff --git a/source/blender/editors/space_outliner/outliner_select.cc b/source/blender/editors/space_outliner/outliner_select.cc index ebb4e529b04..f256475c0da 100644 --- a/source/blender/editors/space_outliner/outliner_select.cc +++ b/source/blender/editors/space_outliner/outliner_select.cc @@ -1198,7 +1198,7 @@ static void outliner_set_properties_tab(bContext *C, TreeElement *te, TreeStoreE case ID_AR: case ID_GD: case ID_LP: - case ID_HA: + case ID_CV: case ID_PT: case ID_VO: context = BCONTEXT_DATA; diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc index 03fc4c20fe5..337649834a4 100644 --- a/source/blender/editors/space_outliner/outliner_tools.cc +++ b/source/blender/editors/space_outliner/outliner_tools.cc @@ -29,8 +29,8 @@ #include "DNA_armature_types.h" #include "DNA_collection_types.h" #include "DNA_constraint_types.h" +#include "DNA_curves_types.h" #include "DNA_gpencil_types.h" -#include "DNA_hair_types.h" #include "DNA_light_types.h" #include "DNA_linestyle_types.h" #include "DNA_material_types.h" @@ -164,7 +164,7 @@ static void get_element_operation_type( case ID_CF: case ID_WS: case ID_LP: - case ID_HA: + case ID_CV: case ID_PT: case ID_VO: case ID_SIM: @@ -262,10 +262,10 @@ static void unlink_material_fn(bContext *UNUSED(C), totcol = mb->totcol; matar = mb->mat; } - else if (GS(tsep->id->name) == ID_HA) { - Hair *hair = (Hair *)tsep->id; - totcol = hair->totcol; - matar = hair->mat; + else if (GS(tsep->id->name) == ID_CV) { + Curves *curves = (Curves *)tsep->id; + totcol = curves->totcol; + matar = curves->mat; } else if (GS(tsep->id->name) == ID_PT) { PointCloud *pointcloud = (PointCloud *)tsep->id; @@ -764,38 +764,6 @@ static void id_local_fn(bContext *C, } } -static void object_proxy_to_override_convert_fn(bContext *C, - ReportList *reports, - Scene *UNUSED(scene), - TreeElement *UNUSED(te), - TreeStoreElem *UNUSED(tsep), - TreeStoreElem *tselem, - void *UNUSED(user_data)) -{ - BLI_assert(TSE_IS_REAL_ID(tselem)); - ID *id_proxy = tselem->id; - BLI_assert(GS(id_proxy->name) == ID_OB); - Object *ob_proxy = (Object *)id_proxy; - Scene *scene = CTX_data_scene(C); - - if (ob_proxy->proxy == nullptr) { - return; - } - - if (!BKE_lib_override_library_proxy_convert( - CTX_data_main(C), scene, CTX_data_view_layer(C), ob_proxy)) { - BKE_reportf( - reports, - RPT_ERROR_INVALID_INPUT, - "Could not create a library override from proxy '%s' (might use already local data?)", - ob_proxy->id.name + 2); - return; - } - - DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS | ID_RECALC_COPY_ON_WRITE); - WM_event_add_notifier(C, NC_WINDOW, nullptr); -} - struct OutlinerLibOverrideData { bool do_hierarchy; /** @@ -874,8 +842,13 @@ static void id_override_library_create_fn(bContext *C, te->store_elem->id->tag |= LIB_TAG_DOIT; } - success = BKE_lib_override_library_create( - bmain, CTX_data_scene(C), CTX_data_view_layer(C), id_root, id_reference, nullptr); + success = BKE_lib_override_library_create(bmain, + CTX_data_scene(C), + CTX_data_view_layer(C), + nullptr, + id_root, + id_reference, + nullptr); } else if (ID_IS_OVERRIDABLE_LIBRARY(id_root)) { success = BKE_lib_override_library_create_from_id(bmain, id_root, true) != nullptr; @@ -1532,7 +1505,6 @@ enum { OL_OP_SELECT_HIERARCHY, OL_OP_REMAP, OL_OP_RENAME, - OL_OP_PROXY_TO_OVERRIDE_CONVERT, }; static const EnumPropertyItem prop_object_op_types[] = { @@ -1545,11 +1517,6 @@ static const EnumPropertyItem prop_object_op_types[] = { "Remap Users", "Make all users of selected data-blocks to use instead a new chosen one"}, {OL_OP_RENAME, "RENAME", 0, "Rename", ""}, - {OL_OP_PROXY_TO_OVERRIDE_CONVERT, - "OBJECT_PROXY_TO_OVERRIDE", - 0, - "Convert Proxy to Override", - "Convert a Proxy object to a full library override, including all its dependencies"}, {0, nullptr, 0, nullptr, nullptr}, }; @@ -1614,15 +1581,6 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op) C, op->reports, scene, space_outliner, &space_outliner->tree, item_rename_fn); str = "Rename Object"; } - else if (event == OL_OP_PROXY_TO_OVERRIDE_CONVERT) { - outliner_do_object_operation(C, - op->reports, - scene, - space_outliner, - &space_outliner->tree, - object_proxy_to_override_convert_fn); - str = "Convert Proxy to Override"; - } else { BLI_assert(0); return OPERATOR_CANCELLED; @@ -1794,7 +1752,6 @@ enum eOutlinerIdOpTypes { OUTLINER_IDOP_LOCAL, OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE, OUTLINER_IDOP_OVERRIDE_LIBRARY_CREATE_HIERARCHY, - OUTLINER_IDOP_OVERRIDE_LIBRARY_PROXY_CONVERT, OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET, OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY, OUTLINER_IDOP_OVERRIDE_LIBRARY_RESYNC_HIERARCHY, @@ -1836,11 +1793,6 @@ static const EnumPropertyItem prop_id_op_types[] = { 0, "Make Library Override Hierarchy", "Make a local override of this linked data-block, and its hierarchy of dependencies"}, - {OUTLINER_IDOP_OVERRIDE_LIBRARY_PROXY_CONVERT, - "OVERRIDE_LIBRARY_PROXY_CONVERT", - 0, - "Convert Proxy to Override", - "Convert a Proxy object to a full library override, including all its dependencies"}, {OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET, "OVERRIDE_LIBRARY_RESET", 0, @@ -1913,16 +1865,6 @@ static bool outliner_id_operation_item_poll(bContext *C, return true; } return false; - case OUTLINER_IDOP_OVERRIDE_LIBRARY_PROXY_CONVERT: { - if (GS(tselem->id->name) == ID_OB) { - Object *ob = (Object *)tselem->id; - - if ((ob != nullptr) && (ob->proxy != nullptr)) { - return true; - } - } - return false; - } case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET: case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET_HIERARCHY: case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESYNC_HIERARCHY: @@ -2099,16 +2041,6 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op) ED_undo_push(C, "Overridden Data Hierarchy"); break; } - case OUTLINER_IDOP_OVERRIDE_LIBRARY_PROXY_CONVERT: { - outliner_do_object_operation(C, - op->reports, - scene, - space_outliner, - &space_outliner->tree, - object_proxy_to_override_convert_fn); - ED_undo_push(C, "Convert Proxy to Override"); - break; - } case OUTLINER_IDOP_OVERRIDE_LIBRARY_RESET: { OutlinerLibOverrideData override_data{}; outliner_do_libdata_operation(C, diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index eb885eba20d..60f5437ad88 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -32,9 +32,9 @@ #include "DNA_camera_types.h" #include "DNA_collection_types.h" #include "DNA_constraint_types.h" +#include "DNA_curves_types.h" #include "DNA_gpencil_modifier_types.h" #include "DNA_gpencil_types.h" -#include "DNA_hair_types.h" #include "DNA_key_types.h" #include "DNA_light_types.h" #include "DNA_lightprobe_types.h" @@ -217,7 +217,7 @@ void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree) if (element->flag & TE_FREE_NAME) { MEM_freeN((void *)element->name); } - element->type = nullptr; + element->abstract_element = nullptr; MEM_delete(element); } @@ -302,10 +302,6 @@ static void outliner_add_object_contents(SpaceOutliner *space_outliner, /* FIXME: add a special type for this. */ outliner_add_element(space_outliner, &te->subtree, ob->poselib, te, TSE_SOME_ID, 0); - if (ob->proxy && !ID_IS_LINKED(ob)) { - outliner_add_element(space_outliner, &te->subtree, ob->proxy, te, TSE_PROXY, 0); - } - outliner_add_element(space_outliner, &te->subtree, ob->data, te, TSE_SOME_ID, 0); if (ob->pose) { @@ -777,10 +773,10 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner, } break; } - case ID_HA: { - Hair *hair = (Hair *)id; - if (outliner_animdata_test(hair->adt)) { - outliner_add_element(space_outliner, &te->subtree, hair, te, TSE_ANIM_DATA, 0); + case ID_CV: { + Curves *curves = (Curves *)id; + if (outliner_animdata_test(curves->adt)) { + outliner_add_element(space_outliner, &te->subtree, curves, te, TSE_ANIM_DATA, 0); } break; } @@ -860,10 +856,10 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, te->parent = parent; te->index = index; /* For data arrays. */ - /* New C++ based type handle. Only some support this, eventually this should replace - * `TreeElement` entirely. */ - te->type = AbstractTreeElement::createFromType(type, *te, idv); - if (te->type) { + /* New inheritance based element representation. Not all element types support this yet, + * eventually it should replace #TreeElement entirely. */ + te->abstract_element = AbstractTreeElement::createFromType(type, *te, idv); + if (te->abstract_element) { /* Element types ported to the new design are expected to have their name set at this point! */ BLI_assert(te->name != nullptr); } @@ -887,12 +883,12 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, /* pass */ } else if (type == TSE_SOME_ID) { - if (!te->type) { + if (!te->abstract_element) { BLI_assert_msg(0, "Expected this ID type to be ported to new Outliner tree-element design"); } } else if (ELEM(type, TSE_LIBRARY_OVERRIDE_BASE, TSE_LIBRARY_OVERRIDE)) { - if (!te->type) { + if (!te->abstract_element) { BLI_assert_msg(0, "Expected override types to be ported to new Outliner tree-element design"); } @@ -903,20 +899,20 @@ TreeElement *outliner_add_element(SpaceOutliner *space_outliner, /* The new type design sets the name already, don't override that here. We need to figure out * how to deal with the idcode for non-TSE_SOME_ID types still. Some rely on it... */ - if (!te->type) { + if (!te->abstract_element) { te->name = id->name + 2; /* Default, can be overridden by Library or non-ID data. */ } te->idcode = GS(id->name); } - if (te->type && te->type->isExpandValid()) { - tree_element_expand(*te->type, *space_outliner); + if (te->abstract_element && te->abstract_element->isExpandValid()) { + tree_element_expand(*te->abstract_element, *space_outliner); } else if (type == TSE_SOME_ID) { /* ID types not (fully) ported to new design yet. */ - if (te->type->expandPoll(*space_outliner)) { + if (te->abstract_element->expandPoll(*space_outliner)) { outliner_add_id_contents(space_outliner, te, tselem, id); - te->type->postExpand(*space_outliner); + te->abstract_element->postExpand(*space_outliner); } } else if (ELEM(type, diff --git a/source/blender/editors/space_outliner/tree/tree_element_id.cc b/source/blender/editors/space_outliner/tree/tree_element_id.cc index afbbd171cf4..3289cb8ac76 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_id.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_id.cc @@ -69,7 +69,7 @@ std::unique_ptr<TreeElementID> TreeElementID::createFromID(TreeElement &legacy_t case ID_LP: case ID_GD: case ID_WS: - case ID_HA: + case ID_CV: case ID_PT: case ID_VO: case ID_SIM: diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt index bf8cf89699d..d93dc0ac0c0 100644 --- a/source/blender/editors/space_sequencer/CMakeLists.txt +++ b/source/blender/editors/space_sequencer/CMakeLists.txt @@ -70,9 +70,5 @@ if(WITH_AUDASPACE) ) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_space_sequencer "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index 5d857f62b47..fd341fc9c0d 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -13,7 +13,7 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Author: Peter Schlaile < peter [at] schlaile [dot] de > + * Copyright 2006-2008 Peter Schlaile < peter [at] schlaile [dot] de > */ /** \file diff --git a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc index 18f383d45fb..357b3e0a8b4 100644 --- a/source/blender/editors/space_spreadsheet/space_spreadsheet.cc +++ b/source/blender/editors/space_spreadsheet/space_spreadsheet.cc @@ -554,7 +554,7 @@ static void spreadsheet_footer_region_draw(const bContext *C, ARegion *region) UI_LAYOUT_HEADER, UI_HEADER_OFFSET, region->winy - (region->winy - UI_UNIT_Y) / 2.0f, - region->sizex, + region->winx, 1, 0, style); diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc index f4b5ff819ed..d9837b7c1a6 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc @@ -127,6 +127,28 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer { UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); } + if (data.type().is<int8_t>()) { + const int8_t value = data.get<int8_t>(real_index); + const std::string value_str = std::to_string(value); + uiBut *but = uiDefIconTextBut(params.block, + UI_BTYPE_LABEL, + 0, + ICON_NONE, + value_str.c_str(), + params.xmin, + params.ymin, + params.width, + params.height, + nullptr, + 0, + 0, + 0, + 0, + nullptr); + /* Right-align Integers. */ + UI_but_drawflag_disable(but, UI_BUT_TEXT_LEFT); + UI_but_drawflag_enable(but, UI_BUT_TEXT_RIGHT); + } else if (data.type().is<float>()) { const float value = data.get<float>(real_index); std::stringstream ss; diff --git a/source/blender/editors/space_text/CMakeLists.txt b/source/blender/editors/space_text/CMakeLists.txt index abd7620ea2b..a85c69caa50 100644 --- a/source/blender/editors/space_text/CMakeLists.txt +++ b/source/blender/editors/space_text/CMakeLists.txt @@ -61,8 +61,5 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() blender_add_lib(bf_editor_space_text "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index 8fb55ed9b46..27941b881b8 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -79,10 +79,8 @@ static void text_font_end(const TextDrawContext *UNUSED(tdc)) static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char *str) { - int columns; - BLF_position(tdc->font_id, x, y, 0); - columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth_px); + const int columns = BLF_draw_mono(tdc->font_id, str, BLF_DRAW_STR_DUMMY_MAX, tdc->cwidth_px); return tdc->cwidth_px * columns; } @@ -90,18 +88,17 @@ static int text_font_draw(const TextDrawContext *tdc, int x, int y, const char * static int text_font_draw_character(const TextDrawContext *tdc, int x, int y, char c) { BLF_position(tdc->font_id, x, y, 0); - BLF_draw(tdc->font_id, &c, 1); + BLF_draw_mono(tdc->font_id, &c, 1, tdc->cwidth_px); return tdc->cwidth_px; } -static int text_font_draw_character_utf8(const TextDrawContext *tdc, int x, int y, const char *c) +static int text_font_draw_character_utf8( + const TextDrawContext *tdc, int x, int y, const char *c, const int c_len) { - int columns; - - const size_t len = BLI_str_utf8_size_safe(c); + BLI_assert(c_len == BLI_str_utf8_size_safe(c)); BLF_position(tdc->font_id, x, y, 0); - columns = BLF_draw_mono(tdc->font_id, c, len, tdc->cwidth_px); + const int columns = BLF_draw_mono(tdc->font_id, c, c_len, tdc->cwidth_px); return tdc->cwidth_px * columns; } @@ -463,13 +460,15 @@ static int text_draw_wrapped(const SpaceText *st, } /* Draw the visible portion of text on the overshot line */ - for (a = fstart, ma = mstart; ma < mend; a++, ma += BLI_str_utf8_size_safe(str + ma)) { + for (a = fstart, ma = mstart; ma < mend; a++) { if (use_syntax) { if (fmt_prev != format[a]) { format_draw_color(tdc, fmt_prev = format[a]); } } - x += text_font_draw_character_utf8(tdc, x, y, str + ma); + const int c_len = BLI_str_utf8_size_safe(str + ma); + x += text_font_draw_character_utf8(tdc, x, y, str + ma, c_len); + ma += c_len; fpos++; } y -= TXT_LINE_HEIGHT(st); @@ -491,15 +490,16 @@ static int text_draw_wrapped(const SpaceText *st, } /* Draw the remaining text */ - for (a = fstart, ma = mstart; str[ma] && y > clip_min_y; - a++, ma += BLI_str_utf8_size_safe(str + ma)) { + for (a = fstart, ma = mstart; str[ma] && y > clip_min_y; a++) { if (use_syntax) { if (fmt_prev != format[a]) { format_draw_color(tdc, fmt_prev = format[a]); } } - x += text_font_draw_character_utf8(tdc, x, y, str + ma); + const int c_len = BLI_str_utf8_size_safe(str + ma); + x += text_font_draw_character_utf8(tdc, x, y, str + ma, c_len); + ma += c_len; } flatten_string_free(&fs); @@ -559,8 +559,9 @@ static void text_draw(const SpaceText *st, if (format[a] != fmt_prev) { format_draw_color(tdc, fmt_prev = format[a]); } - x += text_font_draw_character_utf8(tdc, x, y, in + str_shift); - str_shift += BLI_str_utf8_size_safe(in + str_shift); + const int c_len = BLI_str_utf8_size_safe(in + str_shift); + x += text_font_draw_character_utf8(tdc, x, y, in + str_shift, c_len); + str_shift += c_len; } } else { diff --git a/source/blender/editors/space_userpref/userpref_ops.c b/source/blender/editors/space_userpref/userpref_ops.c index d40229332fd..e4c11bc8668 100644 --- a/source/blender/editors/space_userpref/userpref_ops.c +++ b/source/blender/editors/space_userpref/userpref_ops.c @@ -30,6 +30,7 @@ #ifdef WIN32 # include "BLI_winstuff.h" #endif +#include "BLI_path_util.h" #include "BKE_context.h" #include "BKE_main.h" @@ -142,16 +143,20 @@ static void PREFERENCES_OT_autoexec_path_remove(wmOperatorType *ot) static int preferences_asset_library_add_exec(bContext *UNUSED(C), wmOperator *op) { - char *directory = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL); + char *path = RNA_string_get_alloc(op->ptr, "directory", NULL, 0, NULL); + char dirname[FILE_MAXFILE]; + + BLI_path_slash_rstrip(path); + BLI_split_file_part(path, dirname, sizeof(dirname)); /* NULL is a valid directory path here. A library without path will be created then. */ - BKE_preferences_asset_library_add(&U, NULL, directory); + BKE_preferences_asset_library_add(&U, dirname, path); U.runtime.is_dirty = true; /* There's no dedicated notifier for the Preferences. */ WM_main_add_notifier(NC_WINDOW, NULL); - MEM_freeN(directory); + MEM_freeN(path); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt index 19f869ed50b..7e8b013192f 100644 --- a/source/blender/editors/space_view3d/CMakeLists.txt +++ b/source/blender/editors/space_view3d/CMakeLists.txt @@ -60,8 +60,17 @@ set(SRC view3d_gizmo_tool_generic.c view3d_header.c view3d_iterators.c + view3d_navigate.c + view3d_navigate_dolly.c view3d_navigate_fly.c + view3d_navigate_move.c + view3d_navigate_ndof.c + view3d_navigate_roll.c + view3d_navigate_rotate.c + view3d_navigate_smoothview.c view3d_navigate_walk.c + view3d_navigate_zoom.c + view3d_navigate_zoom_border.c view3d_ops.c view3d_placement.c view3d_project.c @@ -71,6 +80,7 @@ set(SRC view3d_view.c view3d_intern.h + view3d_navigate.h ) set(LIB @@ -83,11 +93,6 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() - -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_FREESTYLE) add_definitions(-DWITH_FREESTYLE) endif() diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 595ae3d8457..51107499d3f 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -89,6 +89,7 @@ #include "DEG_depsgraph_build.h" #include "view3d_intern.h" /* own include */ +#include "view3d_navigate.h" /* ******************** manage regions ********************* */ diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c index 243d4033cbc..6edb0a070c0 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.c +++ b/source/blender/editors/space_view3d/view3d_buttons.c @@ -1764,7 +1764,8 @@ static void view3d_panel_transform(const bContext *C, Panel *panel) v3d_transform_butsR(col, &obptr); /* Dimensions and editmode are mostly the same check. */ - if (OB_TYPE_SUPPORT_EDITMODE(ob->type) || ELEM(ob->type, OB_VOLUME, OB_HAIR, OB_POINTCLOUD)) { + if (OB_TYPE_SUPPORT_EDITMODE(ob->type) || + ELEM(ob->type, OB_VOLUME, OB_CURVES, OB_POINTCLOUD)) { View3D *v3d = CTX_wm_view3d(C); v3d_object_dimension_buts(NULL, col, v3d, ob); } diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index b1f19581543..3f639e8ee1a 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -1036,7 +1036,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d) negate_v3_v3(o, rv3d->ofs); GPU_blend(GPU_BLEND_ALPHA); - GPU_depth_mask(false); /* don't overwrite zbuf */ + GPU_depth_mask(false); /* Don't overwrite the Z-buffer. */ GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); @@ -1258,11 +1258,7 @@ static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *y /* 6 is the maximum size of the axis roll text. */ /* increase size for unicode languages (Chinese in utf-8...) */ -#ifdef WITH_INTERNATIONAL char tmpstr[96 + 6]; -#else - char tmpstr[32 + 6]; -#endif BLF_enable(font_id, BLF_SHADOW); BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); @@ -1689,9 +1685,9 @@ void ED_view3d_draw_offscreen(Depsgraph *depsgraph, G.f |= G_FLAG_RENDER_VIEWPORT; { - /* free images which can have changed on frame-change - * warning! can be slow so only free animated images - campbell */ - BKE_image_free_anim_gputextures(G.main); /* XXX :((( */ + /* Free images which can have changed on frame-change. + * WARNING(@campbellbarton): can be slow so only free animated images. */ + BKE_image_free_anim_gputextures(G.main); } GPU_matrix_push_projection(); diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 80089815284..4c7a7cb4c61 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -23,70 +23,39 @@ * 3D view manipulation/operators. */ -#include <float.h> -#include <math.h> -#include <stdio.h> -#include <string.h> - #include "DNA_armature_types.h" #include "DNA_camera_types.h" -#include "DNA_curve_types.h" -#include "DNA_gpencil_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" #include "DNA_world_types.h" #include "MEM_guardedalloc.h" #include "BLI_blenlib.h" -#include "BLI_dial_2d.h" #include "BLI_math.h" -#include "BLI_utildefines.h" #include "BKE_action.h" #include "BKE_armature.h" #include "BKE_camera.h" -#include "BKE_context.h" -#include "BKE_gpencil_geom.h" -#include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" #include "BKE_object.h" -#include "BKE_paint.h" #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_screen.h" -#include "BKE_vfont.h" -#include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" #include "WM_api.h" #include "WM_message.h" -#include "WM_types.h" #include "RNA_access.h" #include "RNA_define.h" -#include "ED_armature.h" -#include "ED_mesh.h" -#include "ED_particle.h" #include "ED_screen.h" #include "ED_transform.h" #include "ED_transform_snap_object_context.h" -#include "ED_view3d.h" - -#include "UI_resources.h" - -#include "PIL_time.h" #include "view3d_intern.h" /* own include */ -enum { - HAS_TRANSLATE = (1 << 0), - HAS_ROTATE = (1 << 0), -}; - /* test for unlocked camera view in quad view */ static bool view3d_camera_user_poll(bContext *C) { @@ -115,3052 +84,6 @@ static bool view3d_lock_poll(bContext *C) return false; } -static bool view3d_pan_poll(bContext *C) -{ - if (ED_operator_region_view3d_active(C)) { - const RegionView3D *rv3d = CTX_wm_region_view3d(C); - return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_LOCATION); - } - return false; -} - -static bool view3d_zoom_or_dolly_poll(bContext *C) -{ - if (ED_operator_region_view3d_active(C)) { - const RegionView3D *rv3d = CTX_wm_region_view3d(C); - return !(RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ZOOM_AND_DOLLY); - } - return false; -} - -/* -------------------------------------------------------------------- */ -/** \name Generic View Operator Properties - * \{ */ - -enum eV3D_OpPropFlag { - V3D_OP_PROP_MOUSE_CO = (1 << 0), - V3D_OP_PROP_DELTA = (1 << 1), - V3D_OP_PROP_USE_ALL_REGIONS = (1 << 2), - V3D_OP_PROP_USE_MOUSE_INIT = (1 << 3), -}; - -static void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag) -{ - if (flag & V3D_OP_PROP_MOUSE_CO) { - PropertyRNA *prop; - prop = RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Region Position X", "", 0, INT_MAX); - RNA_def_property_flag(prop, PROP_HIDDEN); - prop = RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Region Position Y", "", 0, INT_MAX); - RNA_def_property_flag(prop, PROP_HIDDEN); - } - if (flag & V3D_OP_PROP_DELTA) { - RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX); - } - if (flag & V3D_OP_PROP_USE_ALL_REGIONS) { - PropertyRNA *prop; - prop = RNA_def_boolean( - ot->srna, "use_all_regions", 0, "All Regions", "View selected for all regions"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - } - if (flag & V3D_OP_PROP_USE_MOUSE_INIT) { - WM_operator_properties_use_cursor_init(ot); - } -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Generic View Operator Custom-Data - * \{ */ - -typedef struct ViewOpsData { - /** Context pointers (assigned by #viewops_data_alloc). */ - Main *bmain; - Scene *scene; - ScrArea *area; - ARegion *region; - View3D *v3d; - RegionView3D *rv3d; - Depsgraph *depsgraph; - - /** Needed for continuous zoom. */ - wmTimer *timer; - - /** Viewport state on initialization, don't change afterwards. */ - struct { - float dist; - float camzoom; - float quat[4]; - /** #wmEvent.xy. */ - int event_xy[2]; - /** Offset to use when #VIEWOPS_FLAG_USE_MOUSE_INIT is not set. - * so we can simulate pressing in the middle of the screen. */ - int event_xy_offset[2]; - /** #wmEvent.type that triggered the operator. */ - int event_type; - float ofs[3]; - /** Initial distance to 'ofs'. */ - float zfac; - - /** Trackball rotation only. */ - float trackvec[3]; - /** Dolly only. */ - float mousevec[3]; - - /** - * #RegionView3D.persp set after auto-perspective is applied. - * If we want the value before running the operator, add a separate member. - */ - char persp; - - /** Used for roll */ - Dial *dial; - } init; - - /** Previous state (previous modal event handled). */ - struct { - int event_xy[2]; - /** For operators that use time-steps (continuous zoom). */ - double time; - } prev; - - /** Current state. */ - struct { - /** Working copy of #RegionView3D.viewquat, needed for rotation calculation - * so we can apply snap to the 3D Viewport while keeping the unsnapped rotation - * here to use when snap is disabled and for continued calculation. */ - float viewquat[4]; - } curr; - - float reverse; - bool axis_snap; /* view rotate only */ - - /** Use for orbit selection and auto-dist. */ - float dyn_ofs[3]; - bool use_dyn_ofs; -} ViewOpsData; - -/** - * Size of the sphere being dragged for trackball rotation within the view bounds. - * also affects speed (smaller is faster). - */ -#define TRACKBALLSIZE (1.1f) - -static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3]) -{ - const float radius = TRACKBALLSIZE; - const float t = radius / (float)M_SQRT2; - const float size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}; - /* Aspect correct so dragging in a non-square view doesn't squash the direction. - * So diagonal motion rotates the same direction the cursor is moving. */ - const float size_min = min_ff(size[0], size[1]); - const float aspect[2] = {size_min / size[0], size_min / size[1]}; - - /* Normalize x and y. */ - r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0); - r_dir[1] = (event_xy[1] - BLI_rcti_cent_y(rect)) / ((size[1] * aspect[1]) / 2.0); - const float d = len_v2(r_dir); - if (d < t) { - /* Inside sphere. */ - r_dir[2] = sqrtf(square_f(radius) - square_f(d)); - } - else { - /* On hyperbola. */ - r_dir[2] = square_f(t) / d; - } -} - -/** - * Allocate and fill in context pointers for #ViewOpsData - */ -static void viewops_data_alloc(bContext *C, wmOperator *op) -{ - ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), "viewops data"); - - /* store data */ - op->customdata = vod; - vod->bmain = CTX_data_main(C); - vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - vod->scene = CTX_data_scene(C); - vod->area = CTX_wm_area(C); - vod->region = CTX_wm_region(C); - vod->v3d = vod->area->spacedata.first; - vod->rv3d = vod->region->regiondata; -} - -void view3d_orbit_apply_dyn_ofs(float r_ofs[3], - const float ofs_old[3], - const float viewquat_old[4], - const float viewquat_new[4], - const float dyn_ofs[3]) -{ - float q[4]; - invert_qt_qt_normalized(q, viewquat_old); - mul_qt_qtqt(q, q, viewquat_new); - - invert_qt_normalized(q); - - sub_v3_v3v3(r_ofs, ofs_old, dyn_ofs); - mul_qt_v3(q, r_ofs); - add_v3_v3(r_ofs, dyn_ofs); -} - -static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) -{ - static float lastofs[3] = {0, 0, 0}; - bool is_set = false; - - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); - View3D *v3d = CTX_wm_view3d(C); - Object *ob_act_eval = OBACT(view_layer_eval); - Object *ob_act = DEG_get_original_object(ob_act_eval); - - if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) && - /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */ - ((ob_act->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(ob_act)) == 0) { - /* in case of sculpting use last average stroke position as a rotation - * center, in other cases it's not clear what rotation center shall be - * so just rotate around object origin - */ - if (ob_act->mode & - (OB_MODE_SCULPT | OB_MODE_TEXTURE_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) { - float stroke[3]; - BKE_paint_stroke_get_average(scene, ob_act_eval, stroke); - copy_v3_v3(lastofs, stroke); - } - else { - copy_v3_v3(lastofs, ob_act_eval->obmat[3]); - } - is_set = true; - } - else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) { - Curve *cu = ob_act_eval->data; - EditFont *ef = cu->editfont; - - zero_v3(lastofs); - for (int i = 0; i < 4; i++) { - add_v2_v2(lastofs, ef->textcurs[i]); - } - mul_v2_fl(lastofs, 1.0f / 4.0f); - - mul_m4_v3(ob_act_eval->obmat, lastofs); - - is_set = true; - } - else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) { - /* object mode use boundbox centers */ - Base *base_eval; - uint tot = 0; - float select_center[3]; - - zero_v3(select_center); - for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) { - if (BASE_SELECTED(v3d, base_eval)) { - /* use the boundbox if we can */ - Object *ob_eval = base_eval->object; - - if (ob_eval->runtime.bb && !(ob_eval->runtime.bb->flag & BOUNDBOX_DIRTY)) { - float cent[3]; - - BKE_boundbox_calc_center_aabb(ob_eval->runtime.bb, cent); - - mul_m4_v3(ob_eval->obmat, cent); - add_v3_v3(select_center, cent); - } - else { - add_v3_v3(select_center, ob_eval->obmat[3]); - } - tot++; - } - } - if (tot) { - mul_v3_fl(select_center, 1.0f / (float)tot); - copy_v3_v3(lastofs, select_center); - is_set = true; - } - } - else { - /* If there's no selection, lastofs is unmodified and last value since static */ - is_set = calculateTransformCenter(C, V3D_AROUND_CENTER_MEDIAN, lastofs, NULL); - } - - copy_v3_v3(r_dyn_ofs, lastofs); - - return is_set; -} - -enum eViewOpsFlag { - /** When enabled, rotate around the selection. */ - VIEWOPS_FLAG_ORBIT_SELECT = (1 << 0), - /** When enabled, use the depth under the cursor for navigation. */ - VIEWOPS_FLAG_DEPTH_NAVIGATE = (1 << 1), - /** - * When enabled run #ED_view3d_persp_ensure this may switch out of camera view - * when orbiting or switch from orthographic to perspective when auto-perspective is enabled. - * Some operations don't require this (view zoom/pan or NDOF where subtle rotation is common - * so we don't want it to trigger auto-perspective). */ - VIEWOPS_FLAG_PERSP_ENSURE = (1 << 2), - /** When set, ignore any options that depend on initial cursor location. */ - VIEWOPS_FLAG_USE_MOUSE_INIT = (1 << 3), -}; - -static enum eViewOpsFlag viewops_flag_from_args(bool use_select, bool use_depth) -{ - enum eViewOpsFlag flag = 0; - if (use_select) { - flag |= VIEWOPS_FLAG_ORBIT_SELECT; - } - if (use_depth) { - flag |= VIEWOPS_FLAG_DEPTH_NAVIGATE; - } - - return flag; -} - -static enum eViewOpsFlag viewops_flag_from_prefs(void) -{ - return viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, - (U.uiflag & USER_DEPTH_NAVIGATE) != 0); -} - -/** - * Calculate the values for #ViewOpsData - */ -static void viewops_data_create(bContext *C, - wmOperator *op, - const wmEvent *event, - enum eViewOpsFlag viewops_flag) -{ - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ViewOpsData *vod = op->customdata; - RegionView3D *rv3d = vod->rv3d; - - /* Could do this more nicely. */ - if ((viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) == 0) { - viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE; - } - - /* we need the depth info before changing any viewport options */ - if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) { - float fallback_depth_pt[3]; - - view3d_operator_needs_opengl(C); /* needed for zbuf drawing */ - - negate_v3_v3(fallback_depth_pt, rv3d->ofs); - - vod->use_dyn_ofs = ED_view3d_autodist( - depsgraph, vod->region, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt); - } - else { - vod->use_dyn_ofs = false; - } - - if (viewops_flag & VIEWOPS_FLAG_PERSP_ENSURE) { - if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->region)) { - /* If we're switching from camera view to the perspective one, - * need to tag viewport update, so camera view and borders are properly updated. */ - ED_region_tag_redraw(vod->region); - } - } - - /* set the view from the camera, if view locking is enabled. - * we may want to make this optional but for now its needed always */ - ED_view3d_camera_lock_init(depsgraph, vod->v3d, vod->rv3d); - - vod->init.persp = rv3d->persp; - vod->init.dist = rv3d->dist; - vod->init.camzoom = rv3d->camzoom; - copy_qt_qt(vod->init.quat, rv3d->viewquat); - copy_v2_v2_int(vod->init.event_xy, event->xy); - copy_v2_v2_int(vod->prev.event_xy, event->xy); - - if (viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) { - zero_v2_int(vod->init.event_xy_offset); - } - else { - /* Simulate the event starting in the middle of the region. */ - vod->init.event_xy_offset[0] = BLI_rcti_cent_x(&vod->region->winrct) - event->xy[0]; - vod->init.event_xy_offset[1] = BLI_rcti_cent_y(&vod->region->winrct) - event->xy[1]; - } - - vod->init.event_type = event->type; - copy_v3_v3(vod->init.ofs, rv3d->ofs); - - copy_qt_qt(vod->curr.viewquat, rv3d->viewquat); - - if (viewops_flag & VIEWOPS_FLAG_ORBIT_SELECT) { - float ofs[3]; - if (view3d_orbit_calc_center(C, ofs) || (vod->use_dyn_ofs == false)) { - vod->use_dyn_ofs = true; - negate_v3_v3(vod->dyn_ofs, ofs); - viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE; - } - } - - if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) { - if (vod->use_dyn_ofs) { - if (rv3d->is_persp) { - float my_origin[3]; /* original G.vd->ofs */ - float my_pivot[3]; /* view */ - float dvec[3]; - - /* locals for dist correction */ - float mat[3][3]; - float upvec[3]; - - negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */ - - /* Set the dist value to be the distance from this 3d point this means you'll - * always be able to zoom into it and panning won't go bad when dist was zero. */ - - /* remove dist value */ - upvec[0] = upvec[1] = 0; - upvec[2] = rv3d->dist; - copy_m3_m4(mat, rv3d->viewinv); - - mul_m3_v3(mat, upvec); - sub_v3_v3v3(my_pivot, rv3d->ofs, upvec); - negate_v3(my_pivot); /* ofs is flipped */ - - /* find a new ofs value that is along the view axis - * (rather than the mouse location) */ - closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin); - vod->init.dist = rv3d->dist = len_v3v3(my_pivot, dvec); - - negate_v3_v3(rv3d->ofs, dvec); - } - else { - const float mval_region_mid[2] = {(float)vod->region->winx / 2.0f, - (float)vod->region->winy / 2.0f}; - - ED_view3d_win_to_3d(vod->v3d, vod->region, vod->dyn_ofs, mval_region_mid, rv3d->ofs); - negate_v3(rv3d->ofs); - } - negate_v3(vod->dyn_ofs); - copy_v3_v3(vod->init.ofs, rv3d->ofs); - } - } - - /* For dolly */ - ED_view3d_win_to_vector(vod->region, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec); - - { - int event_xy_offset[2]; - add_v2_v2v2_int(event_xy_offset, event->xy, vod->init.event_xy_offset); - - /* For rotation with trackball rotation. */ - calctrackballvec(&vod->region->winrct, event_xy_offset, vod->init.trackvec); - } - - { - float tvec[3]; - negate_v3_v3(tvec, rv3d->ofs); - vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL); - } - - vod->reverse = 1.0f; - if (rv3d->persmat[2][1] < 0.0f) { - vod->reverse = -1.0f; - } - - rv3d->rflag |= RV3D_NAVIGATING; -} - -static void viewops_data_free(bContext *C, wmOperator *op) -{ - ARegion *region; - if (op->customdata) { - ViewOpsData *vod = op->customdata; - region = vod->region; - vod->rv3d->rflag &= ~RV3D_NAVIGATING; - - if (vod->timer) { - WM_event_remove_timer(CTX_wm_manager(C), vod->timer->win, vod->timer); - } - - if (vod->init.dial) { - MEM_freeN(vod->init.dial); - } - - MEM_freeN(vod); - op->customdata = NULL; - } - else { - region = CTX_wm_region(C); - } - - /* Need to redraw because drawing code uses RV3D_NAVIGATING to draw - * faster while navigation operator runs. */ - ED_region_tag_redraw(region); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Rotate Operator - * \{ */ - -enum { - VIEW_PASS = 0, - VIEW_APPLY, - VIEW_CONFIRM, -}; - -/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */ -enum { - VIEW_MODAL_CONFIRM = 1, /* used for all view operations */ - VIEWROT_MODAL_AXIS_SNAP_ENABLE = 2, - VIEWROT_MODAL_AXIS_SNAP_DISABLE = 3, - VIEWROT_MODAL_SWITCH_ZOOM = 4, - VIEWROT_MODAL_SWITCH_MOVE = 5, - VIEWROT_MODAL_SWITCH_ROTATE = 6, -}; - -void viewrotate_modal_keymap(wmKeyConfig *keyconf) -{ - static const EnumPropertyItem modal_items[] = { - {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - - {VIEWROT_MODAL_AXIS_SNAP_ENABLE, "AXIS_SNAP_ENABLE", 0, "Axis Snap", ""}, - {VIEWROT_MODAL_AXIS_SNAP_DISABLE, "AXIS_SNAP_DISABLE", 0, "Axis Snap (Off)", ""}, - - {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, - {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - - {0, NULL, 0, NULL, NULL}, - }; - - wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Rotate Modal"); - - /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) { - return; - } - - keymap = WM_modalkeymap_ensure(keyconf, "View3D Rotate Modal", modal_items); - - /* disabled mode switching for now, can re-implement better, later on */ -#if 0 - WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); -#endif - - /* assign map to operators */ - WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate"); -} - -static void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4]) -{ - if (vod->use_dyn_ofs) { - RegionView3D *rv3d = vod->rv3d; - view3d_orbit_apply_dyn_ofs( - rv3d->ofs, vod->init.ofs, vod->init.quat, viewquat_new, vod->dyn_ofs); - } -} - -static void viewrotate_apply_snap(ViewOpsData *vod) -{ - const float axis_limit = DEG2RADF(45 / 3); - - RegionView3D *rv3d = vod->rv3d; - - float viewquat_inv[4]; - float zaxis[3] = {0, 0, 1}; - float zaxis_best[3]; - int x, y, z; - bool found = false; - - invert_qt_qt_normalized(viewquat_inv, vod->curr.viewquat); - - mul_qt_v3(viewquat_inv, zaxis); - normalize_v3(zaxis); - - for (x = -1; x < 2; x++) { - for (y = -1; y < 2; y++) { - for (z = -1; z < 2; z++) { - if (x || y || z) { - float zaxis_test[3] = {x, y, z}; - - normalize_v3(zaxis_test); - - if (angle_normalized_v3v3(zaxis_test, zaxis) < axis_limit) { - copy_v3_v3(zaxis_best, zaxis_test); - found = true; - } - } - } - } - } - - if (found) { - - /* find the best roll */ - float quat_roll[4], quat_final[4], quat_best[4], quat_snap[4]; - float viewquat_align[4]; /* viewquat aligned to zaxis_best */ - float viewquat_align_inv[4]; /* viewquat aligned to zaxis_best */ - float best_angle = axis_limit; - int j; - - /* viewquat_align is the original viewquat aligned to the snapped axis - * for testing roll */ - rotation_between_vecs_to_quat(viewquat_align, zaxis_best, zaxis); - normalize_qt(viewquat_align); - mul_qt_qtqt(viewquat_align, vod->curr.viewquat, viewquat_align); - normalize_qt(viewquat_align); - invert_qt_qt_normalized(viewquat_align_inv, viewquat_align); - - vec_to_quat(quat_snap, zaxis_best, OB_NEGZ, OB_POSY); - normalize_qt(quat_snap); - invert_qt_normalized(quat_snap); - - /* check if we can find the roll */ - found = false; - - /* find best roll */ - for (j = 0; j < 8; j++) { - float angle; - float xaxis1[3] = {1, 0, 0}; - float xaxis2[3] = {1, 0, 0}; - float quat_final_inv[4]; - - axis_angle_to_quat(quat_roll, zaxis_best, (float)j * DEG2RADF(45.0f)); - normalize_qt(quat_roll); - - mul_qt_qtqt(quat_final, quat_snap, quat_roll); - normalize_qt(quat_final); - - /* compare 2 vector angles to find the least roll */ - invert_qt_qt_normalized(quat_final_inv, quat_final); - mul_qt_v3(viewquat_align_inv, xaxis1); - mul_qt_v3(quat_final_inv, xaxis2); - angle = angle_v3v3(xaxis1, xaxis2); - - if (angle <= best_angle) { - found = true; - best_angle = angle; - copy_qt_qt(quat_best, quat_final); - } - } - - if (found) { - /* lock 'quat_best' to an axis view if we can */ - ED_view3d_quat_to_axis_view(quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll); - if (rv3d->view != RV3D_VIEW_USER) { - ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_best); - } - } - else { - copy_qt_qt(quat_best, viewquat_align); - } - - copy_qt_qt(rv3d->viewquat, quat_best); - - viewrotate_apply_dyn_ofs(vod, rv3d->viewquat); - - if (U.uiflag & USER_AUTOPERSP) { - if (RV3D_VIEW_IS_AXIS(rv3d->view)) { - if (rv3d->persp == RV3D_PERSP) { - rv3d->persp = RV3D_ORTHO; - } - } - } - } - else if (U.uiflag & USER_AUTOPERSP) { - rv3d->persp = vod->init.persp; - } -} - -static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) -{ - RegionView3D *rv3d = vod->rv3d; - - rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */ - - if (U.flag & USER_TRACKBALL) { - float axis[3], q1[4], dvec[3], newvec[3]; - float angle; - - { - const int event_xy_offset[2] = { - event_xy[0] + vod->init.event_xy_offset[0], - event_xy[1] + vod->init.event_xy_offset[1], - }; - calctrackballvec(&vod->region->winrct, event_xy_offset, newvec); - } - - sub_v3_v3v3(dvec, newvec, vod->init.trackvec); - - angle = (len_v3(dvec) / (2.0f * TRACKBALLSIZE)) * (float)M_PI; - - /* Before applying the sensitivity this is rotating 1:1, - * where the cursor would match the surface of a sphere in the view. */ - angle *= U.view_rotate_sensitivity_trackball; - - /* Allow for rotation beyond the interval [-pi, pi] */ - angle = angle_wrap_rad(angle); - - /* This relation is used instead of the actual angle between vectors - * so that the angle of rotation is linearly proportional to - * the distance that the mouse is dragged. */ - - cross_v3_v3v3(axis, vod->init.trackvec, newvec); - axis_angle_to_quat(q1, axis, angle); - - mul_qt_qtqt(vod->curr.viewquat, q1, vod->init.quat); - - viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); - } - else { - float quat_local_x[4], quat_global_z[4]; - float m[3][3]; - float m_inv[3][3]; - const float zvec_global[3] = {0.0f, 0.0f, 1.0f}; - float xaxis[3]; - - /* Radians per-pixel. */ - const float sensitivity = U.view_rotate_sensitivity_turntable / U.dpi_fac; - - /* Get the 3x3 matrix and its inverse from the quaternion */ - quat_to_mat3(m, vod->curr.viewquat); - invert_m3_m3(m_inv, m); - - /* Avoid Gimbal Lock - * - * Even though turn-table mode is in use, this can occur when the user exits the camera view - * or when aligning the view to a rotated object. - * - * We have gimbal lock when the user's view is rotated +/- 90 degrees along the view axis. - * In this case the vertical rotation is the same as the sideways turntable motion. - * Making it impossible to get out of the gimbal locked state without resetting the view. - * - * The logic below lets the user exit out of this state without any abrupt 'fix' - * which would be disorienting. - * - * This works by blending two horizons: - * - Rotated-horizon: `cross_v3_v3v3(xaxis, zvec_global, m_inv[2])` - * When only this is used, this turntable rotation works - but it's side-ways - * (as if the entire turn-table has been placed on its side) - * While there is no gimbal lock, it's also awkward to use. - * - Un-rotated-horizon: `m_inv[0]` - * When only this is used, the turntable rotation can have gimbal lock. - * - * The solution used here is to blend between these two values, - * so the severity of the gimbal lock is used to blend the rotated horizon. - * Blending isn't essential, it just makes the transition smoother. - * - * This allows sideways turn-table rotation on a Z axis that isn't world-space Z, - * While up-down turntable rotation eventually corrects gimbal lock. */ -#if 1 - if (len_squared_v3v3(zvec_global, m_inv[2]) > 0.001f) { - float fac; - cross_v3_v3v3(xaxis, zvec_global, m_inv[2]); - if (dot_v3v3(xaxis, m_inv[0]) < 0) { - negate_v3(xaxis); - } - fac = angle_normalized_v3v3(zvec_global, m_inv[2]) / (float)M_PI; - fac = fabsf(fac - 0.5f) * 2; - fac = fac * fac; - interp_v3_v3v3(xaxis, xaxis, m_inv[0], fac); - } - else { - copy_v3_v3(xaxis, m_inv[0]); - } -#else - copy_v3_v3(xaxis, m_inv[0]); -#endif - - /* Determine the direction of the x vector (for rotating up and down) */ - /* This can likely be computed directly from the quaternion. */ - - /* Perform the up/down rotation */ - axis_angle_to_quat(quat_local_x, xaxis, sensitivity * -(event_xy[1] - vod->prev.event_xy[1])); - mul_qt_qtqt(quat_local_x, vod->curr.viewquat, quat_local_x); - - /* Perform the orbital rotation */ - axis_angle_to_quat_single( - quat_global_z, 'Z', sensitivity * vod->reverse * (event_xy[0] - vod->prev.event_xy[0])); - mul_qt_qtqt(vod->curr.viewquat, quat_local_x, quat_global_z); - - viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); - } - - /* avoid precision loss over time */ - normalize_qt(vod->curr.viewquat); - - /* use a working copy so view rotation locking doesn't overwrite the locked - * rotation back into the view we calculate with */ - copy_qt_qt(rv3d->viewquat, vod->curr.viewquat); - - /* Check for view snap, - * NOTE: don't apply snap to `vod->viewquat` so the view won't jam up. */ - if (vod->axis_snap) { - viewrotate_apply_snap(vod); - } - vod->prev.event_xy[0] = event_xy[0]; - vod->prev.event_xy[1] = event_xy[1]; - - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d); - - ED_region_tag_redraw(vod->region); -} - -static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod = op->customdata; - short event_code = VIEW_PASS; - bool use_autokey = false; - int ret = OPERATOR_RUNNING_MODAL; - - /* execute the events */ - if (event->type == MOUSEMOVE) { - event_code = VIEW_APPLY; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case VIEW_MODAL_CONFIRM: - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_AXIS_SNAP_ENABLE: - vod->axis_snap = true; - event_code = VIEW_APPLY; - break; - case VIEWROT_MODAL_AXIS_SNAP_DISABLE: - vod->rv3d->persp = vod->init.persp; - vod->axis_snap = false; - event_code = VIEW_APPLY; - break; - case VIEWROT_MODAL_SWITCH_ZOOM: - WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - } - } - else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { - event_code = VIEW_CONFIRM; - } - - if (event_code == VIEW_APPLY) { - viewrotate_apply(vod, event->xy); - if (ED_screen_animation_playing(CTX_wm_manager(C))) { - use_autokey = true; - } - } - else if (event_code == VIEW_CONFIRM) { - use_autokey = true; - ret = OPERATOR_FINISHED; - } - - if (use_autokey) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); - } - - if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); - } - - return ret; -} - -static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod; - - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - /* makes op->customdata */ - viewops_data_alloc(C, op); - vod = op->customdata; - - /* poll should check but in some cases fails, see poll func for details */ - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) { - viewops_data_free(C, op); - return OPERATOR_PASS_THROUGH; - } - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - viewops_data_create(C, - op, - event, - viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - - if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { - /* Rotate direction we keep always same */ - int event_xy[2]; - - if (event->type == MOUSEPAN) { - if (event->is_direction_inverted) { - event_xy[0] = 2 * event->xy[0] - event->prev_xy[0]; - event_xy[1] = 2 * event->xy[1] - event->prev_xy[1]; - } - else { - copy_v2_v2_int(event_xy, event->prev_xy); - } - } - else { - /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ - copy_v2_v2_int(event_xy, event->prev_xy); - } - - viewrotate_apply(vod, event_xy); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; - } - - /* add temp handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static void viewrotate_cancel(bContext *C, wmOperator *op) -{ - viewops_data_free(C, op); -} - -void VIEW3D_OT_rotate(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Rotate View"; - ot->description = "Rotate the view"; - ot->idname = "VIEW3D_OT_rotate"; - - /* api callbacks */ - ot->invoke = viewrotate_invoke; - ot->modal = viewrotate_modal; - ot->poll = ED_operator_region_view3d_active; - ot->cancel = viewrotate_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; - - view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name NDOF Utility Functions - * \{ */ - -#ifdef WITH_INPUT_NDOF -static bool ndof_has_translate(const wmNDOFMotionData *ndof, - const View3D *v3d, - const RegionView3D *rv3d) -{ - return !is_zero_v3(ndof->tvec) && (!ED_view3d_offset_lock_check(v3d, rv3d)); -} - -static bool ndof_has_rotate(const wmNDOFMotionData *ndof, const RegionView3D *rv3d) -{ - return !is_zero_v3(ndof->rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0); -} - -/** - * \param depth_pt: A point to calculate the depth (in perspective mode) - */ -static float view3d_ndof_pan_speed_calc_ex(RegionView3D *rv3d, const float depth_pt[3]) -{ - float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND; - - if (rv3d->is_persp) { - speed *= ED_view3d_calc_zfac(rv3d, depth_pt, NULL); - } - - return speed; -} - -static float view3d_ndof_pan_speed_calc_from_dist(RegionView3D *rv3d, const float dist) -{ - float viewinv[4]; - float tvec[3]; - - BLI_assert(dist >= 0.0f); - - copy_v3_fl3(tvec, 0.0f, 0.0f, dist); - /* rv3d->viewinv isn't always valid */ -# if 0 - mul_mat3_m4_v3(rv3d->viewinv, tvec); -# else - invert_qt_qt_normalized(viewinv, rv3d->viewquat); - mul_qt_v3(viewinv, tvec); -# endif - - return view3d_ndof_pan_speed_calc_ex(rv3d, tvec); -} - -static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d) -{ - float tvec[3]; - negate_v3_v3(tvec, rv3d->ofs); - - return view3d_ndof_pan_speed_calc_ex(rv3d, tvec); -} - -/** - * Zoom and pan in the same function since sometimes zoom is interpreted as dolly (pan forward). - * - * \param has_zoom: zoom, otherwise dolly, - * often `!rv3d->is_persp` since it doesn't make sense to dolly in ortho. - */ -static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, - ScrArea *area, - ARegion *region, - const bool has_translate, - const bool has_zoom) -{ - RegionView3D *rv3d = region->regiondata; - float view_inv[4]; - float pan_vec[3]; - - if (has_translate == false && has_zoom == false) { - return; - } - - WM_event_ndof_pan_get(ndof, pan_vec, false); - - if (has_zoom) { - /* zoom with Z */ - - /* Zoom! - * velocity should be proportional to the linear velocity attained by rotational motion - * of same strength [got that?] proportional to `arclength = radius * angle`. - */ - - pan_vec[2] = 0.0f; - - /* "zoom in" or "translate"? depends on zoom mode in user settings? */ - if (ndof->tvec[2]) { - float zoom_distance = rv3d->dist * ndof->dt * ndof->tvec[2]; - - if (U.ndof_flag & NDOF_ZOOM_INVERT) { - zoom_distance = -zoom_distance; - } - - rv3d->dist += zoom_distance; - } - } - else { - /* dolly with Z */ - - /* all callers must check */ - if (has_translate) { - BLI_assert(ED_view3d_offset_lock_check((View3D *)area->spacedata.first, rv3d) == false); - } - } - - if (has_translate) { - const float speed = view3d_ndof_pan_speed_calc(rv3d); - - mul_v3_fl(pan_vec, speed * ndof->dt); - - /* transform motion from view to world coordinates */ - invert_qt_qt_normalized(view_inv, rv3d->viewquat); - mul_qt_v3(view_inv, pan_vec); - - /* move center of view opposite of hand motion (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, pan_vec); - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(area, region); - } - } -} - -static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, - ScrArea *area, - ARegion *region, - ViewOpsData *vod, - const bool apply_dyn_ofs) -{ - View3D *v3d = area->spacedata.first; - RegionView3D *rv3d = region->regiondata; - - float view_inv[4]; - - BLI_assert((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0); - - ED_view3d_persp_ensure(vod->depsgraph, v3d, region); - - rv3d->view = RV3D_VIEW_USER; - - invert_qt_qt_normalized(view_inv, rv3d->viewquat); - - if (U.ndof_flag & NDOF_TURNTABLE) { - float rot[3]; - - /* Turntable view code adapted for 3D mouse use. */ - float angle, quat[4]; - float xvec[3] = {1, 0, 0}; - - /* only use XY, ignore Z */ - WM_event_ndof_rotate_get(ndof, rot); - - /* Determine the direction of the x vector (for rotating up and down) */ - mul_qt_v3(view_inv, xvec); - - /* Perform the up/down rotation */ - angle = ndof->dt * rot[0]; - axis_angle_to_quat(quat, xvec, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); - - /* Perform the orbital rotation */ - angle = ndof->dt * rot[1]; - - /* update the onscreen doo-dad */ - rv3d->rot_angle = angle; - rv3d->rot_axis[0] = 0; - rv3d->rot_axis[1] = 0; - rv3d->rot_axis[2] = 1; - - axis_angle_to_quat_single(quat, 'Z', angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); - } - else { - float quat[4]; - float axis[3]; - float angle = WM_event_ndof_to_axis_angle(ndof, axis); - - /* transform rotation axis from view to world coordinates */ - mul_qt_v3(view_inv, axis); - - /* update the onscreen doo-dad */ - rv3d->rot_angle = angle; - copy_v3_v3(rv3d->rot_axis, axis); - - axis_angle_to_quat(quat, axis, angle); - - /* apply rotation */ - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); - } - - if (apply_dyn_ofs) { - viewrotate_apply_dyn_ofs(vod, rv3d->viewquat); - } -} - -void view3d_ndof_fly(const wmNDOFMotionData *ndof, - View3D *v3d, - RegionView3D *rv3d, - const bool use_precision, - const short protectflag, - bool *r_has_translate, - bool *r_has_rotate) -{ - bool has_translate = ndof_has_translate(ndof, v3d, rv3d); - bool has_rotate = ndof_has_rotate(ndof, rv3d); - - float view_inv[4]; - invert_qt_qt_normalized(view_inv, rv3d->viewquat); - - rv3d->rot_angle = 0.0f; /* disable onscreen rotation doo-dad */ - - if (has_translate) { - /* ignore real 'dist' since fly has its own speed settings, - * also its overwritten at this point. */ - float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f); - float trans[3], trans_orig_y; - - if (use_precision) { - speed *= 0.2f; - } - - WM_event_ndof_pan_get(ndof, trans, false); - mul_v3_fl(trans, speed * ndof->dt); - trans_orig_y = trans[1]; - - if (U.ndof_flag & NDOF_FLY_HELICOPTER) { - trans[1] = 0.0f; - } - - /* transform motion from view to world coordinates */ - mul_qt_v3(view_inv, trans); - - if (U.ndof_flag & NDOF_FLY_HELICOPTER) { - /* replace world z component with device y (yes it makes sense) */ - trans[2] = trans_orig_y; - } - - if (rv3d->persp == RV3D_CAMOB) { - /* respect camera position locks */ - if (protectflag & OB_LOCK_LOCX) { - trans[0] = 0.0f; - } - if (protectflag & OB_LOCK_LOCY) { - trans[1] = 0.0f; - } - if (protectflag & OB_LOCK_LOCZ) { - trans[2] = 0.0f; - } - } - - if (!is_zero_v3(trans)) { - /* move center of view opposite of hand motion - * (this is camera mode, not object mode) */ - sub_v3_v3(rv3d->ofs, trans); - has_translate = true; - } - else { - has_translate = false; - } - } - - if (has_rotate) { - const float turn_sensitivity = 1.0f; - - float rotation[4]; - float axis[3]; - float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis); - - if (fabsf(angle) > 0.0001f) { - has_rotate = true; - - if (use_precision) { - angle *= 0.2f; - } - - /* transform rotation axis from view to world coordinates */ - mul_qt_v3(view_inv, axis); - - /* apply rotation to view */ - axis_angle_to_quat(rotation, axis, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - - if (U.ndof_flag & NDOF_LOCK_HORIZON) { - /* force an upright viewpoint - * TODO: make this less... sudden */ - float view_horizon[3] = {1.0f, 0.0f, 0.0f}; /* view +x */ - float view_direction[3] = {0.0f, 0.0f, -1.0f}; /* view -z (into screen) */ - - /* find new inverse since viewquat has changed */ - invert_qt_qt_normalized(view_inv, rv3d->viewquat); - /* could apply reverse rotation to existing view_inv to save a few cycles */ - - /* transform view vectors to world coordinates */ - mul_qt_v3(view_inv, view_horizon); - mul_qt_v3(view_inv, view_direction); - - /* find difference between view & world horizons - * true horizon lives in world xy plane, so look only at difference in z */ - angle = -asinf(view_horizon[2]); - - /* rotate view so view horizon = world horizon */ - axis_angle_to_quat(rotation, view_direction, angle); - mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); - } - - rv3d->view = RV3D_VIEW_USER; - } - else { - has_rotate = false; - } - } - - *r_has_translate = has_translate; - *r_has_rotate = has_rotate; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name NDOF Orbit/Translate Operator - * \{ */ - -static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - if (event->type != NDOF_MOTION) { - return OPERATOR_CANCELLED; - } - - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ViewOpsData *vod; - View3D *v3d; - RegionView3D *rv3d; - char xform_flag = 0; - - const wmNDOFMotionData *ndof = event->customdata; - - viewops_data_alloc(C, op); - viewops_data_create( - C, op, event, viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, false)); - vod = op->customdata; - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - v3d = vod->v3d; - rv3d = vod->rv3d; - - /* off by default, until changed later this function */ - rv3d->rot_angle = 0.0f; - - ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); - - if (ndof->progress != P_FINISHING) { - const bool has_rotation = ndof_has_rotate(ndof, rv3d); - /* if we can't rotate, fallback to translate (locked axis views) */ - const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) && - (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION); - const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp; - - if (has_translate || has_zoom) { - view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom); - xform_flag |= HAS_TRANSLATE; - } - - if (has_rotation) { - view3d_ndof_orbit(ndof, vod->area, vod->region, vod, true); - xform_flag |= HAS_ROTATE; - } - } - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - if (xform_flag) { - ED_view3d_camera_lock_autokey( - v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE); - } - - ED_region_tag_redraw(vod->region); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "NDOF Orbit View"; - ot->description = "Orbit the view using the 3D mouse"; - ot->idname = "VIEW3D_OT_ndof_orbit"; - - /* api callbacks */ - ot->invoke = ndof_orbit_invoke; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name NDOF Orbit/Zoom Operator - * \{ */ - -static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - if (event->type != NDOF_MOTION) { - return OPERATOR_CANCELLED; - } - - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ViewOpsData *vod; - View3D *v3d; - RegionView3D *rv3d; - char xform_flag = 0; - - const wmNDOFMotionData *ndof = event->customdata; - - viewops_data_alloc(C, op); - viewops_data_create( - C, op, event, viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, false)); - - vod = op->customdata; - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - v3d = vod->v3d; - rv3d = vod->rv3d; - - /* off by default, until changed later this function */ - rv3d->rot_angle = 0.0f; - - ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); - - if (ndof->progress == P_FINISHING) { - /* pass */ - } - else if ((rv3d->persp == RV3D_ORTHO) && RV3D_VIEW_IS_AXIS(rv3d->view)) { - /* if we can't rotate, fallback to translate (locked axis views) */ - const bool has_translate = ndof_has_translate(ndof, v3d, rv3d); - const bool has_zoom = (ndof->tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d); - - if (has_translate || has_zoom) { - view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, true); - xform_flag |= HAS_TRANSLATE; - } - } - else { - /* NOTE: based on feedback from T67579, users want to have pan and orbit enabled at once. - * It's arguable that orbit shouldn't pan (since we have a pan only operator), - * so if there are users who like to separate orbit/pan operations - it can be a preference. */ - const bool is_orbit_around_pivot = (U.ndof_flag & NDOF_MODE_ORBIT) || - ED_view3d_offset_lock_check(v3d, rv3d); - const bool has_rotation = ndof_has_rotate(ndof, rv3d); - bool has_translate, has_zoom; - - if (is_orbit_around_pivot) { - /* Orbit preference or forced lock (Z zooms). */ - has_translate = !is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d); - has_zoom = (ndof->tvec[2] != 0.0f); - } - else { - /* Free preference (Z translates). */ - has_translate = ndof_has_translate(ndof, v3d, rv3d); - has_zoom = false; - } - - /* Rotation first because dynamic offset resets offset otherwise (and disables panning). */ - if (has_rotation) { - const float dist_backup = rv3d->dist; - if (!is_orbit_around_pivot) { - ED_view3d_distance_set(rv3d, 0.0f); - } - view3d_ndof_orbit(ndof, vod->area, vod->region, vod, is_orbit_around_pivot); - xform_flag |= HAS_ROTATE; - if (!is_orbit_around_pivot) { - ED_view3d_distance_set(rv3d, dist_backup); - } - } - - if (has_translate || has_zoom) { - view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom); - xform_flag |= HAS_TRANSLATE; - } - } - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - if (xform_flag) { - ED_view3d_camera_lock_autokey( - v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE); - } - - ED_region_tag_redraw(vod->region); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "NDOF Orbit View with Zoom"; - ot->description = "Orbit and zoom the view using the 3D mouse"; - ot->idname = "VIEW3D_OT_ndof_orbit_zoom"; - - /* api callbacks */ - ot->invoke = ndof_orbit_zoom_invoke; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name NDOF Pan/Zoom Operator - * \{ */ - -static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) -{ - if (event->type != NDOF_MOTION) { - return OPERATOR_CANCELLED; - } - - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - const wmNDOFMotionData *ndof = event->customdata; - char xform_flag = 0; - - const bool has_translate = ndof_has_translate(ndof, v3d, rv3d); - const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp; - - /* we're panning here! so erase any leftover rotation from other operators */ - rv3d->rot_angle = 0.0f; - - if (!(has_translate || has_zoom)) { - return OPERATOR_CANCELLED; - } - - ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); - - if (ndof->progress != P_FINISHING) { - ScrArea *area = CTX_wm_area(C); - ARegion *region = CTX_wm_region(C); - - if (has_translate || has_zoom) { - view3d_ndof_pan_zoom(ndof, area, region, has_translate, has_zoom); - xform_flag |= HAS_TRANSLATE; - } - } - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - if (xform_flag) { - ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, xform_flag & HAS_TRANSLATE); - } - - ED_region_tag_redraw(CTX_wm_region(C)); - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "NDOF Pan View"; - ot->description = "Pan the view with the 3D mouse"; - ot->idname = "VIEW3D_OT_ndof_pan"; - - /* api callbacks */ - ot->invoke = ndof_pan_invoke; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name NDOF Transform All Operator - * \{ */ - -/** - * wraps #ndof_orbit_zoom but never restrict to orbit. - */ -static int ndof_all_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - /* weak!, but it works */ - const int ndof_flag = U.ndof_flag; - int ret; - - U.ndof_flag &= ~NDOF_MODE_ORBIT; - - ret = ndof_orbit_zoom_invoke(C, op, event); - - U.ndof_flag = ndof_flag; - - return ret; -} - -void VIEW3D_OT_ndof_all(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "NDOF Transform View"; - ot->description = "Pan and rotate the view with the 3D mouse"; - ot->idname = "VIEW3D_OT_ndof_all"; - - /* api callbacks */ - ot->invoke = ndof_all_invoke; - ot->poll = ED_operator_view3d_active; - - /* flags */ - ot->flag = 0; -} - -#endif /* WITH_INPUT_NDOF */ - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Move (Pan) Operator - * \{ */ - -/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */ - -void viewmove_modal_keymap(wmKeyConfig *keyconf) -{ - static const EnumPropertyItem modal_items[] = { - {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - - {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, - {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, - - {0, NULL, 0, NULL, NULL}, - }; - - wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal"); - - /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) { - return; - } - - keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items); - - /* items for modal map */ - WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM); - WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM); - - /* disabled mode switching for now, can re-implement better, later on */ -#if 0 - WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); - WM_modalkeymap_add_item( - keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); -#endif - - /* assign map to operators */ - WM_modalkeymap_assign(keymap, "VIEW3D_OT_move"); -} - -static void viewmove_apply(ViewOpsData *vod, int x, int y) -{ - if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) { - vod->rv3d->ofs_lock[0] -= ((vod->prev.event_xy[0] - x) * 2.0f) / (float)vod->region->winx; - vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->region->winy; - } - else if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) { - const float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; - vod->rv3d->camdx += (vod->prev.event_xy[0] - x) / (vod->region->winx * zoomfac); - vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->region->winy * zoomfac); - CLAMP(vod->rv3d->camdx, -1.0f, 1.0f); - CLAMP(vod->rv3d->camdy, -1.0f, 1.0f); - } - else { - float dvec[3]; - float mval_f[2]; - - mval_f[0] = x - vod->prev.event_xy[0]; - mval_f[1] = y - vod->prev.event_xy[1]; - ED_view3d_win_to_delta(vod->region, mval_f, dvec, vod->init.zfac); - - add_v3_v3(vod->rv3d->ofs, dvec); - - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(vod->area, vod->region); - } - } - - vod->prev.event_xy[0] = x; - vod->prev.event_xy[1] = y; - - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - - ED_region_tag_redraw(vod->region); -} - -static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - - ViewOpsData *vod = op->customdata; - short event_code = VIEW_PASS; - bool use_autokey = false; - int ret = OPERATOR_RUNNING_MODAL; - - /* execute the events */ - if (event->type == MOUSEMOVE) { - event_code = VIEW_APPLY; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case VIEW_MODAL_CONFIRM: - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_ZOOM: - WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - } - } - else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { - event_code = VIEW_CONFIRM; - } - - if (event_code == VIEW_APPLY) { - viewmove_apply(vod, event->xy[0], event->xy[1]); - if (ED_screen_animation_playing(CTX_wm_manager(C))) { - use_autokey = true; - } - } - else if (event_code == VIEW_CONFIRM) { - use_autokey = true; - ret = OPERATOR_FINISHED; - } - - if (use_autokey) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); - } - - if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); - } - - return ret; -} - -static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod; - - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - /* makes op->customdata */ - viewops_data_alloc(C, op); - vod = op->customdata; - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_LOCATION) { - viewops_data_free(C, op); - return OPERATOR_PASS_THROUGH; - } - - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - if (event->type == MOUSEPAN) { - /* invert it, trackpad scroll follows same principle as 2d windows this way */ - viewmove_apply( - vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; - } - - /* add temp handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static void viewmove_cancel(bContext *C, wmOperator *op) -{ - viewops_data_free(C, op); -} - -void VIEW3D_OT_move(wmOperatorType *ot) -{ - - /* identifiers */ - ot->name = "Pan View"; - ot->description = "Move the view"; - ot->idname = "VIEW3D_OT_move"; - - /* api callbacks */ - ot->invoke = viewmove_invoke; - ot->modal = viewmove_modal; - ot->poll = ED_operator_region_view3d_active; - ot->cancel = viewmove_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; - - /* properties */ - view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Zoom Operator - * \{ */ - -/* #viewdolly_modal_keymap has an exact copy of this, apply fixes to both. */ -void viewzoom_modal_keymap(wmKeyConfig *keyconf) -{ - static const EnumPropertyItem modal_items[] = { - {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - - {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, - {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - - {0, NULL, 0, NULL, NULL}, - }; - - wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Zoom Modal"); - - /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) { - return; - } - - keymap = WM_modalkeymap_ensure(keyconf, "View3D Zoom Modal", modal_items); - - /* disabled mode switching for now, can re-implement better, later on */ -#if 0 - WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); -#endif - - /* assign map to operators */ - WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom"); -} - -/** - * \param zoom_xy: Optionally zoom to window location - * (coords compatible w/ #wmEvent.xy). Use when not NULL. - */ -static void view_zoom_to_window_xy_camera(Scene *scene, - Depsgraph *depsgraph, - View3D *v3d, - ARegion *region, - float dfac, - const int zoom_xy[2]) -{ - RegionView3D *rv3d = region->regiondata; - const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); - const float zoomfac_new = clamp_f( - zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR); - const float camzoom_new = BKE_screen_view3d_zoom_from_fac(zoomfac_new); - - if (zoom_xy != NULL) { - float zoomfac_px; - rctf camera_frame_old; - rctf camera_frame_new; - - const float pt_src[2] = {zoom_xy[0], zoom_xy[1]}; - float pt_dst[2]; - float delta_px[2]; - - ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_old, false); - BLI_rctf_translate(&camera_frame_old, region->winrct.xmin, region->winrct.ymin); - - rv3d->camzoom = camzoom_new; - CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); - - ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_new, false); - BLI_rctf_translate(&camera_frame_new, region->winrct.xmin, region->winrct.ymin); - - BLI_rctf_transform_pt_v(&camera_frame_new, &camera_frame_old, pt_dst, pt_src); - sub_v2_v2v2(delta_px, pt_dst, pt_src); - - /* translate the camera offset using pixel space delta - * mapped back to the camera (same logic as panning in camera view) */ - zoomfac_px = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f; - - rv3d->camdx += delta_px[0] / (region->winx * zoomfac_px); - rv3d->camdy += delta_px[1] / (region->winy * zoomfac_px); - CLAMP(rv3d->camdx, -1.0f, 1.0f); - CLAMP(rv3d->camdy, -1.0f, 1.0f); - } - else { - rv3d->camzoom = camzoom_new; - CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); - } -} - -/** - * \param zoom_xy: Optionally zoom to window location - * (coords compatible w/ #wmEvent.xy). Use when not NULL. - */ -static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2]) -{ - RegionView3D *rv3d = region->regiondata; - const float dist_new = rv3d->dist * dfac; - - if (zoom_xy != NULL) { - float dvec[3]; - float tvec[3]; - float tpos[3]; - float mval_f[2]; - - float zfac; - - negate_v3_v3(tpos, rv3d->ofs); - - mval_f[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f; - mval_f[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f; - - /* Project cursor position into 3D space */ - zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL); - ED_view3d_win_to_delta(region, mval_f, dvec, zfac); - - /* Calculate view target position for dolly */ - add_v3_v3v3(tvec, tpos, dvec); - negate_v3(tvec); - - /* Offset to target position and dolly */ - copy_v3_v3(rv3d->ofs, tvec); - rv3d->dist = dist_new; - - /* Calculate final offset */ - madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac); - } - else { - rv3d->dist = dist_new; - } -} - -static float viewzoom_scale_value(const rcti *winrct, - const eViewZoom_Style viewzoom, - const bool zoom_invert, - const bool zoom_invert_force, - const int xy_curr[2], - const int xy_init[2], - const float val, - const float val_orig, - double *r_timer_lastdraw) -{ - float zfac; - - if (viewzoom == USER_ZOOM_CONTINUE) { - double time = PIL_check_seconds_timer(); - float time_step = (float)(time - *r_timer_lastdraw); - float fac; - - if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(xy_init[0] - xy_curr[0]); - } - else { - fac = (float)(xy_init[1] - xy_curr[1]); - } - - fac /= U.dpi_fac; - - if (zoom_invert != zoom_invert_force) { - fac = -fac; - } - - zfac = 1.0f + ((fac / 20.0f) * time_step); - *r_timer_lastdraw = time; - } - else if (viewzoom == USER_ZOOM_SCALE) { - /* method which zooms based on how far you move the mouse */ - - const int ctr[2] = { - BLI_rcti_cent_x(winrct), - BLI_rcti_cent_y(winrct), - }; - float len_new = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_curr) / U.dpi_fac); - float len_old = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_init) / U.dpi_fac); - - /* intentionally ignore 'zoom_invert' for scale */ - if (zoom_invert_force) { - SWAP(float, len_new, len_old); - } - - zfac = val_orig * (len_old / max_ff(len_new, 1.0f)) / val; - } - else { /* USER_ZOOM_DOLLY */ - float len_new = 5 * U.dpi_fac; - float len_old = 5 * U.dpi_fac; - - if (U.uiflag & USER_ZOOM_HORIZ) { - len_new += (winrct->xmax - (xy_curr[0])) / U.dpi_fac; - len_old += (winrct->xmax - (xy_init[0])) / U.dpi_fac; - } - else { - len_new += (winrct->ymax - (xy_curr[1])) / U.dpi_fac; - len_old += (winrct->ymax - (xy_init[1])) / U.dpi_fac; - } - - if (zoom_invert != zoom_invert_force) { - SWAP(float, len_new, len_old); - } - - zfac = val_orig * (2.0f * ((len_new / max_ff(len_old, 1.0f)) - 1.0f) + 1.0f) / val; - } - - return zfac; -} - -static float viewzoom_scale_value_offset(const rcti *winrct, - const eViewZoom_Style viewzoom, - const bool zoom_invert, - const bool zoom_invert_force, - const int xy_curr[2], - const int xy_init[2], - const int xy_offset[2], - const float val, - const float val_orig, - double *r_timer_lastdraw) -{ - const int xy_curr_offset[2] = { - xy_curr[0] + xy_offset[0], - xy_curr[1] + xy_offset[1], - }; - const int xy_init_offset[2] = { - xy_init[0] + xy_offset[0], - xy_init[1] + xy_offset[1], - }; - return viewzoom_scale_value(winrct, - viewzoom, - zoom_invert, - zoom_invert_force, - xy_curr_offset, - xy_init_offset, - val, - val_orig, - r_timer_lastdraw); -} - -static void viewzoom_apply_camera(ViewOpsData *vod, - const int xy[2], - const eViewZoom_Style viewzoom, - const bool zoom_invert, - const bool zoom_to_pos) -{ - float zfac; - float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f; - float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; - - zfac = viewzoom_scale_value_offset(&vod->region->winrct, - viewzoom, - zoom_invert, - true, - xy, - vod->init.event_xy, - vod->init.event_xy_offset, - zoomfac, - zoomfac_prev, - &vod->prev.time); - - if (!ELEM(zfac, 1.0f, 0.0f)) { - /* calculate inverted, then invert again (needed because of camera zoom scaling) */ - zfac = 1.0f / zfac; - view_zoom_to_window_xy_camera(vod->scene, - vod->depsgraph, - vod->v3d, - vod->region, - zfac, - zoom_to_pos ? vod->prev.event_xy : NULL); - } - - ED_region_tag_redraw(vod->region); -} - -static void viewzoom_apply_3d(ViewOpsData *vod, - const int xy[2], - const eViewZoom_Style viewzoom, - const bool zoom_invert, - const bool zoom_to_pos) -{ - float zfac; - float dist_range[2]; - - ED_view3d_dist_range_get(vod->v3d, dist_range); - - zfac = viewzoom_scale_value_offset(&vod->region->winrct, - viewzoom, - zoom_invert, - false, - xy, - vod->init.event_xy, - vod->init.event_xy_offset, - vod->rv3d->dist, - vod->init.dist, - &vod->prev.time); - - if (zfac != 1.0f) { - const float zfac_min = dist_range[0] / vod->rv3d->dist; - const float zfac_max = dist_range[1] / vod->rv3d->dist; - CLAMP(zfac, zfac_min, zfac_max); - - view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL); - } - - /* these limits were in old code too */ - CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]); - - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(vod->area, vod->region); - } - - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - - ED_region_tag_redraw(vod->region); -} - -static void viewzoom_apply(ViewOpsData *vod, - const int xy[2], - const eViewZoom_Style viewzoom, - const bool zoom_invert, - const bool zoom_to_pos) -{ - if ((vod->rv3d->persp == RV3D_CAMOB) && - (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { - viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos); - } - else { - viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos); - } -} - -static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod = op->customdata; - short event_code = VIEW_PASS; - bool use_autokey = false; - int ret = OPERATOR_RUNNING_MODAL; - - /* execute the events */ - if (event->type == TIMER && event->customdata == vod->timer) { - /* continuous zoom */ - event_code = VIEW_APPLY; - } - else if (event->type == MOUSEMOVE) { - event_code = VIEW_APPLY; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case VIEW_MODAL_CONFIRM: - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - } - } - else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { - event_code = VIEW_CONFIRM; - } - - if (event_code == VIEW_APPLY) { - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - viewzoom_apply(vod, - event->xy, - (eViewZoom_Style)U.viewzoom, - (U.uiflag & USER_ZOOM_INVERT) != 0, - (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); - if (ED_screen_animation_playing(CTX_wm_manager(C))) { - use_autokey = true; - } - } - else if (event_code == VIEW_CONFIRM) { - use_autokey = true; - ret = OPERATOR_FINISHED; - } - - if (use_autokey) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); - } - - if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); - } - - return ret; -} - -static int viewzoom_exec(bContext *C, wmOperator *op) -{ - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene = CTX_data_scene(C); - View3D *v3d; - RegionView3D *rv3d; - ScrArea *area; - ARegion *region; - bool use_cam_zoom; - float dist_range[2]; - - const int delta = RNA_int_get(op->ptr, "delta"); - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - if (op->customdata) { - ViewOpsData *vod = op->customdata; - - area = vod->area; - region = vod->region; - } - else { - area = CTX_wm_area(C); - region = CTX_wm_region(C); - } - - v3d = area->spacedata.first; - rv3d = region->regiondata; - - use_cam_zoom = (rv3d->persp == RV3D_CAMOB) && - !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d)); - - int zoom_xy_buf[2]; - const int *zoom_xy = NULL; - if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { - zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : - region->winx / 2; - zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : - region->winy / 2; - zoom_xy = zoom_xy_buf; - } - - ED_view3d_dist_range_get(v3d, dist_range); - - if (delta < 0) { - const float step = 1.2f; - /* this min and max is also in viewmove() */ - if (use_cam_zoom) { - view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); - } - else { - if (rv3d->dist < dist_range[1]) { - view_zoom_to_window_xy_3d(region, step, zoom_xy); - } - } - } - else { - const float step = 1.0f / 1.2f; - if (use_cam_zoom) { - view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); - } - else { - if (rv3d->dist > dist_range[0]) { - view_zoom_to_window_xy_3d(region, step, zoom_xy); - } - } - } - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(area, region); - } - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true); - - ED_region_tag_redraw(region); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; -} - -/* viewdolly_invoke() copied this function, changes here may apply there */ -static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod; - - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - /* makes op->customdata */ - viewops_data_alloc(C, op); - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - vod = op->customdata; - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - /* if one or the other zoom position aren't set, set from event */ - if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { - RNA_int_set(op->ptr, "mx", event->xy[0]); - RNA_int_set(op->ptr, "my", event->xy[1]); - } - - if (RNA_struct_property_is_set(op->ptr, "delta")) { - viewzoom_exec(C, op); - } - else { - if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { - - if (U.uiflag & USER_ZOOM_HORIZ) { - vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; - } - else { - /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ - vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - - event->prev_xy[0]; - } - viewzoom_apply(vod, - event->prev_xy, - USER_ZOOM_DOLLY, - (U.uiflag & USER_ZOOM_INVERT) != 0, - (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); - - viewops_data_free(C, op); - return OPERATOR_FINISHED; - } - - if (U.viewzoom == USER_ZOOM_CONTINUE) { - /* needs a timer to continue redrawing */ - vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); - vod->prev.time = PIL_check_seconds_timer(); - } - - /* add temp handler */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; - } - return OPERATOR_FINISHED; -} - -static void viewzoom_cancel(bContext *C, wmOperator *op) -{ - viewops_data_free(C, op); -} - -void VIEW3D_OT_zoom(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Zoom View"; - ot->description = "Zoom in/out in the view"; - ot->idname = "VIEW3D_OT_zoom"; - - /* api callbacks */ - ot->invoke = viewzoom_invoke; - ot->exec = viewzoom_exec; - ot->modal = viewzoom_modal; - ot->poll = view3d_zoom_or_dolly_poll; - ot->cancel = viewzoom_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; - - /* properties */ - view3d_operator_properties_common( - ot, V3D_OP_PROP_DELTA | V3D_OP_PROP_MOUSE_CO | V3D_OP_PROP_USE_MOUSE_INIT); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Dolly Operator - * - * Like zoom but translates the view offset along the view direction - * which avoids #RegionView3D.dist approaching zero. - * \{ */ - -/* This is an exact copy of #viewzoom_modal_keymap. */ -void viewdolly_modal_keymap(wmKeyConfig *keyconf) -{ - static const EnumPropertyItem modal_items[] = { - {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, - - {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, - {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, - - {0, NULL, 0, NULL, NULL}, - }; - - wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Dolly Modal"); - - /* this function is called for each spacetype, only needs to add map once */ - if (keymap && keymap->modal_items) { - return; - } - - keymap = WM_modalkeymap_ensure(keyconf, "View3D Dolly Modal", modal_items); - - /* disabled mode switching for now, can re-implement better, later on */ -#if 0 - WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); - WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); -#endif - - /* assign map to operators */ - WM_modalkeymap_assign(keymap, "VIEW3D_OT_dolly"); -} - -static bool viewdolly_offset_lock_check(bContext *C, wmOperator *op) -{ - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - if (ED_view3d_offset_lock_check(v3d, rv3d)) { - BKE_report(op->reports, RPT_WARNING, "Cannot dolly when the view offset is locked"); - return true; - } - return false; -} - -static void view_dolly_to_vector_3d(ARegion *region, - const float orig_ofs[3], - const float dvec[3], - float dfac) -{ - RegionView3D *rv3d = region->regiondata; - madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac)); -} - -static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const bool zoom_invert) -{ - float zfac = 1.0; - - { - float len1, len2; - - if (U.uiflag & USER_ZOOM_HORIZ) { - len1 = (vod->region->winrct.xmax - xy[0]) + 5; - len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5; - } - else { - len1 = (vod->region->winrct.ymax - xy[1]) + 5; - len2 = (vod->region->winrct.ymax - vod->init.event_xy[1]) + 5; - } - if (zoom_invert) { - SWAP(float, len1, len2); - } - - zfac = 1.0f + ((len1 - len2) * 0.01f * vod->rv3d->dist); - } - - if (zfac != 1.0f) { - view_dolly_to_vector_3d(vod->region, vod->init.ofs, vod->init.mousevec, zfac); - } - - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(vod->area, vod->region); - } - - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - - ED_region_tag_redraw(vod->region); -} - -static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod = op->customdata; - short event_code = VIEW_PASS; - bool use_autokey = false; - int ret = OPERATOR_RUNNING_MODAL; - - /* execute the events */ - if (event->type == MOUSEMOVE) { - event_code = VIEW_APPLY; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case VIEW_MODAL_CONFIRM: - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - } - } - else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { - event_code = VIEW_CONFIRM; - } - - if (event_code == VIEW_APPLY) { - viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0); - if (ED_screen_animation_playing(CTX_wm_manager(C))) { - use_autokey = true; - } - } - else if (event_code == VIEW_CONFIRM) { - use_autokey = true; - ret = OPERATOR_FINISHED; - } - - if (use_autokey) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); - } - - if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); - } - - return ret; -} - -static int viewdolly_exec(bContext *C, wmOperator *op) -{ - View3D *v3d; - RegionView3D *rv3d; - ScrArea *area; - ARegion *region; - float mousevec[3]; - - const int delta = RNA_int_get(op->ptr, "delta"); - - if (op->customdata) { - ViewOpsData *vod = op->customdata; - - area = vod->area; - region = vod->region; - copy_v3_v3(mousevec, vod->init.mousevec); - } - else { - area = CTX_wm_area(C); - region = CTX_wm_region(C); - negate_v3_v3(mousevec, ((RegionView3D *)region->regiondata)->viewinv[2]); - normalize_v3(mousevec); - } - - v3d = area->spacedata.first; - rv3d = region->regiondata; - - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - /* overwrite the mouse vector with the view direction (zoom into the center) */ - if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { - normalize_v3_v3(mousevec, rv3d->viewinv[2]); - negate_v3(mousevec); - } - - view_dolly_to_vector_3d(region, rv3d->ofs, mousevec, delta < 0 ? 1.8f : 0.2f); - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(area, region); - } - - ED_view3d_camera_lock_sync(CTX_data_ensure_evaluated_depsgraph(C), v3d, rv3d); - - ED_region_tag_redraw(region); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; -} - -/* copied from viewzoom_invoke(), changes here may apply there */ -static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod; - - if (viewdolly_offset_lock_check(C, op)) { - return OPERATOR_CANCELLED; - } - - /* makes op->customdata */ - viewops_data_alloc(C, op); - vod = op->customdata; - - /* poll should check but in some cases fails, see poll func for details */ - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_LOCK_ROTATION) { - viewops_data_free(C, op); - return OPERATOR_PASS_THROUGH; - } - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - /* needs to run before 'viewops_data_create' so the backup 'rv3d->ofs' is correct */ - /* switch from camera view when: */ - if (vod->rv3d->persp != RV3D_PERSP) { - if (vod->rv3d->persp == RV3D_CAMOB) { - /* ignore rv3d->lpersp because dolly only makes sense in perspective mode */ - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ED_view3d_persp_switch_from_camera(depsgraph, vod->v3d, vod->rv3d, RV3D_PERSP); - } - else { - vod->rv3d->persp = RV3D_PERSP; - } - ED_region_tag_redraw(vod->region); - } - - const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); - - viewops_data_create(C, - op, - event, - (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | - (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); - - /* if one or the other zoom position aren't set, set from event */ - if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { - RNA_int_set(op->ptr, "mx", event->xy[0]); - RNA_int_set(op->ptr, "my", event->xy[1]); - } - - if (RNA_struct_property_is_set(op->ptr, "delta")) { - viewdolly_exec(C, op); - } - else { - /* overwrite the mouse vector with the view direction (zoom into the center) */ - if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { - negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); - normalize_v3(vod->init.mousevec); - } - - if (event->type == MOUSEZOOM) { - /* Bypass Zoom invert flag for track pads (pass false always) */ - - if (U.uiflag & USER_ZOOM_HORIZ) { - vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; - } - else { - /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ - vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - - event->prev_xy[0]; - } - viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0); - - viewops_data_free(C, op); - return OPERATOR_FINISHED; - } - - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } - return OPERATOR_FINISHED; -} - -static void viewdolly_cancel(bContext *C, wmOperator *op) -{ - viewops_data_free(C, op); -} - -void VIEW3D_OT_dolly(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Dolly View"; - ot->description = "Dolly in/out in the view"; - ot->idname = "VIEW3D_OT_dolly"; - - /* api callbacks */ - ot->invoke = viewdolly_invoke; - ot->exec = viewdolly_exec; - ot->modal = viewdolly_modal; - ot->poll = ED_operator_region_view3d_active; - ot->cancel = viewdolly_cancel; - - /* flags */ - ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; - - /* properties */ - view3d_operator_properties_common( - ot, V3D_OP_PROP_DELTA | V3D_OP_PROP_MOUSE_CO | V3D_OP_PROP_USE_MOUSE_INIT); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View All Operator - * - * Move & Zoom the view to fit all of its contents. - * \{ */ - -static bool view3d_object_skip_minmax(const View3D *v3d, - const RegionView3D *rv3d, - const Object *ob, - const bool skip_camera, - bool *r_only_center) -{ - BLI_assert(ob->id.orig_id == NULL); - *r_only_center = false; - - if (skip_camera && (ob == v3d->camera)) { - return true; - } - - if ((ob->type == OB_EMPTY) && (ob->empty_drawtype == OB_EMPTY_IMAGE) && - !BKE_object_empty_image_frame_is_visible_in_view3d(ob, rv3d)) { - *r_only_center = true; - return false; - } - - return false; -} - -static void view3d_object_calc_minmax(Depsgraph *depsgraph, - Scene *scene, - Object *ob_eval, - const bool only_center, - float min[3], - float max[3]) -{ - /* Account for duplis. */ - if (BKE_object_minmax_dupli(depsgraph, scene, ob_eval, min, max, false) == 0) { - /* Use if duplis aren't found. */ - if (only_center) { - minmax_v3v3_v3(min, max, ob_eval->obmat[3]); - } - else { - BKE_object_minmax(ob_eval, min, max, false); - } - } -} - -static void view3d_from_minmax(bContext *C, - View3D *v3d, - ARegion *region, - const float min[3], - const float max[3], - bool ok_dist, - const int smooth_viewtx) -{ - RegionView3D *rv3d = region->regiondata; - float afm[3]; - float size; - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - /* SMOOTHVIEW */ - float new_ofs[3]; - float new_dist; - - sub_v3_v3v3(afm, max, min); - size = max_fff(afm[0], afm[1], afm[2]); - - if (ok_dist) { - char persp; - - if (rv3d->is_persp) { - if (rv3d->persp == RV3D_CAMOB && ED_view3d_camera_lock_check(v3d, rv3d)) { - persp = RV3D_CAMOB; - } - else { - persp = RV3D_PERSP; - } - } - else { /* ortho */ - if (size < 0.0001f) { - /* bounding box was a single point so do not zoom */ - ok_dist = false; - } - else { - /* adjust zoom so it looks nicer */ - persp = RV3D_ORTHO; - } - } - - if (ok_dist) { - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - new_dist = ED_view3d_radius_to_dist( - v3d, region, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN); - if (rv3d->is_persp) { - /* don't zoom closer than the near clipping plane */ - new_dist = max_ff(new_dist, v3d->clip_start * 1.5f); - } - } - } - - mid_v3_v3v3(new_ofs, min, max); - negate_v3(new_ofs); - - if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) { - rv3d->persp = RV3D_PERSP; - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = v3d->camera, - .ofs = new_ofs, - .dist = ok_dist ? &new_dist : NULL, - }); - } - else { - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .ofs = new_ofs, - .dist = ok_dist ? &new_dist : NULL, - }); - } - - /* Smooth-view does view-lock #RV3D_BOXVIEW copy. */ -} - -/** - * Same as #view3d_from_minmax but for all regions (except cameras). - */ -static void view3d_from_minmax_multi(bContext *C, - View3D *v3d, - const float min[3], - const float max[3], - const bool ok_dist, - const int smooth_viewtx) -{ - ScrArea *area = CTX_wm_area(C); - ARegion *region; - for (region = area->regionbase.first; region; region = region->next) { - if (region->regiontype == RGN_TYPE_WINDOW) { - RegionView3D *rv3d = region->regiondata; - /* when using all regions, don't jump out of camera view, - * but _do_ allow locked cameras to be moved */ - if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { - view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx); - } - } - } -} - -static int view3d_all_exec(bContext *C, wmOperator *op) -{ - ARegion *region = CTX_wm_region(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); - Base *base_eval; - const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); - const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) || - /* any one of the regions may be locked */ - (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); - const bool center = RNA_boolean_get(op->ptr, "center"); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - float min[3], max[3]; - bool changed = false; - - if (center) { - /* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */ - View3DCursor *cursor = &scene->cursor; - zero_v3(min); - zero_v3(max); - zero_v3(cursor->location); - float mat3[3][3]; - unit_m3(mat3); - BKE_scene_cursor_mat3_to_rot(cursor, mat3, false); - } - else { - INIT_MINMAX(min, max); - } - - for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { - if (BASE_VISIBLE(v3d, base_eval)) { - bool only_center = false; - Object *ob = DEG_get_original_object(base_eval->object); - if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) { - continue; - } - view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max); - changed = true; - } - } - - if (center) { - struct wmMsgBus *mbus = CTX_wm_message_bus(C); - WM_msg_publish_rna_prop(mbus, &scene->id, &scene->cursor, View3DCursor, location); - - DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); - } - - if (!changed) { - ED_region_tag_redraw(region); - /* TODO: should this be cancel? - * I think no, because we always move the cursor, with or without - * object, but in this case there is no change in the scene, - * only the cursor so I choice a ED_region_tag like - * view3d_smooth_view do for the center_cursor. - * See bug T22640. - */ - return OPERATOR_FINISHED; - } - - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - /* This is an approximation, see function documentation for details. */ - ED_view3d_clipping_clamp_minmax(rv3d, min, max); - } - - if (use_all_regions) { - view3d_from_minmax_multi(C, v3d, min, max, true, smooth_viewtx); - } - else { - view3d_from_minmax(C, v3d, region, min, max, true, smooth_viewtx); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_all(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Frame All"; - ot->description = "View all objects in scene"; - ot->idname = "VIEW3D_OT_view_all"; - - /* api callbacks */ - ot->exec = view3d_all_exec; - ot->poll = ED_operator_region_view3d_active; - - /* flags */ - ot->flag = 0; - - /* properties */ - view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); - RNA_def_boolean(ot->srna, "center", 0, "Center", ""); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name Frame Selected Operator - * - * Move & Zoom the view to fit selected contents. - * \{ */ - -static int viewselected_exec(bContext *C, wmOperator *op) -{ - ARegion *region = CTX_wm_region(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); - Object *ob_eval = OBACT(view_layer_eval); - Object *obedit = CTX_data_edit_object(C); - const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL; - const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false; - const bool is_face_map = ((is_gp_edit == false) && region->gizmo_map && - WM_gizmomap_is_any_selected(region->gizmo_map)); - float min[3], max[3]; - bool ok = false, ok_dist = true; - const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); - const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) || - /* any one of the regions may be locked */ - (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - INIT_MINMAX(min, max); - if (is_face_map) { - ob_eval = NULL; - } - - if (ob_eval && (ob_eval->mode & OB_MODE_WEIGHT_PAINT)) { - /* 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... */ - Base *base_eval; - for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { - if (BASE_SELECTED_EDITABLE(v3d, base_eval)) { - if (base_eval->object->type == OB_ARMATURE) { - if (base_eval->object->mode & OB_MODE_POSE) { - break; - } - } - } - } - if (base_eval) { - ob_eval = base_eval->object; - } - } - - if (is_gp_edit) { - CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { - /* we're only interested in selected points here... */ - if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) { - ok |= BKE_gpencil_stroke_minmax(gps, true, min, max); - } - if (gps->editcurve != NULL) { - for (int i = 0; i < gps->editcurve->tot_curve_points; i++) { - BezTriple *bezt = &gps->editcurve->curve_points[i].bezt; - if ((bezt->f1 & SELECT)) { - minmax_v3v3_v3(min, max, bezt->vec[0]); - ok = true; - } - if ((bezt->f2 & SELECT)) { - minmax_v3v3_v3(min, max, bezt->vec[1]); - ok = true; - } - if ((bezt->f3 & SELECT)) { - minmax_v3v3_v3(min, max, bezt->vec[2]); - ok = true; - } - } - } - } - CTX_DATA_END; - - if ((ob_eval) && (ok)) { - mul_m4_v3(ob_eval->obmat, min); - mul_m4_v3(ob_eval->obmat, max); - } - } - else if (is_face_map) { - ok = WM_gizmomap_minmax(region->gizmo_map, true, true, min, max); - } - else if (obedit) { - /* only selected */ - FOREACH_OBJECT_IN_MODE_BEGIN (view_layer_eval, v3d, obedit->type, obedit->mode, ob_eval_iter) { - ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max); - } - FOREACH_OBJECT_IN_MODE_END; - } - else if (ob_eval && (ob_eval->mode & OB_MODE_POSE)) { - FOREACH_OBJECT_IN_MODE_BEGIN ( - view_layer_eval, v3d, ob_eval->type, ob_eval->mode, ob_eval_iter) { - ok |= BKE_pose_minmax(ob_eval_iter, min, max, true, true); - } - FOREACH_OBJECT_IN_MODE_END; - } - else if (BKE_paint_select_face_test(ob_eval)) { - ok = paintface_minmax(ob_eval, min, max); - } - else if (ob_eval && (ob_eval->mode & OB_MODE_PARTICLE_EDIT)) { - ok = PE_minmax(depsgraph, scene, CTX_data_view_layer(C), min, max); - } - else if (ob_eval && (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_eval, min); - copy_v3_v3(max, min); - ok = true; - ok_dist = 0; /* don't zoom */ - } - else { - Base *base_eval; - for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) { - if (BASE_SELECTED(v3d, base_eval)) { - bool only_center = false; - Object *ob = DEG_get_original_object(base_eval->object); - if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) { - continue; - } - view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max); - ok = 1; - } - } - } - - if (ok == 0) { - return OPERATOR_FINISHED; - } - - if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { - /* This is an approximation, see function documentation for details. */ - ED_view3d_clipping_clamp_minmax(rv3d, min, max); - } - - if (use_all_regions) { - view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx); - } - else { - view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_selected(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Frame Selected"; - ot->description = "Move the view to the selection center"; - ot->idname = "VIEW3D_OT_view_selected"; - - /* api callbacks */ - ot->exec = viewselected_exec; - ot->poll = view3d_zoom_or_dolly_poll; - - /* flags */ - ot->flag = 0; - - /* properties */ - view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name View Lock Clear Operator * \{ */ @@ -3256,103 +179,6 @@ void VIEW3D_OT_view_lock_to_active(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name View Center Cursor Operator - * \{ */ - -static int viewcenter_cursor_exec(bContext *C, wmOperator *op) -{ - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - Scene *scene = CTX_data_scene(C); - - if (rv3d) { - ARegion *region = CTX_wm_region(C); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - /* non camera center */ - float new_ofs[3]; - negate_v3_v3(new_ofs, scene->cursor.location); - ED_view3d_smooth_view( - C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs}); - - /* Smooth view does view-lock #RV3D_BOXVIEW copy. */ - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_center_cursor(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Center View to Cursor"; - ot->description = "Center the view so that the cursor is in the middle of the view"; - ot->idname = "VIEW3D_OT_view_center_cursor"; - - /* api callbacks */ - ot->exec = viewcenter_cursor_exec; - ot->poll = view3d_pan_poll; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Center Pick Operator - * \{ */ - -static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - ARegion *region = CTX_wm_region(C); - - if (rv3d) { - struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - float new_ofs[3]; - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - view3d_operator_needs_opengl(C); - - if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, NULL)) { - /* pass */ - } - else { - /* fallback to simple pan */ - negate_v3_v3(new_ofs, rv3d->ofs); - ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs); - } - negate_v3(new_ofs); - ED_view3d_smooth_view( - C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs}); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_center_pick(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Center View to Mouse"; - ot->description = "Center the view to the Z-depth position under the mouse cursor"; - ot->idname = "VIEW3D_OT_view_center_pick"; - - /* api callbacks */ - ot->invoke = viewcenter_pick_invoke; - ot->poll = view3d_pan_poll; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Frame Camera Bounds Operator * \{ */ @@ -3591,189 +417,6 @@ void VIEW3D_OT_clear_render_border(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name Border Zoom Operator - * \{ */ - -static int view3d_zoom_border_exec(bContext *C, wmOperator *op) -{ - ARegion *region = CTX_wm_region(C); - View3D *v3d = CTX_wm_view3d(C); - RegionView3D *rv3d = CTX_wm_region_view3d(C); - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - /* Zooms in on a border drawn by the user */ - rcti rect; - float dvec[3], vb[2], xscale, yscale; - float dist_range[2]; - - /* SMOOTHVIEW */ - float new_dist; - float new_ofs[3]; - - /* ZBuffer depth vars */ - float depth_close = FLT_MAX; - float cent[2], p[3]; - - /* NOTE: otherwise opengl won't work. */ - view3d_operator_needs_opengl(C); - - /* get box select values using rna */ - WM_operator_properties_border_to_rcti(op, &rect); - - /* check if zooming in/out view */ - const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out"); - - ED_view3d_dist_range_get(v3d, dist_range); - - ED_view3d_depth_override( - CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL); - { - /* avoid allocating the whole depth buffer */ - ViewDepths depth_temp = {0}; - - /* avoid view3d_update_depths() for speed. */ - view3d_depths_rect_create(region, &rect, &depth_temp); - - /* find the closest Z pixel */ - depth_close = view3d_depth_near(&depth_temp); - - MEM_SAFE_FREE(depth_temp.depths); - } - - /* Resize border to the same ratio as the window. */ - { - const float region_aspect = (float)region->winx / (float)region->winy; - if (((float)BLI_rcti_size_x(&rect) / (float)BLI_rcti_size_y(&rect)) < region_aspect) { - BLI_rcti_resize_x(&rect, (int)(BLI_rcti_size_y(&rect) * region_aspect)); - } - else { - BLI_rcti_resize_y(&rect, (int)(BLI_rcti_size_x(&rect) / region_aspect)); - } - } - - cent[0] = (((float)rect.xmin) + ((float)rect.xmax)) / 2; - cent[1] = (((float)rect.ymin) + ((float)rect.ymax)) / 2; - - if (rv3d->is_persp) { - float p_corner[3]; - - /* no depths to use, we can't do anything! */ - if (depth_close == FLT_MAX) { - BKE_report(op->reports, RPT_ERROR, "Depth too large"); - return OPERATOR_CANCELLED; - } - /* convert border to 3d coordinates */ - if ((!ED_view3d_unproject_v3(region, cent[0], cent[1], depth_close, p)) || - (!ED_view3d_unproject_v3(region, rect.xmin, rect.ymin, depth_close, p_corner))) { - return OPERATOR_CANCELLED; - } - - sub_v3_v3v3(dvec, p, p_corner); - negate_v3_v3(new_ofs, p); - - new_dist = len_v3(dvec); - - /* Account for the lens, without this a narrow lens zooms in too close. */ - new_dist *= (v3d->lens / DEFAULT_SENSOR_WIDTH); - - /* ignore dist_range min */ - dist_range[0] = v3d->clip_start * 1.5f; - } - else { /* orthographic */ - /* find the current window width and height */ - vb[0] = region->winx; - vb[1] = region->winy; - - new_dist = rv3d->dist; - - /* convert the drawn rectangle into 3d space */ - if (depth_close != FLT_MAX && - ED_view3d_unproject_v3(region, cent[0], cent[1], depth_close, p)) { - negate_v3_v3(new_ofs, p); - } - else { - float mval_f[2]; - float zfac; - - /* We can't use the depth, fallback to the old way that doesn't set the center depth */ - copy_v3_v3(new_ofs, rv3d->ofs); - - { - float tvec[3]; - negate_v3_v3(tvec, new_ofs); - zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL); - } - - mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f; - mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f; - ED_view3d_win_to_delta(region, mval_f, dvec, zfac); - /* center the view to the center of the rectangle */ - sub_v3_v3(new_ofs, dvec); - } - - /* work out the ratios, so that everything selected fits when we zoom */ - xscale = (BLI_rcti_size_x(&rect) / vb[0]); - yscale = (BLI_rcti_size_y(&rect) / vb[1]); - new_dist *= max_ff(xscale, yscale); - } - - if (!zoom_in) { - sub_v3_v3v3(dvec, new_ofs, rv3d->ofs); - new_dist = rv3d->dist * (rv3d->dist / new_dist); - add_v3_v3v3(new_ofs, rv3d->ofs, dvec); - } - - /* clamp after because we may have been zooming out */ - CLAMP(new_dist, dist_range[0], dist_range[1]); - - /* TODO(campbell): 'is_camera_lock' not currently working well. */ - const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d); - if ((rv3d->persp == RV3D_CAMOB) && (is_camera_lock == false)) { - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP); - } - - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .ofs = new_ofs, - .dist = &new_dist, - }); - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(CTX_wm_area(C), region); - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_zoom_border(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Zoom to Border"; - ot->description = "Zoom in the view to the nearest object contained in the border"; - ot->idname = "VIEW3D_OT_zoom_border"; - - /* api callbacks */ - ot->invoke = WM_gesture_box_invoke; - ot->exec = view3d_zoom_border_exec; - ot->modal = WM_gesture_box_modal; - ot->cancel = WM_gesture_box_cancel; - - ot->poll = view3d_zoom_or_dolly_poll; - - /* flags */ - ot->flag = 0; - - /* properties */ - WM_operator_properties_gesture_box_zoom(ot); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Set Camera Zoom 1:1 Operator * * Sets the view to 1:1 camera/render-pixel. @@ -3830,838 +473,6 @@ void VIEW3D_OT_zoom_camera_1_to_1(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ -/** \name View Axis Operator - * \{ */ - -static const EnumPropertyItem prop_view_items[] = { - {RV3D_VIEW_LEFT, "LEFT", ICON_TRIA_LEFT, "Left", "View from the left"}, - {RV3D_VIEW_RIGHT, "RIGHT", ICON_TRIA_RIGHT, "Right", "View from the right"}, - {RV3D_VIEW_BOTTOM, "BOTTOM", ICON_TRIA_DOWN, "Bottom", "View from the bottom"}, - {RV3D_VIEW_TOP, "TOP", ICON_TRIA_UP, "Top", "View from the top"}, - {RV3D_VIEW_FRONT, "FRONT", 0, "Front", "View from the front"}, - {RV3D_VIEW_BACK, "BACK", 0, "Back", "View from the back"}, - {0, NULL, 0, NULL, NULL}, -}; - -/* would like to make this a generic function - outside of transform */ - -/** - * \param align_to_quat: When not NULL, set the axis relative to this rotation. - */ -static void axis_set_view(bContext *C, - View3D *v3d, - ARegion *region, - const float quat_[4], - char view, - char view_axis_roll, - int perspo, - const float *align_to_quat, - const int smooth_viewtx) -{ - RegionView3D *rv3d = region->regiondata; /* no NULL check is needed, poll checks */ - float quat[4]; - const short orig_persp = rv3d->persp; - - normalize_qt_qt(quat, quat_); - - if (align_to_quat) { - mul_qt_qtqt(quat, quat, align_to_quat); - rv3d->view = view = RV3D_VIEW_USER; - rv3d->view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; - } - - if (align_to_quat == NULL) { - rv3d->view = view; - rv3d->view_axis_roll = view_axis_roll; - } - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) { - ED_region_tag_redraw(region); - return; - } - - if (U.uiflag & USER_AUTOPERSP) { - rv3d->persp = RV3D_VIEW_IS_AXIS(view) ? RV3D_ORTHO : perspo; - } - else if (rv3d->persp == RV3D_CAMOB) { - rv3d->persp = perspo; - } - - if (rv3d->persp == RV3D_CAMOB && v3d->camera) { - /* to camera */ - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = v3d->camera, - .ofs = rv3d->ofs, - .quat = quat, - }); - } - else if (orig_persp == RV3D_CAMOB && v3d->camera) { - /* from camera */ - float ofs[3], dist; - - copy_v3_v3(ofs, rv3d->ofs); - dist = rv3d->dist; - - /* so we animate _from_ the camera location */ - Object *camera_eval = DEG_get_evaluated_object(CTX_data_ensure_evaluated_depsgraph(C), - v3d->camera); - ED_view3d_from_object(camera_eval, rv3d->ofs, NULL, &rv3d->dist, NULL); - - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera_old = camera_eval, - .ofs = ofs, - .quat = quat, - .dist = &dist, - }); - } - else { - /* rotate around selection */ - const float *dyn_ofs_pt = NULL; - float dyn_ofs[3]; - - if (U.uiflag & USER_ORBIT_SELECTION) { - if (view3d_orbit_calc_center(C, dyn_ofs)) { - negate_v3(dyn_ofs); - dyn_ofs_pt = dyn_ofs; - } - } - - /* no camera involved */ - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .quat = quat, - .dyn_ofs = dyn_ofs_pt, - }); - } -} - -static int view_axis_exec(bContext *C, wmOperator *op) -{ - View3D *v3d; - ARegion *region; - RegionView3D *rv3d; - static int perspo = RV3D_PERSP; - int viewnum; - int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - /* no NULL check is needed, poll checks */ - ED_view3d_context_user_region(C, &v3d, ®ion); - rv3d = region->regiondata; - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - viewnum = RNA_enum_get(op->ptr, "type"); - - float align_quat_buf[4]; - float *align_quat = NULL; - - if (RNA_boolean_get(op->ptr, "align_active")) { - /* align to active object */ - Object *obact = CTX_data_active_object(C); - if (obact != NULL) { - float twmat[3][3]; - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *obedit = CTX_data_edit_object(C); - /* same as transform gizmo when normal is set */ - ED_getTransformOrientationMatrix(view_layer, v3d, obact, obedit, V3D_AROUND_ACTIVE, twmat); - align_quat = align_quat_buf; - mat3_to_quat(align_quat, twmat); - invert_qt_normalized(align_quat); - } - } - - if (RNA_boolean_get(op->ptr, "relative")) { - float quat_rotate[4]; - float quat_test[4]; - - if (viewnum == RV3D_VIEW_LEFT) { - axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], -M_PI / 2.0f); - } - else if (viewnum == RV3D_VIEW_RIGHT) { - axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], M_PI / 2.0f); - } - else if (viewnum == RV3D_VIEW_TOP) { - axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], -M_PI / 2.0f); - } - else if (viewnum == RV3D_VIEW_BOTTOM) { - axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI / 2.0f); - } - else if (viewnum == RV3D_VIEW_FRONT) { - unit_qt(quat_rotate); - } - else if (viewnum == RV3D_VIEW_BACK) { - axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI); - } - else { - BLI_assert(0); - } - - mul_qt_qtqt(quat_test, rv3d->viewquat, quat_rotate); - - float angle_best = FLT_MAX; - int view_best = -1; - int view_axis_roll_best = -1; - for (int i = RV3D_VIEW_FRONT; i <= RV3D_VIEW_BOTTOM; i++) { - for (int j = RV3D_VIEW_AXIS_ROLL_0; j <= RV3D_VIEW_AXIS_ROLL_270; j++) { - float quat_axis[4]; - ED_view3d_quat_from_axis_view(i, j, quat_axis); - if (align_quat) { - mul_qt_qtqt(quat_axis, quat_axis, align_quat); - } - const float angle_test = fabsf(angle_signed_qtqt(quat_axis, quat_test)); - if (angle_best > angle_test) { - angle_best = angle_test; - view_best = i; - view_axis_roll_best = j; - } - } - } - if (view_best == -1) { - view_best = RV3D_VIEW_FRONT; - view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0; - } - - /* Disallow non-upright views in turn-table modes, - * it's too difficult to navigate out of them. */ - if ((U.flag & USER_TRACKBALL) == 0) { - if (!ELEM(view_best, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) { - view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0; - } - } - - viewnum = view_best; - view_axis_roll = view_axis_roll_best; - } - - /* Use this to test if we started out with a camera */ - const int nextperspo = (rv3d->persp == RV3D_CAMOB) ? rv3d->lpersp : perspo; - float quat[4]; - ED_view3d_quat_from_axis_view(viewnum, view_axis_roll, quat); - axis_set_view( - C, v3d, region, quat, viewnum, view_axis_roll, nextperspo, align_quat, smooth_viewtx); - - perspo = rv3d->persp; - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_axis(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "View Axis"; - ot->description = "Use a preset viewpoint"; - ot->idname = "VIEW3D_OT_view_axis"; - - /* api callbacks */ - ot->exec = view_axis_exec; - ot->poll = ED_operator_rv3d_user_region_poll; - - /* flags */ - ot->flag = 0; - - ot->prop = RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "Preset viewpoint to use"); - RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); - prop = RNA_def_boolean( - ot->srna, "align_active", 0, "Align Active", "Align to the active object's axis"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_boolean( - ot->srna, "relative", 0, "Relative", "Rotate relative to the current orientation"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Camera Operator - * \{ */ - -static int view_camera_exec(bContext *C, wmOperator *op) -{ - View3D *v3d; - ARegion *region; - RegionView3D *rv3d; - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - /* no NULL check is needed, poll checks */ - ED_view3d_context_user_region(C, &v3d, ®ion); - rv3d = region->regiondata; - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) { - ViewLayer *view_layer = CTX_data_view_layer(C); - Scene *scene = CTX_data_scene(C); - - if (rv3d->persp != RV3D_CAMOB) { - Object *ob = OBACT(view_layer); - - if (!rv3d->smooth_timer) { - /* store settings of current view before allowing overwriting with camera view - * only if we're not currently in a view transition */ - - ED_view3d_lastview_store(rv3d); - } - - /* first get the default camera for the view lock type */ - if (v3d->scenelock) { - /* sets the camera view if available */ - v3d->camera = scene->camera; - } - else { - /* use scene camera if one is not set (even though we're unlocked) */ - if (v3d->camera == NULL) { - v3d->camera = scene->camera; - } - } - - /* if the camera isn't found, check a number of options */ - if (v3d->camera == NULL && ob && ob->type == OB_CAMERA) { - v3d->camera = ob; - } - - if (v3d->camera == NULL) { - v3d->camera = BKE_view_layer_camera_find(view_layer); - } - - /* couldn't find any useful camera, bail out */ - if (v3d->camera == NULL) { - return OPERATOR_CANCELLED; - } - - /* important these don't get out of sync for locked scenes */ - if (v3d->scenelock && scene->camera != v3d->camera) { - scene->camera = v3d->camera; - DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); - } - - /* finally do snazzy view zooming */ - rv3d->persp = RV3D_CAMOB; - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .camera = v3d->camera, - .ofs = rv3d->ofs, - .quat = rv3d->viewquat, - .dist = &rv3d->dist, - .lens = &v3d->lens, - }); - } - else { - /* return to settings of last view */ - /* does view3d_smooth_view too */ - axis_set_view(C, - v3d, - region, - rv3d->lviewquat, - rv3d->lview, - rv3d->lview_axis_roll, - rv3d->lpersp, - NULL, - smooth_viewtx); - } - } - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_camera(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "View Camera"; - ot->description = "Toggle the camera view"; - ot->idname = "VIEW3D_OT_view_camera"; - - /* api callbacks */ - ot->exec = view_camera_exec; - ot->poll = ED_operator_rv3d_user_region_poll; - - /* flags */ - ot->flag = 0; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Orbit Operator - * - * Rotate (orbit) in incremental steps. For interactive orbit see #VIEW3D_OT_rotate. - * \{ */ - -enum { - V3D_VIEW_STEPLEFT = 1, - V3D_VIEW_STEPRIGHT, - V3D_VIEW_STEPDOWN, - V3D_VIEW_STEPUP, -}; - -static const EnumPropertyItem prop_view_orbit_items[] = { - {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the left"}, - {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the right"}, - {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view up"}, - {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view down"}, - {0, NULL, 0, NULL, NULL}, -}; - -static int vieworbit_exec(bContext *C, wmOperator *op) -{ - View3D *v3d; - ARegion *region; - RegionView3D *rv3d; - int orbitdir; - char view_opposite; - PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle"); - float angle = RNA_property_is_set(op->ptr, prop_angle) ? - RNA_property_float_get(op->ptr, prop_angle) : - DEG2RADF(U.pad_rot_angle); - - /* no NULL check is needed, poll checks */ - v3d = CTX_wm_view3d(C); - region = CTX_wm_region(C); - rv3d = region->regiondata; - - /* support for switching to the opposite view (even when in locked views) */ - view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) : - RV3D_VIEW_USER; - orbitdir = RNA_enum_get(op->ptr, "type"); - - if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) { - /* no NULL check is needed, poll checks */ - ED_view3d_context_user_region(C, &v3d, ®ion); - rv3d = region->regiondata; - } - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0 || (view_opposite != RV3D_VIEW_USER)) { - if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { - int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - float quat_mul[4]; - float quat_new[4]; - - if (view_opposite == RV3D_VIEW_USER) { - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ED_view3d_persp_ensure(depsgraph, v3d, region); - } - - if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) { - if (orbitdir == V3D_VIEW_STEPRIGHT) { - angle = -angle; - } - - /* z-axis */ - axis_angle_to_quat_single(quat_mul, 'Z', angle); - } - else { - - if (orbitdir == V3D_VIEW_STEPDOWN) { - angle = -angle; - } - - /* horizontal axis */ - axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle); - } - - mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul); - - /* avoid precision loss over time */ - normalize_qt(quat_new); - - if (view_opposite != RV3D_VIEW_USER) { - rv3d->view = view_opposite; - /* avoid float in-precision, just get a new orientation */ - ED_view3d_quat_from_axis_view(view_opposite, rv3d->view_axis_roll, quat_new); - } - else { - rv3d->view = RV3D_VIEW_USER; - } - - float dyn_ofs[3], *dyn_ofs_pt = NULL; - - if (U.uiflag & USER_ORBIT_SELECTION) { - if (view3d_orbit_calc_center(C, dyn_ofs)) { - negate_v3(dyn_ofs); - dyn_ofs_pt = dyn_ofs; - } - } - - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .quat = quat_new, - .dyn_ofs = dyn_ofs_pt, - }); - - return OPERATOR_FINISHED; - } - } - - return OPERATOR_CANCELLED; -} - -void VIEW3D_OT_view_orbit(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "View Orbit"; - ot->description = "Orbit the view"; - ot->idname = "VIEW3D_OT_view_orbit"; - - /* api callbacks */ - ot->exec = vieworbit_exec; - ot->poll = ED_operator_rv3d_user_region_poll; - - /* flags */ - ot->flag = 0; - - /* properties */ - prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - - ot->prop = RNA_def_enum( - ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit"); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Roll Operator - * \{ */ - -static void view_roll_angle( - ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle) -{ - RegionView3D *rv3d = region->regiondata; - float quat_mul[4]; - - /* camera axis */ - axis_angle_normalized_to_quat(quat_mul, dvec, angle); - - mul_qt_qtqt(quat, orig_quat, quat_mul); - - /* avoid precision loss over time */ - normalize_qt(quat); - - rv3d->view = RV3D_VIEW_USER; -} - -static void viewroll_apply(ViewOpsData *vod, int x, int y) -{ - float angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y}); - - if (angle != 0.0f) { - view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle); - } - - if (vod->use_dyn_ofs) { - view3d_orbit_apply_dyn_ofs( - vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs); - } - - if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { - view3d_boxview_sync(vod->area, vod->region); - } - - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - - ED_region_tag_redraw(vod->region); -} - -static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod = op->customdata; - short event_code = VIEW_PASS; - bool use_autokey = false; - int ret = OPERATOR_RUNNING_MODAL; - - /* execute the events */ - if (event->type == MOUSEMOVE) { - event_code = VIEW_APPLY; - } - else if (event->type == EVT_MODAL_MAP) { - switch (event->val) { - case VIEW_MODAL_CONFIRM: - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_MOVE: - WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - case VIEWROT_MODAL_SWITCH_ROTATE: - WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); - event_code = VIEW_CONFIRM; - break; - } - } - else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) { - /* Note this does not remove auto-keys on locked cameras. */ - copy_qt_qt(vod->rv3d->viewquat, vod->init.quat); - ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); - viewops_data_free(C, op); - return OPERATOR_CANCELLED; - } - else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { - event_code = VIEW_CONFIRM; - } - - if (event_code == VIEW_APPLY) { - viewroll_apply(vod, event->xy[0], event->xy[1]); - if (ED_screen_animation_playing(CTX_wm_manager(C))) { - use_autokey = true; - } - } - else if (event_code == VIEW_CONFIRM) { - use_autokey = true; - ret = OPERATOR_FINISHED; - } - - if (use_autokey) { - ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false); - } - - if (ret & OPERATOR_FINISHED) { - viewops_data_free(C, op); - } - - return ret; -} - -static const EnumPropertyItem prop_view_roll_items[] = { - {0, "ANGLE", 0, "Roll Angle", "Roll the view using an angle value"}, - {V3D_VIEW_STEPLEFT, "LEFT", 0, "Roll Left", "Roll the view around to the left"}, - {V3D_VIEW_STEPRIGHT, "RIGHT", 0, "Roll Right", "Roll the view around to the right"}, - {0, NULL, 0, NULL, NULL}, -}; - -static int viewroll_exec(bContext *C, wmOperator *op) -{ - View3D *v3d; - RegionView3D *rv3d; - ARegion *region; - - if (op->customdata) { - ViewOpsData *vod = op->customdata; - region = vod->region; - v3d = vod->v3d; - } - else { - ED_view3d_context_user_region(C, &v3d, ®ion); - } - - rv3d = region->regiondata; - if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { - - ED_view3d_smooth_view_force_finish(C, v3d, region); - - int type = RNA_enum_get(op->ptr, "type"); - float angle = (type == 0) ? RNA_float_get(op->ptr, "angle") : DEG2RADF(U.pad_rot_angle); - float mousevec[3]; - float quat_new[4]; - - const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - - if (type == V3D_VIEW_STEPLEFT) { - angle = -angle; - } - - normalize_v3_v3(mousevec, rv3d->viewinv[2]); - negate_v3(mousevec); - view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle); - - const float *dyn_ofs_pt = NULL; - float dyn_ofs[3]; - if (U.uiflag & USER_ORBIT_SELECTION) { - if (view3d_orbit_calc_center(C, dyn_ofs)) { - negate_v3(dyn_ofs); - dyn_ofs_pt = dyn_ofs; - } - } - - ED_view3d_smooth_view(C, - v3d, - region, - smooth_viewtx, - &(const V3D_SmoothParams){ - .quat = quat_new, - .dyn_ofs = dyn_ofs_pt, - }); - - viewops_data_free(C, op); - return OPERATOR_FINISHED; - } - - viewops_data_free(C, op); - return OPERATOR_CANCELLED; -} - -static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - ViewOpsData *vod; - - bool use_angle = RNA_enum_get(op->ptr, "type") != 0; - - if (use_angle || RNA_struct_property_is_set(op->ptr, "angle")) { - viewroll_exec(C, op); - } - else { - /* makes op->customdata */ - viewops_data_alloc(C, op); - viewops_data_create(C, op, event, viewops_flag_from_prefs()); - vod = op->customdata; - vod->init.dial = BLI_dial_init((const float[2]){BLI_rcti_cent_x(&vod->region->winrct), - BLI_rcti_cent_y(&vod->region->winrct)}, - FLT_EPSILON); - - ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); - - /* overwrite the mouse vector with the view direction */ - normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); - negate_v3(vod->init.mousevec); - - if (event->type == MOUSEROTATE) { - vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; - viewroll_apply(vod, event->prev_xy[0], event->prev_xy[1]); - - viewops_data_free(C, op); - return OPERATOR_FINISHED; - } - - /* add temp handler */ - WM_event_add_modal_handler(C, op); - return OPERATOR_RUNNING_MODAL; - } - return OPERATOR_FINISHED; -} - -static void viewroll_cancel(bContext *C, wmOperator *op) -{ - viewops_data_free(C, op); -} - -void VIEW3D_OT_view_roll(wmOperatorType *ot) -{ - PropertyRNA *prop; - - /* identifiers */ - ot->name = "View Roll"; - ot->description = "Roll the view"; - ot->idname = "VIEW3D_OT_view_roll"; - - /* api callbacks */ - ot->invoke = viewroll_invoke; - ot->exec = viewroll_exec; - ot->modal = viewroll_modal; - ot->poll = ED_operator_rv3d_user_region_poll; - ot->cancel = viewroll_cancel; - - /* flags */ - ot->flag = 0; - - /* properties */ - ot->prop = prop = RNA_def_float( - ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); - prop = RNA_def_enum(ot->srna, - "type", - prop_view_roll_items, - 0, - "Roll Angle Source", - "How roll angle is calculated"); - RNA_def_property_flag(prop, PROP_SKIP_SAVE); -} - -enum { - V3D_VIEW_PANLEFT = 1, - V3D_VIEW_PANRIGHT, - V3D_VIEW_PANDOWN, - V3D_VIEW_PANUP, -}; - -static const EnumPropertyItem prop_view_pan_items[] = { - {V3D_VIEW_PANLEFT, "PANLEFT", 0, "Pan Left", "Pan the view to the left"}, - {V3D_VIEW_PANRIGHT, "PANRIGHT", 0, "Pan Right", "Pan the view to the right"}, - {V3D_VIEW_PANUP, "PANUP", 0, "Pan Up", "Pan the view up"}, - {V3D_VIEW_PANDOWN, "PANDOWN", 0, "Pan Down", "Pan the view down"}, - {0, NULL, 0, NULL, NULL}, -}; - -/** \} */ - -/* -------------------------------------------------------------------- */ -/** \name View Pan Operator - * - * Move (pan) in incremental steps. For interactive pan see #VIEW3D_OT_move. - * \{ */ - -static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event) -{ - int x = 0, y = 0; - int pandir = RNA_enum_get(op->ptr, "type"); - - if (pandir == V3D_VIEW_PANRIGHT) { - x = -32; - } - else if (pandir == V3D_VIEW_PANLEFT) { - x = 32; - } - else if (pandir == V3D_VIEW_PANUP) { - y = -25; - } - else if (pandir == V3D_VIEW_PANDOWN) { - y = 25; - } - - viewops_data_alloc(C, op); - viewops_data_create(C, op, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT)); - ViewOpsData *vod = op->customdata; - - viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y); - - viewops_data_free(C, op); - - return OPERATOR_FINISHED; -} - -void VIEW3D_OT_view_pan(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Pan View Direction"; - ot->description = "Pan the view in a given direction"; - ot->idname = "VIEW3D_OT_view_pan"; - - /* api callbacks */ - ot->invoke = viewpan_invoke; - ot->poll = view3d_pan_poll; - - /* flags */ - ot->flag = 0; - - /* Properties */ - ot->prop = RNA_def_enum( - ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan"); -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name View Toggle Perspective/Orthographic Operator * \{ */ diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 607ca110d0f..7f872c9b1af 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -52,8 +52,6 @@ #include "view3d_intern.h" -static void do_view3d_header_buttons(bContext *C, void *arg, int event); - #define B_SEL_VERT 110 #define B_SEL_EDGE 111 #define B_SEL_FACE 112 @@ -98,101 +96,45 @@ void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot) /** \name UI Templates * \{ */ -static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event) -{ - wmWindow *win = CTX_wm_window(C); - const int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift; - - /* watch it: if area->win does not exist, check that when calling direct drawing routines */ - - switch (event) { - case B_SEL_VERT: - if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_VERTEX, -1, shift, ctrl)) { - ED_undo_push(C, "Selectmode Set: Vertex"); - } - break; - case B_SEL_EDGE: - if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_EDGE, -1, shift, ctrl)) { - ED_undo_push(C, "Selectmode Set: Edge"); - } - break; - case B_SEL_FACE: - if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_FACE, -1, shift, ctrl)) { - ED_undo_push(C, "Selectmode Set: Face"); - } - break; - default: - break; - } -} - void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C) { Object *obedit = CTX_data_edit_object(C); - uiBlock *block = uiLayoutGetBlock(layout); - - UI_block_func_handle_set(block, do_view3d_header_buttons, NULL); - - if (obedit && (obedit->type == OB_MESH)) { - BMEditMesh *em = BKE_editmesh_from_object(obedit); - uiLayout *row; - uiBut *but; - - row = uiLayoutRow(layout, true); - block = uiLayoutGetBlock(row); - but = uiDefIconButBitS( - block, - UI_BTYPE_TOGGLE, - SCE_SELECT_VERTEX, - B_SEL_VERT, - ICON_VERTEXSEL, - 0, - 0, - UI_UNIT_X, - UI_UNIT_Y, - &em->selectmode, - 1.0, - 0.0, - 0, - 0, - TIP_("Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection")); - UI_but_flag_disable(but, UI_BUT_UNDO); - but = uiDefIconButBitS( - block, - UI_BTYPE_TOGGLE, - SCE_SELECT_EDGE, - B_SEL_EDGE, - ICON_EDGESEL, - 0, - 0, - ceilf(UI_UNIT_X - U.pixelsize), - UI_UNIT_Y, - &em->selectmode, - 1.0, - 0.0, - 0, - 0, - TIP_("Edge select - Shift-Click for multiple modes, " - "Ctrl-Click expands/contracts selection depending on the current mode")); - UI_but_flag_disable(but, UI_BUT_UNDO); - but = uiDefIconButBitS( - block, - UI_BTYPE_TOGGLE, - SCE_SELECT_FACE, - B_SEL_FACE, - ICON_FACESEL, - 0, - 0, - ceilf(UI_UNIT_X - U.pixelsize), - UI_UNIT_Y, - &em->selectmode, - 1.0, - 0.0, - 0, - 0, - TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection")); - UI_but_flag_disable(but, UI_BUT_UNDO); + if (!obedit || obedit->type != OB_MESH) { + return; } + + BMEditMesh *em = BKE_editmesh_from_object(obedit); + uiLayout *row = uiLayoutRow(layout, true); + + PointerRNA op_ptr; + wmOperatorType *ot = WM_operatortype_find("MESH_OT_select_mode", true); + uiItemFullO_ptr(row, + ot, + "", + ICON_VERTEXSEL, + NULL, + WM_OP_INVOKE_DEFAULT, + (em->selectmode & SCE_SELECT_VERTEX) ? UI_ITEM_O_DEPRESS : 0, + &op_ptr); + RNA_enum_set(&op_ptr, "type", SCE_SELECT_VERTEX); + uiItemFullO_ptr(row, + ot, + "", + ICON_EDGESEL, + NULL, + WM_OP_INVOKE_DEFAULT, + (em->selectmode & SCE_SELECT_EDGE) ? UI_ITEM_O_DEPRESS : 0, + &op_ptr); + RNA_enum_set(&op_ptr, "type", SCE_SELECT_EDGE); + uiItemFullO_ptr(row, + ot, + "", + ICON_FACESEL, + NULL, + WM_OP_INVOKE_DEFAULT, + (em->selectmode & SCE_SELECT_FACE) ? UI_ITEM_O_DEPRESS : 0, + &op_ptr); + RNA_enum_set(&op_ptr, "type", SCE_SELECT_FACE); } static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C) diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 6a1a09df316..b443ebeed94 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -32,6 +32,8 @@ struct ARegionType; struct BoundBox; struct Depsgraph; struct Object; +struct Scene; +struct ViewContext; struct ViewLayer; struct bContext; struct wmGizmoGroupType; @@ -40,13 +42,6 @@ struct wmKeyConfig; struct wmOperatorType; struct wmWindowManager; -/* drawing flags: */ -enum { - DRAW_PICKING = (1 << 0), - DRAW_CONSTCOLOR = (1 << 1), - DRAW_SCENESET = (1 << 2), -}; - /* view3d_header.c */ void VIEW3D_OT_toggle_matcap_flip(struct wmOperatorType *ot); @@ -54,84 +49,24 @@ void VIEW3D_OT_toggle_matcap_flip(struct wmOperatorType *ot); void view3d_operatortypes(void); /* view3d_edit.c */ -void VIEW3D_OT_zoom(struct wmOperatorType *ot); -void VIEW3D_OT_dolly(struct wmOperatorType *ot); void VIEW3D_OT_zoom_camera_1_to_1(struct wmOperatorType *ot); -void VIEW3D_OT_move(struct wmOperatorType *ot); -void VIEW3D_OT_rotate(struct wmOperatorType *ot); -#ifdef WITH_INPUT_NDOF -void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot); -void VIEW3D_OT_ndof_all(struct wmOperatorType *ot); -#endif /* WITH_INPUT_NDOF */ -void VIEW3D_OT_view_all(struct wmOperatorType *ot); -void VIEW3D_OT_view_axis(struct wmOperatorType *ot); -void VIEW3D_OT_view_camera(struct wmOperatorType *ot); -void VIEW3D_OT_view_selected(struct wmOperatorType *ot); void VIEW3D_OT_view_lock_clear(struct wmOperatorType *ot); void VIEW3D_OT_view_lock_to_active(struct wmOperatorType *ot); -void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot); -void VIEW3D_OT_view_center_pick(struct wmOperatorType *ot); void VIEW3D_OT_view_center_camera(struct wmOperatorType *ot); void VIEW3D_OT_view_center_lock(struct wmOperatorType *ot); -void VIEW3D_OT_view_pan(struct wmOperatorType *ot); void VIEW3D_OT_view_persportho(struct wmOperatorType *ot); void VIEW3D_OT_navigate(struct wmOperatorType *ot); void VIEW3D_OT_background_image_add(struct wmOperatorType *ot); void VIEW3D_OT_background_image_remove(struct wmOperatorType *ot); void VIEW3D_OT_drop_world(struct wmOperatorType *ot); -void VIEW3D_OT_view_orbit(struct wmOperatorType *ot); -void VIEW3D_OT_view_roll(struct wmOperatorType *ot); void VIEW3D_OT_clip_border(struct wmOperatorType *ot); void VIEW3D_OT_cursor3d(struct wmOperatorType *ot); void VIEW3D_OT_render_border(struct wmOperatorType *ot); void VIEW3D_OT_clear_render_border(struct wmOperatorType *ot); -void VIEW3D_OT_zoom_border(struct wmOperatorType *ot); void VIEW3D_OT_toggle_shading(struct wmOperatorType *ot); void VIEW3D_OT_toggle_xray(struct wmOperatorType *ot); -/** - * For home, center etc. - */ -void view3d_boxview_copy(struct ScrArea *area, struct ARegion *region); -/** - * Sync center/zoom view of region to others, for view transforms. - */ -void view3d_boxview_sync(struct ScrArea *area, struct ARegion *region); - -void view3d_orbit_apply_dyn_ofs(float r_ofs[3], - const float ofs_old[3], - const float viewquat_old[4], - const float viewquat_new[4], - const float dyn_ofs[3]); - -#ifdef WITH_INPUT_NDOF -struct wmNDOFMotionData; - -/** - * Called from both fly mode and walk mode, - */ -void view3d_ndof_fly(const struct wmNDOFMotionData *ndof, - struct View3D *v3d, - struct RegionView3D *rv3d, - bool use_precision, - short protectflag, - bool *r_has_translate, - bool *r_has_rotate); -#endif /* WITH_INPUT_NDOF */ - -/* view3d_navigate_fly.c */ - -void view3d_keymap(struct wmKeyConfig *keyconf); -void VIEW3D_OT_fly(struct wmOperatorType *ot); - -/* view3d_navigate_walk.c */ - -void VIEW3D_OT_walk(struct wmOperatorType *ot); - /* view3d_draw.c */ - void view3d_main_region_draw(const struct bContext *C, struct ARegion *region); /** * Information drawn on top of the solid plates and composed data. @@ -141,16 +76,16 @@ void view3d_draw_region_info(const struct bContext *C, struct ARegion *region); /* view3d_draw_legacy.c */ void ED_view3d_draw_select_loop(struct Depsgraph *depsgraph, - ViewContext *vc, - Scene *scene, + struct ViewContext *vc, + struct Scene *scene, struct ViewLayer *view_layer, - View3D *v3d, + struct View3D *v3d, struct ARegion *region, bool use_obedit_skip, bool use_nearest); void ED_view3d_draw_depth_loop(struct Depsgraph *depsgraph, - Scene *scene, + struct Scene *scene, struct ARegion *region, View3D *v3d); @@ -168,57 +103,27 @@ void VIEW3D_OT_select_lasso(struct wmOperatorType *ot); void VIEW3D_OT_select_menu(struct wmOperatorType *ot); void VIEW3D_OT_bone_select_menu(struct wmOperatorType *ot); -/* view3d_view.c */ -void VIEW3D_OT_smoothview(struct wmOperatorType *ot); -void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot); -void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot); -void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot); -void VIEW3D_OT_localview(struct wmOperatorType *ot); -void VIEW3D_OT_localview_remove_from(struct wmOperatorType *ot); +/* view3d_utils.c */ +/** + * For home, center etc. + */ +void view3d_boxview_copy(struct ScrArea *area, struct ARegion *region); +/** + * Sync center/zoom view of region to others, for view transforms. + */ +void view3d_boxview_sync(struct ScrArea *area, struct ARegion *region); bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const struct BoundBox *bb, float obmat[4][4]); bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const struct BoundBox *bb); -/** - * Parameters for setting the new 3D Viewport state. - * - * Each of the struct members may be NULL to signify they aren't to be adjusted. - */ -typedef struct V3D_SmoothParams { - struct Object *camera_old, *camera; - const float *ofs, *quat, *dist, *lens; - - /** Alternate rotation center, when set `ofs` must be NULL. */ - const float *dyn_ofs; -} V3D_SmoothParams; - -/** - * The arguments are the desired situation. - */ -void ED_view3d_smooth_view_ex(const struct Depsgraph *depsgraph, - struct wmWindowManager *wm, - struct wmWindow *win, - struct ScrArea *area, - struct View3D *v3d, - struct ARegion *region, - int smooth_viewtx, - const V3D_SmoothParams *sview); - -void ED_view3d_smooth_view(struct bContext *C, - struct View3D *v3d, - struct ARegion *region, - int smooth_viewtx, - const V3D_SmoothParams *sview); - -/** - * Apply the smooth-view immediately, use when we need to start a new view operation. - * (so we don't end up half-applying a view operation when pressing keys quickly). - */ -void ED_view3d_smooth_view_force_finish(struct bContext *C, - struct View3D *v3d, - struct ARegion *region); +/* view3d_view.c */ +void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot); +void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot); +void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot); +void VIEW3D_OT_localview(struct wmOperatorType *ot); +void VIEW3D_OT_localview_remove_from(struct wmOperatorType *ot); /** * \param rect: optional for picking (can be NULL). @@ -247,12 +152,7 @@ void view3d_viewmatrix_set(struct Depsgraph *depsgraph, /* Called in transform_ops.c, on each regeneration of key-maps. */ -void fly_modal_keymap(struct wmKeyConfig *keyconf); -void walk_modal_keymap(struct wmKeyConfig *keyconf); -void viewrotate_modal_keymap(struct wmKeyConfig *keyconf); -void viewmove_modal_keymap(struct wmKeyConfig *keyconf); -void viewzoom_modal_keymap(struct wmKeyConfig *keyconf); -void viewdolly_modal_keymap(struct wmKeyConfig *keyconf); +/* view3d_placement.c */ void viewplace_modal_keymap(struct wmKeyConfig *keyconf); /* view3d_buttons.c */ @@ -267,7 +167,7 @@ void view3d_buttons_register(struct ARegionType *art); * the view for first-person style navigation. */ struct View3DCameraControl *ED_view3d_cameracontrol_acquire(struct Depsgraph *depsgraph, - Scene *scene, + struct Scene *scene, View3D *v3d, RegionView3D *rv3d); /** diff --git a/source/blender/editors/space_view3d/view3d_navigate.c b/source/blender/editors/space_view3d/view3d_navigate.c new file mode 100644 index 00000000000..98eef94d5fb --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate.c @@ -0,0 +1,1593 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "DNA_curve_types.h" +#include "DNA_gpencil_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_rect.h" + +#include "BKE_armature.h" +#include "BKE_context.h" +#include "BKE_gpencil_geom.h" +#include "BKE_layer.h" +#include "BKE_object.h" +#include "BKE_paint.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_vfont.h" + +#include "DEG_depsgraph_query.h" + +#include "ED_mesh.h" +#include "ED_particle.h" +#include "ED_screen.h" +#include "ED_transform.h" + +#include "WM_api.h" +#include "WM_message.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "UI_resources.h" + +#include "view3d_intern.h" + +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name Navigation Polls + * \{ */ + +static bool view3d_navigation_poll_impl(bContext *C, const char viewlock) +{ + if (!ED_operator_region_view3d_active(C)) { + return false; + } + + const RegionView3D *rv3d = CTX_wm_region_view3d(C); + return !(RV3D_LOCK_FLAGS(rv3d) & viewlock); +} + +bool view3d_location_poll(bContext *C) +{ + return view3d_navigation_poll_impl(C, RV3D_LOCK_LOCATION); +} + +bool view3d_rotation_poll(bContext *C) +{ + return view3d_navigation_poll_impl(C, RV3D_LOCK_ROTATION); +} + +bool view3d_zoom_or_dolly_poll(bContext *C) +{ + return view3d_navigation_poll_impl(C, RV3D_LOCK_ZOOM_AND_DOLLY); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Generic View Operator Properties + * \{ */ + +void view3d_operator_properties_common(wmOperatorType *ot, const enum eV3D_OpPropFlag flag) +{ + if (flag & V3D_OP_PROP_MOUSE_CO) { + PropertyRNA *prop; + prop = RNA_def_int(ot->srna, "mx", 0, 0, INT_MAX, "Region Position X", "", 0, INT_MAX); + RNA_def_property_flag(prop, PROP_HIDDEN); + prop = RNA_def_int(ot->srna, "my", 0, 0, INT_MAX, "Region Position Y", "", 0, INT_MAX); + RNA_def_property_flag(prop, PROP_HIDDEN); + } + if (flag & V3D_OP_PROP_DELTA) { + RNA_def_int(ot->srna, "delta", 0, INT_MIN, INT_MAX, "Delta", "", INT_MIN, INT_MAX); + } + if (flag & V3D_OP_PROP_USE_ALL_REGIONS) { + PropertyRNA *prop; + prop = RNA_def_boolean( + ot->srna, "use_all_regions", 0, "All Regions", "View selected for all regions"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + } + if (flag & V3D_OP_PROP_USE_MOUSE_INIT) { + WM_operator_properties_use_cursor_init(ot); + } +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Generic View Operator Custom-Data + * \{ */ + +void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3]) +{ + const float radius = V3D_OP_TRACKBALLSIZE; + const float t = radius / (float)M_SQRT2; + const float size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)}; + /* Aspect correct so dragging in a non-square view doesn't squash the direction. + * So diagonal motion rotates the same direction the cursor is moving. */ + const float size_min = min_ff(size[0], size[1]); + const float aspect[2] = {size_min / size[0], size_min / size[1]}; + + /* Normalize x and y. */ + r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((size[0] * aspect[0]) / 2.0); + r_dir[1] = (event_xy[1] - BLI_rcti_cent_y(rect)) / ((size[1] * aspect[1]) / 2.0); + const float d = len_v2(r_dir); + if (d < t) { + /* Inside sphere. */ + r_dir[2] = sqrtf(square_f(radius) - square_f(d)); + } + else { + /* On hyperbola. */ + r_dir[2] = square_f(t) / d; + } +} + +void view3d_orbit_apply_dyn_ofs(float r_ofs[3], + const float ofs_old[3], + const float viewquat_old[4], + const float viewquat_new[4], + const float dyn_ofs[3]) +{ + float q[4]; + invert_qt_qt_normalized(q, viewquat_old); + mul_qt_qtqt(q, q, viewquat_new); + + invert_qt_normalized(q); + + sub_v3_v3v3(r_ofs, ofs_old, dyn_ofs); + mul_qt_v3(q, r_ofs); + add_v3_v3(r_ofs, dyn_ofs); +} + +void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4]) +{ + if (vod->use_dyn_ofs) { + RegionView3D *rv3d = vod->rv3d; + view3d_orbit_apply_dyn_ofs( + rv3d->ofs, vod->init.ofs, vod->init.quat, viewquat_new, vod->dyn_ofs); + } +} + +bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) +{ + static float lastofs[3] = {0, 0, 0}; + bool is_set = false; + + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); + View3D *v3d = CTX_wm_view3d(C); + Object *ob_act_eval = OBACT(view_layer_eval); + Object *ob_act = DEG_get_original_object(ob_act_eval); + + if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) && + /* with weight-paint + pose-mode, fall through to using calculateTransformCenter */ + ((ob_act->mode & OB_MODE_WEIGHT_PAINT) && BKE_object_pose_armature_get(ob_act)) == 0) { + /* in case of sculpting use last average stroke position as a rotation + * center, in other cases it's not clear what rotation center shall be + * so just rotate around object origin + */ + if (ob_act->mode & + (OB_MODE_SCULPT | OB_MODE_TEXTURE_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) { + float stroke[3]; + BKE_paint_stroke_get_average(scene, ob_act_eval, stroke); + copy_v3_v3(lastofs, stroke); + } + else { + copy_v3_v3(lastofs, ob_act_eval->obmat[3]); + } + is_set = true; + } + else if (ob_act && (ob_act->mode & OB_MODE_EDIT) && (ob_act->type == OB_FONT)) { + Curve *cu = ob_act_eval->data; + EditFont *ef = cu->editfont; + + zero_v3(lastofs); + for (int i = 0; i < 4; i++) { + add_v2_v2(lastofs, ef->textcurs[i]); + } + mul_v2_fl(lastofs, 1.0f / 4.0f); + + mul_m4_v3(ob_act_eval->obmat, lastofs); + + is_set = true; + } + else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) { + /* object mode use boundbox centers */ + Base *base_eval; + uint tot = 0; + float select_center[3]; + + zero_v3(select_center); + for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) { + if (BASE_SELECTED(v3d, base_eval)) { + /* use the boundbox if we can */ + Object *ob_eval = base_eval->object; + + if (ob_eval->runtime.bb && !(ob_eval->runtime.bb->flag & BOUNDBOX_DIRTY)) { + float cent[3]; + + BKE_boundbox_calc_center_aabb(ob_eval->runtime.bb, cent); + + mul_m4_v3(ob_eval->obmat, cent); + add_v3_v3(select_center, cent); + } + else { + add_v3_v3(select_center, ob_eval->obmat[3]); + } + tot++; + } + } + if (tot) { + mul_v3_fl(select_center, 1.0f / (float)tot); + copy_v3_v3(lastofs, select_center); + is_set = true; + } + } + else { + /* If there's no selection, `lastofs` is unmodified and last value since static. */ + is_set = calculateTransformCenter(C, V3D_AROUND_CENTER_MEDIAN, lastofs, NULL); + } + + copy_v3_v3(r_dyn_ofs, lastofs); + + return is_set; +} + +static enum eViewOpsFlag viewops_flag_from_args(bool use_select, bool use_depth) +{ + enum eViewOpsFlag flag = 0; + if (use_select) { + flag |= VIEWOPS_FLAG_ORBIT_SELECT; + } + if (use_depth) { + flag |= VIEWOPS_FLAG_DEPTH_NAVIGATE; + } + + return flag; +} + +enum eViewOpsFlag viewops_flag_from_prefs(void) +{ + return viewops_flag_from_args((U.uiflag & USER_ORBIT_SELECTION) != 0, + (U.uiflag & USER_DEPTH_NAVIGATE) != 0); +} + +ViewOpsData *viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag) +{ + ViewOpsData *vod = MEM_callocN(sizeof(ViewOpsData), __func__); + + /* Store data. */ + vod->bmain = CTX_data_main(C); + vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + vod->scene = CTX_data_scene(C); + vod->area = CTX_wm_area(C); + vod->region = CTX_wm_region(C); + vod->v3d = vod->area->spacedata.first; + vod->rv3d = vod->region->regiondata; + + Depsgraph *depsgraph = vod->depsgraph; + RegionView3D *rv3d = vod->rv3d; + + /* Could do this more nicely. */ + if ((viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) == 0) { + viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE; + } + + /* we need the depth info before changing any viewport options */ + if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) { + float fallback_depth_pt[3]; + + view3d_operator_needs_opengl(C); /* Needed for Z-buffer drawing. */ + + negate_v3_v3(fallback_depth_pt, rv3d->ofs); + + vod->use_dyn_ofs = ED_view3d_autodist( + depsgraph, vod->region, vod->v3d, event->mval, vod->dyn_ofs, true, fallback_depth_pt); + } + else { + vod->use_dyn_ofs = false; + } + + if (viewops_flag & VIEWOPS_FLAG_PERSP_ENSURE) { + if (ED_view3d_persp_ensure(depsgraph, vod->v3d, vod->region)) { + /* If we're switching from camera view to the perspective one, + * need to tag viewport update, so camera view and borders are properly updated. */ + ED_region_tag_redraw(vod->region); + } + } + + /* set the view from the camera, if view locking is enabled. + * we may want to make this optional but for now its needed always */ + ED_view3d_camera_lock_init(depsgraph, vod->v3d, vod->rv3d); + + vod->init.persp = rv3d->persp; + vod->init.dist = rv3d->dist; + vod->init.camzoom = rv3d->camzoom; + copy_qt_qt(vod->init.quat, rv3d->viewquat); + copy_v2_v2_int(vod->init.event_xy, event->xy); + copy_v2_v2_int(vod->prev.event_xy, event->xy); + + if (viewops_flag & VIEWOPS_FLAG_USE_MOUSE_INIT) { + zero_v2_int(vod->init.event_xy_offset); + } + else { + /* Simulate the event starting in the middle of the region. */ + vod->init.event_xy_offset[0] = BLI_rcti_cent_x(&vod->region->winrct) - event->xy[0]; + vod->init.event_xy_offset[1] = BLI_rcti_cent_y(&vod->region->winrct) - event->xy[1]; + } + + vod->init.event_type = event->type; + copy_v3_v3(vod->init.ofs, rv3d->ofs); + + copy_qt_qt(vod->curr.viewquat, rv3d->viewquat); + + if (viewops_flag & VIEWOPS_FLAG_ORBIT_SELECT) { + float ofs[3]; + if (view3d_orbit_calc_center(C, ofs) || (vod->use_dyn_ofs == false)) { + vod->use_dyn_ofs = true; + negate_v3_v3(vod->dyn_ofs, ofs); + viewops_flag &= ~VIEWOPS_FLAG_DEPTH_NAVIGATE; + } + } + + if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) { + if (vod->use_dyn_ofs) { + if (rv3d->is_persp) { + float my_origin[3]; /* Original #RegionView3D.ofs. */ + float my_pivot[3]; /* View pivot. */ + float dvec[3]; + + /* locals for dist correction */ + float mat[3][3]; + float upvec[3]; + + negate_v3_v3(my_origin, rv3d->ofs); /* ofs is flipped */ + + /* Set the dist value to be the distance from this 3d point this means you'll + * always be able to zoom into it and panning won't go bad when dist was zero. */ + + /* remove dist value */ + upvec[0] = upvec[1] = 0; + upvec[2] = rv3d->dist; + copy_m3_m4(mat, rv3d->viewinv); + + mul_m3_v3(mat, upvec); + sub_v3_v3v3(my_pivot, rv3d->ofs, upvec); + negate_v3(my_pivot); /* ofs is flipped */ + + /* find a new ofs value that is along the view axis + * (rather than the mouse location) */ + closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin); + vod->init.dist = rv3d->dist = len_v3v3(my_pivot, dvec); + + negate_v3_v3(rv3d->ofs, dvec); + } + else { + const float mval_region_mid[2] = {(float)vod->region->winx / 2.0f, + (float)vod->region->winy / 2.0f}; + + ED_view3d_win_to_3d(vod->v3d, vod->region, vod->dyn_ofs, mval_region_mid, rv3d->ofs); + negate_v3(rv3d->ofs); + } + negate_v3(vod->dyn_ofs); + copy_v3_v3(vod->init.ofs, rv3d->ofs); + } + } + + /* For dolly */ + ED_view3d_win_to_vector(vod->region, (const float[2]){UNPACK2(event->mval)}, vod->init.mousevec); + + { + int event_xy_offset[2]; + add_v2_v2v2_int(event_xy_offset, event->xy, vod->init.event_xy_offset); + + /* For rotation with trackball rotation. */ + calctrackballvec(&vod->region->winrct, event_xy_offset, vod->init.trackvec); + } + + { + float tvec[3]; + negate_v3_v3(tvec, rv3d->ofs); + vod->init.zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL); + } + + vod->reverse = 1.0f; + if (rv3d->persmat[2][1] < 0.0f) { + vod->reverse = -1.0f; + } + + rv3d->rflag |= RV3D_NAVIGATING; + + return vod; +} + +void viewops_data_free(bContext *C, ViewOpsData *vod) +{ + ARegion *region; + if (vod) { + region = vod->region; + vod->rv3d->rflag &= ~RV3D_NAVIGATING; + + if (vod->timer) { + WM_event_remove_timer(CTX_wm_manager(C), vod->timer->win, vod->timer); + } + + if (vod->init.dial) { + MEM_freeN(vod->init.dial); + } + + MEM_freeN(vod); + } + else { + region = CTX_wm_region(C); + } + + /* Need to redraw because drawing code uses RV3D_NAVIGATING to draw + * faster while navigation operator runs. */ + ED_region_tag_redraw(region); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Generic View Operator Utilities + * \{ */ + +/** + * \param align_to_quat: When not NULL, set the axis relative to this rotation. + */ +static void axis_set_view(bContext *C, + View3D *v3d, + ARegion *region, + const float quat_[4], + char view, + char view_axis_roll, + int perspo, + const float *align_to_quat, + const int smooth_viewtx) +{ + RegionView3D *rv3d = region->regiondata; /* no NULL check is needed, poll checks */ + float quat[4]; + const short orig_persp = rv3d->persp; + + normalize_qt_qt(quat, quat_); + + if (align_to_quat) { + mul_qt_qtqt(quat, quat, align_to_quat); + rv3d->view = view = RV3D_VIEW_USER; + rv3d->view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; + } + + if (align_to_quat == NULL) { + rv3d->view = view; + rv3d->view_axis_roll = view_axis_roll; + } + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) { + ED_region_tag_redraw(region); + return; + } + + if (U.uiflag & USER_AUTOPERSP) { + rv3d->persp = RV3D_VIEW_IS_AXIS(view) ? RV3D_ORTHO : perspo; + } + else if (rv3d->persp == RV3D_CAMOB) { + rv3d->persp = perspo; + } + + if (rv3d->persp == RV3D_CAMOB && v3d->camera) { + /* to camera */ + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = v3d->camera, + .ofs = rv3d->ofs, + .quat = quat, + }); + } + else if (orig_persp == RV3D_CAMOB && v3d->camera) { + /* from camera */ + float ofs[3], dist; + + copy_v3_v3(ofs, rv3d->ofs); + dist = rv3d->dist; + + /* so we animate _from_ the camera location */ + Object *camera_eval = DEG_get_evaluated_object(CTX_data_ensure_evaluated_depsgraph(C), + v3d->camera); + ED_view3d_from_object(camera_eval, rv3d->ofs, NULL, &rv3d->dist, NULL); + + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = camera_eval, + .ofs = ofs, + .quat = quat, + .dist = &dist, + }); + } + else { + /* rotate around selection */ + const float *dyn_ofs_pt = NULL; + float dyn_ofs[3]; + + if (U.uiflag & USER_ORBIT_SELECTION) { + if (view3d_orbit_calc_center(C, dyn_ofs)) { + negate_v3(dyn_ofs); + dyn_ofs_pt = dyn_ofs; + } + } + + /* no camera involved */ + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .quat = quat, + .dyn_ofs = dyn_ofs_pt, + }); + } +} + +void viewmove_apply(ViewOpsData *vod, int x, int y) +{ + if (ED_view3d_offset_lock_check(vod->v3d, vod->rv3d)) { + vod->rv3d->ofs_lock[0] -= ((vod->prev.event_xy[0] - x) * 2.0f) / (float)vod->region->winx; + vod->rv3d->ofs_lock[1] -= ((vod->prev.event_xy[1] - y) * 2.0f) / (float)vod->region->winy; + } + else if ((vod->rv3d->persp == RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) { + const float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; + vod->rv3d->camdx += (vod->prev.event_xy[0] - x) / (vod->region->winx * zoomfac); + vod->rv3d->camdy += (vod->prev.event_xy[1] - y) / (vod->region->winy * zoomfac); + CLAMP(vod->rv3d->camdx, -1.0f, 1.0f); + CLAMP(vod->rv3d->camdy, -1.0f, 1.0f); + } + else { + float dvec[3]; + float mval_f[2]; + + mval_f[0] = x - vod->prev.event_xy[0]; + mval_f[1] = y - vod->prev.event_xy[1]; + ED_view3d_win_to_delta(vod->region, mval_f, dvec, vod->init.zfac); + + add_v3_v3(vod->rv3d->ofs, dvec); + + if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(vod->area, vod->region); + } + } + + vod->prev.event_xy[0] = x; + vod->prev.event_xy[1] = y; + + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); + + ED_region_tag_redraw(vod->region); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View All Operator + * + * Move & Zoom the view to fit all of its contents. + * \{ */ + +static bool view3d_object_skip_minmax(const View3D *v3d, + const RegionView3D *rv3d, + const Object *ob, + const bool skip_camera, + bool *r_only_center) +{ + BLI_assert(ob->id.orig_id == NULL); + *r_only_center = false; + + if (skip_camera && (ob == v3d->camera)) { + return true; + } + + if ((ob->type == OB_EMPTY) && (ob->empty_drawtype == OB_EMPTY_IMAGE) && + !BKE_object_empty_image_frame_is_visible_in_view3d(ob, rv3d)) { + *r_only_center = true; + return false; + } + + return false; +} + +static void view3d_object_calc_minmax(Depsgraph *depsgraph, + Scene *scene, + Object *ob_eval, + const bool only_center, + float min[3], + float max[3]) +{ + /* Account for duplis. */ + if (BKE_object_minmax_dupli(depsgraph, scene, ob_eval, min, max, false) == 0) { + /* Use if duplis aren't found. */ + if (only_center) { + minmax_v3v3_v3(min, max, ob_eval->obmat[3]); + } + else { + BKE_object_minmax(ob_eval, min, max, false); + } + } +} + +static void view3d_from_minmax(bContext *C, + View3D *v3d, + ARegion *region, + const float min[3], + const float max[3], + bool ok_dist, + const int smooth_viewtx) +{ + RegionView3D *rv3d = region->regiondata; + float afm[3]; + float size; + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + /* SMOOTHVIEW */ + float new_ofs[3]; + float new_dist; + + sub_v3_v3v3(afm, max, min); + size = max_fff(afm[0], afm[1], afm[2]); + + if (ok_dist) { + char persp; + + if (rv3d->is_persp) { + if (rv3d->persp == RV3D_CAMOB && ED_view3d_camera_lock_check(v3d, rv3d)) { + persp = RV3D_CAMOB; + } + else { + persp = RV3D_PERSP; + } + } + else { /* ortho */ + if (size < 0.0001f) { + /* bounding box was a single point so do not zoom */ + ok_dist = false; + } + else { + /* adjust zoom so it looks nicer */ + persp = RV3D_ORTHO; + } + } + + if (ok_dist) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + new_dist = ED_view3d_radius_to_dist( + v3d, region, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN); + if (rv3d->is_persp) { + /* don't zoom closer than the near clipping plane */ + new_dist = max_ff(new_dist, v3d->clip_start * 1.5f); + } + } + } + + mid_v3_v3v3(new_ofs, min, max); + negate_v3(new_ofs); + + if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) { + rv3d->persp = RV3D_PERSP; + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .camera_old = v3d->camera, + .ofs = new_ofs, + .dist = ok_dist ? &new_dist : NULL, + }); + } + else { + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .ofs = new_ofs, + .dist = ok_dist ? &new_dist : NULL, + }); + } + + /* Smooth-view does view-lock #RV3D_BOXVIEW copy. */ +} + +/** + * Same as #view3d_from_minmax but for all regions (except cameras). + */ +static void view3d_from_minmax_multi(bContext *C, + View3D *v3d, + const float min[3], + const float max[3], + const bool ok_dist, + const int smooth_viewtx) +{ + ScrArea *area = CTX_wm_area(C); + ARegion *region; + for (region = area->regionbase.first; region; region = region->next) { + if (region->regiontype == RGN_TYPE_WINDOW) { + RegionView3D *rv3d = region->regiondata; + /* when using all regions, don't jump out of camera view, + * but _do_ allow locked cameras to be moved */ + if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { + view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx); + } + } + } +} + +static int view3d_all_exec(bContext *C, wmOperator *op) +{ + ARegion *region = CTX_wm_region(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); + Base *base_eval; + const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); + const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) || + /* any one of the regions may be locked */ + (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); + const bool center = RNA_boolean_get(op->ptr, "center"); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + float min[3], max[3]; + bool changed = false; + + if (center) { + /* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */ + View3DCursor *cursor = &scene->cursor; + zero_v3(min); + zero_v3(max); + zero_v3(cursor->location); + float mat3[3][3]; + unit_m3(mat3); + BKE_scene_cursor_mat3_to_rot(cursor, mat3, false); + } + else { + INIT_MINMAX(min, max); + } + + for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { + if (BASE_VISIBLE(v3d, base_eval)) { + bool only_center = false; + Object *ob = DEG_get_original_object(base_eval->object); + if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) { + continue; + } + view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max); + changed = true; + } + } + + if (center) { + struct wmMsgBus *mbus = CTX_wm_message_bus(C); + WM_msg_publish_rna_prop(mbus, &scene->id, &scene->cursor, View3DCursor, location); + + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); + } + + if (!changed) { + ED_region_tag_redraw(region); + /* TODO: should this be cancel? + * I think no, because we always move the cursor, with or without + * object, but in this case there is no change in the scene, + * only the cursor so I choice a ED_region_tag like + * view3d_smooth_view do for the center_cursor. + * See bug T22640. + */ + return OPERATOR_FINISHED; + } + + if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { + /* This is an approximation, see function documentation for details. */ + ED_view3d_clipping_clamp_minmax(rv3d, min, max); + } + + if (use_all_regions) { + view3d_from_minmax_multi(C, v3d, min, max, true, smooth_viewtx); + } + else { + view3d_from_minmax(C, v3d, region, min, max, true, smooth_viewtx); + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_all(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Frame All"; + ot->description = "View all objects in scene"; + ot->idname = "VIEW3D_OT_view_all"; + + /* api callbacks */ + ot->exec = view3d_all_exec; + ot->poll = ED_operator_region_view3d_active; + + /* flags */ + ot->flag = 0; + + /* properties */ + view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); + RNA_def_boolean(ot->srna, "center", 0, "Center", ""); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Frame Selected Operator + * + * Move & Zoom the view to fit selected contents. + * \{ */ + +static int viewselected_exec(bContext *C, wmOperator *op) +{ + ARegion *region = CTX_wm_region(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + Scene *scene = CTX_data_scene(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); + Object *ob_eval = OBACT(view_layer_eval); + Object *obedit = CTX_data_edit_object(C); + const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL; + const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false; + const bool is_face_map = ((is_gp_edit == false) && region->gizmo_map && + WM_gizmomap_is_any_selected(region->gizmo_map)); + float min[3], max[3]; + bool ok = false, ok_dist = true; + const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); + const bool skip_camera = (ED_view3d_camera_lock_check(v3d, region->regiondata) || + /* any one of the regions may be locked */ + (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA)); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + INIT_MINMAX(min, max); + if (is_face_map) { + ob_eval = NULL; + } + + if (ob_eval && (ob_eval->mode & OB_MODE_WEIGHT_PAINT)) { + /* 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... */ + Base *base_eval; + for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) { + if (BASE_SELECTED_EDITABLE(v3d, base_eval)) { + if (base_eval->object->type == OB_ARMATURE) { + if (base_eval->object->mode & OB_MODE_POSE) { + break; + } + } + } + } + if (base_eval) { + ob_eval = base_eval->object; + } + } + + if (is_gp_edit) { + CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { + /* we're only interested in selected points here... */ + if ((gps->flag & GP_STROKE_SELECT) && (gps->flag & GP_STROKE_3DSPACE)) { + ok |= BKE_gpencil_stroke_minmax(gps, true, min, max); + } + if (gps->editcurve != NULL) { + for (int i = 0; i < gps->editcurve->tot_curve_points; i++) { + BezTriple *bezt = &gps->editcurve->curve_points[i].bezt; + if ((bezt->f1 & SELECT)) { + minmax_v3v3_v3(min, max, bezt->vec[0]); + ok = true; + } + if ((bezt->f2 & SELECT)) { + minmax_v3v3_v3(min, max, bezt->vec[1]); + ok = true; + } + if ((bezt->f3 & SELECT)) { + minmax_v3v3_v3(min, max, bezt->vec[2]); + ok = true; + } + } + } + } + CTX_DATA_END; + + if ((ob_eval) && (ok)) { + mul_m4_v3(ob_eval->obmat, min); + mul_m4_v3(ob_eval->obmat, max); + } + } + else if (is_face_map) { + ok = WM_gizmomap_minmax(region->gizmo_map, true, true, min, max); + } + else if (obedit) { + /* only selected */ + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer_eval, v3d, obedit->type, obedit->mode, ob_eval_iter) { + ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max); + } + FOREACH_OBJECT_IN_MODE_END; + } + else if (ob_eval && (ob_eval->mode & OB_MODE_POSE)) { + FOREACH_OBJECT_IN_MODE_BEGIN ( + view_layer_eval, v3d, ob_eval->type, ob_eval->mode, ob_eval_iter) { + ok |= BKE_pose_minmax(ob_eval_iter, min, max, true, true); + } + FOREACH_OBJECT_IN_MODE_END; + } + else if (BKE_paint_select_face_test(ob_eval)) { + ok = paintface_minmax(ob_eval, min, max); + } + else if (ob_eval && (ob_eval->mode & OB_MODE_PARTICLE_EDIT)) { + ok = PE_minmax(depsgraph, scene, CTX_data_view_layer(C), min, max); + } + else if (ob_eval && (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_eval, min); + copy_v3_v3(max, min); + ok = true; + ok_dist = 0; /* don't zoom */ + } + else { + Base *base_eval; + for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) { + if (BASE_SELECTED(v3d, base_eval)) { + bool only_center = false; + Object *ob = DEG_get_original_object(base_eval->object); + if (view3d_object_skip_minmax(v3d, rv3d, ob, skip_camera, &only_center)) { + continue; + } + view3d_object_calc_minmax(depsgraph, scene, base_eval->object, only_center, min, max); + ok = 1; + } + } + } + + if (ok == 0) { + return OPERATOR_FINISHED; + } + + if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) { + /* This is an approximation, see function documentation for details. */ + ED_view3d_clipping_clamp_minmax(rv3d, min, max); + } + + if (use_all_regions) { + view3d_from_minmax_multi(C, v3d, min, max, ok_dist, smooth_viewtx); + } + else { + view3d_from_minmax(C, v3d, region, min, max, ok_dist, smooth_viewtx); + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_selected(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Frame Selected"; + ot->description = "Move the view to the selection center"; + ot->idname = "VIEW3D_OT_view_selected"; + + /* api callbacks */ + ot->exec = viewselected_exec; + ot->poll = view3d_zoom_or_dolly_poll; + + /* flags */ + ot->flag = 0; + + /* properties */ + view3d_operator_properties_common(ot, V3D_OP_PROP_USE_ALL_REGIONS); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Center Cursor Operator + * \{ */ + +static int viewcenter_cursor_exec(bContext *C, wmOperator *op) +{ + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + Scene *scene = CTX_data_scene(C); + + if (rv3d) { + ARegion *region = CTX_wm_region(C); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + /* non camera center */ + float new_ofs[3]; + negate_v3_v3(new_ofs, scene->cursor.location); + ED_view3d_smooth_view( + C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs}); + + /* Smooth view does view-lock #RV3D_BOXVIEW copy. */ + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_center_cursor(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Center View to Cursor"; + ot->description = "Center the view so that the cursor is in the middle of the view"; + ot->idname = "VIEW3D_OT_view_center_cursor"; + + /* api callbacks */ + ot->exec = viewcenter_cursor_exec; + ot->poll = view3d_location_poll; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Center Pick Operator + * \{ */ + +static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + ARegion *region = CTX_wm_region(C); + + if (rv3d) { + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + float new_ofs[3]; + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + view3d_operator_needs_opengl(C); + + if (ED_view3d_autodist(depsgraph, region, v3d, event->mval, new_ofs, false, NULL)) { + /* pass */ + } + else { + /* fallback to simple pan */ + negate_v3_v3(new_ofs, rv3d->ofs); + ED_view3d_win_to_3d_int(v3d, region, new_ofs, event->mval, new_ofs); + } + negate_v3(new_ofs); + ED_view3d_smooth_view( + C, v3d, region, smooth_viewtx, &(const V3D_SmoothParams){.ofs = new_ofs}); + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_center_pick(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Center View to Mouse"; + ot->description = "Center the view to the Z-depth position under the mouse cursor"; + ot->idname = "VIEW3D_OT_view_center_pick"; + + /* api callbacks */ + ot->invoke = viewcenter_pick_invoke; + ot->poll = view3d_location_poll; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Axis Operator + * \{ */ + +static const EnumPropertyItem prop_view_items[] = { + {RV3D_VIEW_LEFT, "LEFT", ICON_TRIA_LEFT, "Left", "View from the left"}, + {RV3D_VIEW_RIGHT, "RIGHT", ICON_TRIA_RIGHT, "Right", "View from the right"}, + {RV3D_VIEW_BOTTOM, "BOTTOM", ICON_TRIA_DOWN, "Bottom", "View from the bottom"}, + {RV3D_VIEW_TOP, "TOP", ICON_TRIA_UP, "Top", "View from the top"}, + {RV3D_VIEW_FRONT, "FRONT", 0, "Front", "View from the front"}, + {RV3D_VIEW_BACK, "BACK", 0, "Back", "View from the back"}, + {0, NULL, 0, NULL, NULL}, +}; + +static int view_axis_exec(bContext *C, wmOperator *op) +{ + View3D *v3d; + ARegion *region; + RegionView3D *rv3d; + static int perspo = RV3D_PERSP; + int viewnum; + int view_axis_roll = RV3D_VIEW_AXIS_ROLL_0; + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + /* no NULL check is needed, poll checks */ + ED_view3d_context_user_region(C, &v3d, ®ion); + rv3d = region->regiondata; + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + viewnum = RNA_enum_get(op->ptr, "type"); + + float align_quat_buf[4]; + float *align_quat = NULL; + + if (RNA_boolean_get(op->ptr, "align_active")) { + /* align to active object */ + Object *obact = CTX_data_active_object(C); + if (obact != NULL) { + float twmat[3][3]; + struct ViewLayer *view_layer = CTX_data_view_layer(C); + Object *obedit = CTX_data_edit_object(C); + /* same as transform gizmo when normal is set */ + ED_getTransformOrientationMatrix(view_layer, v3d, obact, obedit, V3D_AROUND_ACTIVE, twmat); + align_quat = align_quat_buf; + mat3_to_quat(align_quat, twmat); + invert_qt_normalized(align_quat); + } + } + + if (RNA_boolean_get(op->ptr, "relative")) { + float quat_rotate[4]; + float quat_test[4]; + + if (viewnum == RV3D_VIEW_LEFT) { + axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], -M_PI / 2.0f); + } + else if (viewnum == RV3D_VIEW_RIGHT) { + axis_angle_to_quat(quat_rotate, rv3d->viewinv[1], M_PI / 2.0f); + } + else if (viewnum == RV3D_VIEW_TOP) { + axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], -M_PI / 2.0f); + } + else if (viewnum == RV3D_VIEW_BOTTOM) { + axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI / 2.0f); + } + else if (viewnum == RV3D_VIEW_FRONT) { + unit_qt(quat_rotate); + } + else if (viewnum == RV3D_VIEW_BACK) { + axis_angle_to_quat(quat_rotate, rv3d->viewinv[0], M_PI); + } + else { + BLI_assert(0); + } + + mul_qt_qtqt(quat_test, rv3d->viewquat, quat_rotate); + + float angle_best = FLT_MAX; + int view_best = -1; + int view_axis_roll_best = -1; + for (int i = RV3D_VIEW_FRONT; i <= RV3D_VIEW_BOTTOM; i++) { + for (int j = RV3D_VIEW_AXIS_ROLL_0; j <= RV3D_VIEW_AXIS_ROLL_270; j++) { + float quat_axis[4]; + ED_view3d_quat_from_axis_view(i, j, quat_axis); + if (align_quat) { + mul_qt_qtqt(quat_axis, quat_axis, align_quat); + } + const float angle_test = fabsf(angle_signed_qtqt(quat_axis, quat_test)); + if (angle_best > angle_test) { + angle_best = angle_test; + view_best = i; + view_axis_roll_best = j; + } + } + } + if (view_best == -1) { + view_best = RV3D_VIEW_FRONT; + view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0; + } + + /* Disallow non-upright views in turn-table modes, + * it's too difficult to navigate out of them. */ + if ((U.flag & USER_TRACKBALL) == 0) { + if (!ELEM(view_best, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) { + view_axis_roll_best = RV3D_VIEW_AXIS_ROLL_0; + } + } + + viewnum = view_best; + view_axis_roll = view_axis_roll_best; + } + + /* Use this to test if we started out with a camera */ + const int nextperspo = (rv3d->persp == RV3D_CAMOB) ? rv3d->lpersp : perspo; + float quat[4]; + ED_view3d_quat_from_axis_view(viewnum, view_axis_roll, quat); + axis_set_view( + C, v3d, region, quat, viewnum, view_axis_roll, nextperspo, align_quat, smooth_viewtx); + + perspo = rv3d->persp; + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_axis(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "View Axis"; + ot->description = "Use a preset viewpoint"; + ot->idname = "VIEW3D_OT_view_axis"; + + /* api callbacks */ + ot->exec = view_axis_exec; + ot->poll = ED_operator_rv3d_user_region_poll; + + /* flags */ + ot->flag = 0; + + ot->prop = RNA_def_enum(ot->srna, "type", prop_view_items, 0, "View", "Preset viewpoint to use"); + RNA_def_property_flag(ot->prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean( + ot->srna, "align_active", 0, "Align Active", "Align to the active object's axis"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_boolean( + ot->srna, "relative", 0, "Relative", "Rotate relative to the current orientation"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Camera Operator + * \{ */ + +static int view_camera_exec(bContext *C, wmOperator *op) +{ + View3D *v3d; + ARegion *region; + RegionView3D *rv3d; + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + /* no NULL check is needed, poll checks */ + ED_view3d_context_user_region(C, &v3d, ®ion); + rv3d = region->regiondata; + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ANY_TRANSFORM) == 0) { + ViewLayer *view_layer = CTX_data_view_layer(C); + Scene *scene = CTX_data_scene(C); + + if (rv3d->persp != RV3D_CAMOB) { + Object *ob = OBACT(view_layer); + + if (!rv3d->smooth_timer) { + /* store settings of current view before allowing overwriting with camera view + * only if we're not currently in a view transition */ + + ED_view3d_lastview_store(rv3d); + } + + /* first get the default camera for the view lock type */ + if (v3d->scenelock) { + /* sets the camera view if available */ + v3d->camera = scene->camera; + } + else { + /* use scene camera if one is not set (even though we're unlocked) */ + if (v3d->camera == NULL) { + v3d->camera = scene->camera; + } + } + + /* if the camera isn't found, check a number of options */ + if (v3d->camera == NULL && ob && ob->type == OB_CAMERA) { + v3d->camera = ob; + } + + if (v3d->camera == NULL) { + v3d->camera = BKE_view_layer_camera_find(view_layer); + } + + /* couldn't find any useful camera, bail out */ + if (v3d->camera == NULL) { + return OPERATOR_CANCELLED; + } + + /* important these don't get out of sync for locked scenes */ + if (v3d->scenelock && scene->camera != v3d->camera) { + scene->camera = v3d->camera; + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); + } + + /* finally do snazzy view zooming */ + rv3d->persp = RV3D_CAMOB; + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .camera = v3d->camera, + .ofs = rv3d->ofs, + .quat = rv3d->viewquat, + .dist = &rv3d->dist, + .lens = &v3d->lens, + }); + } + else { + /* return to settings of last view */ + /* does view3d_smooth_view too */ + axis_set_view(C, + v3d, + region, + rv3d->lviewquat, + rv3d->lview, + rv3d->lview_axis_roll, + rv3d->lpersp, + NULL, + smooth_viewtx); + } + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_camera(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "View Camera"; + ot->description = "Toggle the camera view"; + ot->idname = "VIEW3D_OT_view_camera"; + + /* api callbacks */ + ot->exec = view_camera_exec; + ot->poll = ED_operator_rv3d_user_region_poll; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Orbit Operator + * + * Rotate (orbit) in incremental steps. For interactive orbit see #VIEW3D_OT_rotate. + * \{ */ + +enum { + V3D_VIEW_STEPLEFT = 1, + V3D_VIEW_STEPRIGHT, + V3D_VIEW_STEPDOWN, + V3D_VIEW_STEPUP, +}; + +static const EnumPropertyItem prop_view_orbit_items[] = { + {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the left"}, + {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the right"}, + {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view up"}, + {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view down"}, + {0, NULL, 0, NULL, NULL}, +}; + +static int vieworbit_exec(bContext *C, wmOperator *op) +{ + View3D *v3d; + ARegion *region; + RegionView3D *rv3d; + int orbitdir; + char view_opposite; + PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle"); + float angle = RNA_property_is_set(op->ptr, prop_angle) ? + RNA_property_float_get(op->ptr, prop_angle) : + DEG2RADF(U.pad_rot_angle); + + /* no NULL check is needed, poll checks */ + v3d = CTX_wm_view3d(C); + region = CTX_wm_region(C); + rv3d = region->regiondata; + + /* support for switching to the opposite view (even when in locked views) */ + view_opposite = (fabsf(angle) == (float)M_PI) ? ED_view3d_axis_view_opposite(rv3d->view) : + RV3D_VIEW_USER; + orbitdir = RNA_enum_get(op->ptr, "type"); + + if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) { + /* no NULL check is needed, poll checks */ + ED_view3d_context_user_region(C, &v3d, ®ion); + rv3d = region->regiondata; + } + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0 || (view_opposite != RV3D_VIEW_USER)) { + if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { + int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + float quat_mul[4]; + float quat_new[4]; + + if (view_opposite == RV3D_VIEW_USER) { + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ED_view3d_persp_ensure(depsgraph, v3d, region); + } + + if (ELEM(orbitdir, V3D_VIEW_STEPLEFT, V3D_VIEW_STEPRIGHT)) { + if (orbitdir == V3D_VIEW_STEPRIGHT) { + angle = -angle; + } + + /* z-axis */ + axis_angle_to_quat_single(quat_mul, 'Z', angle); + } + else { + + if (orbitdir == V3D_VIEW_STEPDOWN) { + angle = -angle; + } + + /* horizontal axis */ + axis_angle_to_quat(quat_mul, rv3d->viewinv[0], angle); + } + + mul_qt_qtqt(quat_new, rv3d->viewquat, quat_mul); + + /* avoid precision loss over time */ + normalize_qt(quat_new); + + if (view_opposite != RV3D_VIEW_USER) { + rv3d->view = view_opposite; + /* avoid float in-precision, just get a new orientation */ + ED_view3d_quat_from_axis_view(view_opposite, rv3d->view_axis_roll, quat_new); + } + else { + rv3d->view = RV3D_VIEW_USER; + } + + float dyn_ofs[3], *dyn_ofs_pt = NULL; + + if (U.uiflag & USER_ORBIT_SELECTION) { + if (view3d_orbit_calc_center(C, dyn_ofs)) { + negate_v3(dyn_ofs); + dyn_ofs_pt = dyn_ofs; + } + } + + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .quat = quat_new, + .dyn_ofs = dyn_ofs_pt, + }); + + return OPERATOR_FINISHED; + } + } + + return OPERATOR_CANCELLED; +} + +void VIEW3D_OT_view_orbit(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "View Orbit"; + ot->description = "Orbit the view"; + ot->idname = "VIEW3D_OT_view_orbit"; + + /* api callbacks */ + ot->exec = vieworbit_exec; + ot->poll = ED_operator_rv3d_user_region_poll; + + /* flags */ + ot->flag = 0; + + /* properties */ + prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + + ot->prop = RNA_def_enum( + ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit"); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name View Pan Operator + * + * Move (pan) in incremental steps. For interactive pan see #VIEW3D_OT_move. + * \{ */ + +enum { + V3D_VIEW_PANLEFT = 1, + V3D_VIEW_PANRIGHT, + V3D_VIEW_PANDOWN, + V3D_VIEW_PANUP, +}; + +static const EnumPropertyItem prop_view_pan_items[] = { + {V3D_VIEW_PANLEFT, "PANLEFT", 0, "Pan Left", "Pan the view to the left"}, + {V3D_VIEW_PANRIGHT, "PANRIGHT", 0, "Pan Right", "Pan the view to the right"}, + {V3D_VIEW_PANUP, "PANUP", 0, "Pan Up", "Pan the view up"}, + {V3D_VIEW_PANDOWN, "PANDOWN", 0, "Pan Down", "Pan the view down"}, + {0, NULL, 0, NULL, NULL}, +}; + +static int viewpan_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + int x = 0, y = 0; + int pandir = RNA_enum_get(op->ptr, "type"); + + if (pandir == V3D_VIEW_PANRIGHT) { + x = -32; + } + else if (pandir == V3D_VIEW_PANLEFT) { + x = 32; + } + else if (pandir == V3D_VIEW_PANUP) { + y = -25; + } + else if (pandir == V3D_VIEW_PANDOWN) { + y = 25; + } + + ViewOpsData *vod = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT)); + + viewmove_apply(vod, vod->prev.event_xy[0] + x, vod->prev.event_xy[1] + y); + + viewops_data_free(C, vod); + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_view_pan(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Pan View Direction"; + ot->description = "Pan the view in a given direction"; + ot->idname = "VIEW3D_OT_view_pan"; + + /* api callbacks */ + ot->invoke = viewpan_invoke; + ot->poll = view3d_location_poll; + + /* flags */ + ot->flag = 0; + + /* Properties */ + ot->prop = RNA_def_enum( + ot->srna, "type", prop_view_pan_items, 0, "Pan", "Direction of View Pan"); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate.h b/source/blender/editors/space_view3d/view3d_navigate.h new file mode 100644 index 00000000000..792d2a83bc2 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate.h @@ -0,0 +1,282 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup spview3d + */ + +#pragma once + +/** + * Size of the sphere being dragged for trackball rotation within the view bounds. + * also affects speed (smaller is faster). + */ +#define V3D_OP_TRACKBALLSIZE (1.1f) + +struct ARegion; +struct bContext; +struct Depsgraph; +struct Dial; +struct Main; +struct rcti; +struct RegionView3D; +struct Scene; +struct ScrArea; +struct View3D; +struct wmEvent; +struct wmOperator; + +enum eV3D_OpPropFlag { + V3D_OP_PROP_MOUSE_CO = (1 << 0), + V3D_OP_PROP_DELTA = (1 << 1), + V3D_OP_PROP_USE_ALL_REGIONS = (1 << 2), + V3D_OP_PROP_USE_MOUSE_INIT = (1 << 3), +}; + +enum { + VIEW_PASS = 0, + VIEW_APPLY, + VIEW_CONFIRM, +}; + +/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */ +enum { + VIEW_MODAL_CONFIRM = 1, /* used for all view operations */ + VIEWROT_MODAL_AXIS_SNAP_ENABLE = 2, + VIEWROT_MODAL_AXIS_SNAP_DISABLE = 3, + VIEWROT_MODAL_SWITCH_ZOOM = 4, + VIEWROT_MODAL_SWITCH_MOVE = 5, + VIEWROT_MODAL_SWITCH_ROTATE = 6, +}; + +enum eViewOpsFlag { + /** When enabled, rotate around the selection. */ + VIEWOPS_FLAG_ORBIT_SELECT = (1 << 0), + /** When enabled, use the depth under the cursor for navigation. */ + VIEWOPS_FLAG_DEPTH_NAVIGATE = (1 << 1), + /** + * When enabled run #ED_view3d_persp_ensure this may switch out of camera view + * when orbiting or switch from orthographic to perspective when auto-perspective is enabled. + * Some operations don't require this (view zoom/pan or NDOF where subtle rotation is common + * so we don't want it to trigger auto-perspective). */ + VIEWOPS_FLAG_PERSP_ENSURE = (1 << 2), + /** When set, ignore any options that depend on initial cursor location. */ + VIEWOPS_FLAG_USE_MOUSE_INIT = (1 << 3), +}; + +/** Generic View Operator Custom-Data */ +typedef struct ViewOpsData { + /** Context pointers (assigned by #viewops_data_create). */ + struct Main *bmain; + struct Scene *scene; + struct ScrArea *area; + struct ARegion *region; + struct View3D *v3d; + struct RegionView3D *rv3d; + struct Depsgraph *depsgraph; + + /** Needed for continuous zoom. */ + struct wmTimer *timer; + + /** Viewport state on initialization, don't change afterwards. */ + struct { + float dist; + float camzoom; + float quat[4]; + /** #wmEvent.xy. */ + int event_xy[2]; + /** Offset to use when #VIEWOPS_FLAG_USE_MOUSE_INIT is not set. + * so we can simulate pressing in the middle of the screen. */ + int event_xy_offset[2]; + /** #wmEvent.type that triggered the operator. */ + int event_type; + float ofs[3]; + /** Initial distance to 'ofs'. */ + float zfac; + + /** Trackball rotation only. */ + float trackvec[3]; + /** Dolly only. */ + float mousevec[3]; + + /** + * #RegionView3D.persp set after auto-perspective is applied. + * If we want the value before running the operator, add a separate member. + */ + char persp; + + /** Used for roll */ + struct Dial *dial; + } init; + + /** Previous state (previous modal event handled). */ + struct { + int event_xy[2]; + /** For operators that use time-steps (continuous zoom). */ + double time; + } prev; + + /** Current state. */ + struct { + /** Working copy of #RegionView3D.viewquat, needed for rotation calculation + * so we can apply snap to the 3D Viewport while keeping the unsnapped rotation + * here to use when snap is disabled and for continued calculation. */ + float viewquat[4]; + } curr; + + float reverse; + bool axis_snap; /* view rotate only */ + + /** Use for orbit selection and auto-dist. */ + float dyn_ofs[3]; + bool use_dyn_ofs; +} ViewOpsData; + +/* view3d_navigate.c */ +bool view3d_location_poll(struct bContext *C); +bool view3d_rotation_poll(struct bContext *C); +bool view3d_zoom_or_dolly_poll(struct bContext *C); + +enum eViewOpsFlag viewops_flag_from_prefs(void); +void calctrackballvec(const struct rcti *rect, const int event_xy[2], float r_dir[3]); +void viewmove_apply(ViewOpsData *vod, int x, int y); +void view3d_orbit_apply_dyn_ofs(float r_ofs[3], + const float ofs_old[3], + const float viewquat_old[4], + const float viewquat_new[4], + const float dyn_ofs[3]); +void viewrotate_apply_dyn_ofs(ViewOpsData *vod, const float viewquat_new[4]); +bool view3d_orbit_calc_center(struct bContext *C, float r_dyn_ofs[3]); + +void view3d_operator_properties_common(struct wmOperatorType *ot, const enum eV3D_OpPropFlag flag); + +/** + * Allocate and fill in context pointers for #ViewOpsData + */ +void viewops_data_free(struct bContext *C, ViewOpsData *vod); + +/** + * Allocate, fill in context pointers and calculate the values for #ViewOpsData + */ +ViewOpsData *viewops_data_create(struct bContext *C, + const struct wmEvent *event, + enum eViewOpsFlag viewops_flag); + +void VIEW3D_OT_view_all(struct wmOperatorType *ot); +void VIEW3D_OT_view_selected(struct wmOperatorType *ot); +void VIEW3D_OT_view_center_cursor(struct wmOperatorType *ot); +void VIEW3D_OT_view_center_pick(struct wmOperatorType *ot); +void VIEW3D_OT_view_axis(struct wmOperatorType *ot); +void VIEW3D_OT_view_camera(struct wmOperatorType *ot); +void VIEW3D_OT_view_orbit(struct wmOperatorType *ot); +void VIEW3D_OT_view_pan(struct wmOperatorType *ot); + +/* view3d_navigate_dolly.c */ +void viewdolly_modal_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_dolly(struct wmOperatorType *ot); + +/* view3d_navigate_fly.c */ +void fly_modal_keymap(struct wmKeyConfig *keyconf); +void view3d_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_fly(struct wmOperatorType *ot); + +/* view3d_navigate_move.c */ +void viewmove_modal_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_move(struct wmOperatorType *ot); + +/* view3d_navigate_ndof.c */ +#ifdef WITH_INPUT_NDOF +struct wmNDOFMotionData; + +/** + * Called from both fly mode and walk mode, + */ +void view3d_ndof_fly(const struct wmNDOFMotionData *ndof, + struct View3D *v3d, + struct RegionView3D *rv3d, + bool use_precision, + short protectflag, + bool *r_has_translate, + bool *r_has_rotate); +void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot); +void VIEW3D_OT_ndof_all(struct wmOperatorType *ot); +#endif /* WITH_INPUT_NDOF */ + +/* view3d_navigate_roll.c */ +void VIEW3D_OT_view_roll(struct wmOperatorType *ot); + +/* view3d_navigate_rotate.c */ +void viewrotate_modal_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_rotate(struct wmOperatorType *ot); + +/* view3d_navigate_smoothview.c */ + +/** + * Parameters for setting the new 3D Viewport state. + * + * Each of the struct members may be NULL to signify they aren't to be adjusted. + */ +typedef struct V3D_SmoothParams { + struct Object *camera_old, *camera; + const float *ofs, *quat, *dist, *lens; + + /** Alternate rotation center, when set `ofs` must be NULL. */ + const float *dyn_ofs; +} V3D_SmoothParams; + +/** + * The arguments are the desired situation. + */ +void ED_view3d_smooth_view_ex(const struct Depsgraph *depsgraph, + struct wmWindowManager *wm, + struct wmWindow *win, + struct ScrArea *area, + struct View3D *v3d, + struct ARegion *region, + int smooth_viewtx, + const V3D_SmoothParams *sview); + +void ED_view3d_smooth_view(struct bContext *C, + struct View3D *v3d, + struct ARegion *region, + int smooth_viewtx, + const V3D_SmoothParams *sview); + +/** + * Apply the smooth-view immediately, use when we need to start a new view operation. + * (so we don't end up half-applying a view operation when pressing keys quickly). + */ +void ED_view3d_smooth_view_force_finish(struct bContext *C, + struct View3D *v3d, + struct ARegion *region); + +void VIEW3D_OT_smoothview(struct wmOperatorType *ot); + +/* view3d_navigate_walk.c */ +void walk_modal_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_walk(struct wmOperatorType *ot); + +/* view3d_navigate_zoom.c */ +void viewzoom_modal_keymap(struct wmKeyConfig *keyconf); +void VIEW3D_OT_zoom(struct wmOperatorType *ot); + +/* view3d_navigate_zoom_border.c */ +void VIEW3D_OT_zoom_border(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_view3d/view3d_navigate_dolly.c b/source/blender/editors/space_view3d/view3d_navigate_dolly.c new file mode 100644 index 00000000000..02783c2a244 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_dolly.c @@ -0,0 +1,337 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BLI_math.h" + +#include "BKE_context.h" +#include "BKE_report.h" + +#include "DEG_depsgraph.h" + +#include "WM_api.h" + +#include "RNA_access.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name View Dolly Operator + * + * Like zoom but translates the view offset along the view direction + * which avoids #RegionView3D.dist approaching zero. + * \{ */ + +/* This is an exact copy of #viewzoom_modal_keymap. */ +void viewdolly_modal_keymap(wmKeyConfig *keyconf) +{ + static const EnumPropertyItem modal_items[] = { + {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + + {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, + {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, + + {0, NULL, 0, NULL, NULL}, + }; + + wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Dolly Modal"); + + /* this function is called for each spacetype, only needs to add map once */ + if (keymap && keymap->modal_items) { + return; + } + + keymap = WM_modalkeymap_ensure(keyconf, "View3D Dolly Modal", modal_items); + + /* disabled mode switching for now, can re-implement better, later on */ +#if 0 + WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); + WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); +#endif + + /* assign map to operators */ + WM_modalkeymap_assign(keymap, "VIEW3D_OT_dolly"); +} + +static bool viewdolly_offset_lock_check(bContext *C, wmOperator *op) +{ + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + if (ED_view3d_offset_lock_check(v3d, rv3d)) { + BKE_report(op->reports, RPT_WARNING, "Cannot dolly when the view offset is locked"); + return true; + } + return false; +} + +static void view_dolly_to_vector_3d(ARegion *region, + const float orig_ofs[3], + const float dvec[3], + float dfac) +{ + RegionView3D *rv3d = region->regiondata; + madd_v3_v3v3fl(rv3d->ofs, orig_ofs, dvec, -(1.0f - dfac)); +} + +static void viewdolly_apply(ViewOpsData *vod, const int xy[2], const bool zoom_invert) +{ + float zfac = 1.0; + + { + float len1, len2; + + if (U.uiflag & USER_ZOOM_HORIZ) { + len1 = (vod->region->winrct.xmax - xy[0]) + 5; + len2 = (vod->region->winrct.xmax - vod->init.event_xy[0]) + 5; + } + else { + len1 = (vod->region->winrct.ymax - xy[1]) + 5; + len2 = (vod->region->winrct.ymax - vod->init.event_xy[1]) + 5; + } + if (zoom_invert) { + SWAP(float, len1, len2); + } + + zfac = 1.0f + ((len1 - len2) * 0.01f * vod->rv3d->dist); + } + + if (zfac != 1.0f) { + view_dolly_to_vector_3d(vod->region, vod->init.ofs, vod->init.mousevec, zfac); + } + + if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(vod->area, vod->region); + } + + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); + + ED_region_tag_redraw(vod->region); +} + +static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod = op->customdata; + short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; + + /* execute the events */ + if (event->type == MOUSEMOVE) { + event_code = VIEW_APPLY; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case VIEW_MODAL_CONFIRM: + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_MOVE: + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_ROTATE: + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + } + } + else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { + event_code = VIEW_CONFIRM; + } + + if (event_code == VIEW_APPLY) { + viewdolly_apply(vod, event->xy, (U.uiflag & USER_ZOOM_INVERT) != 0); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } + } + else if (event_code == VIEW_CONFIRM) { + use_autokey = true; + ret = OPERATOR_FINISHED; + } + + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, vod); + op->customdata = NULL; + } + + return ret; +} + +static int viewdolly_exec(bContext *C, wmOperator *op) +{ + View3D *v3d; + RegionView3D *rv3d; + ScrArea *area; + ARegion *region; + float mousevec[3]; + + const int delta = RNA_int_get(op->ptr, "delta"); + + if (op->customdata) { + ViewOpsData *vod = op->customdata; + + area = vod->area; + region = vod->region; + copy_v3_v3(mousevec, vod->init.mousevec); + } + else { + area = CTX_wm_area(C); + region = CTX_wm_region(C); + negate_v3_v3(mousevec, ((RegionView3D *)region->regiondata)->viewinv[2]); + normalize_v3(mousevec); + } + + v3d = area->spacedata.first; + rv3d = region->regiondata; + + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + /* overwrite the mouse vector with the view direction (zoom into the center) */ + if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { + normalize_v3_v3(mousevec, rv3d->viewinv[2]); + negate_v3(mousevec); + } + + view_dolly_to_vector_3d(region, rv3d->ofs, mousevec, delta < 0 ? 1.8f : 0.2f); + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(area, region); + } + + ED_view3d_camera_lock_sync(CTX_data_ensure_evaluated_depsgraph(C), v3d, rv3d); + + ED_region_tag_redraw(region); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; +} + +/* copied from viewzoom_invoke(), changes here may apply there */ +static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod; + + if (viewdolly_offset_lock_check(C, op)) { + return OPERATOR_CANCELLED; + } + + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + /* needs to run before 'viewops_data_create' so the backup 'rv3d->ofs' is correct */ + /* switch from camera view when: */ + if (vod->rv3d->persp != RV3D_PERSP) { + if (vod->rv3d->persp == RV3D_CAMOB) { + /* ignore rv3d->lpersp because dolly only makes sense in perspective mode */ + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ED_view3d_persp_switch_from_camera(depsgraph, vod->v3d, vod->rv3d, RV3D_PERSP); + } + else { + vod->rv3d->persp = RV3D_PERSP; + } + ED_region_tag_redraw(vod->region); + } + + /* if one or the other zoom position aren't set, set from event */ + if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { + RNA_int_set(op->ptr, "mx", event->xy[0]); + RNA_int_set(op->ptr, "my", event->xy[1]); + } + + if (RNA_struct_property_is_set(op->ptr, "delta")) { + viewdolly_exec(C, op); + } + else { + /* overwrite the mouse vector with the view direction (zoom into the center) */ + if ((use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) == 0) { + negate_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); + normalize_v3(vod->init.mousevec); + } + + if (event->type == MOUSEZOOM) { + /* Bypass Zoom invert flag for track pads (pass false always) */ + + if (U.uiflag & USER_ZOOM_HORIZ) { + vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; + } + else { + /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ + vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - + event->prev_xy[0]; + } + viewdolly_apply(vod, event->prev_xy, (U.uiflag & USER_ZOOM_INVERT) == 0); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_FINISHED; + } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + return OPERATOR_RUNNING_MODAL; + } + return OPERATOR_FINISHED; +} + +static void viewdolly_cancel(bContext *C, wmOperator *op) +{ + viewops_data_free(C, op->customdata); + op->customdata = NULL; +} + +void VIEW3D_OT_dolly(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Dolly View"; + ot->description = "Dolly in/out in the view"; + ot->idname = "VIEW3D_OT_dolly"; + + /* api callbacks */ + ot->invoke = viewdolly_invoke; + ot->exec = viewdolly_exec; + ot->modal = viewdolly_modal; + ot->poll = view3d_rotation_poll; + ot->cancel = viewdolly_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; + + /* properties */ + view3d_operator_properties_common( + ot, V3D_OP_PROP_DELTA | V3D_OP_PROP_MOUSE_CO | V3D_OP_PROP_USE_MOUSE_INIT); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_fly.c b/source/blender/editors/space_view3d/view3d_navigate_fly.c index 2e9cb419e2e..940616eec1f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_fly.c +++ b/source/blender/editors/space_view3d/view3d_navigate_fly.c @@ -58,6 +58,7 @@ #include "DEG_depsgraph.h" #include "view3d_intern.h" /* own include */ +#include "view3d_navigate.h" /* -------------------------------------------------------------------- */ /** \name Modal Key-map diff --git a/source/blender/editors/space_view3d/view3d_navigate_move.c b/source/blender/editors/space_view3d/view3d_navigate_move.c new file mode 100644 index 00000000000..90acf20d24f --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_move.c @@ -0,0 +1,188 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BKE_context.h" + +#include "WM_api.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name View Move (Pan) Operator + * \{ */ + +/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */ + +void viewmove_modal_keymap(wmKeyConfig *keyconf) +{ + static const EnumPropertyItem modal_items[] = { + {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + + {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, + {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, + + {0, NULL, 0, NULL, NULL}, + }; + + wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Move Modal"); + + /* this function is called for each spacetype, only needs to add map once */ + if (keymap && keymap->modal_items) { + return; + } + + keymap = WM_modalkeymap_ensure(keyconf, "View3D Move Modal", modal_items); + + /* items for modal map */ + WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, VIEW_MODAL_CONFIRM); + WM_modalkeymap_add_item(keymap, EVT_ESCKEY, KM_PRESS, KM_ANY, 0, VIEW_MODAL_CONFIRM); + + /* disabled mode switching for now, can re-implement better, later on */ +#if 0 + WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); + WM_modalkeymap_add_item( + keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); +#endif + + /* assign map to operators */ + WM_modalkeymap_assign(keymap, "VIEW3D_OT_move"); +} + +static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + + ViewOpsData *vod = op->customdata; + short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; + + /* execute the events */ + if (event->type == MOUSEMOVE) { + event_code = VIEW_APPLY; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case VIEW_MODAL_CONFIRM: + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_ZOOM: + WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_ROTATE: + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + } + } + else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { + event_code = VIEW_CONFIRM; + } + + if (event_code == VIEW_APPLY) { + viewmove_apply(vod, event->xy[0], event->xy[1]); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } + } + else if (event_code == VIEW_CONFIRM) { + use_autokey = true; + ret = OPERATOR_FINISHED; + } + + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op->customdata); + op->customdata = NULL; + } + + return ret; +} + +static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod; + + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + vod = op->customdata; + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + if (event->type == MOUSEPAN) { + /* invert it, trackpad scroll follows same principle as 2d windows this way */ + viewmove_apply( + vod, 2 * event->xy[0] - event->prev_xy[0], 2 * event->xy[1] - event->prev_xy[1]); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; + } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static void viewmove_cancel(bContext *C, wmOperator *op) +{ + viewops_data_free(C, op->customdata); + op->customdata = NULL; +} + +void VIEW3D_OT_move(wmOperatorType *ot) +{ + + /* identifiers */ + ot->name = "Pan View"; + ot->description = "Move the view"; + ot->idname = "VIEW3D_OT_move"; + + /* api callbacks */ + ot->invoke = viewmove_invoke; + ot->modal = viewmove_modal; + ot->poll = view3d_location_poll; + ot->cancel = viewmove_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; + + /* properties */ + view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_ndof.c b/source/blender/editors/space_view3d/view3d_navigate_ndof.c new file mode 100644 index 00000000000..285d5c02db2 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_ndof.c @@ -0,0 +1,661 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BLI_math.h" + +#include "BKE_context.h" + +#include "DEG_depsgraph.h" + +#include "WM_api.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name NDOF Utility Functions + * \{ */ + +#ifdef WITH_INPUT_NDOF + +enum { + HAS_TRANSLATE = (1 << 0), + HAS_ROTATE = (1 << 0), +}; + +static bool ndof_has_translate(const wmNDOFMotionData *ndof, + const View3D *v3d, + const RegionView3D *rv3d) +{ + return !is_zero_v3(ndof->tvec) && (!ED_view3d_offset_lock_check(v3d, rv3d)); +} + +static bool ndof_has_rotate(const wmNDOFMotionData *ndof, const RegionView3D *rv3d) +{ + return !is_zero_v3(ndof->rvec) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0); +} + +/** + * \param depth_pt: A point to calculate the depth (in perspective mode) + */ +static float view3d_ndof_pan_speed_calc_ex(RegionView3D *rv3d, const float depth_pt[3]) +{ + float speed = rv3d->pixsize * NDOF_PIXELS_PER_SECOND; + + if (rv3d->is_persp) { + speed *= ED_view3d_calc_zfac(rv3d, depth_pt, NULL); + } + + return speed; +} + +static float view3d_ndof_pan_speed_calc_from_dist(RegionView3D *rv3d, const float dist) +{ + float viewinv[4]; + float tvec[3]; + + BLI_assert(dist >= 0.0f); + + copy_v3_fl3(tvec, 0.0f, 0.0f, dist); + /* rv3d->viewinv isn't always valid */ +# if 0 + mul_mat3_m4_v3(rv3d->viewinv, tvec); +# else + invert_qt_qt_normalized(viewinv, rv3d->viewquat); + mul_qt_v3(viewinv, tvec); +# endif + + return view3d_ndof_pan_speed_calc_ex(rv3d, tvec); +} + +static float view3d_ndof_pan_speed_calc(RegionView3D *rv3d) +{ + float tvec[3]; + negate_v3_v3(tvec, rv3d->ofs); + + return view3d_ndof_pan_speed_calc_ex(rv3d, tvec); +} + +/** + * Zoom and pan in the same function since sometimes zoom is interpreted as dolly (pan forward). + * + * \param has_zoom: zoom, otherwise dolly, + * often `!rv3d->is_persp` since it doesn't make sense to dolly in ortho. + */ +static void view3d_ndof_pan_zoom(const struct wmNDOFMotionData *ndof, + ScrArea *area, + ARegion *region, + const bool has_translate, + const bool has_zoom) +{ + RegionView3D *rv3d = region->regiondata; + float view_inv[4]; + float pan_vec[3]; + + if (has_translate == false && has_zoom == false) { + return; + } + + WM_event_ndof_pan_get(ndof, pan_vec, false); + + if (has_zoom) { + /* zoom with Z */ + + /* Zoom! + * velocity should be proportional to the linear velocity attained by rotational motion + * of same strength [got that?] proportional to `arclength = radius * angle`. + */ + + pan_vec[2] = 0.0f; + + /* "zoom in" or "translate"? depends on zoom mode in user settings? */ + if (ndof->tvec[2]) { + float zoom_distance = rv3d->dist * ndof->dt * ndof->tvec[2]; + + if (U.ndof_flag & NDOF_ZOOM_INVERT) { + zoom_distance = -zoom_distance; + } + + rv3d->dist += zoom_distance; + } + } + else { + /* dolly with Z */ + + /* all callers must check */ + if (has_translate) { + BLI_assert(ED_view3d_offset_lock_check((View3D *)area->spacedata.first, rv3d) == false); + } + } + + if (has_translate) { + const float speed = view3d_ndof_pan_speed_calc(rv3d); + + mul_v3_fl(pan_vec, speed * ndof->dt); + + /* transform motion from view to world coordinates */ + invert_qt_qt_normalized(view_inv, rv3d->viewquat); + mul_qt_v3(view_inv, pan_vec); + + /* move center of view opposite of hand motion (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, pan_vec); + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(area, region); + } + } +} + +static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, + ScrArea *area, + ARegion *region, + ViewOpsData *vod, + const bool apply_dyn_ofs) +{ + View3D *v3d = area->spacedata.first; + RegionView3D *rv3d = region->regiondata; + + float view_inv[4]; + + BLI_assert((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0); + + ED_view3d_persp_ensure(vod->depsgraph, v3d, region); + + rv3d->view = RV3D_VIEW_USER; + + invert_qt_qt_normalized(view_inv, rv3d->viewquat); + + if (U.ndof_flag & NDOF_TURNTABLE) { + float rot[3]; + + /* Turntable view code adapted for 3D mouse use. */ + float angle, quat[4]; + float xvec[3] = {1, 0, 0}; + + /* only use XY, ignore Z */ + WM_event_ndof_rotate_get(ndof, rot); + + /* Determine the direction of the x vector (for rotating up and down) */ + mul_qt_v3(view_inv, xvec); + + /* Perform the up/down rotation */ + angle = ndof->dt * rot[0]; + axis_angle_to_quat(quat, xvec, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); + + /* Perform the orbital rotation */ + angle = ndof->dt * rot[1]; + + /* Update the onscreen axis-angle indicator. */ + rv3d->rot_angle = angle; + rv3d->rot_axis[0] = 0; + rv3d->rot_axis[1] = 0; + rv3d->rot_axis[2] = 1; + + axis_angle_to_quat_single(quat, 'Z', angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); + } + else { + float quat[4]; + float axis[3]; + float angle = WM_event_ndof_to_axis_angle(ndof, axis); + + /* transform rotation axis from view to world coordinates */ + mul_qt_v3(view_inv, axis); + + /* Update the onscreen axis-angle indicator. */ + rv3d->rot_angle = angle; + copy_v3_v3(rv3d->rot_axis, axis); + + axis_angle_to_quat(quat, axis, angle); + + /* apply rotation */ + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, quat); + } + + if (apply_dyn_ofs) { + viewrotate_apply_dyn_ofs(vod, rv3d->viewquat); + } +} + +void view3d_ndof_fly(const wmNDOFMotionData *ndof, + View3D *v3d, + RegionView3D *rv3d, + const bool use_precision, + const short protectflag, + bool *r_has_translate, + bool *r_has_rotate) +{ + bool has_translate = ndof_has_translate(ndof, v3d, rv3d); + bool has_rotate = ndof_has_rotate(ndof, rv3d); + + float view_inv[4]; + invert_qt_qt_normalized(view_inv, rv3d->viewquat); + + rv3d->rot_angle = 0.0f; /* Disable onscreen rotation indicator. */ + + if (has_translate) { + /* ignore real 'dist' since fly has its own speed settings, + * also its overwritten at this point. */ + float speed = view3d_ndof_pan_speed_calc_from_dist(rv3d, 1.0f); + float trans[3], trans_orig_y; + + if (use_precision) { + speed *= 0.2f; + } + + WM_event_ndof_pan_get(ndof, trans, false); + mul_v3_fl(trans, speed * ndof->dt); + trans_orig_y = trans[1]; + + if (U.ndof_flag & NDOF_FLY_HELICOPTER) { + trans[1] = 0.0f; + } + + /* transform motion from view to world coordinates */ + mul_qt_v3(view_inv, trans); + + if (U.ndof_flag & NDOF_FLY_HELICOPTER) { + /* replace world z component with device y (yes it makes sense) */ + trans[2] = trans_orig_y; + } + + if (rv3d->persp == RV3D_CAMOB) { + /* respect camera position locks */ + if (protectflag & OB_LOCK_LOCX) { + trans[0] = 0.0f; + } + if (protectflag & OB_LOCK_LOCY) { + trans[1] = 0.0f; + } + if (protectflag & OB_LOCK_LOCZ) { + trans[2] = 0.0f; + } + } + + if (!is_zero_v3(trans)) { + /* move center of view opposite of hand motion + * (this is camera mode, not object mode) */ + sub_v3_v3(rv3d->ofs, trans); + has_translate = true; + } + else { + has_translate = false; + } + } + + if (has_rotate) { + const float turn_sensitivity = 1.0f; + + float rotation[4]; + float axis[3]; + float angle = turn_sensitivity * WM_event_ndof_to_axis_angle(ndof, axis); + + if (fabsf(angle) > 0.0001f) { + has_rotate = true; + + if (use_precision) { + angle *= 0.2f; + } + + /* transform rotation axis from view to world coordinates */ + mul_qt_v3(view_inv, axis); + + /* apply rotation to view */ + axis_angle_to_quat(rotation, axis, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + + if (U.ndof_flag & NDOF_LOCK_HORIZON) { + /* force an upright viewpoint + * TODO: make this less... sudden */ + float view_horizon[3] = {1.0f, 0.0f, 0.0f}; /* view +x */ + float view_direction[3] = {0.0f, 0.0f, -1.0f}; /* view -z (into screen) */ + + /* find new inverse since viewquat has changed */ + invert_qt_qt_normalized(view_inv, rv3d->viewquat); + /* could apply reverse rotation to existing view_inv to save a few cycles */ + + /* transform view vectors to world coordinates */ + mul_qt_v3(view_inv, view_horizon); + mul_qt_v3(view_inv, view_direction); + + /* find difference between view & world horizons + * true horizon lives in world xy plane, so look only at difference in z */ + angle = -asinf(view_horizon[2]); + + /* rotate view so view horizon = world horizon */ + axis_angle_to_quat(rotation, view_direction, angle); + mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rotation); + } + + rv3d->view = RV3D_VIEW_USER; + } + else { + has_rotate = false; + } + } + + *r_has_translate = has_translate; + *r_has_rotate = has_rotate; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name NDOF Orbit/Translate Operator + * \{ */ + +static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + if (event->type != NDOF_MOTION) { + return OPERATOR_CANCELLED; + } + + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ViewOpsData *vod; + View3D *v3d; + RegionView3D *rv3d; + char xform_flag = 0; + + const wmNDOFMotionData *ndof = event->customdata; + + vod = op->customdata = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + v3d = vod->v3d; + rv3d = vod->rv3d; + + /* off by default, until changed later this function */ + rv3d->rot_angle = 0.0f; + + ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); + + if (ndof->progress != P_FINISHING) { + const bool has_rotation = ndof_has_rotate(ndof, rv3d); + /* if we can't rotate, fallback to translate (locked axis views) */ + const bool has_translate = ndof_has_translate(ndof, v3d, rv3d) && + (RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION); + const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp; + + if (has_translate || has_zoom) { + view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom); + xform_flag |= HAS_TRANSLATE; + } + + if (has_rotation) { + view3d_ndof_orbit(ndof, vod->area, vod->region, vod, true); + xform_flag |= HAS_ROTATE; + } + } + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + if (xform_flag) { + ED_view3d_camera_lock_autokey( + v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE); + } + + ED_region_tag_redraw(vod->region); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_ndof_orbit(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "NDOF Orbit View"; + ot->description = "Orbit the view using the 3D mouse"; + ot->idname = "VIEW3D_OT_ndof_orbit"; + + /* api callbacks */ + ot->invoke = ndof_orbit_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name NDOF Orbit/Zoom Operator + * \{ */ + +static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + if (event->type != NDOF_MOTION) { + return OPERATOR_CANCELLED; + } + + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ViewOpsData *vod; + View3D *v3d; + RegionView3D *rv3d; + char xform_flag = 0; + + const wmNDOFMotionData *ndof = event->customdata; + + vod = op->customdata = viewops_data_create( + C, event, (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_DEPTH_NAVIGATE)); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + v3d = vod->v3d; + rv3d = vod->rv3d; + + /* off by default, until changed later this function */ + rv3d->rot_angle = 0.0f; + + ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); + + if (ndof->progress == P_FINISHING) { + /* pass */ + } + else if ((rv3d->persp == RV3D_ORTHO) && RV3D_VIEW_IS_AXIS(rv3d->view)) { + /* if we can't rotate, fallback to translate (locked axis views) */ + const bool has_translate = ndof_has_translate(ndof, v3d, rv3d); + const bool has_zoom = (ndof->tvec[2] != 0.0f) && ED_view3d_offset_lock_check(v3d, rv3d); + + if (has_translate || has_zoom) { + view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, true); + xform_flag |= HAS_TRANSLATE; + } + } + else { + /* NOTE: based on feedback from T67579, users want to have pan and orbit enabled at once. + * It's arguable that orbit shouldn't pan (since we have a pan only operator), + * so if there are users who like to separate orbit/pan operations - it can be a preference. */ + const bool is_orbit_around_pivot = (U.ndof_flag & NDOF_MODE_ORBIT) || + ED_view3d_offset_lock_check(v3d, rv3d); + const bool has_rotation = ndof_has_rotate(ndof, rv3d); + bool has_translate, has_zoom; + + if (is_orbit_around_pivot) { + /* Orbit preference or forced lock (Z zooms). */ + has_translate = !is_zero_v2(ndof->tvec) && ndof_has_translate(ndof, v3d, rv3d); + has_zoom = (ndof->tvec[2] != 0.0f); + } + else { + /* Free preference (Z translates). */ + has_translate = ndof_has_translate(ndof, v3d, rv3d); + has_zoom = false; + } + + /* Rotation first because dynamic offset resets offset otherwise (and disables panning). */ + if (has_rotation) { + const float dist_backup = rv3d->dist; + if (!is_orbit_around_pivot) { + ED_view3d_distance_set(rv3d, 0.0f); + } + view3d_ndof_orbit(ndof, vod->area, vod->region, vod, is_orbit_around_pivot); + xform_flag |= HAS_ROTATE; + if (!is_orbit_around_pivot) { + ED_view3d_distance_set(rv3d, dist_backup); + } + } + + if (has_translate || has_zoom) { + view3d_ndof_pan_zoom(ndof, vod->area, vod->region, has_translate, has_zoom); + xform_flag |= HAS_TRANSLATE; + } + } + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + if (xform_flag) { + ED_view3d_camera_lock_autokey( + v3d, rv3d, C, xform_flag & HAS_ROTATE, xform_flag & HAS_TRANSLATE); + } + + ED_region_tag_redraw(vod->region); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_ndof_orbit_zoom(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "NDOF Orbit View with Zoom"; + ot->description = "Orbit and zoom the view using the 3D mouse"; + ot->idname = "VIEW3D_OT_ndof_orbit_zoom"; + + /* api callbacks */ + ot->invoke = ndof_orbit_zoom_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name NDOF Pan/Zoom Operator + * \{ */ + +static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +{ + if (event->type != NDOF_MOTION) { + return OPERATOR_CANCELLED; + } + + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + const wmNDOFMotionData *ndof = event->customdata; + char xform_flag = 0; + + const bool has_translate = ndof_has_translate(ndof, v3d, rv3d); + const bool has_zoom = (ndof->tvec[2] != 0.0f) && !rv3d->is_persp; + + /* we're panning here! so erase any leftover rotation from other operators */ + rv3d->rot_angle = 0.0f; + + if (!(has_translate || has_zoom)) { + return OPERATOR_CANCELLED; + } + + ED_view3d_camera_lock_init_ex(depsgraph, v3d, rv3d, false); + + if (ndof->progress != P_FINISHING) { + ScrArea *area = CTX_wm_area(C); + ARegion *region = CTX_wm_region(C); + + if (has_translate || has_zoom) { + view3d_ndof_pan_zoom(ndof, area, region, has_translate, has_zoom); + xform_flag |= HAS_TRANSLATE; + } + } + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + if (xform_flag) { + ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, xform_flag & HAS_TRANSLATE); + } + + ED_region_tag_redraw(CTX_wm_region(C)); + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_ndof_pan(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "NDOF Pan View"; + ot->description = "Pan the view with the 3D mouse"; + ot->idname = "VIEW3D_OT_ndof_pan"; + + /* api callbacks */ + ot->invoke = ndof_pan_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name NDOF Transform All Operator + * \{ */ + +/** + * wraps #ndof_orbit_zoom but never restrict to orbit. + */ +static int ndof_all_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + /* weak!, but it works */ + const int ndof_flag = U.ndof_flag; + int ret; + + U.ndof_flag &= ~NDOF_MODE_ORBIT; + + ret = ndof_orbit_zoom_invoke(C, op, event); + + U.ndof_flag = ndof_flag; + + return ret; +} + +void VIEW3D_OT_ndof_all(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "NDOF Transform View"; + ot->description = "Pan and rotate the view with the 3D mouse"; + ot->idname = "VIEW3D_OT_ndof_all"; + + /* api callbacks */ + ot->invoke = ndof_all_invoke; + ot->poll = ED_operator_view3d_active; + + /* flags */ + ot->flag = 0; +} + +#endif /* WITH_INPUT_NDOF */ + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_roll.c b/source/blender/editors/space_view3d/view3d_navigate_roll.c new file mode 100644 index 00000000000..c9bfdc4412a --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_roll.c @@ -0,0 +1,292 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BLI_blenlib.h" +#include "BLI_dial_2d.h" +#include "BLI_math.h" + +#include "BKE_context.h" + +#include "WM_api.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name View Roll Operator + * \{ */ + +static void view_roll_angle( + ARegion *region, float quat[4], const float orig_quat[4], const float dvec[3], float angle) +{ + RegionView3D *rv3d = region->regiondata; + float quat_mul[4]; + + /* camera axis */ + axis_angle_normalized_to_quat(quat_mul, dvec, angle); + + mul_qt_qtqt(quat, orig_quat, quat_mul); + + /* avoid precision loss over time */ + normalize_qt(quat); + + rv3d->view = RV3D_VIEW_USER; +} + +static void viewroll_apply(ViewOpsData *vod, int x, int y) +{ + float angle = BLI_dial_angle(vod->init.dial, (const float[2]){x, y}); + + if (angle != 0.0f) { + view_roll_angle(vod->region, vod->rv3d->viewquat, vod->init.quat, vod->init.mousevec, angle); + } + + if (vod->use_dyn_ofs) { + view3d_orbit_apply_dyn_ofs( + vod->rv3d->ofs, vod->init.ofs, vod->init.quat, vod->rv3d->viewquat, vod->dyn_ofs); + } + + if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(vod->area, vod->region); + } + + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); + + ED_region_tag_redraw(vod->region); +} + +static int viewroll_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod = op->customdata; + short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; + + /* execute the events */ + if (event->type == MOUSEMOVE) { + event_code = VIEW_APPLY; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case VIEW_MODAL_CONFIRM: + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_MOVE: + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_ROTATE: + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + } + } + else if (ELEM(event->type, EVT_ESCKEY, RIGHTMOUSE)) { + /* Note this does not remove auto-keys on locked cameras. */ + copy_qt_qt(vod->rv3d->viewquat, vod->init.quat); + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_CANCELLED; + } + else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { + event_code = VIEW_CONFIRM; + } + + if (event_code == VIEW_APPLY) { + viewroll_apply(vod, event->xy[0], event->xy[1]); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } + } + else if (event_code == VIEW_CONFIRM) { + use_autokey = true; + ret = OPERATOR_FINISHED; + } + + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, false); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op->customdata); + op->customdata = NULL; + } + + return ret; +} + +enum { + V3D_VIEW_STEPLEFT = 1, + V3D_VIEW_STEPRIGHT, +}; + +static const EnumPropertyItem prop_view_roll_items[] = { + {0, "ANGLE", 0, "Roll Angle", "Roll the view using an angle value"}, + {V3D_VIEW_STEPLEFT, "LEFT", 0, "Roll Left", "Roll the view around to the left"}, + {V3D_VIEW_STEPRIGHT, "RIGHT", 0, "Roll Right", "Roll the view around to the right"}, + {0, NULL, 0, NULL, NULL}, +}; + +static int viewroll_exec(bContext *C, wmOperator *op) +{ + View3D *v3d; + RegionView3D *rv3d; + ARegion *region; + + if (op->customdata) { + ViewOpsData *vod = op->customdata; + region = vod->region; + v3d = vod->v3d; + } + else { + ED_view3d_context_user_region(C, &v3d, ®ion); + } + + rv3d = region->regiondata; + if ((rv3d->persp != RV3D_CAMOB) || ED_view3d_camera_lock_check(v3d, rv3d)) { + + ED_view3d_smooth_view_force_finish(C, v3d, region); + + int type = RNA_enum_get(op->ptr, "type"); + float angle = (type == 0) ? RNA_float_get(op->ptr, "angle") : DEG2RADF(U.pad_rot_angle); + float mousevec[3]; + float quat_new[4]; + + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + if (type == V3D_VIEW_STEPLEFT) { + angle = -angle; + } + + normalize_v3_v3(mousevec, rv3d->viewinv[2]); + negate_v3(mousevec); + view_roll_angle(region, quat_new, rv3d->viewquat, mousevec, angle); + + const float *dyn_ofs_pt = NULL; + float dyn_ofs[3]; + if (U.uiflag & USER_ORBIT_SELECTION) { + if (view3d_orbit_calc_center(C, dyn_ofs)) { + negate_v3(dyn_ofs); + dyn_ofs_pt = dyn_ofs; + } + } + + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .quat = quat_new, + .dyn_ofs = dyn_ofs_pt, + }); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_FINISHED; + } + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_CANCELLED; +} + +static int viewroll_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod; + + bool use_angle = RNA_enum_get(op->ptr, "type") != 0; + + if (use_angle || RNA_struct_property_is_set(op->ptr, "angle")) { + viewroll_exec(C, op); + } + else { + /* makes op->customdata */ + vod = op->customdata = viewops_data_create(C, event, viewops_flag_from_prefs()); + vod->init.dial = BLI_dial_init((const float[2]){BLI_rcti_cent_x(&vod->region->winrct), + BLI_rcti_cent_y(&vod->region->winrct)}, + FLT_EPSILON); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + /* overwrite the mouse vector with the view direction */ + normalize_v3_v3(vod->init.mousevec, vod->rv3d->viewinv[2]); + negate_v3(vod->init.mousevec); + + if (event->type == MOUSEROTATE) { + vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; + viewroll_apply(vod, event->prev_xy[0], event->prev_xy[1]); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_FINISHED; + } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + return OPERATOR_RUNNING_MODAL; + } + return OPERATOR_FINISHED; +} + +static void viewroll_cancel(bContext *C, wmOperator *op) +{ + viewops_data_free(C, op->customdata); + op->customdata = NULL; +} + +void VIEW3D_OT_view_roll(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "View Roll"; + ot->description = "Roll the view"; + ot->idname = "VIEW3D_OT_view_roll"; + + /* api callbacks */ + ot->invoke = viewroll_invoke; + ot->exec = viewroll_exec; + ot->modal = viewroll_modal; + ot->poll = ED_operator_rv3d_user_region_poll; + ot->cancel = viewroll_cancel; + + /* flags */ + ot->flag = 0; + + /* properties */ + ot->prop = prop = RNA_def_float( + ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + prop = RNA_def_enum(ot->srna, + "type", + prop_view_roll_items, + 0, + "Roll Angle Source", + "How roll angle is calculated"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_rotate.c b/source/blender/editors/space_view3d/view3d_navigate_rotate.c new file mode 100644 index 00000000000..c3730b3b3b1 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_rotate.c @@ -0,0 +1,452 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BLI_math.h" + +#include "BKE_context.h" + +#include "WM_api.h" + +#include "RNA_access.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name View Rotate Operator + * \{ */ + +void viewrotate_modal_keymap(wmKeyConfig *keyconf) +{ + static const EnumPropertyItem modal_items[] = { + {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + + {VIEWROT_MODAL_AXIS_SNAP_ENABLE, "AXIS_SNAP_ENABLE", 0, "Axis Snap", ""}, + {VIEWROT_MODAL_AXIS_SNAP_DISABLE, "AXIS_SNAP_DISABLE", 0, "Axis Snap (Off)", ""}, + + {VIEWROT_MODAL_SWITCH_ZOOM, "SWITCH_TO_ZOOM", 0, "Switch to Zoom"}, + {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, + + {0, NULL, 0, NULL, NULL}, + }; + + wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Rotate Modal"); + + /* this function is called for each spacetype, only needs to add map once */ + if (keymap && keymap->modal_items) { + return; + } + + keymap = WM_modalkeymap_ensure(keyconf, "View3D Rotate Modal", modal_items); + + /* disabled mode switching for now, can re-implement better, later on */ +#if 0 + WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ZOOM); + WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); +#endif + + /* assign map to operators */ + WM_modalkeymap_assign(keymap, "VIEW3D_OT_rotate"); +} + +static void viewrotate_apply_snap(ViewOpsData *vod) +{ + const float axis_limit = DEG2RADF(45 / 3); + + RegionView3D *rv3d = vod->rv3d; + + float viewquat_inv[4]; + float zaxis[3] = {0, 0, 1}; + float zaxis_best[3]; + int x, y, z; + bool found = false; + + invert_qt_qt_normalized(viewquat_inv, vod->curr.viewquat); + + mul_qt_v3(viewquat_inv, zaxis); + normalize_v3(zaxis); + + for (x = -1; x < 2; x++) { + for (y = -1; y < 2; y++) { + for (z = -1; z < 2; z++) { + if (x || y || z) { + float zaxis_test[3] = {x, y, z}; + + normalize_v3(zaxis_test); + + if (angle_normalized_v3v3(zaxis_test, zaxis) < axis_limit) { + copy_v3_v3(zaxis_best, zaxis_test); + found = true; + } + } + } + } + } + + if (found) { + + /* find the best roll */ + float quat_roll[4], quat_final[4], quat_best[4], quat_snap[4]; + float viewquat_align[4]; /* viewquat aligned to zaxis_best */ + float viewquat_align_inv[4]; /* viewquat aligned to zaxis_best */ + float best_angle = axis_limit; + int j; + + /* viewquat_align is the original viewquat aligned to the snapped axis + * for testing roll */ + rotation_between_vecs_to_quat(viewquat_align, zaxis_best, zaxis); + normalize_qt(viewquat_align); + mul_qt_qtqt(viewquat_align, vod->curr.viewquat, viewquat_align); + normalize_qt(viewquat_align); + invert_qt_qt_normalized(viewquat_align_inv, viewquat_align); + + vec_to_quat(quat_snap, zaxis_best, OB_NEGZ, OB_POSY); + normalize_qt(quat_snap); + invert_qt_normalized(quat_snap); + + /* check if we can find the roll */ + found = false; + + /* find best roll */ + for (j = 0; j < 8; j++) { + float angle; + float xaxis1[3] = {1, 0, 0}; + float xaxis2[3] = {1, 0, 0}; + float quat_final_inv[4]; + + axis_angle_to_quat(quat_roll, zaxis_best, (float)j * DEG2RADF(45.0f)); + normalize_qt(quat_roll); + + mul_qt_qtqt(quat_final, quat_snap, quat_roll); + normalize_qt(quat_final); + + /* compare 2 vector angles to find the least roll */ + invert_qt_qt_normalized(quat_final_inv, quat_final); + mul_qt_v3(viewquat_align_inv, xaxis1); + mul_qt_v3(quat_final_inv, xaxis2); + angle = angle_v3v3(xaxis1, xaxis2); + + if (angle <= best_angle) { + found = true; + best_angle = angle; + copy_qt_qt(quat_best, quat_final); + } + } + + if (found) { + /* lock 'quat_best' to an axis view if we can */ + ED_view3d_quat_to_axis_view(quat_best, 0.01f, &rv3d->view, &rv3d->view_axis_roll); + if (rv3d->view != RV3D_VIEW_USER) { + ED_view3d_quat_from_axis_view(rv3d->view, rv3d->view_axis_roll, quat_best); + } + } + else { + copy_qt_qt(quat_best, viewquat_align); + } + + copy_qt_qt(rv3d->viewquat, quat_best); + + viewrotate_apply_dyn_ofs(vod, rv3d->viewquat); + + if (U.uiflag & USER_AUTOPERSP) { + if (RV3D_VIEW_IS_AXIS(rv3d->view)) { + if (rv3d->persp == RV3D_PERSP) { + rv3d->persp = RV3D_ORTHO; + } + } + } + } + else if (U.uiflag & USER_AUTOPERSP) { + rv3d->persp = vod->init.persp; + } +} + +static void viewrotate_apply(ViewOpsData *vod, const int event_xy[2]) +{ + RegionView3D *rv3d = vod->rv3d; + + rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */ + + if (U.flag & USER_TRACKBALL) { + float axis[3], q1[4], dvec[3], newvec[3]; + float angle; + + { + const int event_xy_offset[2] = { + event_xy[0] + vod->init.event_xy_offset[0], + event_xy[1] + vod->init.event_xy_offset[1], + }; + calctrackballvec(&vod->region->winrct, event_xy_offset, newvec); + } + + sub_v3_v3v3(dvec, newvec, vod->init.trackvec); + + angle = (len_v3(dvec) / (2.0f * V3D_OP_TRACKBALLSIZE)) * (float)M_PI; + + /* Before applying the sensitivity this is rotating 1:1, + * where the cursor would match the surface of a sphere in the view. */ + angle *= U.view_rotate_sensitivity_trackball; + + /* Allow for rotation beyond the interval [-pi, pi] */ + angle = angle_wrap_rad(angle); + + /* This relation is used instead of the actual angle between vectors + * so that the angle of rotation is linearly proportional to + * the distance that the mouse is dragged. */ + + cross_v3_v3v3(axis, vod->init.trackvec, newvec); + axis_angle_to_quat(q1, axis, angle); + + mul_qt_qtqt(vod->curr.viewquat, q1, vod->init.quat); + + viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); + } + else { + float quat_local_x[4], quat_global_z[4]; + float m[3][3]; + float m_inv[3][3]; + const float zvec_global[3] = {0.0f, 0.0f, 1.0f}; + float xaxis[3]; + + /* Radians per-pixel. */ + const float sensitivity = U.view_rotate_sensitivity_turntable / U.dpi_fac; + + /* Get the 3x3 matrix and its inverse from the quaternion */ + quat_to_mat3(m, vod->curr.viewquat); + invert_m3_m3(m_inv, m); + + /* Avoid Gimbal Lock + * + * Even though turn-table mode is in use, this can occur when the user exits the camera view + * or when aligning the view to a rotated object. + * + * We have gimbal lock when the user's view is rotated +/- 90 degrees along the view axis. + * In this case the vertical rotation is the same as the sideways turntable motion. + * Making it impossible to get out of the gimbal locked state without resetting the view. + * + * The logic below lets the user exit out of this state without any abrupt 'fix' + * which would be disorienting. + * + * This works by blending two horizons: + * - Rotated-horizon: `cross_v3_v3v3(xaxis, zvec_global, m_inv[2])` + * When only this is used, this turntable rotation works - but it's side-ways + * (as if the entire turn-table has been placed on its side) + * While there is no gimbal lock, it's also awkward to use. + * - Un-rotated-horizon: `m_inv[0]` + * When only this is used, the turntable rotation can have gimbal lock. + * + * The solution used here is to blend between these two values, + * so the severity of the gimbal lock is used to blend the rotated horizon. + * Blending isn't essential, it just makes the transition smoother. + * + * This allows sideways turn-table rotation on a Z axis that isn't world-space Z, + * While up-down turntable rotation eventually corrects gimbal lock. */ +#if 1 + if (len_squared_v3v3(zvec_global, m_inv[2]) > 0.001f) { + float fac; + cross_v3_v3v3(xaxis, zvec_global, m_inv[2]); + if (dot_v3v3(xaxis, m_inv[0]) < 0) { + negate_v3(xaxis); + } + fac = angle_normalized_v3v3(zvec_global, m_inv[2]) / (float)M_PI; + fac = fabsf(fac - 0.5f) * 2; + fac = fac * fac; + interp_v3_v3v3(xaxis, xaxis, m_inv[0], fac); + } + else { + copy_v3_v3(xaxis, m_inv[0]); + } +#else + copy_v3_v3(xaxis, m_inv[0]); +#endif + + /* Determine the direction of the x vector (for rotating up and down) */ + /* This can likely be computed directly from the quaternion. */ + + /* Perform the up/down rotation */ + axis_angle_to_quat(quat_local_x, xaxis, sensitivity * -(event_xy[1] - vod->prev.event_xy[1])); + mul_qt_qtqt(quat_local_x, vod->curr.viewquat, quat_local_x); + + /* Perform the orbital rotation */ + axis_angle_to_quat_single( + quat_global_z, 'Z', sensitivity * vod->reverse * (event_xy[0] - vod->prev.event_xy[0])); + mul_qt_qtqt(vod->curr.viewquat, quat_local_x, quat_global_z); + + viewrotate_apply_dyn_ofs(vod, vod->curr.viewquat); + } + + /* avoid precision loss over time */ + normalize_qt(vod->curr.viewquat); + + /* use a working copy so view rotation locking doesn't overwrite the locked + * rotation back into the view we calculate with */ + copy_qt_qt(rv3d->viewquat, vod->curr.viewquat); + + /* Check for view snap, + * NOTE: don't apply snap to `vod->viewquat` so the view won't jam up. */ + if (vod->axis_snap) { + viewrotate_apply_snap(vod); + } + vod->prev.event_xy[0] = event_xy[0]; + vod->prev.event_xy[1] = event_xy[1]; + + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, rv3d); + + ED_region_tag_redraw(vod->region); +} + +static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod = op->customdata; + short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; + + /* execute the events */ + if (event->type == MOUSEMOVE) { + event_code = VIEW_APPLY; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case VIEW_MODAL_CONFIRM: + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_AXIS_SNAP_ENABLE: + vod->axis_snap = true; + event_code = VIEW_APPLY; + break; + case VIEWROT_MODAL_AXIS_SNAP_DISABLE: + vod->rv3d->persp = vod->init.persp; + vod->axis_snap = false; + event_code = VIEW_APPLY; + break; + case VIEWROT_MODAL_SWITCH_ZOOM: + WM_operator_name_call(C, "VIEW3D_OT_zoom", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_MOVE: + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + } + } + else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { + event_code = VIEW_CONFIRM; + } + + if (event_code == VIEW_APPLY) { + viewrotate_apply(vod, event->xy); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } + } + else if (event_code == VIEW_CONFIRM) { + use_autokey = true; + ret = OPERATOR_FINISHED; + } + + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, true, true); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op->customdata); + op->customdata = NULL; + } + + return ret; +} + +static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod; + + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + /* makes op->customdata */ + vod = op->customdata = viewops_data_create( + C, + event, + viewops_flag_from_prefs() | VIEWOPS_FLAG_PERSP_ENSURE | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + if (ELEM(event->type, MOUSEPAN, MOUSEROTATE)) { + /* Rotate direction we keep always same */ + int event_xy[2]; + + if (event->type == MOUSEPAN) { + if (event->is_direction_inverted) { + event_xy[0] = 2 * event->xy[0] - event->prev_xy[0]; + event_xy[1] = 2 * event->xy[1] - event->prev_xy[1]; + } + else { + copy_v2_v2_int(event_xy, event->prev_xy); + } + } + else { + /* MOUSEROTATE performs orbital rotation, so y axis delta is set to 0 */ + copy_v2_v2_int(event_xy, event->prev_xy); + } + + viewrotate_apply(vod, event_xy); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; + } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +static void viewrotate_cancel(bContext *C, wmOperator *op) +{ + viewops_data_free(C, op->customdata); + op->customdata = NULL; +} + +void VIEW3D_OT_rotate(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Rotate View"; + ot->description = "Rotate the view"; + ot->idname = "VIEW3D_OT_rotate"; + + /* api callbacks */ + ot->invoke = viewrotate_invoke; + ot->modal = viewrotate_modal; + ot->poll = view3d_rotation_poll; + ot->cancel = viewrotate_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; + + view3d_operator_properties_common(ot, V3D_OP_PROP_USE_MOUSE_INIT); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_smoothview.c b/source/blender/editors/space_view3d/view3d_navigate_smoothview.c new file mode 100644 index 00000000000..aeffb520b0a --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_smoothview.c @@ -0,0 +1,406 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "DNA_camera_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" + +#include "BKE_context.h" + +#include "DEG_depsgraph_query.h" + +#include "WM_api.h" + +#include "ED_screen.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name Smooth View Operator & Utilities + * + * Use for view transitions to have smooth (animated) transitions. + * \{ */ + +/* This operator is one of the 'timer refresh' ones like animation playback */ + +struct SmoothView3DState { + float dist; + float lens; + float quat[4]; + float ofs[3]; +}; + +struct SmoothView3DStore { + /* Source. */ + struct SmoothView3DState src; /* source */ + struct SmoothView3DState dst; /* destination */ + struct SmoothView3DState org; /* original */ + + bool to_camera; + + bool use_dyn_ofs; + float dyn_ofs[3]; + + /* When smooth-view is enabled, store the 'rv3d->view' here, + * assign back when the view motion is completed. */ + char org_view; + + double time_allowed; +}; + +static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state, + const View3D *v3d, + const RegionView3D *rv3d) +{ + copy_v3_v3(sms_state->ofs, rv3d->ofs); + copy_qt_qt(sms_state->quat, rv3d->viewquat); + sms_state->dist = rv3d->dist; + sms_state->lens = v3d->lens; +} + +static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state, + View3D *v3d, + RegionView3D *rv3d) +{ + copy_v3_v3(rv3d->ofs, sms_state->ofs); + copy_qt_qt(rv3d->viewquat, sms_state->quat); + rv3d->dist = sms_state->dist; + v3d->lens = sms_state->lens; +} + +/* will start timer if appropriate */ +void ED_view3d_smooth_view_ex( + /* avoid passing in the context */ + const Depsgraph *depsgraph, + wmWindowManager *wm, + wmWindow *win, + ScrArea *area, + View3D *v3d, + ARegion *region, + const int smooth_viewtx, + const V3D_SmoothParams *sview) +{ + RegionView3D *rv3d = region->regiondata; + struct SmoothView3DStore sms = {{0}}; + + /* initialize sms */ + view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d); + view3d_smooth_view_state_backup(&sms.src, v3d, rv3d); + /* If smooth-view runs multiple times. */ + if (rv3d->sms == NULL) { + view3d_smooth_view_state_backup(&sms.org, v3d, rv3d); + } + else { + sms.org = rv3d->sms->org; + } + sms.org_view = rv3d->view; + + /* sms.to_camera = false; */ /* initialized to zero anyway */ + + /* note on camera locking, this is a little confusing but works ok. + * we may be changing the view 'as if' there is no active camera, but in fact + * there is an active camera which is locked to the view. + * + * In the case where smooth view is moving _to_ a camera we don't want that + * camera to be moved or changed, so only when the camera is not being set should + * we allow camera option locking to initialize the view settings from the camera. + */ + if (sview->camera == NULL && sview->camera_old == NULL) { + ED_view3d_camera_lock_init(depsgraph, v3d, rv3d); + } + + /* store the options we want to end with */ + if (sview->ofs) { + copy_v3_v3(sms.dst.ofs, sview->ofs); + } + if (sview->quat) { + copy_qt_qt(sms.dst.quat, sview->quat); + } + if (sview->dist) { + sms.dst.dist = *sview->dist; + } + if (sview->lens) { + sms.dst.lens = *sview->lens; + } + + if (sview->dyn_ofs) { + BLI_assert(sview->ofs == NULL); + BLI_assert(sview->quat != NULL); + + copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs); + sms.use_dyn_ofs = true; + + /* calculate the final destination offset */ + view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs); + } + + if (sview->camera) { + Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); + if (sview->ofs != NULL) { + sms.dst.dist = ED_view3d_offset_distance( + ob_camera_eval->obmat, sview->ofs, VIEW3D_DIST_FALLBACK); + } + ED_view3d_from_object(ob_camera_eval, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); + sms.to_camera = true; /* restore view3d values in end */ + } + + if ((sview->camera_old == sview->camera) && /* Camera. */ + (sms.dst.dist == rv3d->dist) && /* Distance. */ + (sms.dst.lens == v3d->lens) && /* Lens. */ + equals_v3v3(sms.dst.ofs, rv3d->ofs) && /* Offset. */ + equals_v4v4(sms.dst.quat, rv3d->viewquat) /* Rotation. */ + ) { + /* Early return if nothing changed. */ + return; + } + + /* Skip smooth viewing for external render engine draw. */ + if (smooth_viewtx && !(v3d->shading.type == OB_RENDER && rv3d->render_engine)) { + + /* original values */ + if (sview->camera_old) { + Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old); + if (sview->ofs != NULL) { + sms.src.dist = ED_view3d_offset_distance(ob_camera_old_eval->obmat, sview->ofs, 0.0f); + } + ED_view3d_from_object( + ob_camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); + } + /* grid draw as floor */ + if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) { + /* use existing if exists, means multiple calls to smooth view + * won't lose the original 'view' setting */ + rv3d->view = RV3D_VIEW_USER; + } + + sms.time_allowed = (double)smooth_viewtx / 1000.0; + + /* If this is view rotation only we can decrease the time allowed by the angle between quats + * this means small rotations won't lag. */ + if (sview->quat && !sview->ofs && !sview->dist) { + /* scale the time allowed by the rotation */ + /* 180deg == 1.0 */ + sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / + M_PI; + } + + /* ensure it shows correct */ + if (sms.to_camera) { + /* use ortho if we move from an ortho view to an ortho camera */ + Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); + rv3d->persp = (((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) && + (((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ? + RV3D_ORTHO : + RV3D_PERSP); + } + + rv3d->rflag |= RV3D_NAVIGATING; + + /* not essential but in some cases the caller will tag the area for redraw, and in that + * case we can get a flicker of the 'org' user view but we want to see 'src' */ + view3d_smooth_view_state_restore(&sms.src, v3d, rv3d); + + /* keep track of running timer! */ + if (rv3d->sms == NULL) { + rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d"); + } + *rv3d->sms = sms; + if (rv3d->smooth_timer) { + WM_event_remove_timer(wm, win, rv3d->smooth_timer); + } + /* #TIMER1 is hard-coded in key-map. */ + rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); + } + else { + /* Animation is disabled, apply immediately. */ + if (sms.to_camera == false) { + copy_v3_v3(rv3d->ofs, sms.dst.ofs); + copy_qt_qt(rv3d->viewquat, sms.dst.quat); + rv3d->dist = sms.dst.dist; + v3d->lens = sms.dst.lens; + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + } + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { + view3d_boxview_copy(area, region); + } + + ED_region_tag_redraw(region); + + WM_event_add_mousemove(win); + } +} + +void ED_view3d_smooth_view(bContext *C, + View3D *v3d, + ARegion *region, + const int smooth_viewtx, + const struct V3D_SmoothParams *sview) +{ + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + wmWindowManager *wm = CTX_wm_manager(C); + wmWindow *win = CTX_wm_window(C); + ScrArea *area = CTX_wm_area(C); + + ED_view3d_smooth_view_ex(depsgraph, wm, win, area, v3d, region, smooth_viewtx, sview); +} + +/* only meant for timer usage */ +static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *region, bool sync_boxview) +{ + wmWindowManager *wm = CTX_wm_manager(C); + RegionView3D *rv3d = region->regiondata; + struct SmoothView3DStore *sms = rv3d->sms; + float step, step_inv; + + if (sms->time_allowed != 0.0) { + step = (float)((rv3d->smooth_timer->duration) / sms->time_allowed); + } + else { + step = 1.0f; + } + + /* end timer */ + if (step >= 1.0f) { + wmWindow *win = CTX_wm_window(C); + + /* if we went to camera, store the original */ + if (sms->to_camera) { + rv3d->persp = RV3D_CAMOB; + view3d_smooth_view_state_restore(&sms->org, v3d, rv3d); + } + else { + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + + view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d); + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true); + } + + if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) { + rv3d->view = sms->org_view; + } + + MEM_freeN(rv3d->sms); + rv3d->sms = NULL; + + WM_event_remove_timer(wm, win, rv3d->smooth_timer); + rv3d->smooth_timer = NULL; + rv3d->rflag &= ~RV3D_NAVIGATING; + + /* Event handling won't know if a UI item has been moved under the pointer. */ + WM_event_add_mousemove(win); + } + else { + /* ease in/out */ + step = (3.0f * step * step - 2.0f * step * step * step); + + step_inv = 1.0f - step; + + interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, step); + + if (sms->use_dyn_ofs) { + view3d_orbit_apply_dyn_ofs( + rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs); + } + else { + interp_v3_v3v3(rv3d->ofs, sms->src.ofs, sms->dst.ofs, step); + } + + rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv; + v3d->lens = sms->dst.lens * step + sms->src.lens * step_inv; + + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + if (ED_screen_animation_playing(wm)) { + ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true); + } + } + + if (sync_boxview && (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW)) { + view3d_boxview_copy(CTX_wm_area(C), region); + } + + /* NOTE: this doesn't work right because the v3d->lens is now used in ortho mode r51636, + * when switching camera in quad-view the other ortho views would zoom & reset. + * + * For now only redraw all regions when smooth-view finishes. + */ + if (step >= 1.0f) { + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); + } + else { + ED_region_tag_redraw(region); + } +} + +static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) +{ + View3D *v3d = CTX_wm_view3d(C); + ARegion *region = CTX_wm_region(C); + RegionView3D *rv3d = region->regiondata; + + /* escape if not our timer */ + if (rv3d->smooth_timer == NULL || rv3d->smooth_timer != event->customdata) { + return OPERATOR_PASS_THROUGH; + } + + view3d_smoothview_apply(C, v3d, region, true); + + return OPERATOR_FINISHED; +} + +void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region) +{ + RegionView3D *rv3d = region->regiondata; + + if (rv3d && rv3d->sms) { + rv3d->sms->time_allowed = 0.0; /* force finishing */ + view3d_smoothview_apply(C, v3d, region, false); + + /* force update of view matrix so tools that run immediately after + * can use them without redrawing first */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene = CTX_data_scene(C); + ED_view3d_update_viewmat(depsgraph, scene, v3d, region, NULL, NULL, NULL, false); + } +} + +void VIEW3D_OT_smoothview(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Smooth View"; + ot->idname = "VIEW3D_OT_smoothview"; + + /* api callbacks */ + ot->invoke = view3d_smoothview_invoke; + + /* flags */ + ot->flag = OPTYPE_INTERNAL; + + ot->poll = ED_operator_view3d_active; +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_walk.c b/source/blender/editors/space_view3d/view3d_navigate_walk.c index ed76b10c95a..d72fa3cb90f 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_walk.c +++ b/source/blender/editors/space_view3d/view3d_navigate_walk.c @@ -58,6 +58,7 @@ #include "DEG_depsgraph.h" #include "view3d_intern.h" /* own include */ +#include "view3d_navigate.h" #ifdef WITH_INPUT_NDOF //# define NDOF_WALK_DEBUG diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom.c b/source/blender/editors/space_view3d/view3d_navigate_zoom.c new file mode 100644 index 00000000000..a6c7d06c079 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom.c @@ -0,0 +1,598 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "BLI_math.h" +#include "BLI_rect.h" + +#include "BKE_context.h" +#include "BKE_screen.h" + +#include "DEG_depsgraph_query.h" + +#include "WM_api.h" + +#include "RNA_access.h" + +#include "ED_screen.h" + +#include "PIL_time.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name View Zoom Operator + * \{ */ + +/* #viewdolly_modal_keymap has an exact copy of this, apply fixes to both. */ +void viewzoom_modal_keymap(wmKeyConfig *keyconf) +{ + static const EnumPropertyItem modal_items[] = { + {VIEW_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""}, + + {VIEWROT_MODAL_SWITCH_ROTATE, "SWITCH_TO_ROTATE", 0, "Switch to Rotate"}, + {VIEWROT_MODAL_SWITCH_MOVE, "SWITCH_TO_MOVE", 0, "Switch to Move"}, + + {0, NULL, 0, NULL, NULL}, + }; + + wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Zoom Modal"); + + /* this function is called for each spacetype, only needs to add map once */ + if (keymap && keymap->modal_items) { + return; + } + + keymap = WM_modalkeymap_ensure(keyconf, "View3D Zoom Modal", modal_items); + + /* disabled mode switching for now, can re-implement better, later on */ +#if 0 + WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, VIEWROT_MODAL_SWITCH_ROTATE); + WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, VIEWROT_MODAL_SWITCH_MOVE); +#endif + + /* assign map to operators */ + WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom"); +} + +/** + * \param zoom_xy: Optionally zoom to window location + * (coords compatible w/ #wmEvent.xy). Use when not NULL. + */ +static void view_zoom_to_window_xy_camera(Scene *scene, + Depsgraph *depsgraph, + View3D *v3d, + ARegion *region, + float dfac, + const int zoom_xy[2]) +{ + RegionView3D *rv3d = region->regiondata; + const float zoomfac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); + const float zoomfac_new = clamp_f( + zoomfac * (1.0f / dfac), RV3D_CAMZOOM_MIN_FACTOR, RV3D_CAMZOOM_MAX_FACTOR); + const float camzoom_new = BKE_screen_view3d_zoom_from_fac(zoomfac_new); + + if (zoom_xy != NULL) { + float zoomfac_px; + rctf camera_frame_old; + rctf camera_frame_new; + + const float pt_src[2] = {zoom_xy[0], zoom_xy[1]}; + float pt_dst[2]; + float delta_px[2]; + + ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_old, false); + BLI_rctf_translate(&camera_frame_old, region->winrct.xmin, region->winrct.ymin); + + rv3d->camzoom = camzoom_new; + CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); + + ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &camera_frame_new, false); + BLI_rctf_translate(&camera_frame_new, region->winrct.xmin, region->winrct.ymin); + + BLI_rctf_transform_pt_v(&camera_frame_new, &camera_frame_old, pt_dst, pt_src); + sub_v2_v2v2(delta_px, pt_dst, pt_src); + + /* translate the camera offset using pixel space delta + * mapped back to the camera (same logic as panning in camera view) */ + zoomfac_px = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom) * 2.0f; + + rv3d->camdx += delta_px[0] / (region->winx * zoomfac_px); + rv3d->camdy += delta_px[1] / (region->winy * zoomfac_px); + CLAMP(rv3d->camdx, -1.0f, 1.0f); + CLAMP(rv3d->camdy, -1.0f, 1.0f); + } + else { + rv3d->camzoom = camzoom_new; + CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); + } +} + +/** + * \param zoom_xy: Optionally zoom to window location + * (coords compatible w/ #wmEvent.xy). Use when not NULL. + */ +static void view_zoom_to_window_xy_3d(ARegion *region, float dfac, const int zoom_xy[2]) +{ + RegionView3D *rv3d = region->regiondata; + const float dist_new = rv3d->dist * dfac; + + if (zoom_xy != NULL) { + float dvec[3]; + float tvec[3]; + float tpos[3]; + float mval_f[2]; + + float zfac; + + negate_v3_v3(tpos, rv3d->ofs); + + mval_f[0] = (float)(((zoom_xy[0] - region->winrct.xmin) * 2) - region->winx) / 2.0f; + mval_f[1] = (float)(((zoom_xy[1] - region->winrct.ymin) * 2) - region->winy) / 2.0f; + + /* Project cursor position into 3D space */ + zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL); + ED_view3d_win_to_delta(region, mval_f, dvec, zfac); + + /* Calculate view target position for dolly */ + add_v3_v3v3(tvec, tpos, dvec); + negate_v3(tvec); + + /* Offset to target position and dolly */ + copy_v3_v3(rv3d->ofs, tvec); + rv3d->dist = dist_new; + + /* Calculate final offset */ + madd_v3_v3v3fl(rv3d->ofs, tvec, dvec, dfac); + } + else { + rv3d->dist = dist_new; + } +} + +static float viewzoom_scale_value(const rcti *winrct, + const eViewZoom_Style viewzoom, + const bool zoom_invert, + const bool zoom_invert_force, + const int xy_curr[2], + const int xy_init[2], + const float val, + const float val_orig, + double *r_timer_lastdraw) +{ + float zfac; + + if (viewzoom == USER_ZOOM_CONTINUE) { + double time = PIL_check_seconds_timer(); + float time_step = (float)(time - *r_timer_lastdraw); + float fac; + + if (U.uiflag & USER_ZOOM_HORIZ) { + fac = (float)(xy_init[0] - xy_curr[0]); + } + else { + fac = (float)(xy_init[1] - xy_curr[1]); + } + + fac /= U.dpi_fac; + + if (zoom_invert != zoom_invert_force) { + fac = -fac; + } + + zfac = 1.0f + ((fac / 20.0f) * time_step); + *r_timer_lastdraw = time; + } + else if (viewzoom == USER_ZOOM_SCALE) { + /* method which zooms based on how far you move the mouse */ + + const int ctr[2] = { + BLI_rcti_cent_x(winrct), + BLI_rcti_cent_y(winrct), + }; + float len_new = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_curr) / U.dpi_fac); + float len_old = (5 * U.dpi_fac) + ((float)len_v2v2_int(ctr, xy_init) / U.dpi_fac); + + /* intentionally ignore 'zoom_invert' for scale */ + if (zoom_invert_force) { + SWAP(float, len_new, len_old); + } + + zfac = val_orig * (len_old / max_ff(len_new, 1.0f)) / val; + } + else { /* USER_ZOOM_DOLLY */ + float len_new = 5 * U.dpi_fac; + float len_old = 5 * U.dpi_fac; + + if (U.uiflag & USER_ZOOM_HORIZ) { + len_new += (winrct->xmax - (xy_curr[0])) / U.dpi_fac; + len_old += (winrct->xmax - (xy_init[0])) / U.dpi_fac; + } + else { + len_new += (winrct->ymax - (xy_curr[1])) / U.dpi_fac; + len_old += (winrct->ymax - (xy_init[1])) / U.dpi_fac; + } + + if (zoom_invert != zoom_invert_force) { + SWAP(float, len_new, len_old); + } + + zfac = val_orig * (2.0f * ((len_new / max_ff(len_old, 1.0f)) - 1.0f) + 1.0f) / val; + } + + return zfac; +} + +static float viewzoom_scale_value_offset(const rcti *winrct, + const eViewZoom_Style viewzoom, + const bool zoom_invert, + const bool zoom_invert_force, + const int xy_curr[2], + const int xy_init[2], + const int xy_offset[2], + const float val, + const float val_orig, + double *r_timer_lastdraw) +{ + const int xy_curr_offset[2] = { + xy_curr[0] + xy_offset[0], + xy_curr[1] + xy_offset[1], + }; + const int xy_init_offset[2] = { + xy_init[0] + xy_offset[0], + xy_init[1] + xy_offset[1], + }; + return viewzoom_scale_value(winrct, + viewzoom, + zoom_invert, + zoom_invert_force, + xy_curr_offset, + xy_init_offset, + val, + val_orig, + r_timer_lastdraw); +} + +static void viewzoom_apply_camera(ViewOpsData *vod, + const int xy[2], + const eViewZoom_Style viewzoom, + const bool zoom_invert, + const bool zoom_to_pos) +{ + float zfac; + float zoomfac_prev = BKE_screen_view3d_zoom_to_fac(vod->init.camzoom) * 2.0f; + float zoomfac = BKE_screen_view3d_zoom_to_fac(vod->rv3d->camzoom) * 2.0f; + + zfac = viewzoom_scale_value_offset(&vod->region->winrct, + viewzoom, + zoom_invert, + true, + xy, + vod->init.event_xy, + vod->init.event_xy_offset, + zoomfac, + zoomfac_prev, + &vod->prev.time); + + if (!ELEM(zfac, 1.0f, 0.0f)) { + /* calculate inverted, then invert again (needed because of camera zoom scaling) */ + zfac = 1.0f / zfac; + view_zoom_to_window_xy_camera(vod->scene, + vod->depsgraph, + vod->v3d, + vod->region, + zfac, + zoom_to_pos ? vod->prev.event_xy : NULL); + } + + ED_region_tag_redraw(vod->region); +} + +static void viewzoom_apply_3d(ViewOpsData *vod, + const int xy[2], + const eViewZoom_Style viewzoom, + const bool zoom_invert, + const bool zoom_to_pos) +{ + float zfac; + float dist_range[2]; + + ED_view3d_dist_range_get(vod->v3d, dist_range); + + zfac = viewzoom_scale_value_offset(&vod->region->winrct, + viewzoom, + zoom_invert, + false, + xy, + vod->init.event_xy, + vod->init.event_xy_offset, + vod->rv3d->dist, + vod->init.dist, + &vod->prev.time); + + if (zfac != 1.0f) { + const float zfac_min = dist_range[0] / vod->rv3d->dist; + const float zfac_max = dist_range[1] / vod->rv3d->dist; + CLAMP(zfac, zfac_min, zfac_max); + + view_zoom_to_window_xy_3d(vod->region, zfac, zoom_to_pos ? vod->prev.event_xy : NULL); + } + + /* these limits were in old code too */ + CLAMP(vod->rv3d->dist, dist_range[0], dist_range[1]); + + if (RV3D_LOCK_FLAGS(vod->rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(vod->area, vod->region); + } + + ED_view3d_camera_lock_sync(vod->depsgraph, vod->v3d, vod->rv3d); + + ED_region_tag_redraw(vod->region); +} + +static void viewzoom_apply(ViewOpsData *vod, + const int xy[2], + const eViewZoom_Style viewzoom, + const bool zoom_invert, + const bool zoom_to_pos) +{ + if ((vod->rv3d->persp == RV3D_CAMOB) && + (vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) == 0) { + viewzoom_apply_camera(vod, xy, viewzoom, zoom_invert, zoom_to_pos); + } + else { + viewzoom_apply_3d(vod, xy, viewzoom, zoom_invert, zoom_to_pos); + } +} + +static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod = op->customdata; + short event_code = VIEW_PASS; + bool use_autokey = false; + int ret = OPERATOR_RUNNING_MODAL; + + /* execute the events */ + if (event->type == TIMER && event->customdata == vod->timer) { + /* continuous zoom */ + event_code = VIEW_APPLY; + } + else if (event->type == MOUSEMOVE) { + event_code = VIEW_APPLY; + } + else if (event->type == EVT_MODAL_MAP) { + switch (event->val) { + case VIEW_MODAL_CONFIRM: + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_MOVE: + WM_operator_name_call(C, "VIEW3D_OT_move", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + case VIEWROT_MODAL_SWITCH_ROTATE: + WM_operator_name_call(C, "VIEW3D_OT_rotate", WM_OP_INVOKE_DEFAULT, NULL); + event_code = VIEW_CONFIRM; + break; + } + } + else if (event->type == vod->init.event_type && event->val == KM_RELEASE) { + event_code = VIEW_CONFIRM; + } + + if (event_code == VIEW_APPLY) { + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + viewzoom_apply(vod, + event->xy, + (eViewZoom_Style)U.viewzoom, + (U.uiflag & USER_ZOOM_INVERT) != 0, + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); + if (ED_screen_animation_playing(CTX_wm_manager(C))) { + use_autokey = true; + } + } + else if (event_code == VIEW_CONFIRM) { + use_autokey = true; + ret = OPERATOR_FINISHED; + } + + if (use_autokey) { + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + } + + if (ret & OPERATOR_FINISHED) { + viewops_data_free(C, op->customdata); + op->customdata = NULL; + } + + return ret; +} + +static int viewzoom_exec(bContext *C, wmOperator *op) +{ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene = CTX_data_scene(C); + View3D *v3d; + RegionView3D *rv3d; + ScrArea *area; + ARegion *region; + bool use_cam_zoom; + float dist_range[2]; + + const int delta = RNA_int_get(op->ptr, "delta"); + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + if (op->customdata) { + ViewOpsData *vod = op->customdata; + + area = vod->area; + region = vod->region; + } + else { + area = CTX_wm_area(C); + region = CTX_wm_region(C); + } + + v3d = area->spacedata.first; + rv3d = region->regiondata; + + use_cam_zoom = (rv3d->persp == RV3D_CAMOB) && + !(rv3d->is_persp && ED_view3d_camera_lock_check(v3d, rv3d)); + + int zoom_xy_buf[2]; + const int *zoom_xy = NULL; + if (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)) { + zoom_xy_buf[0] = RNA_struct_property_is_set(op->ptr, "mx") ? RNA_int_get(op->ptr, "mx") : + region->winx / 2; + zoom_xy_buf[1] = RNA_struct_property_is_set(op->ptr, "my") ? RNA_int_get(op->ptr, "my") : + region->winy / 2; + zoom_xy = zoom_xy_buf; + } + + ED_view3d_dist_range_get(v3d, dist_range); + + if (delta < 0) { + const float step = 1.2f; + if (use_cam_zoom) { + view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); + } + else { + if (rv3d->dist < dist_range[1]) { + view_zoom_to_window_xy_3d(region, step, zoom_xy); + } + } + } + else { + const float step = 1.0f / 1.2f; + if (use_cam_zoom) { + view_zoom_to_window_xy_camera(scene, depsgraph, v3d, region, step, zoom_xy); + } + else { + if (rv3d->dist > dist_range[0]) { + view_zoom_to_window_xy_3d(region, step, zoom_xy); + } + } + } + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(area, region); + } + + ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); + ED_view3d_camera_lock_autokey(v3d, rv3d, C, false, true); + + ED_region_tag_redraw(region); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + + return OPERATOR_FINISHED; +} + +/* viewdolly_invoke() copied this function, changes here may apply there */ +static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + ViewOpsData *vod; + + const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init"); + + vod = op->customdata = viewops_data_create( + C, + event, + (viewops_flag_from_prefs() & ~VIEWOPS_FLAG_ORBIT_SELECT) | + (use_cursor_init ? VIEWOPS_FLAG_USE_MOUSE_INIT : 0)); + + ED_view3d_smooth_view_force_finish(C, vod->v3d, vod->region); + + /* if one or the other zoom position aren't set, set from event */ + if (!RNA_struct_property_is_set(op->ptr, "mx") || !RNA_struct_property_is_set(op->ptr, "my")) { + RNA_int_set(op->ptr, "mx", event->xy[0]); + RNA_int_set(op->ptr, "my", event->xy[1]); + } + + if (RNA_struct_property_is_set(op->ptr, "delta")) { + viewzoom_exec(C, op); + } + else { + if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) { + + if (U.uiflag & USER_ZOOM_HORIZ) { + vod->init.event_xy[0] = vod->prev.event_xy[0] = event->xy[0]; + } + else { + /* Set y move = x move as MOUSEZOOM uses only x axis to pass magnification value */ + vod->init.event_xy[1] = vod->prev.event_xy[1] = vod->init.event_xy[1] + event->xy[0] - + event->prev_xy[0]; + } + viewzoom_apply(vod, + event->prev_xy, + USER_ZOOM_DOLLY, + (U.uiflag & USER_ZOOM_INVERT) != 0, + (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS))); + ED_view3d_camera_lock_autokey(vod->v3d, vod->rv3d, C, false, true); + + viewops_data_free(C, op->customdata); + op->customdata = NULL; + return OPERATOR_FINISHED; + } + + if (U.viewzoom == USER_ZOOM_CONTINUE) { + /* needs a timer to continue redrawing */ + vod->timer = WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); + vod->prev.time = PIL_check_seconds_timer(); + } + + /* add temp handler */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; + } + return OPERATOR_FINISHED; +} + +static void viewzoom_cancel(bContext *C, wmOperator *op) +{ + viewops_data_free(C, op->customdata); + op->customdata = NULL; +} + +void VIEW3D_OT_zoom(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Zoom View"; + ot->description = "Zoom in/out in the view"; + ot->idname = "VIEW3D_OT_zoom"; + + /* api callbacks */ + ot->invoke = viewzoom_invoke; + ot->exec = viewzoom_exec; + ot->modal = viewzoom_modal; + ot->poll = view3d_zoom_or_dolly_poll; + ot->cancel = viewzoom_cancel; + + /* flags */ + ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_XY; + + /* properties */ + view3d_operator_properties_common( + ot, V3D_OP_PROP_DELTA | V3D_OP_PROP_MOUSE_CO | V3D_OP_PROP_USE_MOUSE_INIT); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c new file mode 100644 index 00000000000..38c3e37bac6 --- /dev/null +++ b/source/blender/editors/space_view3d/view3d_navigate_zoom_border.c @@ -0,0 +1,221 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup spview3d + */ + +#include "DNA_camera_types.h" + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_rect.h" + +#include "BKE_context.h" +#include "BKE_report.h" + +#include "DEG_depsgraph_query.h" + +#include "WM_api.h" + +#include "RNA_access.h" + +#include "view3d_intern.h" +#include "view3d_navigate.h" /* own include */ + +/* -------------------------------------------------------------------- */ +/** \name Border Zoom Operator + * \{ */ + +static int view3d_zoom_border_exec(bContext *C, wmOperator *op) +{ + ARegion *region = CTX_wm_region(C); + View3D *v3d = CTX_wm_view3d(C); + RegionView3D *rv3d = CTX_wm_region_view3d(C); + const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); + + /* Zooms in on a border drawn by the user */ + rcti rect; + float dvec[3], vb[2], xscale, yscale; + float dist_range[2]; + + /* SMOOTHVIEW */ + float new_dist; + float new_ofs[3]; + + /* ZBuffer depth vars */ + float depth_close = FLT_MAX; + float cent[2], p[3]; + + /* NOTE: otherwise opengl won't work. */ + view3d_operator_needs_opengl(C); + + /* get box select values using rna */ + WM_operator_properties_border_to_rcti(op, &rect); + + /* check if zooming in/out view */ + const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out"); + + ED_view3d_dist_range_get(v3d, dist_range); + + ED_view3d_depth_override( + CTX_data_ensure_evaluated_depsgraph(C), region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL); + { + /* avoid allocating the whole depth buffer */ + ViewDepths depth_temp = {0}; + + /* avoid view3d_update_depths() for speed. */ + view3d_depths_rect_create(region, &rect, &depth_temp); + + /* find the closest Z pixel */ + depth_close = view3d_depth_near(&depth_temp); + + MEM_SAFE_FREE(depth_temp.depths); + } + + /* Resize border to the same ratio as the window. */ + { + const float region_aspect = (float)region->winx / (float)region->winy; + if (((float)BLI_rcti_size_x(&rect) / (float)BLI_rcti_size_y(&rect)) < region_aspect) { + BLI_rcti_resize_x(&rect, (int)(BLI_rcti_size_y(&rect) * region_aspect)); + } + else { + BLI_rcti_resize_y(&rect, (int)(BLI_rcti_size_x(&rect) / region_aspect)); + } + } + + cent[0] = (((float)rect.xmin) + ((float)rect.xmax)) / 2; + cent[1] = (((float)rect.ymin) + ((float)rect.ymax)) / 2; + + if (rv3d->is_persp) { + float p_corner[3]; + + /* no depths to use, we can't do anything! */ + if (depth_close == FLT_MAX) { + BKE_report(op->reports, RPT_ERROR, "Depth too large"); + return OPERATOR_CANCELLED; + } + /* convert border to 3d coordinates */ + if ((!ED_view3d_unproject_v3(region, cent[0], cent[1], depth_close, p)) || + (!ED_view3d_unproject_v3(region, rect.xmin, rect.ymin, depth_close, p_corner))) { + return OPERATOR_CANCELLED; + } + + sub_v3_v3v3(dvec, p, p_corner); + negate_v3_v3(new_ofs, p); + + new_dist = len_v3(dvec); + + /* Account for the lens, without this a narrow lens zooms in too close. */ + new_dist *= (v3d->lens / DEFAULT_SENSOR_WIDTH); + + /* ignore dist_range min */ + dist_range[0] = v3d->clip_start * 1.5f; + } + else { /* orthographic */ + /* find the current window width and height */ + vb[0] = region->winx; + vb[1] = region->winy; + + new_dist = rv3d->dist; + + /* convert the drawn rectangle into 3d space */ + if (depth_close != FLT_MAX && + ED_view3d_unproject_v3(region, cent[0], cent[1], depth_close, p)) { + negate_v3_v3(new_ofs, p); + } + else { + float mval_f[2]; + float zfac; + + /* We can't use the depth, fallback to the old way that doesn't set the center depth */ + copy_v3_v3(new_ofs, rv3d->ofs); + + { + float tvec[3]; + negate_v3_v3(tvec, new_ofs); + zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL); + } + + mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f; + mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f; + ED_view3d_win_to_delta(region, mval_f, dvec, zfac); + /* center the view to the center of the rectangle */ + sub_v3_v3(new_ofs, dvec); + } + + /* work out the ratios, so that everything selected fits when we zoom */ + xscale = (BLI_rcti_size_x(&rect) / vb[0]); + yscale = (BLI_rcti_size_y(&rect) / vb[1]); + new_dist *= max_ff(xscale, yscale); + } + + if (!zoom_in) { + sub_v3_v3v3(dvec, new_ofs, rv3d->ofs); + new_dist = rv3d->dist * (rv3d->dist / new_dist); + add_v3_v3v3(new_ofs, rv3d->ofs, dvec); + } + + /* clamp after because we may have been zooming out */ + CLAMP(new_dist, dist_range[0], dist_range[1]); + + /* TODO(campbell): 'is_camera_lock' not currently working well. */ + const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d); + if ((rv3d->persp == RV3D_CAMOB) && (is_camera_lock == false)) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP); + } + + ED_view3d_smooth_view(C, + v3d, + region, + smooth_viewtx, + &(const V3D_SmoothParams){ + .ofs = new_ofs, + .dist = &new_dist, + }); + + if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { + view3d_boxview_sync(CTX_wm_area(C), region); + } + + return OPERATOR_FINISHED; +} + +void VIEW3D_OT_zoom_border(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Zoom to Border"; + ot->description = "Zoom in the view to the nearest object contained in the border"; + ot->idname = "VIEW3D_OT_zoom_border"; + + /* api callbacks */ + ot->invoke = WM_gesture_box_invoke; + ot->exec = view3d_zoom_border_exec; + ot->modal = WM_gesture_box_modal; + ot->cancel = WM_gesture_box_cancel; + + ot->poll = view3d_zoom_or_dolly_poll; + + /* flags */ + ot->flag = 0; + + /* properties */ + WM_operator_properties_gesture_box_zoom(ot); +} + +/** \} */ diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c index 823aa3b6643..52db8526937 100644 --- a/source/blender/editors/space_view3d/view3d_ops.c +++ b/source/blender/editors/space_view3d/view3d_ops.c @@ -50,6 +50,7 @@ #include "ED_transform.h" #include "view3d_intern.h" +#include "view3d_navigate.h" #ifdef WIN32 # include "BLI_math_base.h" /* M_PI */ diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 45899880b41..34aa24a1eef 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -99,6 +99,7 @@ #include "UI_resources.h" #include "GPU_matrix.h" +#include "GPU_select.h" #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" @@ -1566,8 +1567,8 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot) static Base *object_mouse_select_menu(bContext *C, ViewContext *vc, - const uint *buffer, - int hits, + const GPUSelectResult *buffer, + const int hits, const int mval[2], bool extend, bool deselect, @@ -1585,7 +1586,7 @@ static Base *object_mouse_select_menu(bContext *C, if (buffer) { for (int a = 0; a < hits; a++) { /* index was converted */ - if (base->object->runtime.select_id == (buffer[(4 * a) + 3] & ~0xFFFF0000)) { + if (base->object->runtime.select_id == (buffer[a].id & ~0xFFFF0000)) { ok = true; break; } @@ -1742,7 +1743,7 @@ void VIEW3D_OT_bone_select_menu(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } static bool bone_mouse_select_menu(bContext *C, - const uint *buffer, + const GPUSelectResult *buffer, const int hits, const bool is_editmode, const bool extend, @@ -1760,7 +1761,7 @@ static bool bone_mouse_select_menu(bContext *C, for (int a = 0; a < hits; a++) { void *bone_ptr = NULL; Base *bone_base = NULL; - uint hitresult = buffer[3 + (a * 4)]; + uint hitresult = buffer[a].id; if (!(hitresult & BONESEL_ANY)) { /* To avoid including objects in selection. */ @@ -1874,10 +1875,10 @@ static bool bone_mouse_select_menu(bContext *C, return true; } -static bool selectbuffer_has_bones(const uint *buffer, const uint hits) +static bool selectbuffer_has_bones(const GPUSelectResult *buffer, const uint hits) { for (uint i = 0; i < hits; i++) { - if (buffer[(4 * i) + 3] & 0xFFFF0000) { + if (buffer[i].id & 0xFFFF0000) { return true; } } @@ -1885,25 +1886,25 @@ static bool selectbuffer_has_bones(const uint *buffer, const uint hits) } /* utility function for mixed_bones_object_selectbuffer */ -static int selectbuffer_ret_hits_15(uint *UNUSED(buffer), const int hits15) +static int selectbuffer_ret_hits_15(GPUSelectResult *UNUSED(buffer), const int hits15) { return hits15; } -static int selectbuffer_ret_hits_9(uint *buffer, const int hits15, const int hits9) +static int selectbuffer_ret_hits_9(GPUSelectResult *buffer, const int hits15, const int hits9) { - const int ofs = 4 * hits15; - memcpy(buffer, buffer + ofs, 4 * hits9 * sizeof(uint)); + const int ofs = hits15; + memcpy(buffer, buffer + ofs, hits9 * sizeof(GPUSelectResult)); return hits9; } -static int selectbuffer_ret_hits_5(uint *buffer, +static int selectbuffer_ret_hits_5(GPUSelectResult *buffer, const int hits15, const int hits9, const int hits5) { - const int ofs = 4 * hits15 + 4 * hits9; - memcpy(buffer, buffer + ofs, 4 * hits5 * sizeof(uint)); + const int ofs = hits15 + hits9; + memcpy(buffer, buffer + ofs, hits5 * sizeof(GPUSelectResult)); return hits5; } @@ -1916,7 +1917,8 @@ static int selectbuffer_ret_hits_5(uint *buffer, * Needed so we can step to the next, non-active object when it's already selected, see: T76445. */ static int mixed_bones_object_selectbuffer(ViewContext *vc, - uint *buffer, + GPUSelectResult *buffer, + const int buffer_len, const int mval[2], eV3DSelectObjectFilter select_filter, bool do_nearest, @@ -1941,7 +1943,7 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc, BLI_rcti_init_pt_radius(&rect, mval, 14); hits15 = view3d_opengl_select_ex( - vc, buffer, MAXPICKBUF, &rect, select_mode, select_filter, do_material_slot_selection); + vc, buffer, buffer_len, &rect, select_mode, select_filter, do_material_slot_selection); if (hits15 == 1) { hits = selectbuffer_ret_hits_15(buffer, hits15); goto finally; @@ -1950,10 +1952,10 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc, int ofs; has_bones15 = selectbuffer_has_bones(buffer, hits15); - ofs = 4 * hits15; + ofs = hits15; BLI_rcti_init_pt_radius(&rect, mval, 9); hits9 = view3d_opengl_select( - vc, buffer + ofs, MAXPICKBUF - ofs, &rect, select_mode, select_filter); + vc, buffer + ofs, buffer_len - ofs, &rect, select_mode, select_filter); if (hits9 == 1) { hits = selectbuffer_ret_hits_9(buffer, hits15, hits9); goto finally; @@ -1961,10 +1963,10 @@ static int mixed_bones_object_selectbuffer(ViewContext *vc, else if (hits9 > 0) { has_bones9 = selectbuffer_has_bones(buffer + ofs, hits9); - ofs += 4 * hits9; + ofs += hits9; BLI_rcti_init_pt_radius(&rect, mval, 5); hits5 = view3d_opengl_select( - vc, buffer + ofs, MAXPICKBUF - ofs, &rect, select_mode, select_filter); + vc, buffer + ofs, buffer_len - ofs, &rect, select_mode, select_filter); if (hits5 == 1) { hits = selectbuffer_ret_hits_5(buffer, hits15, hits9, hits5); goto finally; @@ -2007,7 +2009,8 @@ finally: } static int mixed_bones_object_selectbuffer_extended(ViewContext *vc, - uint *buffer, + GPUSelectResult *buffer, + const int buffer_len, const int mval[2], eV3DSelectObjectFilter select_filter, bool use_cycle, @@ -2038,7 +2041,7 @@ static int mixed_bones_object_selectbuffer_extended(ViewContext *vc, do_nearest = do_nearest && !enumerate; int hits = mixed_bones_object_selectbuffer( - vc, buffer, mval, select_filter, do_nearest, true, false); + vc, buffer, buffer_len, mval, select_filter, do_nearest, true, false); return hits; } @@ -2051,7 +2054,7 @@ static int mixed_bones_object_selectbuffer_extended(ViewContext *vc, * \return the active base or NULL. */ static Base *mouse_select_eval_buffer(ViewContext *vc, - const uint *buffer, + const GPUSelectResult *buffer, int hits, Base *startbase, bool has_bones, @@ -2071,10 +2074,10 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, if (has_bones) { /* we skip non-bone hits */ for (a = 0; a < hits; a++) { - if (min > buffer[4 * a + 1] && (buffer[4 * a + 3] & 0xFFFF0000)) { - min = buffer[4 * a + 1]; - selcol = buffer[4 * a + 3] & 0xFFFF; - sub_selection_id = (buffer[4 * a + 3] & 0xFFFF0000) >> 16; + if (min > buffer[a].depth && (buffer[a].id & 0xFFFF0000)) { + min = buffer[a].depth; + selcol = buffer[a].id & 0xFFFF; + sub_selection_id = (buffer[a].id & 0xFFFF0000) >> 16; } } } @@ -2085,10 +2088,10 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, } for (a = 0; a < hits; a++) { - if (min > buffer[4 * a + 1] && notcol != (buffer[4 * a + 3] & 0xFFFF)) { - min = buffer[4 * a + 1]; - selcol = buffer[4 * a + 3] & 0xFFFF; - sub_selection_id = (buffer[4 * a + 3] & 0xFFFF0000) >> 16; + if (min > buffer[a].depth && notcol != (buffer[a].id & 0xFFFF)) { + min = buffer[a].depth; + selcol = buffer[a].id & 0xFFFF; + sub_selection_id = (buffer[a].id & 0xFFFF0000) >> 16; } } } @@ -2127,14 +2130,14 @@ static Base *mouse_select_eval_buffer(ViewContext *vc, for (a = 0; a < hits; a++) { if (has_bones) { /* skip non-bone objects */ - if (buffer[4 * a + 3] & 0xFFFF0000) { - if (base->object->runtime.select_id == (buffer[(4 * a) + 3] & 0xFFFF)) { + if (buffer[a].id & 0xFFFF0000) { + if (base->object->runtime.select_id == (buffer[a].id & 0xFFFF)) { basact = base; } } } else { - if (base->object->runtime.select_id == (buffer[(4 * a) + 3] & 0xFFFF)) { + if (base->object->runtime.select_id == (buffer[a].id & 0xFFFF)) { basact = base; } } @@ -2169,7 +2172,7 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C, Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; Base *basact = NULL; - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; /* setup view context for argument to callbacks */ view3d_operator_needs_opengl(C); @@ -2179,8 +2182,14 @@ static Base *ed_view3d_give_base_under_cursor_ex(bContext *C, const bool do_nearest = !XRAY_ACTIVE(vc.v3d); const bool do_material_slot_selection = r_material_slot != NULL; - const int hits = mixed_bones_object_selectbuffer( - &vc, buffer, mval, VIEW3D_SELECT_FILTER_NOP, do_nearest, false, do_material_slot_selection); + const int hits = mixed_bones_object_selectbuffer(&vc, + buffer, + ARRAY_SIZE(buffer), + mval, + VIEW3D_SELECT_FILTER_NOP, + do_nearest, + false, + do_material_slot_selection); if (hits > 0) { const bool has_bones = (r_material_slot == NULL) && selectbuffer_has_bones(buffer, hits); @@ -2342,7 +2351,7 @@ static bool ed_object_select_pick(bContext *C, } } else { - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; bool do_nearest; // TIMEIT_START(select_time); @@ -2353,7 +2362,7 @@ static bool ed_object_select_pick(bContext *C, vc.obact) : VIEW3D_SELECT_FILTER_NOP); hits = mixed_bones_object_selectbuffer_extended( - &vc, buffer, mval, select_filter, true, enumerate, &do_nearest); + &vc, buffer, ARRAY_SIZE(buffer), mval, select_filter, true, enumerate, &do_nearest); // TIMEIT_END(select_time); @@ -2383,7 +2392,7 @@ static bool ed_object_select_pick(bContext *C, bool changed = false; for (int i = 0; i < hits; i++) { - int hitresult = buffer[3 + (i * 4)]; + const int hitresult = buffer[i].id; /* if there's bundles in buffer select bundles first, * so non-camera elements should be ignored in buffer */ @@ -2394,7 +2403,7 @@ static bool ed_object_select_pick(bContext *C, /* index of bundle is 1<<16-based. if there's no "bone" index * in height word, this buffer value belongs to camera. not to bundle */ - if (buffer[4 * i + 3] & 0xFFFF0000) { + if (hitresult & 0xFFFF0000) { MovieTracking *tracking = &clip->tracking; ListBase *tracksbase; MovieTrackingTrack *track; @@ -2674,9 +2683,15 @@ static int view3d_select_exec(bContext *C, wmOperator *op) ViewContext vc; ED_view3d_viewcontext_init(C, &vc, depsgraph); - uint buffer[MAXPICKBUF]; - const int hits = mixed_bones_object_selectbuffer( - &vc, buffer, location, VIEW3D_SELECT_FILTER_NOP, false, true, false); + GPUSelectResult buffer[MAXPICKELEMS]; + const int hits = mixed_bones_object_selectbuffer(&vc, + buffer, + ARRAY_SIZE(buffer), + location, + VIEW3D_SELECT_FILTER_NOP, + false, + true, + false); retval = bone_mouse_select_menu(C, buffer, hits, true, extend, deselect, toggle); } if (!retval) { @@ -3256,11 +3271,11 @@ static bool do_meta_box_select(ViewContext *vc, const rcti *rect, const eSelectO int a; bool changed = false; - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; int hits; hits = view3d_opengl_select( - vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL, VIEW3D_SELECT_FILTER_NOP); + vc, buffer, MAXPICKELEMS, rect, VIEW3D_SELECT_ALL, VIEW3D_SELECT_FILTER_NOP); if (SEL_OP_USE_PRE_DESELECT(sel_op)) { changed |= BKE_mball_deselect_all(mb); @@ -3272,7 +3287,7 @@ static bool do_meta_box_select(ViewContext *vc, const rcti *rect, const eSelectO bool is_inside_stiff = false; for (a = 0; a < hits; a++) { - int hitresult = buffer[(4 * a) + 3]; + const int hitresult = buffer[a].id; if (hitresult == -1) { continue; @@ -3323,11 +3338,11 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel bool changed = false; int a; - uint buffer[MAXPICKBUF]; + GPUSelectResult buffer[MAXPICKELEMS]; int hits; hits = view3d_opengl_select( - vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL, VIEW3D_SELECT_FILTER_NOP); + vc, buffer, MAXPICKELEMS, rect, VIEW3D_SELECT_ALL, VIEW3D_SELECT_FILTER_NOP); uint bases_len = 0; Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data( @@ -3347,7 +3362,7 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel /* first we only check points inside the border */ for (a = 0; a < hits; a++) { - int select_id = buffer[(4 * a) + 3]; + const int select_id = buffer[a].id; if (select_id != -1) { if ((select_id & 0xFFFF0000) == 0) { continue; @@ -3375,14 +3390,13 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel } /** - * Compare result of 'GPU_select': 'uint[4]', + * Compare result of 'GPU_select': 'GPUSelectResult', * needed for when we need to align with object draw-order. */ static int opengl_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_p) { - /* 4th element is select id */ - uint sel_a = ((uint *)sel_a_p)[3]; - uint sel_b = ((uint *)sel_b_p)[3]; + uint sel_a = ((GPUSelectResult *)sel_a_p)->id; + uint sel_b = ((GPUSelectResult *)sel_b_p)->id; #ifdef __BIG_ENDIAN__ BLI_endian_switch_uint32(&sel_a); @@ -3401,14 +3415,15 @@ static int opengl_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const eSelectOp sel_op) { View3D *v3d = vc->v3d; - int totobj = MAXPICKBUF; /* XXX solve later */ + int totobj = MAXPICKELEMS; /* XXX solve later */ - /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ - uint *vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(uint[4]), "selection buffer"); + /* Selection buffer has bones potentially too, so we add #MAXPICKELEMS. */ + GPUSelectResult *buffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult), + "selection buffer"); const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene, vc->obact); const int hits = view3d_opengl_select( - vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); + vc, buffer, (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); LISTBASE_FOREACH (Base *, base, &vc->view_layer->object_bases) { base->object->id.tag &= ~LIB_TAG_DOIT; @@ -3435,12 +3450,13 @@ static bool do_object_box_select(bContext *C, ViewContext *vc, rcti *rect, const } /* The draw order doesn't always match the order we populate the engine, see: T51695. */ - qsort(vbuffer, hits, sizeof(uint[4]), opengl_bone_select_buffer_cmp); + qsort(buffer, hits, sizeof(GPUSelectResult), opengl_bone_select_buffer_cmp); - for (const uint *col = vbuffer + 3, *col_end = col + (hits * 4); col < col_end; col += 4) { + for (const GPUSelectResult *buf_iter = buffer, *buf_end = buf_iter + hits; buf_iter < buf_end; + buf_iter++) { bPoseChannel *pchan_dummy; Base *base = ED_armature_base_and_pchan_from_select_buffer( - bases, BLI_array_len(bases), *col, &pchan_dummy); + bases, BLI_array_len(bases), buf_iter->id, &pchan_dummy); if (base != NULL) { base->object->id.tag |= LIB_TAG_DOIT; } @@ -3463,7 +3479,7 @@ finally: MEM_freeN(bases); } - MEM_freeN(vbuffer); + MEM_freeN(buffer); if (changed) { DEG_id_tag_update(&vc->scene->id, ID_RECALC_SELECT); @@ -3477,14 +3493,15 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e uint bases_len; Base **bases = do_pose_tag_select_op_prepare(vc, &bases_len); - int totobj = MAXPICKBUF; /* XXX solve later */ + int totobj = MAXPICKELEMS; /* XXX solve later */ - /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ - uint *vbuffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(uint[4]), "selection buffer"); + /* Selection buffer has bones potentially too, so add #MAXPICKELEMS. */ + GPUSelectResult *buffer = MEM_mallocN((totobj + MAXPICKELEMS) * sizeof(GPUSelectResult), + "selection buffer"); const eV3DSelectObjectFilter select_filter = ED_view3d_select_filter_from_mode(vc->scene, vc->obact); const int hits = view3d_opengl_select( - vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); + vc, buffer, (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL, select_filter); /* * LOGIC NOTES (theeth): * The buffer and ListBase have the same relative order, which makes the selection @@ -3498,18 +3515,20 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e /* no need to loop if there's no hit */ /* The draw order doesn't always match the order we populate the engine, see: T51695. */ - qsort(vbuffer, hits, sizeof(uint[4]), opengl_bone_select_buffer_cmp); + qsort(buffer, hits, sizeof(GPUSelectResult), opengl_bone_select_buffer_cmp); - for (const uint *col = vbuffer + 3, *col_end = col + (hits * 4); col < col_end; col += 4) { + for (const GPUSelectResult *buf_iter = buffer, *buf_end = buf_iter + hits; buf_iter < buf_end; + buf_iter++) { Bone *bone; - Base *base = ED_armature_base_and_bone_from_select_buffer(bases, bases_len, *col, &bone); + Base *base = ED_armature_base_and_bone_from_select_buffer( + bases, bases_len, buf_iter->id, &bone); if (base == NULL) { continue; } /* Loop over contiguous bone hits for 'base'. */ - for (; col != col_end; col += 4) { + for (; buf_iter != buf_end; buf_iter++) { /* should never fail */ if (bone != NULL) { base->object->id.tag |= LIB_TAG_DOIT; @@ -3517,12 +3536,13 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e } /* Select the next bone if we're not switching bases. */ - if (col + 4 != col_end) { - if ((base->object->runtime.select_id & 0x0000FFFF) != (col[4] & 0x0000FFFF)) { + if (buf_iter + 1 != buf_end) { + const GPUSelectResult *col_next = buf_iter + 1; + if ((base->object->runtime.select_id & 0x0000FFFF) != (col_next->id & 0x0000FFFF)) { break; } if (base->object->pose != NULL) { - const uint hit_bone = (col[4] & ~BONESEL_ANY) >> 16; + const uint hit_bone = (col_next->id & ~BONESEL_ANY) >> 16; bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone); bone = pchan ? pchan->bone : NULL; } @@ -3543,7 +3563,7 @@ static bool do_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, const e if (bases != NULL) { MEM_freeN(bases); } - MEM_freeN(vbuffer); + MEM_freeN(buffer); return changed_multi; } diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index 165f931394d..ddd5cc640bb 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -21,21 +21,14 @@ * \ingroup spview3d */ -#include "DNA_camera_types.h" -#include "DNA_gpencil_modifier_types.h" -#include "DNA_object_types.h" -#include "DNA_scene_types.h" - #include "MEM_guardedalloc.h" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" #include "BLI_rect.h" -#include "BLI_utildefines.h" #include "BKE_action.h" -#include "BKE_camera.h" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_gpencil_modifier.h" @@ -47,7 +40,6 @@ #include "BKE_report.h" #include "BKE_scene.h" -#include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" #include "UI_resources.h" @@ -57,7 +49,6 @@ #include "GPU_state.h" #include "WM_api.h" -#include "WM_types.h" #include "ED_object.h" #include "ED_screen.h" @@ -68,376 +59,7 @@ #include "RNA_define.h" #include "view3d_intern.h" /* own include */ - -/* -------------------------------------------------------------------- */ -/** \name Smooth View Operator & Utilities - * - * Use for view transitions to have smooth (animated) transitions. - * \{ */ - -/* This operator is one of the 'timer refresh' ones like animation playback */ - -struct SmoothView3DState { - float dist; - float lens; - float quat[4]; - float ofs[3]; -}; - -struct SmoothView3DStore { - /* Source. */ - struct SmoothView3DState src; /* source */ - struct SmoothView3DState dst; /* destination */ - struct SmoothView3DState org; /* original */ - - bool to_camera; - - bool use_dyn_ofs; - float dyn_ofs[3]; - - /* When smooth-view is enabled, store the 'rv3d->view' here, - * assign back when the view motion is completed. */ - char org_view; - - double time_allowed; -}; - -static void view3d_smooth_view_state_backup(struct SmoothView3DState *sms_state, - const View3D *v3d, - const RegionView3D *rv3d) -{ - copy_v3_v3(sms_state->ofs, rv3d->ofs); - copy_qt_qt(sms_state->quat, rv3d->viewquat); - sms_state->dist = rv3d->dist; - sms_state->lens = v3d->lens; -} - -static void view3d_smooth_view_state_restore(const struct SmoothView3DState *sms_state, - View3D *v3d, - RegionView3D *rv3d) -{ - copy_v3_v3(rv3d->ofs, sms_state->ofs); - copy_qt_qt(rv3d->viewquat, sms_state->quat); - rv3d->dist = sms_state->dist; - v3d->lens = sms_state->lens; -} - -/* will start timer if appropriate */ -void ED_view3d_smooth_view_ex( - /* avoid passing in the context */ - const Depsgraph *depsgraph, - wmWindowManager *wm, - wmWindow *win, - ScrArea *area, - View3D *v3d, - ARegion *region, - const int smooth_viewtx, - const V3D_SmoothParams *sview) -{ - RegionView3D *rv3d = region->regiondata; - struct SmoothView3DStore sms = {{0}}; - - /* initialize sms */ - view3d_smooth_view_state_backup(&sms.dst, v3d, rv3d); - view3d_smooth_view_state_backup(&sms.src, v3d, rv3d); - /* If smooth-view runs multiple times. */ - if (rv3d->sms == NULL) { - view3d_smooth_view_state_backup(&sms.org, v3d, rv3d); - } - else { - sms.org = rv3d->sms->org; - } - sms.org_view = rv3d->view; - - /* sms.to_camera = false; */ /* initialized to zero anyway */ - - /* note on camera locking, this is a little confusing but works ok. - * we may be changing the view 'as if' there is no active camera, but in fact - * there is an active camera which is locked to the view. - * - * In the case where smooth view is moving _to_ a camera we don't want that - * camera to be moved or changed, so only when the camera is not being set should - * we allow camera option locking to initialize the view settings from the camera. - */ - if (sview->camera == NULL && sview->camera_old == NULL) { - ED_view3d_camera_lock_init(depsgraph, v3d, rv3d); - } - - /* store the options we want to end with */ - if (sview->ofs) { - copy_v3_v3(sms.dst.ofs, sview->ofs); - } - if (sview->quat) { - copy_qt_qt(sms.dst.quat, sview->quat); - } - if (sview->dist) { - sms.dst.dist = *sview->dist; - } - if (sview->lens) { - sms.dst.lens = *sview->lens; - } - - if (sview->dyn_ofs) { - BLI_assert(sview->ofs == NULL); - BLI_assert(sview->quat != NULL); - - copy_v3_v3(sms.dyn_ofs, sview->dyn_ofs); - sms.use_dyn_ofs = true; - - /* calculate the final destination offset */ - view3d_orbit_apply_dyn_ofs(sms.dst.ofs, sms.src.ofs, sms.src.quat, sms.dst.quat, sms.dyn_ofs); - } - - if (sview->camera) { - Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); - if (sview->ofs != NULL) { - sms.dst.dist = ED_view3d_offset_distance( - ob_camera_eval->obmat, sview->ofs, VIEW3D_DIST_FALLBACK); - } - ED_view3d_from_object(ob_camera_eval, sms.dst.ofs, sms.dst.quat, &sms.dst.dist, &sms.dst.lens); - sms.to_camera = true; /* restore view3d values in end */ - } - - if ((sview->camera_old == sview->camera) && /* Camera. */ - (sms.dst.dist == rv3d->dist) && /* Distance. */ - (sms.dst.lens == v3d->lens) && /* Lens. */ - equals_v3v3(sms.dst.ofs, rv3d->ofs) && /* Offset. */ - equals_v4v4(sms.dst.quat, rv3d->viewquat) /* Rotation. */ - ) { - /* Early return if nothing changed. */ - return; - } - - /* Skip smooth viewing for external render engine draw. */ - if (smooth_viewtx && !(v3d->shading.type == OB_RENDER && rv3d->render_engine)) { - - /* original values */ - if (sview->camera_old) { - Object *ob_camera_old_eval = DEG_get_evaluated_object(depsgraph, sview->camera_old); - if (sview->ofs != NULL) { - sms.src.dist = ED_view3d_offset_distance(ob_camera_old_eval->obmat, sview->ofs, 0.0f); - } - ED_view3d_from_object( - ob_camera_old_eval, sms.src.ofs, sms.src.quat, &sms.src.dist, &sms.src.lens); - } - /* grid draw as floor */ - if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) { - /* use existing if exists, means multiple calls to smooth view - * won't lose the original 'view' setting */ - rv3d->view = RV3D_VIEW_USER; - } - - sms.time_allowed = (double)smooth_viewtx / 1000.0; - - /* If this is view rotation only we can decrease the time allowed by the angle between quats - * this means small rotations won't lag. */ - if (sview->quat && !sview->ofs && !sview->dist) { - /* scale the time allowed by the rotation */ - /* 180deg == 1.0 */ - sms.time_allowed *= (double)fabsf(angle_signed_normalized_qtqt(sms.dst.quat, sms.src.quat)) / - M_PI; - } - - /* ensure it shows correct */ - if (sms.to_camera) { - /* use ortho if we move from an ortho view to an ortho camera */ - Object *ob_camera_eval = DEG_get_evaluated_object(depsgraph, sview->camera); - rv3d->persp = (((rv3d->is_persp == false) && (ob_camera_eval->type == OB_CAMERA) && - (((Camera *)ob_camera_eval->data)->type == CAM_ORTHO)) ? - RV3D_ORTHO : - RV3D_PERSP); - } - - rv3d->rflag |= RV3D_NAVIGATING; - - /* not essential but in some cases the caller will tag the area for redraw, and in that - * case we can get a flicker of the 'org' user view but we want to see 'src' */ - view3d_smooth_view_state_restore(&sms.src, v3d, rv3d); - - /* keep track of running timer! */ - if (rv3d->sms == NULL) { - rv3d->sms = MEM_mallocN(sizeof(struct SmoothView3DStore), "smoothview v3d"); - } - *rv3d->sms = sms; - if (rv3d->smooth_timer) { - WM_event_remove_timer(wm, win, rv3d->smooth_timer); - } - /* #TIMER1 is hard-coded in key-map. */ - rv3d->smooth_timer = WM_event_add_timer(wm, win, TIMER1, 1.0 / 100.0); - } - else { - /* Animation is disabled, apply immediately. */ - if (sms.to_camera == false) { - copy_v3_v3(rv3d->ofs, sms.dst.ofs); - copy_qt_qt(rv3d->viewquat, sms.dst.quat); - rv3d->dist = sms.dst.dist; - v3d->lens = sms.dst.lens; - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - } - - if (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW) { - view3d_boxview_copy(area, region); - } - - ED_region_tag_redraw(region); - - WM_event_add_mousemove(win); - } -} - -void ED_view3d_smooth_view(bContext *C, - View3D *v3d, - ARegion *region, - const int smooth_viewtx, - const struct V3D_SmoothParams *sview) -{ - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - wmWindowManager *wm = CTX_wm_manager(C); - wmWindow *win = CTX_wm_window(C); - ScrArea *area = CTX_wm_area(C); - - ED_view3d_smooth_view_ex(depsgraph, wm, win, area, v3d, region, smooth_viewtx, sview); -} - -/* only meant for timer usage */ -static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *region, bool sync_boxview) -{ - wmWindowManager *wm = CTX_wm_manager(C); - RegionView3D *rv3d = region->regiondata; - struct SmoothView3DStore *sms = rv3d->sms; - float step, step_inv; - - if (sms->time_allowed != 0.0) { - step = (float)((rv3d->smooth_timer->duration) / sms->time_allowed); - } - else { - step = 1.0f; - } - - /* end timer */ - if (step >= 1.0f) { - wmWindow *win = CTX_wm_window(C); - - /* if we went to camera, store the original */ - if (sms->to_camera) { - rv3d->persp = RV3D_CAMOB; - view3d_smooth_view_state_restore(&sms->org, v3d, rv3d); - } - else { - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - - view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d); - - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true); - } - - if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) { - rv3d->view = sms->org_view; - } - - MEM_freeN(rv3d->sms); - rv3d->sms = NULL; - - WM_event_remove_timer(wm, win, rv3d->smooth_timer); - rv3d->smooth_timer = NULL; - rv3d->rflag &= ~RV3D_NAVIGATING; - - /* Event handling won't know if a UI item has been moved under the pointer. */ - WM_event_add_mousemove(win); - } - else { - /* ease in/out */ - step = (3.0f * step * step - 2.0f * step * step * step); - - step_inv = 1.0f - step; - - interp_qt_qtqt(rv3d->viewquat, sms->src.quat, sms->dst.quat, step); - - if (sms->use_dyn_ofs) { - view3d_orbit_apply_dyn_ofs( - rv3d->ofs, sms->src.ofs, sms->src.quat, rv3d->viewquat, sms->dyn_ofs); - } - else { - interp_v3_v3v3(rv3d->ofs, sms->src.ofs, sms->dst.ofs, step); - } - - rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv; - v3d->lens = sms->dst.lens * step + sms->src.lens * step_inv; - - const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); - if (ED_screen_animation_playing(wm)) { - ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true); - } - } - - if (sync_boxview && (RV3D_LOCK_FLAGS(rv3d) & RV3D_BOXVIEW)) { - view3d_boxview_copy(CTX_wm_area(C), region); - } - - /* NOTE: this doesn't work right because the v3d->lens is now used in ortho mode r51636, - * when switching camera in quad-view the other ortho views would zoom & reset. - * - * For now only redraw all regions when smooth-view finishes. - */ - if (step >= 1.0f) { - WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); - } - else { - ED_region_tag_redraw(region); - } -} - -static int view3d_smoothview_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) -{ - View3D *v3d = CTX_wm_view3d(C); - ARegion *region = CTX_wm_region(C); - RegionView3D *rv3d = region->regiondata; - - /* escape if not our timer */ - if (rv3d->smooth_timer == NULL || rv3d->smooth_timer != event->customdata) { - return OPERATOR_PASS_THROUGH; - } - - view3d_smoothview_apply(C, v3d, region, true); - - return OPERATOR_FINISHED; -} - -void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region) -{ - RegionView3D *rv3d = region->regiondata; - - if (rv3d && rv3d->sms) { - rv3d->sms->time_allowed = 0.0; /* force finishing */ - view3d_smoothview_apply(C, v3d, region, false); - - /* force update of view matrix so tools that run immediately after - * can use them without redrawing first */ - Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); - Scene *scene = CTX_data_scene(C); - ED_view3d_update_viewmat(depsgraph, scene, v3d, region, NULL, NULL, NULL, false); - } -} - -void VIEW3D_OT_smoothview(wmOperatorType *ot) -{ - /* identifiers */ - ot->name = "Smooth View"; - ot->idname = "VIEW3D_OT_smoothview"; - - /* api callbacks */ - ot->invoke = view3d_smoothview_invoke; - - /* flags */ - ot->flag = OPTYPE_INTERNAL; - - ot->poll = ED_operator_view3d_active; -} - -/** \} */ +#include "view3d_navigate.h" /* -------------------------------------------------------------------- */ /** \name Camera to View Operator @@ -863,10 +485,10 @@ void view3d_opengl_select_cache_end(void) struct DrawSelectLoopUserData { uint pass; uint hits; - uint *buffer; + GPUSelectResult *buffer; uint buffer_len; const rcti *rect; - char gpu_select_mode; + eGPUSelectMode gpu_select_mode; }; static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data) @@ -927,8 +549,8 @@ static bool drw_select_filter_object_mode_lock_for_weight_paint(Object *ob, void } int view3d_opengl_select_ex(ViewContext *vc, - uint *buffer, - uint bufsize, + GPUSelectResult *buffer, + uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, @@ -950,7 +572,7 @@ int view3d_opengl_select_ex(ViewContext *vc, const bool use_nearest = (is_pick_select && select_mode == VIEW3D_SELECT_PICK_NEAREST); bool draw_surface = true; - char gpu_select_mode; + eGPUSelectMode gpu_select_mode; /* case not a box select */ if (input->xmin == input->xmax) { @@ -981,6 +603,15 @@ int view3d_opengl_select_ex(ViewContext *vc, } } + /* Re-use cache (rect must be smaller than the cached) + * other context is assumed to be unchanged */ + if (GPU_select_is_cached()) { + GPU_select_begin(buffer, buffer_len, &rect, gpu_select_mode, 0); + GPU_select_cache_load_id(); + hits = GPU_select_end(); + goto finally; + } + /* Important to use 'vc->obact', not 'OBACT(vc->view_layer)' below, * so it will be NULL when hidden. */ struct { @@ -1040,15 +671,6 @@ int view3d_opengl_select_ex(ViewContext *vc, UI_Theme_Store(&theme_state); UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); - /* Re-use cache (rect must be smaller than the cached) - * other context is assumed to be unchanged */ - if (GPU_select_is_cached()) { - GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0); - GPU_select_cache_load_id(); - hits = GPU_select_end(); - goto finally; - } - /* All of the queries need to be perform on the drawing context. */ DRW_opengl_context_enable(); @@ -1071,7 +693,7 @@ int view3d_opengl_select_ex(ViewContext *vc, .pass = 0, .hits = 0, .buffer = buffer, - .buffer_len = bufsize, + .buffer_len = buffer_len, .rect = &rect, .gpu_select_mode = gpu_select_mode, }; @@ -1101,7 +723,7 @@ int view3d_opengl_select_ex(ViewContext *vc, .pass = 0, .hits = 0, .buffer = buffer, - .buffer_len = bufsize, + .buffer_len = buffer_len, .rect = &rect, .gpu_select_mode = gpu_select_mode, }; @@ -1132,36 +754,36 @@ int view3d_opengl_select_ex(ViewContext *vc, DRW_opengl_context_disable(); + UI_Theme_Restore(&theme_state); + finally: if (hits < 0) { printf("Too many objects in select buffer\n"); /* XXX make error message */ } - UI_Theme_Restore(&theme_state); - return hits; } int view3d_opengl_select(ViewContext *vc, - uint *buffer, - uint bufsize, + GPUSelectResult *buffer, + uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter) { - return view3d_opengl_select_ex(vc, buffer, bufsize, input, select_mode, select_filter, false); + return view3d_opengl_select_ex(vc, buffer, buffer_len, input, select_mode, select_filter, false); } int view3d_opengl_select_with_id_filter(ViewContext *vc, - uint *buffer, - uint bufsize, + GPUSelectResult *buffer, + const uint buffer_len, const rcti *input, eV3DSelectMode select_mode, eV3DSelectObjectFilter select_filter, uint select_id) { - int hits = view3d_opengl_select(vc, buffer, bufsize, input, select_mode, select_filter); + int hits = view3d_opengl_select(vc, buffer, buffer_len, input, select_mode, select_filter); /* Selection sometimes uses -1 for an invalid selection ID, remove these as they * interfere with detection of actual number of hits in the selection. */ diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt index 64a720322c1..09c53d7196c 100644 --- a/source/blender/editors/transform/CMakeLists.txt +++ b/source/blender/editors/transform/CMakeLists.txt @@ -125,9 +125,5 @@ set(LIB bf_gpu ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_transform "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index 642de550812..8d91f90ea29 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -580,11 +580,11 @@ typedef struct TransInfo { /** Mouse side of the current frame, 'L', 'R' or 'B' */ char frame_side; - /** copy from G.vd, prevents feedback. */ + /** copy from #RegionView3D, prevents feedback. */ float viewmat[4][4]; /** and to make sure we don't have to. */ float viewinv[4][4]; - /** access G.vd from other space types. */ + /** Access #RegionView3D from other space types. */ float persmat[4][4]; float persinv[4][4]; short persp; diff --git a/source/blender/editors/transform/transform_convert.h b/source/blender/editors/transform/transform_convert.h index c40f3c28a79..90f78d4abf1 100644 --- a/source/blender/editors/transform/transform_convert.h +++ b/source/blender/editors/transform/transform_convert.h @@ -124,10 +124,8 @@ void special_aftertrans_update__actedit(bContext *C, TransInfo *t); * Sets transform flags in the bones. * Returns total number of bones with #BONE_TRANSFORM. */ -int transform_convert_pose_transflags_update(Object *ob, - int mode, - short around, - bool has_translate_rotate[2]); +void transform_convert_pose_transflags_update(Object *ob, int mode, short around); + /** * When objects array is NULL, use 't->data_container' as is. */ diff --git a/source/blender/editors/transform/transform_convert_armature.c b/source/blender/editors/transform/transform_convert_armature.c index 5d0a3bd9dd1..04a8d462924 100644 --- a/source/blender/editors/transform/transform_convert_armature.c +++ b/source/blender/editors/transform/transform_convert_armature.c @@ -739,9 +739,43 @@ void createTransPose(TransInfo *t) const bool mirror = ((pose->flag & POSE_MIRROR_EDIT) != 0); - /* set flags and count total */ - tc->data_len = transform_convert_pose_transflags_update( - ob, t->mode, t->around, has_translate_rotate); + /* Set flags. */ + transform_convert_pose_transflags_update(ob, t->mode, t->around); + + /* Now count, and check if we have autoIK or have to switch from translate to rotate. */ + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + Bone *bone = pchan->bone; + if (!(bone->flag & BONE_TRANSFORM)) { + continue; + } + + tc->data_len++; + + if (has_translate_rotate != NULL) { + if (has_translate_rotate[0] && has_translate_rotate[1]) { + continue; + } + + if (has_targetless_ik(pchan) == NULL) { + if (pchan->parent && (bone->flag & BONE_CONNECTED)) { + if (bone->flag & BONE_HINGE_CHILD_TRANSFORM) { + has_translate_rotate[0] = true; + } + } + else { + if ((pchan->protectflag & OB_LOCK_LOC) != OB_LOCK_LOC) { + has_translate_rotate[0] = true; + } + } + if ((pchan->protectflag & OB_LOCK_ROT) != OB_LOCK_ROT) { + has_translate_rotate[1] = true; + } + } + else { + has_translate_rotate[0] = true; + } + } + } if (tc->data_len == 0) { continue; @@ -1499,15 +1533,11 @@ static void bone_children_clear_transflag(int mode, short around, ListBase *lb) } } -int transform_convert_pose_transflags_update(Object *ob, - const int mode, - const short around, - bool has_translate_rotate[2]) +void transform_convert_pose_transflags_update(Object *ob, const int mode, const short around) { bArmature *arm = ob->data; bPoseChannel *pchan; Bone *bone; - int total = 0; for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { bone = pchan->bone; @@ -1537,36 +1567,6 @@ int transform_convert_pose_transflags_update(Object *ob, } } } - /* now count, and check if we have autoIK or have to switch from translate to rotate */ - for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - bone = pchan->bone; - if (bone->flag & BONE_TRANSFORM) { - total++; - - if (has_translate_rotate != NULL) { - if (has_targetless_ik(pchan) == NULL) { - if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED)) { - if (pchan->bone->flag & BONE_HINGE_CHILD_TRANSFORM) { - has_translate_rotate[0] = true; - } - } - else { - if ((pchan->protectflag & OB_LOCK_LOC) != OB_LOCK_LOC) { - has_translate_rotate[0] = true; - } - } - if ((pchan->protectflag & OB_LOCK_ROT) != OB_LOCK_ROT) { - has_translate_rotate[1] = true; - } - } - else { - has_translate_rotate[0] = true; - } - } - } - } - - return total; } static short apply_targetless_ik(Object *ob) @@ -1733,7 +1733,7 @@ void special_aftertrans_update__pose(bContext *C, TransInfo *t) /* Set BONE_TRANSFORM flags for auto-key, gizmo draw might have changed them. */ if (!canceled && (t->mode != TFM_DUMMY)) { - transform_convert_pose_transflags_update(ob, t->mode, t->around, NULL); + transform_convert_pose_transflags_update(ob, t->mode, t->around); } /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */ diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index 9bd55d78039..c0572478481 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -953,32 +953,25 @@ int ED_transform_calc_gizmo_stats(const bContext *C, for (uint ob_index = 0; ob_index < objects_len; ob_index++) { Object *ob_iter = objects[ob_index]; - const bool use_mat_local = (ob_iter != ob); - bPoseChannel *pchan; - + const bool use_mat_local = params->use_local_axis && (ob_iter != ob); /* mislead counting bones... bah. We don't know the gizmo mode, could be mixed */ const int mode = TFM_ROTATION; - const int totsel_iter = transform_convert_pose_transflags_update( - ob_iter, mode, V3D_AROUND_CENTER_BOUNDS, NULL); + transform_convert_pose_transflags_update(ob_iter, mode, V3D_AROUND_CENTER_BOUNDS); - if (totsel_iter) { - float mat_local[4][4]; - if (params->use_local_axis) { - if (use_mat_local) { - mul_m4_m4m4(mat_local, ob->imat, ob_iter->obmat); - } - } + float mat_local[4][4]; + if (use_mat_local) { + mul_m4_m4m4(mat_local, ob->imat, ob_iter->obmat); + } - /* use channels to get stats */ - for (pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) { - Bone *bone = pchan->bone; - if (bone && (bone->flag & BONE_TRANSFORM)) { - calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local); - protectflag_to_drawflags_pchan(rv3d, pchan, orient_index); - } + /* Use channels to get stats. */ + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + if (!(pchan->bone->flag & BONE_TRANSFORM)) { + continue; } - totsel += totsel_iter; + calc_tw_center_with_matrix(tbounds, pchan->pose_head, use_mat_local, mat_local); + protectflag_to_drawflags_pchan(rv3d, pchan, orient_index); + totsel++; } } MEM_freeN(objects); diff --git a/source/blender/editors/undo/CMakeLists.txt b/source/blender/editors/undo/CMakeLists.txt index 0f4152c9128..6f659e383fe 100644 --- a/source/blender/editors/undo/CMakeLists.txt +++ b/source/blender/editors/undo/CMakeLists.txt @@ -46,8 +46,4 @@ set(LIB bf_editor_physics ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_undo "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt index 90a09c87cc6..66cda0fc3f8 100644 --- a/source/blender/editors/util/CMakeLists.txt +++ b/source/blender/editors/util/CMakeLists.txt @@ -115,10 +115,6 @@ set(LIB ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) list(APPEND INC diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt index 1c8a56e0608..a3b29f29354 100644 --- a/source/blender/editors/uvedit/CMakeLists.txt +++ b/source/blender/editors/uvedit/CMakeLists.txt @@ -52,9 +52,5 @@ set(LIB bf_bmesh ) -if(WITH_INTERNATIONAL) - add_definitions(-DWITH_INTERNATIONAL) -endif() - blender_add_lib(bf_editor_uvedit "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") |