Transform: Full snapping support for Vert Slide

Now all options for "snap to" affect the Vert Slide mode.

Reviewed By: campbellbarton

Maniphest Tasks: T66426

Differential Revision: https://developer.blender.org/D3440
This commit is contained in:
2020-06-22 09:07:51 -03:00
parent 85c6f0b472
commit e2fc9a88bc
6 changed files with 70 additions and 14 deletions

View File

@@ -320,7 +320,7 @@ static void axisProjection(const TransInfo *t,
/**
* Snap to the intersection between the edge direction and the constraint plane.
*/
static void constraint_plane_to_edge(const TransInfo *t, const float plane[4], float r_out[3])
static void constraint_snap_plane_to_edge(const TransInfo *t, const float plane[4], float r_out[3])
{
float lambda;
const float *edge_snap_point = t->tsnap.snapPoint;
@@ -336,7 +336,7 @@ static void constraint_plane_to_edge(const TransInfo *t, const float plane[4], f
* Snap to the nearest point between the snap point and the line that
* intersects the face plane with the constraint plane.
*/
static void constraint_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3])
static void constraint_snap_plane_to_face(const TransInfo *t, const float plane[4], float r_out[3])
{
float face_plane[4], isect_orig[3], isect_dir[3];
const float *face_snap_point = t->tsnap.snapPoint;
@@ -352,7 +352,9 @@ static void constraint_plane_to_face(const TransInfo *t, const float plane[4], f
/**
* Snap to the nearest point on the axis to the edge/line element.
*/
static void constraint_axis_to_edge(const TransInfo *t, const float axis[3], float r_out[3])
void transform_constraint_snap_axis_to_edge(const TransInfo *t,
const float axis[3],
float r_out[3])
{
float lambda;
const float *edge_snap_point = t->tsnap.snapPoint;
@@ -367,7 +369,9 @@ static void constraint_axis_to_edge(const TransInfo *t, const float axis[3], flo
/**
* Snap to the intersection of the axis and the plane defined by the face.
*/
static void constraint_axis_to_face(const TransInfo *t, const float axis[3], float r_out[3])
void transform_constraint_snap_axis_to_face(const TransInfo *t,
const float axis[3],
float r_out[3])
{
float lambda;
float face_plane[4];
@@ -444,10 +448,10 @@ static void applyAxisConstraintVec(
constraint_plane_calc(t, plane);
if (is_snap_to_edge) {
constraint_plane_to_edge(t, plane, out);
constraint_snap_plane_to_edge(t, plane, out);
}
else if (is_snap_to_face) {
constraint_plane_to_face(t, plane, out);
constraint_snap_plane_to_face(t, plane, out);
}
else {
/* View alignment correction. */
@@ -471,10 +475,10 @@ static void applyAxisConstraintVec(
}
if (is_snap_to_edge) {
constraint_axis_to_edge(t, c, out);
transform_constraint_snap_axis_to_edge(t, c, out);
}
else if (is_snap_to_face) {
constraint_axis_to_face(t, c, out);
transform_constraint_snap_axis_to_face(t, c, out);
}
else {
/* View alignment correction. */

View File

@@ -27,6 +27,12 @@
struct TransInfo;
void constraintNumInput(TransInfo *t, float vec[3]);
void transform_constraint_snap_axis_to_edge(const TransInfo *t,
const float axis[3],
float r_out[3]);
void transform_constraint_snap_axis_to_face(const TransInfo *t,
const float axis[3],
float r_out[3]);
void setConstraint(TransInfo *t, int mode, const char text[]);
void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[]);
void setLocalConstraint(TransInfo *t, int mode, const char text[]);

View File

@@ -215,11 +215,6 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
}
}
static float TranslationBetween(TransInfo *UNUSED(t), const float p1[3], const float p2[3])
{
return len_squared_v3v3(p1, p2);
}
static void ApplySnapTranslation(TransInfo *t, float vec[3])
{
float point[3];
@@ -411,7 +406,7 @@ void initTranslation(TransInfo *t)
t->transform = applyTranslation;
t->tsnap.applySnap = ApplySnapTranslation;
t->tsnap.distance = TranslationBetween;
t->tsnap.distance = transform_snap_distance_len_squared_fn;
initMouseInputMode(t, &t->mouse, INPUT_VECTOR);

View File

@@ -47,6 +47,7 @@
#include "BLT_translation.h"
#include "transform.h"
#include "transform_constraints.h"
#include "transform_convert.h"
#include "transform_mode.h"
#include "transform_snap.h"
@@ -538,6 +539,37 @@ void doVertSlide(TransInfo *t, float perc)
}
}
static void vert_slide_snap_apply(TransInfo *t, float *value)
{
TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t);
VertSlideData *sld = tc->custom.mode.data;
TransDataVertSlideVert *sv = &sld->sv[sld->curr_sv_index];
float snap_point[3], co_orig_3d[3], co_curr_3d[3], dvec[3];
copy_v3_v3(co_orig_3d, sv->co_orig_3d);
copy_v3_v3(co_curr_3d, sv->co_link_orig_3d[sv->co_link_curr]);
if (tc->use_local_mat) {
mul_m4_v3(tc->mat, co_orig_3d);
mul_m4_v3(tc->mat, co_curr_3d);
}
getSnapPoint(t, dvec);
sub_v3_v3(dvec, t->tsnap.snapTarget);
if (t->tsnap.snapElem & (SCE_SNAP_MODE_EDGE | SCE_SNAP_MODE_FACE)) {
float co_dir_3d[3];
sub_v3_v3v3(co_dir_3d, co_curr_3d, co_orig_3d);
if (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) {
transform_constraint_snap_axis_to_edge(t, co_dir_3d, dvec);
}
else {
transform_constraint_snap_axis_to_face(t, co_dir_3d, dvec);
}
}
add_v3_v3v3(snap_point, co_orig_3d, dvec);
*value = line_point_factor_v3(snap_point, co_orig_3d, co_curr_3d);
}
static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
{
char str[UI_MAX_DRAW_STR];
@@ -551,6 +583,7 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
final = t->values[0];
applySnapping(t, &final);
snapGridIncrement(t, &final);
/* only do this so out of range values are not displayed */
@@ -596,6 +629,8 @@ void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
t->mode = TFM_VERT_SLIDE;
t->transform = applyVertSlide;
t->handleEvent = handleEventVertSlide;
t->tsnap.applySnap = vert_slide_snap_apply;
t->tsnap.distance = transform_snap_distance_len_squared_fn;
{
VertSlideParams *slp = MEM_callocN(sizeof(*slp), __func__);

View File

@@ -124,6 +124,9 @@ bool transformModeUseSnap(const TransInfo *t)
if (t->mode == TFM_RESIZE) {
return (ts->snap_transform_mode_flag & SCE_SNAP_TRANSFORM_MODE_SCALE) != 0;
}
if (t->mode == TFM_VERT_SLIDE) {
return true;
}
return false;
}
@@ -1540,3 +1543,14 @@ static void applyGridIncrement(
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Generic callbacks
* \{ */
float transform_snap_distance_len_squared_fn(TransInfo *UNUSED(t), const float p1[3], const float p2[3])
{
return len_squared_v3v3(p1, p2);
}
/** \} */

View File

@@ -87,4 +87,6 @@ void addSnapPoint(TransInfo *t);
eRedrawFlag updateSelectedSnapPoint(TransInfo *t);
void removeSnapPoint(TransInfo *t);
float transform_snap_distance_len_squared_fn(TransInfo *t, const float p1[3], const float p2[3]);
#endif /* __TRANSFORM_SNAP_H__ */