Blender  V2.93
transform_mode_resize.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdlib.h>
25 
26 #include "BLI_math.h"
27 
28 #include "BKE_context.h"
29 #include "BKE_unit.h"
30 
31 #include "ED_screen.h"
32 
33 #include "UI_interface.h"
34 
35 #include "transform.h"
36 #include "transform_constraints.h"
37 #include "transform_convert.h"
38 #include "transform_mode.h"
39 #include "transform_snap.h"
40 
41 /* -------------------------------------------------------------------- */
45 static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3])
46 {
47  float d1[3], d2[3], len_d1;
48 
49  sub_v3_v3v3(d1, p1, t->center_global);
50  sub_v3_v3v3(d2, p2, t->center_global);
51 
52  if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
53  mul_m3_v3(t->con.pmtx, d1);
54  mul_m3_v3(t->con.pmtx, d2);
55  }
56 
57  project_v3_v3v3(d1, d1, d2);
58 
59  len_d1 = len_v3(d1);
60 
61  /* Use 'invalid' dist when `center == p1` (after projecting),
62  * in this case scale will _never_ move the point in relation to the center,
63  * so it makes no sense to take it into account when scaling. see: T46503 */
64  return len_d1 != 0.0f ? len_v3(d2) / len_d1 : TRANSFORM_DIST_INVALID;
65 }
66 
67 static void ApplySnapResize(TransInfo *t, float vec[3])
68 {
69  float point[3];
70  getSnapPoint(t, point);
71 
72  float dist = ResizeBetween(t, t->tsnap.snapTarget, point);
73  if (dist != TRANSFORM_DIST_INVALID) {
74  copy_v3_fl(vec, dist);
75  }
76 }
77 
78 static void applyResize(TransInfo *t, const int UNUSED(mval[2]))
79 {
80  float mat[3][3];
81  int i;
82  char str[UI_MAX_DRAW_STR];
83 
84  if (t->flag & T_INPUT_IS_VALUES_FINAL) {
85  copy_v3_v3(t->values_final, t->values);
86  }
87  else {
88  float ratio = t->values[0];
89 
90  copy_v3_fl(t->values_final, ratio);
91 
92  transform_snap_increment(t, t->values_final);
93 
94  if (applyNumInput(&t->num, t->values_final)) {
95  constraintNumInput(t, t->values_final);
96  }
97 
98  applySnapping(t, t->values_final);
99  }
100 
101  size_to_mat3(mat, t->values_final);
102  if (t->con.mode & CON_APPLY) {
103  t->con.applySize(t, NULL, NULL, mat);
104 
105  /* Only so we have re-usable value with redo. */
106  float pvec[3] = {0.0f, 0.0f, 0.0f};
107  int j = 0;
108  for (i = 0; i < 3; i++) {
109  if (!(t->con.mode & (CON_AXIS0 << i))) {
110  t->values_final[i] = 1.0f;
111  }
112  else {
113  pvec[j++] = t->values_final[i];
114  }
115  }
116  headerResize(t, pvec, str);
117  }
118  else {
119  headerResize(t, t->values_final, str);
120  }
121 
122  copy_m3_m3(t->mat, mat); /* used in gizmo */
123 
125  TransData *td = tc->data;
126  for (i = 0; i < tc->data_len; i++, td++) {
127  if (td->flag & TD_SKIP) {
128  continue;
129  }
130 
131  ElementResize(t, tc, td, mat);
132  }
133  }
134 
135  /* Evil hack - redo resize if clipping needed. */
136  if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values_final, 1)) {
137  size_to_mat3(mat, t->values_final);
138 
139  if (t->con.mode & CON_APPLY) {
140  t->con.applySize(t, NULL, NULL, mat);
141  }
142 
144  TransData *td = tc->data;
145  for (i = 0; i < tc->data_len; i++, td++) {
146  ElementResize(t, tc, td, mat);
147  }
148 
149  /* In proportional edit it can happen that */
150  /* vertices in the radius of the brush end */
151  /* outside the clipping area */
152  /* XXX HACK - dg */
153  if (t->flag & T_PROP_EDIT) {
154  clipUVData(t);
155  }
156  }
157  }
158 
159  recalcData(t);
160 
161  ED_area_status_text(t->area, str);
162 }
163 
165 {
166  t->mode = TFM_RESIZE;
167  t->transform = applyResize;
168  t->tsnap.applySnap = ApplySnapResize;
169  t->tsnap.distance = ResizeBetween;
170 
172 
173  t->flag |= T_NULL_ONE;
174  t->num.val_flag[0] |= NUM_NULL_ONE;
175  t->num.val_flag[1] |= NUM_NULL_ONE;
176  t->num.val_flag[2] |= NUM_NULL_ONE;
177  t->num.flag |= NUM_AFFECT_ALL;
178  if ((t->flag & T_EDIT) == 0) {
179  t->flag |= T_NO_ZERO;
180 #ifdef USE_NUM_NO_ZERO
181  t->num.val_flag[0] |= NUM_NO_ZERO;
182  t->num.val_flag[1] |= NUM_NO_ZERO;
183  t->num.val_flag[2] |= NUM_NO_ZERO;
184 #endif
185  }
186 
187  t->idx_max = 2;
188  t->num.idx_max = 2;
189  t->snap[0] = 0.1f;
190  t->snap[1] = t->snap[0] * 0.1f;
191 
192  copy_v3_fl(t->num.val_inc, t->snap[0]);
193  t->num.unit_sys = t->scene->unit.system;
194  t->num.unit_type[0] = B_UNIT_NONE;
195  t->num.unit_type[1] = B_UNIT_NONE;
196  t->num.unit_type[2] = B_UNIT_NONE;
197 
199 }
@ B_UNIT_NONE
Definition: BKE_unit.h:78
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:930
void size_to_mat3(float R[3][3], const float size[3])
Definition: math_matrix.c:2105
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:89
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])
Definition: math_vector.c:674
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
#define UNUSED(x)
@ V3D_ORIENT_GLOBAL
@ NUM_NULL_ONE
Definition: ED_numinput.h:69
@ NUM_NO_ZERO
Definition: ED_numinput.h:71
@ NUM_AFFECT_ALL
Definition: ED_numinput.h:62
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:207
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:815
@ TFM_RESIZE
Definition: ED_transform.h:48
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:90
#define str(s)
@ INPUT_SPRING_FLIP
Definition: transform.h:730
@ CON_APPLY
Definition: transform.h:177
@ CON_AXIS0
Definition: transform.h:179
void recalcData(TransInfo *t)
@ T_PROP_EDIT
Definition: transform.h:111
@ T_INPUT_IS_VALUES_FINAL
Definition: transform.h:129
@ T_NULL_ONE
Definition: transform.h:107
@ T_CLIP_UV
Definition: transform.h:119
@ T_NO_ZERO
Definition: transform.h:108
@ T_EDIT
Definition: transform.h:102
#define TRANSFORM_DIST_INVALID
Definition: transform.h:804
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
void constraintNumInput(TransInfo *t, float vec[3])
void clipUVData(TransInfo *t)
bool clipUVTransform(TransInfo *t, float vec[2], const bool resize)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
void headerResize(TransInfo *t, const float vec[3], char str[UI_MAX_DRAW_STR])
void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3])
void transform_mode_default_modal_orientation_set(TransInfo *t, int type)
transform modes used by different operators.
void initResize(TransInfo *t)
static void ApplySnapResize(TransInfo *t, float vec[3])
static void applyResize(TransInfo *t, const int UNUSED(mval[2]))
static float ResizeBetween(TransInfo *t, const float p1[3], const float p2[3])
void applySnapping(TransInfo *t, float *vec)
bool transform_snap_increment(TransInfo *t, float *r_val)
void getSnapPoint(const TransInfo *t, float vec[3])