Fix T81951: Add Cube new tool surface snaping not working

For the `plane_depth` of type `PLACE_DEPTH_SURFACE` to take effect, a `snap_context` is needed.

But, even if a temporary `snap_context` was created for `plane_orient == PLACE_ORIENT_SURFACE`,
this context was not used for `plane_depth`.

So, use a temporary `snap_context` for `PLACE_DEPTH_SURFACE` (as it is done for `PLACE_ORIENT_SURFACE`).

Differential Revision: https://developer.blender.org/D9345
Differential Revision: https://developer.blender.org/D9435
This commit is contained in:
Germano Cavalcante 2020-11-10 10:59:25 -03:00 committed by Germano Cavalcante
parent 2ecab4c8a6
commit 23614c49e9
Notes: blender-bot 2023-02-14 05:36:11 +01:00
Referenced by issue #81951, Add Cube new tool surface snaping not working
1 changed files with 22 additions and 23 deletions

View File

@ -639,23 +639,27 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
}
}
SnapObjectContext *snap_context = NULL;
bool snap_context_free = false;
if ((plane_orient == PLACE_ORIENT_SURFACE) || (plane_depth == PLACE_DEPTH_SURFACE)) {
/* Need# snap_context */
if (ipd->snap_gizmo) {
snap_context = ED_gizmotypes_snap_3d_context_ensure(
ipd->scene, ipd->region, ipd->v3d, ipd->snap_gizmo);
}
else {
snap_context = ED_transform_snap_object_context_create_view3d(
ipd->scene, 0, ipd->region, ipd->v3d);
snap_context_free = true;
}
}
ipd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
ED_transform_calc_orientation_from_type(C, ipd->matrix_orient);
/* Set the orientation. */
if (plane_orient == PLACE_ORIENT_SURFACE) {
bool snap_context_free = false;
SnapObjectContext *snap_context =
(ipd->snap_gizmo ? ED_gizmotypes_snap_3d_context_ensure(
ipd->scene, ipd->region, ipd->v3d, ipd->snap_gizmo) :
NULL);
if (snap_context == NULL) {
snap_context = ED_transform_snap_object_context_create_view3d(
ipd->scene, 0, ipd->region, ipd->v3d);
snap_context_free = true;
}
if (snap_context && (plane_orient == PLACE_ORIENT_SURFACE)) {
float matrix_orient_surface[3][3];
/* Use the snap normal as a fallback in case the cursor isn't over a surface
@ -673,10 +677,6 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
matrix_orient_surface)) {
copy_m3_m3(ipd->matrix_orient, matrix_orient_surface);
}
if (snap_context_free) {
ED_transform_snap_object_context_destroy(snap_context);
}
}
ipd->orient_axis = plane_axis;
@ -751,13 +751,8 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
ipd->v3d, ipd->region, ipd->scene->cursor.location, mval_fl, ipd->co_src);
use_depth_fallback = false;
}
else if (plane_depth == PLACE_DEPTH_SURFACE) {
SnapObjectContext *snap_context =
(ipd->snap_gizmo ? ED_gizmotypes_snap_3d_context_ensure(
ipd->scene, ipd->region, ipd->v3d, ipd->snap_gizmo) :
NULL);
if ((snap_context != NULL) &&
ED_transform_snap_object_project_view3d(snap_context,
else if (snap_context && (plane_depth == PLACE_DEPTH_SURFACE)) {
if (ED_transform_snap_object_project_view3d(snap_context,
CTX_data_ensure_evaluated_depsgraph(C),
SCE_SNAP_MODE_FACE,
&(const struct SnapObjectParams){
@ -804,6 +799,10 @@ static void view3d_interactive_add_begin(bContext *C, wmOperator *op, const wmEv
ipd->step[0].plane, ipd->co_src, ipd->matrix_orient[ipd->orient_axis]);
copy_v3_v3(ipd->step[0].co_dst, ipd->co_src);
if (snap_context_free) {
ED_transform_snap_object_context_destroy(snap_context);
}
}
static int view3d_interactive_add_invoke(bContext *C, wmOperator *op, const wmEvent *event)