Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-11-06 21:46:32 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-11-06 21:46:32 +0400
commit73986000902c34020f581a6ef7395a9259b7f6c2 (patch)
treeb79234644a3b81a66514abb3fe9e16e877294050 /source/blender/editors/transform/transform_snap.c
parent480d4317ded845dd69d167c909807290bddd77ab (diff)
True grid snapping for nodes: This snaps nodes to the actual background grid instead of using incremental offset (which is not useful for nodes). Increment snapping has been disabled for nodes to avoid
confusion, grid snap is now the default as it seems to be the most wanted and easy to use mode. Absolute grid snapping happens in a somewhat generic function 'applyGridAbsolute', which could also be used for objects and other transforms later on. It is conceptually similar to the 'project' snapping option, in that it calculates a delta vector for each element on top of the overall transform, which places each node on the grid. Node transform now uses the top-left node corner for TransformData->loc. The transform center is still the average of node centers, so that scaling and rotation works nicely. snapGrid*** functions have been renamed to snapGridIncrement*** to distinguish better between incremental and absolute grid snapping.
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c80
1 files changed, 72 insertions, 8 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 354164ce36f..5ace7e3a738 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -344,6 +344,70 @@ void applyProject(TransInfo *t)
}
}
+void applyGridAbsolute(TransInfo *t)
+{
+ float grid_size = 0.0f;
+ GearsType grid_action;
+ TransData *td;
+ float imat[4][4];
+ int i;
+
+ if (!(activeSnap(t) && (t->tsnap.mode == SCE_SNAP_MODE_GRID)))
+ return;
+
+ grid_action = BIG_GEARS;
+ if (t->modifiers & MOD_PRECISION)
+ grid_action = SMALL_GEARS;
+
+ switch (grid_action) {
+ case NO_GEARS: grid_size = t->snap[0]; break;
+ case BIG_GEARS: grid_size = t->snap[1]; break;
+ case SMALL_GEARS: grid_size = t->snap[2]; break;
+ }
+ /* early exit on unusable grid size */
+ if (grid_size == 0.0f)
+ return;
+
+ if (t->flag & (T_EDIT | T_POSE)) {
+ Object *ob = t->obedit ? t->obedit : t->poseobj;
+ invert_m4_m4(imat, ob->obmat);
+ }
+
+ for (i = 0, td = t->data; i < t->total; i++, td++) {
+ float iloc[3], loc[3], tvec[3];
+
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f))
+ continue;
+
+ copy_v3_v3(iloc, td->loc);
+ if (t->flag & (T_EDIT | T_POSE)) {
+ Object *ob = t->obedit ? t->obedit : t->poseobj;
+ mul_m4_v3(ob->obmat, iloc);
+ }
+ else if (t->flag & T_OBJECT) {
+ td->ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
+ BKE_object_handle_update(t->scene, td->ob);
+ copy_v3_v3(iloc, td->ob->obmat[3]);
+ }
+
+ mul_v3_v3fl(loc, iloc, 1.0f/grid_size);
+ loc[0] = floorf(loc[0]);
+ loc[1] = floorf(loc[1]);
+ loc[2] = floorf(loc[2]);
+ mul_v3_fl(loc, grid_size);
+
+ sub_v3_v3v3(tvec, loc, iloc);
+ mul_m3_v3(td->smtx, tvec);
+ add_v3_v3(td->loc, tvec);
+ }
+}
+
void applySnapping(TransInfo *t, float *vec)
{
/* project is not applied this way */
@@ -818,7 +882,7 @@ static float ResizeBetween(TransInfo *t, float p1[3], float p2[3])
static void UNUSED_FUNCTION(CalcSnapGrid) (TransInfo *t, float *UNUSED(vec))
{
- snapGridAction(t, t->tsnap.snapPoint, BIG_GEARS);
+ snapGridIncrementAction(t, t->tsnap.snapPoint, BIG_GEARS);
}
static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
@@ -2169,10 +2233,10 @@ bool snapNodesContext(bContext *C, const int mval[2], float *r_dist_px, float r_
/*================================================================*/
-static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], GearsType action);
+static void applyGridIncrement(TransInfo *t, float *val, int max_index, float fac[3], GearsType action);
-void snapGridAction(TransInfo *t, float *val, GearsType action)
+void snapGridIncrementAction(TransInfo *t, float *val, GearsType action)
{
float fac[3];
@@ -2180,11 +2244,11 @@ void snapGridAction(TransInfo *t, float *val, GearsType action)
fac[BIG_GEARS] = t->snap[1];
fac[SMALL_GEARS] = t->snap[2];
- applyGrid(t, val, t->idx_max, fac, action);
+ applyGridIncrement(t, val, t->idx_max, fac, action);
}
-void snapGrid(TransInfo *t, float *val)
+void snapGridIncrement(TransInfo *t, float *val)
{
GearsType action;
@@ -2198,17 +2262,17 @@ void snapGrid(TransInfo *t, float *val)
action = SMALL_GEARS;
}
- snapGridAction(t, val, action);
+ snapGridIncrementAction(t, val, action);
}
-static void applyGrid(TransInfo *t, float *val, int max_index, float fac[3], GearsType action)
+static void applyGridIncrement(TransInfo *t, float *val, int max_index, float fac[3], GearsType action)
{
int i;
float asp[3] = {1.0f, 1.0f, 1.0f}; // TODO: Remove hard coded limit here (3)
if (max_index > 2) {
- printf("applyGrid: invalid index %d, clamping\n", max_index);
+ printf("applyGridIncrement: invalid index %d, clamping\n", max_index);
max_index = 2;
}