Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_select.c
| Show First 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
| /* TODO: should return whether there is valid context to continue */ | /* TODO: should return whether there is valid context to continue */ | ||||
| void view3d_set_viewcontext(bContext *C, ViewContext *vc) | void view3d_set_viewcontext(bContext *C, ViewContext *vc) | ||||
| { | { | ||||
| memset(vc, 0, sizeof(ViewContext)); | memset(vc, 0, sizeof(ViewContext)); | ||||
| vc->ar = CTX_wm_region(C); | vc->ar = CTX_wm_region(C); | ||||
| vc->depsgraph = CTX_data_depsgraph(C); | vc->depsgraph = CTX_data_depsgraph(C); | ||||
| vc->scene = CTX_data_scene(C); | vc->scene = CTX_data_scene(C); | ||||
| vc->scene_layer = CTX_data_scene_layer(C); | vc->view_layer = CTX_data_view_layer(C); | ||||
| vc->engine = CTX_data_engine(C); | vc->engine = CTX_data_engine(C); | ||||
| vc->v3d = CTX_wm_view3d(C); | vc->v3d = CTX_wm_view3d(C); | ||||
| vc->win = CTX_wm_window(C); | vc->win = CTX_wm_window(C); | ||||
| vc->rv3d = CTX_wm_region_view3d(C); | vc->rv3d = CTX_wm_region_view3d(C); | ||||
| vc->obact = CTX_data_active_object(C); | vc->obact = CTX_data_active_object(C); | ||||
| vc->obedit = CTX_data_edit_object(C); | vc->obedit = CTX_data_edit_object(C); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Lines | if (data.is_changed) { | ||||
| bArmature *arm = ob->data; | bArmature *arm = ob->data; | ||||
| if (arm->flag & ARM_HAS_VIZ_DEPS) { | if (arm->flag & ARM_HAS_VIZ_DEPS) { | ||||
| /* mask modifier ('armature' mode), etc. */ | /* mask modifier ('armature' mode), etc. */ | ||||
| DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | DEG_id_tag_update(&ob->id, OB_RECALC_DATA); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void object_deselect_all_visible(SceneLayer *sl) | static void object_deselect_all_visible(ViewLayer *sl) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| for (base = sl->object_bases.first; base; base = base->next) { | for (base = sl->object_bases.first; base; base = base->next) { | ||||
| if (BASE_SELECTABLE(base)) { | if (BASE_SELECTABLE(base)) { | ||||
| ED_object_base_select(base, BA_DESELECT); | ED_object_base_select(base, BA_DESELECT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void do_lasso_select_objects(ViewContext *vc, const int mcords[][2], const short moves, | static void do_lasso_select_objects(ViewContext *vc, const int mcords[][2], const short moves, | ||||
| const bool extend, const bool select) | const bool extend, const bool select) | ||||
| { | { | ||||
| Base *base; | Base *base; | ||||
| if (extend == false && select) | if (extend == false && select) | ||||
| object_deselect_all_visible(vc->scene_layer); | object_deselect_all_visible(vc->view_layer); | ||||
| for (base = vc->scene_layer->object_bases.first; base; base = base->next) { | for (base = vc->view_layer->object_bases.first; base; base = base->next) { | ||||
| if (BASE_SELECTABLE(base)) { /* use this to avoid un-needed lasso lookups */ | if (BASE_SELECTABLE(base)) { /* use this to avoid un-needed lasso lookups */ | ||||
| if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) { | if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) { | ||||
| if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) { | if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) { | ||||
| ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); | ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT); | ||||
| } | } | ||||
| } | } | ||||
| if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) { | if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) { | ||||
| ▲ Show 20 Lines • Show All 645 Lines • ▼ Show 20 Lines | void VIEW3D_OT_select_menu(wmOperatorType *ot) | ||||
| prop = RNA_def_enum(ot->srna, "name", DummyRNA_NULL_items, 0, "Object Name", ""); | prop = RNA_def_enum(ot->srna, "name", DummyRNA_NULL_items, 0, "Object Name", ""); | ||||
| RNA_def_enum_funcs(prop, object_select_menu_enum_itemf); | RNA_def_enum_funcs(prop, object_select_menu_enum_itemf); | ||||
| RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE); | RNA_def_property_flag(prop, PROP_HIDDEN | PROP_ENUM_NO_TRANSLATE); | ||||
| ot->prop = prop; | ot->prop = prop; | ||||
| RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle selection instead of deselecting everything first"); | RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle selection instead of deselecting everything first"); | ||||
| } | } | ||||
| static void deselectall_except(SceneLayer *sl, Base *b) /* deselect all except b */ | static void deselectall_except(ViewLayer *sl, Base *b) /* deselect all except b */ | ||||
| { | { | ||||
| for (Base *base = sl->object_bases.first; base; base = base->next) { | for (Base *base = sl->object_bases.first; base; base = base->next) { | ||||
| if (base->flag & BASE_SELECTED) { | if (base->flag & BASE_SELECTED) { | ||||
| if (b != base) { | if (b != base) { | ||||
| ED_object_base_select(base, BA_DESELECT); | ED_object_base_select(base, BA_DESELECT); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 200 Lines • ▼ Show 20 Lines | finally: | ||||
| return hits; | return hits; | ||||
| } | } | ||||
| /* returns basact */ | /* returns basact */ | ||||
| static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int hits, | static Base *mouse_select_eval_buffer(ViewContext *vc, unsigned int *buffer, int hits, | ||||
| Base *startbase, bool has_bones, bool do_nearest) | Base *startbase, bool has_bones, bool do_nearest) | ||||
| { | { | ||||
| SceneLayer *sl = vc->scene_layer; | ViewLayer *sl = vc->view_layer; | ||||
| Base *base, *basact = NULL; | Base *base, *basact = NULL; | ||||
| int a; | int a; | ||||
| if (do_nearest) { | if (do_nearest) { | ||||
| unsigned int min = 0xFFFFFFFF; | unsigned int min = 0xFFFFFFFF; | ||||
| int selcol = 0, notcol = 0; | int selcol = 0, notcol = 0; | ||||
| ▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2]) | ||||
| CTX_data_eval_ctx(C, &eval_ctx); | CTX_data_eval_ctx(C, &eval_ctx); | ||||
| view3d_set_viewcontext(C, &vc); | view3d_set_viewcontext(C, &vc); | ||||
| hits = mixed_bones_object_selectbuffer(&eval_ctx, &vc, buffer, mval, false, false, &do_nearest); | hits = mixed_bones_object_selectbuffer(&eval_ctx, &vc, buffer, mval, false, false, &do_nearest); | ||||
| if (hits > 0) { | if (hits > 0) { | ||||
| const bool has_bones = selectbuffer_has_bones(buffer, hits); | const bool has_bones = selectbuffer_has_bones(buffer, hits); | ||||
| basact = mouse_select_eval_buffer(&vc, buffer, hits, vc.scene_layer->object_bases.first, has_bones, do_nearest); | basact = mouse_select_eval_buffer(&vc, buffer, hits, vc.view_layer->object_bases.first, has_bones, do_nearest); | ||||
| } | } | ||||
| return basact; | return basact; | ||||
| } | } | ||||
| static void deselect_all_tracks(MovieTracking *tracking) | static void deselect_all_tracks(MovieTracking *tracking) | ||||
| { | { | ||||
| MovieTrackingObject *object; | MovieTrackingObject *object; | ||||
| Show All 17 Lines | |||||
| static bool ed_object_select_pick( | static bool ed_object_select_pick( | ||||
| bContext *C, const int mval[2], | bContext *C, const int mval[2], | ||||
| bool extend, bool deselect, bool toggle, bool obcenter, bool enumerate, bool object) | bool extend, bool deselect, bool toggle, bool obcenter, bool enumerate, bool object) | ||||
| { | { | ||||
| EvaluationContext eval_ctx; | EvaluationContext eval_ctx; | ||||
| ViewContext vc; | ViewContext vc; | ||||
| ARegion *ar = CTX_wm_region(C); | ARegion *ar = CTX_wm_region(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| SceneLayer *sl = CTX_data_scene_layer(C); | ViewLayer *sl = CTX_data_view_layer(C); | ||||
| Base *base, *startbase = NULL, *basact = NULL, *oldbasact = NULL; | Base *base, *startbase = NULL, *basact = NULL, *oldbasact = NULL; | ||||
| bool is_obedit; | bool is_obedit; | ||||
| float dist = ED_view3d_select_dist_px() * 1.3333f; | float dist = ED_view3d_select_dist_px() * 1.3333f; | ||||
| bool retval = false; | bool retval = false; | ||||
| int hits; | int hits; | ||||
| const float mval_fl[2] = {(float)mval[0], (float)mval[1]}; | const float mval_fl[2] = {(float)mval[0], (float)mval[1]}; | ||||
| ▲ Show 20 Lines • Show All 641 Lines • ▼ Show 20 Lines | if (bone_only) { | ||||
| { | { | ||||
| if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) { | if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) { | ||||
| pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); | pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL); | ||||
| } | } | ||||
| } | } | ||||
| CTX_DATA_END; | CTX_DATA_END; | ||||
| } | } | ||||
| else { | else { | ||||
| object_deselect_all_visible(vc->scene_layer); | object_deselect_all_visible(vc->view_layer); | ||||
| } | } | ||||
| } | } | ||||
| /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ | /* selection buffer now has bones potentially too, so we add MAXPICKBUF */ | ||||
| vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(unsigned int), "selection buffer"); | vbuffer = MEM_mallocN(4 * (totobj + MAXPICKELEMS) * sizeof(unsigned int), "selection buffer"); | ||||
| hits = view3d_opengl_select(&eval_ctx, vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL); | hits = view3d_opengl_select(&eval_ctx, vc, vbuffer, 4 * (totobj + MAXPICKELEMS), rect, VIEW3D_SELECT_ALL); | ||||
| /* | /* | ||||
| * LOGIC NOTES (theeth): | * LOGIC NOTES (theeth): | ||||
| Show All 10 Lines | if (hits > 0) { /* no need to loop if there's no hit */ | ||||
| /* The draw order doesn't always match the order we populate the engine, see: T51695. */ | /* The draw order doesn't always match the order we populate the engine, see: T51695. */ | ||||
| qsort(vbuffer, hits, sizeof(uint[4]), opengl_select_buffer_cmp); | qsort(vbuffer, hits, sizeof(uint[4]), opengl_select_buffer_cmp); | ||||
| /* | /* | ||||
| * Even though 'DRW_draw_select_loop' uses 'DEG_OBJECT_ITER', | * Even though 'DRW_draw_select_loop' uses 'DEG_OBJECT_ITER', | ||||
| * we can be sure the order remains the same between both. | * we can be sure the order remains the same between both. | ||||
| */ | */ | ||||
| for (base = vc->scene_layer->object_bases.first; base && hits; base = base->next) { | for (base = vc->view_layer->object_bases.first; base && hits; base = base->next) { | ||||
| if (BASE_SELECTABLE(base)) { | if (BASE_SELECTABLE(base)) { | ||||
| while (base->object->select_color == (*col & 0xFFFF)) { /* we got an object */ | while (base->object->select_color == (*col & 0xFFFF)) { /* we got an object */ | ||||
| if (*col & 0xFFFF0000) { /* we got a bone */ | if (*col & 0xFFFF0000) { /* we got a bone */ | ||||
| bone = get_indexed_bone(base->object, *col & ~(BONESEL_ANY)); | bone = get_indexed_bone(base->object, *col & ~(BONESEL_ANY)); | ||||
| if (bone) { | if (bone) { | ||||
| if (select) { | if (select) { | ||||
| if ((bone->flag & BONE_UNSELECTABLE) == 0) { | if ((bone->flag & BONE_UNSELECTABLE) == 0) { | ||||
| bone->flag |= BONE_SELECTED; | bone->flag |= BONE_SELECTED; | ||||
| ▲ Show 20 Lines • Show All 718 Lines • ▼ Show 20 Lines | case OB_MBALL: | ||||
| break; | break; | ||||
| default: | default: | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| static bool object_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad) | static bool object_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad) | ||||
| { | { | ||||
| SceneLayer *sl = vc->scene_layer; | ViewLayer *sl = vc->view_layer; | ||||
| const float radius_squared = rad * rad; | const float radius_squared = rad * rad; | ||||
| const float mval_fl[2] = {mval[0], mval[1]}; | const float mval_fl[2] = {mval[0], mval[1]}; | ||||
| bool changed = false; | bool changed = false; | ||||
| const int select_flag = select ? BASE_SELECTED : 0; | const int select_flag = select ? BASE_SELECTED : 0; | ||||
| Base *base; | Base *base; | ||||
| for (base = FIRSTBASE(sl); base; base = base->next) { | for (base = FIRSTBASE(sl); base; base = base->next) { | ||||
| ▲ Show 20 Lines • Show All 87 Lines • Show Last 20 Lines | |||||