Blender V5.0
transform_mode_bbone_resize.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
15#include "BKE_unit.hh"
16
17#include "ED_screen.hh"
18
19#include "UI_interface_types.hh"
20
21#include "BLT_translation.hh"
22
23#include "transform.hh"
25#include "transform_convert.hh"
26#include "transform_snap.hh"
27
28#include "transform_mode.hh"
29
30namespace blender::ed::transform {
31
32/* -------------------------------------------------------------------- */
35
36static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR])
37{
38 char tvec[NUM_STR_REP_LEN * 3];
39 if (hasNumInput(&t->num)) {
40 outputNumInput(&(t->num), tvec, t->scene->unit);
41 }
42 else {
43 BLI_snprintf_utf8(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
44 BLI_snprintf_utf8(&tvec[NUM_STR_REP_LEN], NUM_STR_REP_LEN, "%.4f", vec[1]);
45 BLI_snprintf_utf8(&tvec[NUM_STR_REP_LEN * 2], NUM_STR_REP_LEN, "%.4f", vec[2]);
46 }
47
48 /* Hmm... perhaps the y-axis values don't need to be shown? */
49 if (t->con.mode & CON_APPLY) {
50 if (t->num.idx_max == 0) {
52 str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext);
53 }
54 else {
57 IFACE_("ScaleB: %s : %s : %s%s %s"),
58 &tvec[0],
59 &tvec[NUM_STR_REP_LEN],
60 &tvec[NUM_STR_REP_LEN * 2],
61 t->con.text,
62 t->proptext);
63 }
64 }
65 else {
68 IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"),
69 &tvec[0],
70 &tvec[NUM_STR_REP_LEN],
71 &tvec[NUM_STR_REP_LEN * 2],
72 t->con.text,
73 t->proptext);
74 }
75}
76
79 TransData *td,
80 const float mat[3][3])
81{
82 float tmat[3][3], smat[3][3], oldy;
83 float sizemat[3][3];
84
85 mul_m3_m3m3(smat, mat, td->mtx);
86 mul_m3_m3m3(tmat, td->smtx, smat);
87
88 if (t->con.applySize) {
89 t->con.applySize(t, tc, td, tmat);
90 }
91
92 /* We've tucked the scale in loc. */
93 oldy = td->iloc[1];
94 size_to_mat3(sizemat, td->iloc);
95 mul_m3_m3m3(tmat, tmat, sizemat);
96 mat3_to_size(td->loc, tmat);
97 td->loc[1] = oldy;
98}
99
101{
102 float mat[3][3];
103 int i;
104 char str[UI_MAX_DRAW_STR];
105
106 if (t->flag & T_INPUT_IS_VALUES_FINAL) {
108 }
109 else {
110 float ratio = t->values[0];
111
112 copy_v3_fl(t->values_final, ratio);
114
116
117 if (applyNumInput(&t->num, t->values_final)) {
119 }
120 }
121
122 size_to_mat3(mat, t->values_final);
123
124 if (t->con.applySize) {
125 t->con.applySize(t, nullptr, nullptr, mat);
126 for (i = 0; i < 3; i++) {
127 if (!(t->con.mode & (CON_AXIS0 << i))) {
128 t->values_final[i] = 1.0f;
129 }
130 }
131 }
132
133 copy_m3_m3(t->mat, mat); /* Used in gizmo. */
134
136
138 TransData *td = tc->data;
139 for (i = 0; i < tc->data_len; i++, td++) {
140 if (td->flag & TD_SKIP) {
141 continue;
142 }
143
144 ElementBoneSize(t, tc, td, mat);
145 }
146 }
147
148 recalc_data(t);
149
151}
152
153static void initBoneSize(TransInfo *t, wmOperator * /*op*/)
154{
155 t->mode = TFM_BONESIZE;
156
158
159 t->idx_max = 2;
160 t->num.idx_max = 2;
161 t->num.val_flag[0] |= NUM_NULL_ONE;
162 t->num.val_flag[1] |= NUM_NULL_ONE;
163 t->num.val_flag[2] |= NUM_NULL_ONE;
164 t->num.flag |= NUM_AFFECT_ALL;
165 t->increment = float3(0.1f);
166 t->increment_precision = 0.1f;
167
168 copy_v3_fl(t->num.val_inc, t->increment[0]);
169 t->num.unit_sys = t->scene->unit.system;
170 t->num.unit_type[0] = B_UNIT_NONE;
171 t->num.unit_type[1] = B_UNIT_NONE;
172 t->num.unit_type[2] = B_UNIT_NONE;
173}
174
176
178 /*flags*/ 0,
179 /*init_fn*/ initBoneSize,
180 /*transform_fn*/ applyBoneSize,
181 /*transform_matrix_fn*/ nullptr,
182 /*handle_event_fn*/ nullptr,
183 /*snap_distance_fn*/ nullptr,
184 /*snap_apply_fn*/ nullptr,
185 /*draw_fn*/ nullptr,
186};
187
188} // namespace blender::ed::transform
@ B_UNIT_NONE
Definition BKE_unit.hh:136
void size_to_mat3(float R[3][3], const float size[3])
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void mat3_to_size(float size[3], const float M[3][3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
@ NUM_AFFECT_ALL
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
@ NUM_NULL_ONE
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)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
static void ElementBoneSize(TransInfo *t, TransDataContainer *tc, TransData *td, const float mat[3][3])
bool transform_snap_increment(const TransInfo *t, float *r_val)
static void applyBoneSize(TransInfo *t)
static void initBoneSize(TransInfo *t, wmOperator *)
static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR])
void constraintNumInput(TransInfo *t, float vec[3])
VecBase< float, 3 > float3
short idx_max
short val_flag[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
short flag
struct UnitSettings unit
void(* applySize)(const TransInfo *t, const TransDataContainer *tc, const TransData *td, float r_smat[3][3])
Definition transform.hh:591
i
Definition text_draw.cc:230
#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.