Blender V4.3
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
9#include <cstdlib>
10
11#include "BLI_math_matrix.h"
12#include "BLI_math_vector.h"
13#include "BLI_string.h"
14
15#include "BKE_unit.hh"
16
17#include "ED_screen.hh"
18
19#include "UI_interface.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
30/* -------------------------------------------------------------------- */
34static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR])
35{
36 char tvec[NUM_STR_REP_LEN * 3];
37 if (hasNumInput(&t->num)) {
38 outputNumInput(&(t->num), tvec, &t->scene->unit);
39 }
40 else {
41 BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
42 BLI_snprintf(&tvec[NUM_STR_REP_LEN], NUM_STR_REP_LEN, "%.4f", vec[1]);
43 BLI_snprintf(&tvec[NUM_STR_REP_LEN * 2], NUM_STR_REP_LEN, "%.4f", vec[2]);
44 }
45
46 /* Hmm... perhaps the y-axis values don't need to be shown? */
47 if (t->con.mode & CON_APPLY) {
48 if (t->num.idx_max == 0) {
50 str, UI_MAX_DRAW_STR, IFACE_("ScaleB: %s%s %s"), &tvec[0], t->con.text, t->proptext);
51 }
52 else {
55 IFACE_("ScaleB: %s : %s : %s%s %s"),
56 &tvec[0],
57 &tvec[NUM_STR_REP_LEN],
58 &tvec[NUM_STR_REP_LEN * 2],
59 t->con.text,
60 t->proptext);
61 }
62 }
63 else {
66 IFACE_("ScaleB X: %s Y: %s Z: %s%s %s"),
67 &tvec[0],
68 &tvec[NUM_STR_REP_LEN],
69 &tvec[NUM_STR_REP_LEN * 2],
70 t->con.text,
71 t->proptext);
72 }
73}
74
77 TransData *td,
78 const float mat[3][3])
79{
80 float tmat[3][3], smat[3][3], oldy;
81 float sizemat[3][3];
82
83 mul_m3_m3m3(smat, mat, td->mtx);
84 mul_m3_m3m3(tmat, td->smtx, smat);
85
86 if (t->con.applySize) {
87 t->con.applySize(t, tc, td, tmat);
88 }
89
90 /* We've tucked the scale in loc. */
91 oldy = td->iloc[1];
92 size_to_mat3(sizemat, td->iloc);
93 mul_m3_m3m3(tmat, tmat, sizemat);
94 mat3_to_size(td->loc, tmat);
95 td->loc[1] = oldy;
96}
97
98static void applyBoneSize(TransInfo *t)
99{
100 float mat[3][3];
101 int i;
102 char str[UI_MAX_DRAW_STR];
103
104 if (t->flag & T_INPUT_IS_VALUES_FINAL) {
106 }
107 else {
108 float ratio = t->values[0];
109
110 copy_v3_fl(t->values_final, ratio);
112
114
115 if (applyNumInput(&t->num, t->values_final)) {
117 }
118 }
119
120 size_to_mat3(mat, t->values_final);
121
122 if (t->con.applySize) {
123 t->con.applySize(t, nullptr, nullptr, mat);
124 for (i = 0; i < 3; i++) {
125 if (!(t->con.mode & (CON_AXIS0 << i))) {
126 t->values_final[i] = 1.0f;
127 }
128 }
129 }
130
131 copy_m3_m3(t->mat, mat); /* Used in gizmo. */
132
134
136 TransData *td = tc->data;
137 for (i = 0; i < tc->data_len; i++, td++) {
138 if (td->flag & TD_SKIP) {
139 continue;
140 }
141
142 ElementBoneSize(t, tc, td, mat);
143 }
144 }
145
146 recalc_data(t);
147
149}
150
151static void initBoneSize(TransInfo *t, wmOperator * /*op*/)
152{
153 t->mode = TFM_BONESIZE;
154
156
157 t->idx_max = 2;
158 t->num.idx_max = 2;
159 t->num.val_flag[0] |= NUM_NULL_ONE;
160 t->num.val_flag[1] |= NUM_NULL_ONE;
161 t->num.val_flag[2] |= NUM_NULL_ONE;
162 t->num.flag |= NUM_AFFECT_ALL;
163 t->snap[0] = 0.1f;
164 t->snap[1] = t->snap[0] * 0.1f;
165
166 copy_v3_fl(t->num.val_inc, t->snap[0]);
167 t->num.unit_sys = t->scene->unit.system;
168 t->num.unit_type[0] = B_UNIT_NONE;
169 t->num.unit_type[1] = B_UNIT_NONE;
170 t->num.unit_type[2] = B_UNIT_NONE;
171}
172
176 /*flags*/ 0,
177 /*init_fn*/ initBoneSize,
178 /*transform_fn*/ applyBoneSize,
179 /*transform_matrix_fn*/ nullptr,
180 /*handle_event_fn*/ nullptr,
181 /*snap_distance_fn*/ nullptr,
182 /*snap_apply_fn*/ nullptr,
183 /*draw_fn*/ nullptr,
184};
@ B_UNIT_NONE
Definition BKE_unit.hh:106
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 BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define IFACE_(msgid)
@ NUM_AFFECT_ALL
#define NUM_STR_REP_LEN
void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings)
Definition numinput.cc:88
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
@ NUM_NULL_ONE
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:803
@ TFM_BONESIZE
#define UI_MAX_DRAW_STR
#define str(s)
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:366
char text[50]
Definition transform.hh:347
eTConstraint mode
Definition transform.hh:351
float smtx[3][3]
float mtx[3][3]
eTfmMode mode
Definition transform.hh:517
float snap[2]
Definition transform.hh:561
float values[4]
Definition transform.hh:624
char proptext[20]
Definition transform.hh:548
short idx_max
Definition transform.hh:559
float values_modal_offset[4]
Definition transform.hh:627
NumInput num
Definition transform.hh:540
Scene * scene
Definition transform.hh:654
eTFlag flag
Definition transform.hh:523
MouseInput mouse
Definition transform.hh:543
float values_final[4]
Definition transform.hh:632
float mat[3][3]
Definition transform.hh:589
TransCon con
Definition transform.hh:534
ScrArea * area
Definition transform.hh:651
@ INPUT_SPRING_FLIP
Definition transform.hh:744
@ CON_APPLY
Definition transform.hh:193
@ CON_AXIS0
Definition transform.hh:195
@ T_INPUT_IS_VALUES_FINAL
Definition transform.hh:115
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:854
void constraintNumInput(TransInfo *t, float vec[3])
void recalc_data(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
transform modes used by different operators.
static void applyBoneSize(TransInfo *t)
static void initBoneSize(TransInfo *t, wmOperator *)
static void ElementBoneSize(TransInfo *t, TransDataContainer *tc, TransData *td, const float mat[3][3])
static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR])
TransModeInfo TransMode_bboneresize
bool transform_snap_increment(const TransInfo *t, float *r_val)