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:
authorGermano Cavalcante <germano.costa@ig.com.br>2021-02-05 17:01:30 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-02-08 15:54:54 +0300
commitbe60b3b23984ff7a9b973a37800522e4b5e7918f (patch)
tree4bef4e93dc7c23e44d4fa0a7871f95f3a6e37f9a /source/blender/editors/transform/transform_snap.c
parentbc56c127704f937d7fdfee082975bc0fa01f4b52 (diff)
Transform: Grid snap target refactor
The code takes many turns to get a suitable "target" for the snap to grid. Perhaps there were other reasons awaited for `transformCenter_from_type` and `TransCenterData center_cache[5]`. But since nothing is defined, it is better to simplify the code. No user functional changes
Diffstat (limited to 'source/blender/editors/transform/transform_snap.c')
-rw-r--r--source/blender/editors/transform/transform_snap.c116
1 files changed, 61 insertions, 55 deletions
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 575c736cf51..8500ff25a1f 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -926,6 +926,64 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
/** \name Target
* \{ */
+static void snap_target_median_impl(TransInfo *t, float r_median[3])
+{
+ int i_accum = 0;
+
+ zero_v3(r_median);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ int i;
+ float v[3];
+ zero_v3(v);
+
+ for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
+ add_v3_v3(v, td->center);
+ }
+
+ if (i == 0) {
+ /* Is this possible? */
+ continue;
+ }
+
+ mul_v3_fl(v, 1.0 / i);
+
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->mat, v);
+ }
+
+ add_v3_v3(r_median, v);
+ i_accum++;
+ }
+
+ mul_v3_fl(r_median, 1.0 / i_accum);
+
+ // TargetSnapOffset(t, NULL);
+}
+
+static void snap_target_grid_ensure(TransInfo *t)
+{
+ /* Only need to calculate once. */
+ if ((t->tsnap.status & TARGET_GRID_INIT) == 0) {
+ if (t->data_type == TC_CURSOR_VIEW3D) {
+ /* Use a fallback when transforming the cursor.
+ * In this case the center is _not_ derived from the cursor which is being transformed. */
+ copy_v3_v3(t->tsnap.snapTargetGrid, TRANS_DATA_CONTAINER_FIRST_SINGLE(t)->data->iloc);
+ }
+ else if (t->around == V3D_AROUND_CURSOR) {
+ /* Use a fallback for cursor selection,
+ * this isn't useful as a global center for absolute grid snapping
+ * since its not based on the position of the selection. */
+ snap_target_median_impl(t, t->tsnap.snapTargetGrid);
+ }
+ else {
+ copy_v3_v3(t->tsnap.snapTargetGrid, t->center_global);
+ }
+ t->tsnap.status |= TARGET_GRID_INIT;
+ }
+}
+
static void TargetSnapOffset(TransInfo *t, TransData *td)
{
if (t->spacetype == SPACE_NODE && td != NULL) {
@@ -997,41 +1055,7 @@ static void TargetSnapMedian(TransInfo *t)
{
/* Only need to calculate once. */
if ((t->tsnap.status & TARGET_INIT) == 0) {
- int i_accum = 0;
-
- t->tsnap.snapTarget[0] = 0;
- t->tsnap.snapTarget[1] = 0;
- t->tsnap.snapTarget[2] = 0;
-
- FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- TransData *td = tc->data;
- int i;
- float v[3];
- zero_v3(v);
-
- for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
- add_v3_v3(v, td->center);
- }
-
- if (i == 0) {
- /* Is this possible? */
- continue;
- }
-
- mul_v3_fl(v, 1.0 / i);
-
- if (tc->use_local_mat) {
- mul_m4_v3(tc->mat, v);
- }
-
- add_v3_v3(t->tsnap.snapTarget, v);
- i_accum++;
- }
-
- mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum);
-
- TargetSnapOffset(t, NULL);
-
+ snap_target_median_impl(t, t->tsnap.snapTarget);
t->tsnap.status |= TARGET_INIT;
}
}
@@ -1431,28 +1455,10 @@ static void snap_grid_apply(
TransInfo *t, const int max_index, const float grid_dist, const float loc[3], float r_out[3])
{
BLI_assert(max_index <= 2);
- const float *center_global = t->center_global;
+ snap_target_grid_ensure(t);
+ const float *center_global = t->tsnap.snapTargetGrid;
const float *asp = t->aspect;
- if (t->options & CTX_CURSOR) {
- /* Note that we must already have called #transformCenter_from_type, otherwise
- * we would be lazy-initializing data which is being transformed,
- * causing the transformed cursor location to be used instead of it's initial location. */
- BLI_assert(t->center_cache[V3D_AROUND_CURSOR].is_set);
-
- /* Use a fallback when transforming the cursor.
- * In this case the center is _not_ derived from the cursor which is being transformed. */
- const TransCenterData *cd = transformCenter_from_type(t, V3D_AROUND_CURSOR);
- center_global = cd->global;
- }
- else if (t->around == V3D_AROUND_CURSOR) {
- /* Use a fallback for cursor selection,
- * this isn't useful as a global center for absolute grid snapping
- * since its not based on the position of the selection. */
- const TransCenterData *cd = transformCenter_from_type(t, V3D_AROUND_CENTER_MEDIAN);
- center_global = cd->global;
- }
-
float in[3];
if (t->con.mode & CON_APPLY) {
BLI_assert(t->tsnap.snapElem == 0);