Cleanup: use descriptive names for transform snapping functions
activeSnap --> transform_snap_is_active activeSnap_SnappingIndividual --> transform_snap_project_individual_is_active activeSnap_SnappingAsGroup --> transform_snap_mixed_is_active applySnappingIndividual --> transform_snap_project_individual_apply applySnappingAsGroup --> transform_snap_mixed_apply Also rearrange functions to be close to where they are used. And use static when possible.
This commit is contained in:
parent
39c30f6983
commit
63b9a57f8b
Notes:
blender-bot
2023-02-14 02:58:19 +01:00
Referenced by commit92449e634f
, Fix duplicate code in63b9a57f8b
|
@ -393,7 +393,7 @@ static void applyAxisConstraintVec(const TransInfo *t,
|
|||
if (!td && t->con.mode & CON_APPLY) {
|
||||
bool is_snap_to_point = false, is_snap_to_edge = false, is_snap_to_face = false;
|
||||
|
||||
if (activeSnap(t)) {
|
||||
if (transform_snap_is_active(t)) {
|
||||
if (validSnap(t)) {
|
||||
is_snap_to_edge = (t->tsnap.snapElem & SCE_SNAP_MODE_EDGE) != 0;
|
||||
is_snap_to_face = (t->tsnap.snapElem & SCE_SNAP_MODE_FACE_RAYCAST) != 0;
|
||||
|
|
|
@ -1193,7 +1193,7 @@ static void restoreBones(TransDataContainer *tc)
|
|||
static void recalcData_edit_armature(TransInfo *t)
|
||||
{
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -419,7 +419,7 @@ static void createTransCurveVerts(bContext *UNUSED(C), TransInfo *t)
|
|||
static void recalcData_curve(TransInfo *t)
|
||||
{
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -102,7 +102,7 @@ static void createTransLatticeVerts(bContext *UNUSED(C), TransInfo *t)
|
|||
static void recalcData_lattice(TransInfo *t)
|
||||
{
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -123,7 +123,7 @@ static void createTransMBallVerts(bContext *UNUSED(C), TransInfo *t)
|
|||
static void recalcData_mball(TransInfo *t)
|
||||
{
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
if (tc->data_len) {
|
||||
|
|
|
@ -1895,7 +1895,7 @@ static void tc_mesh_partial_types_calc(TransInfo *t, struct PartialTypeState *r_
|
|||
partial_for_looptri = PARTIAL_TYPE_GROUP;
|
||||
partial_for_normals = PARTIAL_TYPE_GROUP;
|
||||
/* Translation can rotate when snapping to normal. */
|
||||
if (activeSnap(t) && usingSnappingNormal(t) && validSnappingNormal(t)) {
|
||||
if (transform_snap_is_active(t) && usingSnappingNormal(t) && validSnappingNormal(t)) {
|
||||
partial_for_normals = PARTIAL_TYPE_ALL;
|
||||
}
|
||||
break;
|
||||
|
@ -1926,7 +1926,7 @@ static void tc_mesh_partial_types_calc(TransInfo *t, struct PartialTypeState *r_
|
|||
}
|
||||
|
||||
/* With projection, transform isn't affine. */
|
||||
if (activeSnap_SnappingIndividual(t)) {
|
||||
if (transform_snap_project_individual_is_active(t)) {
|
||||
if (partial_for_looptri == PARTIAL_TYPE_GROUP) {
|
||||
partial_for_looptri = PARTIAL_TYPE_ALL;
|
||||
}
|
||||
|
@ -2042,7 +2042,7 @@ static void recalcData_mesh(TransInfo *t)
|
|||
bool is_canceling = t->state == TRANS_CANCEL;
|
||||
/* Apply corrections. */
|
||||
if (!is_canceling) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
|
||||
bool do_mirror = !(t->flag & T_NO_MIRROR);
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -156,7 +156,7 @@ static void node_snap_grid_apply(TransInfo *t)
|
|||
{
|
||||
using namespace blender;
|
||||
|
||||
if (!(activeSnap(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
|
||||
if (!(transform_snap_is_active(t) && (t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -878,7 +878,7 @@ static void recalcData_objects(TransInfo *t)
|
|||
bool motionpath_update = false;
|
||||
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -92,7 +92,7 @@ static void recalcData_texspace(TransInfo *t)
|
|||
{
|
||||
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
|
||||
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
|
||||
|
|
|
@ -241,7 +241,7 @@ static void flushTransParticles(TransInfo *t)
|
|||
static void recalcData_particles(TransInfo *t)
|
||||
{
|
||||
if (t->state != TRANS_CANCEL) {
|
||||
applySnappingIndividual(t);
|
||||
transform_snap_project_individual_apply(t);
|
||||
}
|
||||
flushTransParticles(t);
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ static void applyNormalRotation(TransInfo *t, const int UNUSED(mval[2]))
|
|||
|
||||
transform_snap_increment(t, &angle);
|
||||
|
||||
applySnappingAsGroup(t, &angle);
|
||||
transform_snap_mixed_apply(t, &angle);
|
||||
|
||||
applyNumInput(&t->num, &angle);
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ static void applySeqSlide(TransInfo *t, const int UNUSED(mval[2]))
|
|||
}
|
||||
else {
|
||||
copy_v2_v2(values_final, t->values);
|
||||
applySnappingAsGroup(t, values_final);
|
||||
transform_snap_mixed_apply(t, values_final);
|
||||
transform_convert_sequencer_channel_clamp(t, values_final);
|
||||
|
||||
if (t->con.mode & CON_APPLY) {
|
||||
|
|
|
@ -1447,7 +1447,7 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
|
|||
|
||||
final = t->values[0] + t->values_modal_offset[0];
|
||||
|
||||
applySnappingAsGroup(t, &final);
|
||||
transform_snap_mixed_apply(t, &final);
|
||||
if (!validSnap(t)) {
|
||||
transform_snap_increment(t, &final);
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ static void applyResize(TransInfo *t, const int UNUSED(mval[2]))
|
|||
constraintNumInput(t, t->values_final);
|
||||
}
|
||||
|
||||
applySnappingAsGroup(t, t->values_final);
|
||||
transform_snap_mixed_apply(t, t->values_final);
|
||||
}
|
||||
|
||||
size_to_mat3(mat, t->values_final);
|
||||
|
|
|
@ -368,8 +368,8 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
|
|||
final = large_rotation_limit(final);
|
||||
}
|
||||
else {
|
||||
applySnappingAsGroup(t, &final);
|
||||
if (!(activeSnap(t) && validSnap(t))) {
|
||||
transform_snap_mixed_apply(t, &final);
|
||||
if (!(transform_snap_is_active(t) && validSnap(t))) {
|
||||
transform_snap_increment(t, &final);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2]))
|
|||
constraintNumInput(t, t->values_final);
|
||||
}
|
||||
|
||||
applySnappingAsGroup(t, t->values_final);
|
||||
transform_snap_mixed_apply(t, t->values_final);
|
||||
}
|
||||
|
||||
size_to_mat3(mat_final, t->values_final);
|
||||
|
|
|
@ -398,7 +398,7 @@ static void translate_snap_grid_apply(TransInfo *t,
|
|||
|
||||
static bool translate_snap_grid(TransInfo *t, float *val)
|
||||
{
|
||||
if (!activeSnap(t)) {
|
||||
if (!transform_snap_is_active(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -475,7 +475,7 @@ static void applyTranslationValue(TransInfo *t, const float vec[3])
|
|||
|
||||
enum eTranslateRotateMode rotate_mode = TRANSLATE_ROTATE_OFF;
|
||||
|
||||
if (activeSnap(t) && usingSnappingNormal(t) && validSnappingNormal(t)) {
|
||||
if (transform_snap_is_active(t) && usingSnappingNormal(t) && validSnappingNormal(t)) {
|
||||
rotate_mode = TRANSLATE_ROTATE_ON;
|
||||
}
|
||||
|
||||
|
@ -610,7 +610,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2]))
|
|||
}
|
||||
|
||||
t->tsnap.snapElem = SCE_SNAP_MODE_NONE;
|
||||
applySnappingAsGroup(t, global_dir);
|
||||
transform_snap_mixed_apply(t, global_dir);
|
||||
translate_snap_grid(t, global_dir);
|
||||
|
||||
if (t->con.mode & CON_APPLY) {
|
||||
|
@ -621,7 +621,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2]))
|
|||
|
||||
float incr_dir[3];
|
||||
copy_v3_v3(incr_dir, global_dir);
|
||||
if (!(activeSnap(t) && validSnap(t)) &&
|
||||
if (!(transform_snap_is_active(t) && validSnap(t)) &&
|
||||
transform_snap_increment_ex(t, (t->con.mode & CON_APPLY) != 0, incr_dir)) {
|
||||
|
||||
/* Test for mixed snap with grid. */
|
||||
|
|
|
@ -562,7 +562,7 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
|
|||
|
||||
final = t->values[0] + t->values_modal_offset[0];
|
||||
|
||||
applySnappingAsGroup(t, &final);
|
||||
transform_snap_mixed_apply(t, &final);
|
||||
if (!validSnap(t)) {
|
||||
transform_snap_increment(t, &final);
|
||||
}
|
||||
|
|
|
@ -119,50 +119,12 @@ bool validSnap(const TransInfo *t)
|
|||
(t->tsnap.status & (MULTI_POINTS | TARGET_INIT)) == (MULTI_POINTS | TARGET_INIT);
|
||||
}
|
||||
|
||||
bool activeSnap(const TransInfo *t)
|
||||
bool transform_snap_is_active(const TransInfo *t)
|
||||
{
|
||||
return ((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP) ||
|
||||
((t->modifiers & (MOD_SNAP | MOD_SNAP_INVERT)) == MOD_SNAP_INVERT);
|
||||
}
|
||||
|
||||
bool activeSnap_SnappingIndividual(const TransInfo *t)
|
||||
{
|
||||
if (!activeSnap(t) || (t->flag & T_NO_PROJECT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(t->tsnap.project || (t->tsnap.mode & SCE_SNAP_MODE_FACE_NEAREST))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doForceIncrementSnap(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool activeSnap_SnappingAsGroup(const TransInfo *t)
|
||||
{
|
||||
if (!activeSnap(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t->tsnap.mode == SCE_SNAP_MODE_FACE_RAYCAST && t->tsnap.project) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t->tsnap.mode == SCE_SNAP_MODE_FACE_NEAREST) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doForceIncrementSnap(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool transformModeUseSnap(const TransInfo *t)
|
||||
{
|
||||
ToolSettings *ts = t->settings;
|
||||
|
@ -190,7 +152,7 @@ static bool doForceIncrementSnap(const TransInfo *t)
|
|||
void drawSnapping(const struct bContext *C, TransInfo *t)
|
||||
{
|
||||
uchar col[4], selectedCol[4], activeCol[4];
|
||||
if (!activeSnap(t)) {
|
||||
if (!transform_snap_is_active(t)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -483,9 +445,30 @@ static void applyFaceNearest(TransInfo *t, TransDataContainer *tc, TransData *td
|
|||
/* TODO: support snap alignment similar to #SCE_SNAP_MODE_FACE_RAYCAST? */
|
||||
}
|
||||
|
||||
void applySnappingIndividual(TransInfo *t)
|
||||
bool transform_snap_project_individual_is_active(const TransInfo *t)
|
||||
{
|
||||
if (!activeSnap_SnappingIndividual(t)) {
|
||||
if (!transform_snap_is_active(t) || (t->flag & T_NO_PROJECT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!transform_snap_is_active(t) || (t->flag & T_NO_PROJECT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(t->tsnap.project || (t->tsnap.mode & SCE_SNAP_MODE_FACE_NEAREST))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doForceIncrementSnap(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void transform_snap_project_individual_apply(TransInfo *t)
|
||||
{
|
||||
if (!transform_snap_project_individual_is_active(t)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -514,9 +497,30 @@ void applySnappingIndividual(TransInfo *t)
|
|||
}
|
||||
}
|
||||
|
||||
void applySnappingAsGroup(TransInfo *t, float *vec)
|
||||
static bool transform_snap_mixed_is_active(const TransInfo *t)
|
||||
{
|
||||
if (!activeSnap_SnappingAsGroup(t)) {
|
||||
if (!transform_snap_is_active(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t->tsnap.mode == SCE_SNAP_MODE_FACE_RAYCAST && t->tsnap.project) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t->tsnap.mode == SCE_SNAP_MODE_FACE_NEAREST) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (doForceIncrementSnap(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void transform_snap_mixed_apply(TransInfo *t, float *vec)
|
||||
{
|
||||
if (!transform_snap_mixed_is_active(t)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -526,7 +530,7 @@ void applySnappingAsGroup(TransInfo *t, float *vec)
|
|||
t->tsnap.applySnap(t, vec);
|
||||
}
|
||||
else if (((t->tsnap.mode & ~(SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)) != 0) &&
|
||||
activeSnap(t)) {
|
||||
transform_snap_is_active(t)) {
|
||||
double current = PIL_check_seconds_timer();
|
||||
|
||||
/* Time base quirky code to go around find-nearest slowness. */
|
||||
|
@ -1628,7 +1632,7 @@ static void snap_increment_apply(const TransInfo *t,
|
|||
|
||||
bool transform_snap_increment_ex(const TransInfo *t, bool use_local_space, float *r_val)
|
||||
{
|
||||
if (!activeSnap(t)) {
|
||||
if (!transform_snap_is_active(t)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1664,8 +1668,9 @@ bool transform_snap_increment(const TransInfo *t, float *r_val)
|
|||
|
||||
float transform_snap_increment_get(const TransInfo *t)
|
||||
{
|
||||
if (activeSnap(t) && (!transformModeUseSnap(t) ||
|
||||
(t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
|
||||
if (transform_snap_is_active(t) &&
|
||||
(!transformModeUseSnap(t) ||
|
||||
(t->tsnap.mode & (SCE_SNAP_MODE_INCREMENT | SCE_SNAP_MODE_GRID)))) {
|
||||
return (t->modifiers & MOD_PRECISION) ? t->snap[1] : t->snap[0];
|
||||
}
|
||||
|
||||
|
|
|
@ -43,16 +43,15 @@ bool transform_snap_increment_ex(const TransInfo *t, bool use_local_space, float
|
|||
bool transform_snap_increment(const TransInfo *t, float *val);
|
||||
float transform_snap_increment_get(const TransInfo *t);
|
||||
|
||||
bool activeSnap(const TransInfo *t);
|
||||
bool activeSnap_SnappingIndividual(const TransInfo *t);
|
||||
bool activeSnap_SnappingAsGroup(const TransInfo *t);
|
||||
bool transform_snap_is_active(const TransInfo *t);
|
||||
|
||||
bool validSnap(const TransInfo *t);
|
||||
|
||||
void initSnapping(struct TransInfo *t, struct wmOperator *op);
|
||||
void freeSnapping(struct TransInfo *t);
|
||||
void applySnappingIndividual(TransInfo *t);
|
||||
void applySnappingAsGroup(TransInfo *t, float *vec);
|
||||
bool transform_snap_project_individual_is_active(const TransInfo *t);
|
||||
void transform_snap_project_individual_apply(TransInfo *t);
|
||||
void transform_snap_mixed_apply(TransInfo *t, float *vec);
|
||||
void resetSnapping(TransInfo *t);
|
||||
eRedrawFlag handleSnapping(TransInfo *t, const struct wmEvent *event);
|
||||
void drawSnapping(const struct bContext *C, TransInfo *t);
|
||||
|
|
|
@ -34,7 +34,7 @@ short getAnimEdit_SnapMode(TransInfo *t)
|
|||
}
|
||||
}
|
||||
else if (t->spacetype == SPACE_GRAPH) {
|
||||
if ((t->mode == TFM_TRANSLATION) && activeSnap(t)) {
|
||||
if ((t->mode == TFM_TRANSLATION) && transform_snap_is_active(t)) {
|
||||
return autosnap;
|
||||
}
|
||||
SpaceGraph *sipo = (SpaceGraph *)t->area->spacedata.first;
|
||||
|
|
Loading…
Reference in New Issue