Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_snap.c
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_mball.h" | #include "BKE_mball.h" | ||||
| #include "BKE_object.h" | #include "BKE_object.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "BKE_tracking.h" | #include "BKE_tracking.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "RNA_define.h" | #include "RNA_define.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| ▲ Show 20 Lines • Show All 431 Lines • ▼ Show 20 Lines | static int snap_curs_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| gridf = rv3d->gridview; | gridf = rv3d->gridview; | ||||
| curs = ED_view3d_cursor3d_get(scene, v3d)->location; | curs = ED_view3d_cursor3d_get(scene, v3d)->location; | ||||
| curs[0] = gridf * floorf(0.5f + curs[0] / gridf); | curs[0] = gridf * floorf(0.5f + curs[0] / gridf); | ||||
| curs[1] = gridf * floorf(0.5f + curs[1] / gridf); | curs[1] = gridf * floorf(0.5f + curs[1] / gridf); | ||||
| curs[2] = gridf * floorf(0.5f + curs[2] / gridf); | curs[2] = gridf * floorf(0.5f + curs[2] / gridf); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); /* hrm */ | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); /* hrm */ | ||||
| DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot) | void VIEW3D_OT_snap_cursor_to_grid(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Snap Cursor to Grid"; | ot->name = "Snap Cursor to Grid"; | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | static void bundle_midpoint(Scene *scene, Object *ob, float vec[3]) | ||||
| if (ok) { | if (ok) { | ||||
| mid_v3_v3v3(vec, min, max); | mid_v3_v3v3(vec, min, max); | ||||
| } | } | ||||
| } | } | ||||
| static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) | static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) | ||||
| { | { | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); | |||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| TransVertStore tvs = {NULL}; | TransVertStore tvs = {NULL}; | ||||
| TransVert *tv; | TransVert *tv; | ||||
| float bmat[3][3], vec[3], min[3], max[3], centroid[3]; | float bmat[3][3], vec[3], min[3], max[3], centroid[3]; | ||||
| int count, a; | int count, a; | ||||
| count = 0; | count = 0; | ||||
| INIT_MINMAX(min, max); | INIT_MINMAX(min, max); | ||||
| zero_v3(centroid); | zero_v3(centroid); | ||||
| if (obedit) { | if (obedit) { | ||||
| if (ED_transverts_check_obedit(obedit)) | if (ED_transverts_check_obedit(obedit)) | ||||
| ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); | ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES); | ||||
| if (tvs.transverts_tot == 0) { | if (tvs.transverts_tot == 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| copy_m3_m4(bmat, obedit->obmat); | Object *obedit_eval = DEG_get_evaluated_object(depsgraph, obedit); | ||||
| copy_m3_m4(bmat, obedit_eval->obmat); | |||||
| tv = tvs.transverts; | tv = tvs.transverts; | ||||
| for (a = 0; a < tvs.transverts_tot; a++, tv++) { | for (a = 0; a < tvs.transverts_tot; a++, tv++) { | ||||
| copy_v3_v3(vec, tv->loc); | copy_v3_v3(vec, tv->loc); | ||||
| mul_m3_v3(bmat, vec); | mul_m3_v3(bmat, vec); | ||||
| add_v3_v3(vec, obedit->obmat[3]); | add_v3_v3(vec, obedit_eval->obmat[3]); | ||||
| add_v3_v3(centroid, vec); | add_v3_v3(centroid, vec); | ||||
| minmax_v3v3_v3(min, max, vec); | minmax_v3v3_v3(min, max, vec); | ||||
| } | } | ||||
| if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEAN) { | if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEAN) { | ||||
| mul_v3_fl(centroid, 1.0f / (float)tvs.transverts_tot); | mul_v3_fl(centroid, 1.0f / (float)tvs.transverts_tot); | ||||
| copy_v3_v3(cursor, centroid); | copy_v3_v3(cursor, centroid); | ||||
| } | } | ||||
| else { | else { | ||||
| mid_v3_v3v3(cursor, min, max); | mid_v3_v3v3(cursor, min, max); | ||||
| } | } | ||||
| ED_transverts_free(&tvs); | ED_transverts_free(&tvs); | ||||
| } | } | ||||
| else { | else { | ||||
| Object *obact = CTX_data_active_object(C); | Object *obact_eval = OBACT(view_layer_eval); | ||||
brita_: @aligorith this is not working correctly! (snap to selected in pose mode)
can you help me… | |||||
| if (obact && (obact->mode & OB_MODE_POSE)) { | if (obact_eval && (obact_eval->mode & OB_MODE_POSE)) { | ||||
| bArmature *arm = obact->data; | bArmature *arm = obact_eval->data; | ||||
| bPoseChannel *pchan; | bPoseChannel *pchan; | ||||
| for (pchan = obact->pose->chanbase.first; pchan; pchan = pchan->next) { | for (pchan = obact_eval->pose->chanbase.first; pchan; pchan = pchan->next) { | ||||
| if (arm->layer & pchan->bone->layer) { | if (arm->layer & pchan->bone->layer) { | ||||
| if (pchan->bone->flag & BONE_SELECTED) { | if (pchan->bone->flag & BONE_SELECTED) { | ||||
| copy_v3_v3(vec, pchan->pose_head); | copy_v3_v3(vec, pchan->pose_head); | ||||
| mul_m4_v3(obact->obmat, vec); | mul_m4_v3(obact_eval->obmat, vec); | ||||
| add_v3_v3(centroid, vec); | add_v3_v3(centroid, vec); | ||||
| minmax_v3v3_v3(min, max, vec); | minmax_v3v3_v3(min, max, vec); | ||||
| count++; | count++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| CTX_DATA_BEGIN (C, Object *, ob, selected_objects) | FOREACH_SELECTED_OBJECT_BEGIN(view_layer_eval, ob_eval) | ||||
| { | { | ||||
| copy_v3_v3(vec, ob->obmat[3]); | copy_v3_v3(vec, ob_eval->obmat[3]); | ||||
| /* special case for camera -- snap to bundles */ | /* special case for camera -- snap to bundles */ | ||||
| if (ob->type == OB_CAMERA) { | if (ob_eval->type == OB_CAMERA) { | ||||
| /* snap to bundles should happen only when bundles are visible */ | /* snap to bundles should happen only when bundles are visible */ | ||||
| if (v3d->flag2 & V3D_SHOW_RECONSTRUCTION) { | if (v3d->flag2 & V3D_SHOW_RECONSTRUCTION) { | ||||
| bundle_midpoint(scene, ob, vec); | bundle_midpoint(scene, DEG_get_original_object(ob_eval), vec); | ||||
brita_AuthorUnsubmitted Not Done Inline Actionsno idea what this is. tracking related? then it can be checked later, because it is not high priority to have Spring starting to use 2.8 brita_: no idea what this is. tracking related? then it can be checked later, because it is not high… | |||||
| } | } | ||||
| } | } | ||||
| add_v3_v3(centroid, vec); | add_v3_v3(centroid, vec); | ||||
| minmax_v3v3_v3(min, max, vec); | minmax_v3v3_v3(min, max, vec); | ||||
| count++; | count++; | ||||
| } | } | ||||
| CTX_DATA_END; | FOREACH_SELECTED_OBJECT_END; | ||||
| } | } | ||||
| if (count == 0) { | if (count == 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEAN) { | if (scene->toolsettings->transform_pivot_point == V3D_AROUND_CENTER_MEAN) { | ||||
| mul_v3_fl(centroid, 1.0f / (float)count); | mul_v3_fl(centroid, 1.0f / (float)count); | ||||
| Show All 11 Lines | static int snap_curs_to_sel_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| float *curs; | float *curs; | ||||
| curs = ED_view3d_cursor3d_get(scene, v3d)->location; | curs = ED_view3d_cursor3d_get(scene, v3d)->location; | ||||
| if (snap_curs_to_sel_ex(C, curs)) { | if (snap_curs_to_sel_ex(C, curs)) { | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | ||||
| DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| Show All 14 Lines | |||||
| /* ********************************************** */ | /* ********************************************** */ | ||||
| /* this could be exported to be a generic function | /* this could be exported to be a generic function | ||||
| * see: calculateCenterActive */ | * see: calculateCenterActive */ | ||||
| static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]) | static bool snap_calc_active_center(bContext *C, const bool select_only, float r_center[3]) | ||||
| { | { | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| Object *obedit = CTX_data_edit_object(C); | Object *obedit = CTX_data_edit_object(C); | ||||
| if (obedit) { | if (obedit) { | ||||
| if (ED_object_editmode_calc_active_center(obedit, select_only, r_center)) { | Object *ob_edit_eval = DEG_get_evaluated_object(depsgraph, obedit); | ||||
| mul_m4_v3(obedit->obmat, r_center); | |||||
| if (ED_object_editmode_calc_active_center(ob_edit_eval, select_only, r_center)) { | |||||
| mul_m4_v3(ob_edit_eval->obmat, r_center); | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| if (ob) { | if (ob) { | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| if (ob->mode & OB_MODE_POSE) { | if (ob->mode & OB_MODE_POSE) { | ||||
| bPoseChannel *pchan = BKE_pose_channel_active(ob); | bPoseChannel *pchan = BKE_pose_channel_active(ob_eval); | ||||
| if (pchan) { | if (pchan) { | ||||
| if (!select_only || (pchan->bone->flag & BONE_SELECTED)) { | if (!select_only || (pchan->bone->flag & BONE_SELECTED)) { | ||||
| copy_v3_v3(r_center, pchan->pose_head); | copy_v3_v3(r_center, pchan->pose_head); | ||||
| mul_m4_v3(ob->obmat, r_center); | mul_m4_v3(ob_eval->obmat, r_center); | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (!select_only || (ob->flag & SELECT)) { | |||||
| copy_v3_v3(r_center, ob->obmat[3]); | if (!select_only || (ob_eval->flag & SELECT)) { | ||||
| copy_v3_v3(r_center, ob_eval->obmat[3]); | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static int snap_curs_to_active_exec(bContext *C, wmOperator *UNUSED(op)) | static int snap_curs_to_active_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| float *curs; | float *curs; | ||||
| curs = ED_view3d_cursor3d_get(scene, v3d)->location; | curs = ED_view3d_cursor3d_get(scene, v3d)->location; | ||||
| if (snap_calc_active_center(C, false, curs)) { | if (snap_calc_active_center(C, false, curs)) { | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | ||||
| DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| else { | else { | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| } | } | ||||
| } | } | ||||
| void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) | void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) | ||||
| Show All 18 Lines | static int snap_curs_to_center_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| float *curs; | float *curs; | ||||
| curs = ED_view3d_cursor3d_get(scene, v3d)->location; | curs = ED_view3d_cursor3d_get(scene, v3d)->location; | ||||
| zero_v3(curs); | zero_v3(curs); | ||||
| WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d); | ||||
| DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE); | |||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void VIEW3D_OT_snap_cursor_to_center(wmOperatorType *ot) | void VIEW3D_OT_snap_cursor_to_center(wmOperatorType *ot) | ||||
| { | { | ||||
| /* identifiers */ | /* identifiers */ | ||||
| ot->name = "Snap Cursor to Center"; | ot->name = "Snap Cursor to Center"; | ||||
| ot->description = "Snap cursor to the Center"; | ot->description = "Snap cursor to the Center"; | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||
@Joshua Leung (aligorith) this is not working correctly! (snap to selected in pose mode)
can you help me check why? snap to active is working well.
These 2 are giving different pointers!?
Object *obact_eval = OBACT(view_layer_eval);
Object *obact_eval2 = DEG_get_evaluated_object(depsgraph, CTX_data_active_object(C));