Blender V5.0
transform_mode_push_pull.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_math_matrix.h"
12#include "BLI_math_vector.h"
13#include "BLI_string_utf8.h"
14#include "BLI_task.hh"
15
16#include "BKE_unit.hh"
17
18#include "ED_screen.hh"
19
20#include "BLT_translation.hh"
21
22#include "UI_interface_types.hh"
23
24#include "transform.hh"
26#include "transform_convert.hh"
27#include "transform_snap.hh"
28
29#include "transform_mode.hh"
30
31namespace blender::ed::transform {
32
33/* -------------------------------------------------------------------- */
36
38 const TransDataContainer *tc,
39 TransData *td,
40 const float distance,
41 const float axis_global[3],
42 const bool is_lock_constraint,
43 const bool is_data_space)
44{
45 float vec[3];
46 sub_v3_v3v3(vec, tc->center_local, td->center);
47 if (t->con.applyRot && t->con.mode & CON_APPLY) {
48 float axis[3];
49 copy_v3_v3(axis, axis_global);
50 t->con.applyRot(t, tc, td, axis);
51
52 mul_m3_v3(td->smtx, axis);
53 if (is_lock_constraint) {
54 float dvec[3];
55 project_v3_v3v3(dvec, vec, axis);
56 sub_v3_v3(vec, dvec);
57 }
58 else {
59 project_v3_v3v3(vec, vec, axis);
60 }
61 }
63 if (is_data_space) {
64 mul_m3_v3(td->smtx, vec);
65 }
66
67 add_v3_v3v3(td->loc, td->iloc, vec);
68}
69
70static void applyPushPull(TransInfo *t)
71{
72 float axis_global[3];
73 float distance;
74 char str[UI_MAX_DRAW_STR];
75
76 distance = t->values[0] + t->values_modal_offset[0];
77
79
81
82 t->values_final[0] = distance;
83
84 /* Header print for NumInput. */
85 if (hasNumInput(&t->num)) {
86 char c[NUM_STR_REP_LEN];
87
88 outputNumInput(&(t->num), c, t->scene->unit);
89
90 SNPRINTF_UTF8(str, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext);
91 }
92 else {
93 /* Default header print. */
94 SNPRINTF_UTF8(str, IFACE_("Push/Pull: %.4f%s %s"), distance, t->con.text, t->proptext);
95 }
96
97 if (t->con.applyRot && t->con.mode & CON_APPLY) {
98 t->con.applyRot(t, nullptr, nullptr, axis_global);
99 }
100
101 const bool is_lock_constraint = isLockConstraint(t);
102 const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
103
105 threading::parallel_for(IndexRange(tc->data_len), 1024, [&](const IndexRange range) {
106 for (const int i : range) {
107 TransData *td = &tc->data[i];
108 if (td->flag & TD_SKIP) {
109 continue;
110 }
111 transdata_elem_push_pull(
112 t, tc, td, distance, axis_global, is_lock_constraint, is_data_space);
113 }
114 });
115 }
116
117 recalc_data(t);
118
119 ED_area_status_text(t->area, str);
120}
121
122static void initPushPull(TransInfo *t, wmOperator * /*op*/)
123{
124 t->mode = TFM_PUSHPULL;
125
127
128 t->idx_max = 0;
129 t->num.idx_max = 0;
130 t->increment[0] = 1.0f;
131 t->increment_precision = 0.1f;
132
133 copy_v3_fl(t->num.val_inc, t->increment[0]);
134 t->num.unit_sys = t->scene->unit.system;
136}
137
139
141 /*flags*/ 0,
142 /*init_fn*/ initPushPull,
143 /*transform_fn*/ applyPushPull,
144 /*transform_matrix_fn*/ nullptr,
145 /*handle_event_fn*/ nullptr,
146 /*snap_distance_fn*/ nullptr,
147 /*snap_apply_fn*/ nullptr,
148 /*draw_fn*/ nullptr,
149};
150
151} // namespace blender::ed::transform
@ B_UNIT_LENGTH
Definition BKE_unit.hh:137
void mul_m3_v3(const float M[3][3], float r[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void project_v3_v3v3(float out[3], const float p[3], const float v_proj[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE float normalize_v3_length(float n[3], float unit_length)
#define SNPRINTF_UTF8(dst, format,...)
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:88
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:851
#define UI_MAX_DRAW_STR
#define str(s)
float distance(VecOp< float, D >, VecOp< float, D >) RET
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)
bool isLockConstraint(const TransInfo *t)
static void applyPushPull(TransInfo *t)
static void transdata_elem_push_pull(const TransInfo *t, const TransDataContainer *tc, TransData *td, const float distance, const float axis_global[3], const bool is_lock_constraint, const bool is_data_space)
static void initPushPull(TransInfo *t, wmOperator *)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
struct UnitSettings unit
void(* applyRot)(const TransInfo *t, const TransDataContainer *tc, const TransData *td, float r_axis[3])
Definition transform.hh:596
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.