Blender  V3.3
transform_mode_tosphere.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdlib.h>
9 
10 #include "BLI_math.h"
11 #include "BLI_string.h"
12 #include "BLI_task.h"
13 
14 #include "MEM_guardedalloc.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_unit.h"
18 
19 #include "ED_screen.h"
20 
21 #include "UI_interface.h"
22 
23 #include "BLT_translation.h"
24 
25 #include "transform.h"
26 #include "transform_convert.h"
27 #include "transform_snap.h"
28 
29 #include "transform_mode.h"
30 
31 /* -------------------------------------------------------------------- */
35 struct ToSphereInfo {
37  float radius;
38 };
39 
42 {
43  struct ToSphereInfo *data = t->custom.mode.data;
44  float radius = 0.0f;
45  float vec[3];
46 
47  const bool is_local_center = transdata_check_local_center(t, t->around);
48  const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
49 
50  if (t->flag & T_PROP_EDIT_ALL) {
51  int factor_accum = 0.0f;
53  TransData *td = tc->data;
54  for (int i = 0; i < tc->data_len; i++, td++) {
55  if (td->factor == 0.0f) {
56  continue;
57  }
58  const float *center = is_local_center ? td->center : tc->center_local;
59  if (is_data_space) {
60  copy_v3_v3(vec, td->center);
61  }
62  else {
63  copy_v3_v3(vec, td->iloc);
64  }
65 
66  sub_v3_v3(vec, center);
67  radius += td->factor * len_v3(vec);
68  factor_accum += td->factor;
69  }
70  }
71  if (factor_accum != 0.0f) {
72  radius /= factor_accum;
73  }
74  }
75  else {
77  TransData *td = tc->data;
78  for (int i = 0; i < tc->data_len; i++, td++) {
79  const float *center = is_local_center ? td->center : tc->center_local;
80  if (is_data_space) {
81  copy_v3_v3(vec, td->center);
82  }
83  else {
84  copy_v3_v3(vec, td->iloc);
85  }
86 
87  sub_v3_v3(vec, center);
88  radius += len_v3(vec);
89  }
90  }
91  radius /= (float)t->data_len_all;
92  }
93 
94  data->prop_size_prev = t->prop_size;
95  data->radius = radius;
96 }
97 
100 /* -------------------------------------------------------------------- */
108  const TransInfo *t;
110  float ratio;
111  const struct ToSphereInfo to_sphere_info;
114 };
115 
117  const TransDataContainer *tc,
118  TransData *td,
119  const float ratio,
120  const struct ToSphereInfo *to_sphere_info,
121  const bool is_local_center,
122  const bool is_data_space)
123 {
124  float vec[3];
125  const float *center = is_local_center ? td->center : tc->center_local;
126  if (is_data_space) {
127  copy_v3_v3(vec, td->center);
128  }
129  else {
130  copy_v3_v3(vec, td->iloc);
131  }
132 
133  sub_v3_v3(vec, center);
134  const float radius = normalize_v3(vec);
135  const float tratio = ratio * td->factor;
136  mul_v3_fl(vec, radius * (1.0f - tratio) + to_sphere_info->radius * tratio);
137  add_v3_v3(vec, center);
138 
139  if (is_data_space) {
140  sub_v3_v3(vec, td->center);
141  mul_m3_v3(td->smtx, vec);
142  add_v3_v3(vec, td->iloc);
143  }
144 
145  copy_v3_v3(td->loc, vec);
146 }
147 
148 static void transdata_elem_to_sphere_fn(void *__restrict iter_data_v,
149  const int iter,
150  const TaskParallelTLS *__restrict UNUSED(tls))
151 {
152  struct TransDataArgs_ToSphere *data = iter_data_v;
153  TransData *td = &data->tc->data[iter];
154  if (td->flag & TD_SKIP) {
155  return;
156  }
158  data->tc,
159  td,
160  data->ratio,
161  &data->to_sphere_info,
162  data->is_local_center,
163  data->is_data_space);
164 }
165 
168 /* -------------------------------------------------------------------- */
172 static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
173 {
174  const bool is_local_center = transdata_check_local_center(t, t->around);
175  const bool is_data_space = (t->options & CTX_POSE_BONE) != 0;
176 
177  float ratio;
178  int i;
179  char str[UI_MAX_DRAW_STR];
180 
181  ratio = t->values[0] + t->values_modal_offset[0];
182 
184 
185  applyNumInput(&t->num, &ratio);
186 
187  CLAMP(ratio, 0.0f, 1.0f);
188 
189  t->values_final[0] = ratio;
190 
191  /* header print for NumInput */
192  if (hasNumInput(&t->num)) {
193  char c[NUM_STR_REP_LEN];
194 
195  outputNumInput(&(t->num), c, &t->scene->unit);
196 
197  BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %s %s"), c, t->proptext);
198  }
199  else {
200  /* default header print */
201  BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %.4f %s"), ratio, t->proptext);
202  }
203 
204  const struct ToSphereInfo *to_sphere_info = t->custom.mode.data;
205  if (to_sphere_info->prop_size_prev != t->prop_size) {
207  }
208 
210  if (tc->data_len < TRANSDATA_THREAD_LIMIT) {
211  TransData *td = tc->data;
212  for (i = 0; i < tc->data_len; i++, td++) {
213  if (td->flag & TD_SKIP) {
214  continue;
215  }
216  transdata_elem_to_sphere(t, tc, td, ratio, to_sphere_info, is_local_center, is_data_space);
217  }
218  }
219  else {
220  struct TransDataArgs_ToSphere data = {
221  .t = t,
222  .tc = tc,
223  .ratio = ratio,
224  .to_sphere_info = *to_sphere_info,
225  .is_local_center = is_local_center,
226  .is_data_space = is_data_space,
227  };
228  TaskParallelSettings settings;
231  }
232  }
233 
234  recalcData(t);
235 
236  ED_area_status_text(t->area, str);
237 }
238 
240 {
241  t->mode = TFM_TOSPHERE;
242  t->transform = applyToSphere;
243 
245 
246  t->idx_max = 0;
247  t->num.idx_max = 0;
248  t->snap[0] = 0.1f;
249  t->snap[1] = t->snap[0] * 0.1f;
250 
251  copy_v3_fl(t->num.val_inc, t->snap[0]);
252  t->num.unit_sys = t->scene->unit.system;
253  t->num.unit_type[0] = B_UNIT_NONE;
254 
255  t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
256  t->flag |= T_NO_CONSTRAINT;
257 
258  struct ToSphereInfo *data = MEM_callocN(sizeof(*data), __func__);
259  t->custom.mode.data = data;
260  t->custom.mode.use_free = true;
261 
263 }
264 
typedef float(TangentPoint)[2]
@ B_UNIT_NONE
Definition: BKE_unit.h:100
void mul_m3_v3(const float M[3][3], float r[3])
Definition: math_matrix.c:926
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3(float r[3], const float a[3])
MINLINE void mul_v3_fl(float r[3], float f)
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])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:94
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
Definition: BLI_task.h:293
#define UNUSED(x)
#define TIP_(msgid)
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:87
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:13
@ NUM_NO_NEGATIVE
Definition: ED_numinput.h:56
@ NUM_NULL_ONE
Definition: ED_numinput.h:55
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:189
bool hasNumInput(const NumInput *n)
Definition: numinput.c:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:792
@ TFM_TOSPHERE
Definition: ED_transform.h:34
NSNotificationCenter * center
_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
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position CLAMP
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:91
#define str(s)
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static unsigned c
Definition: RandGen.cpp:83
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
const struct ToSphereInfo to_sphere_info
const TransDataContainer * tc
float smtx[3][3]
void recalcData(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
#define TRANSDATA_THREAD_LIMIT
bool transdata_check_local_center(const TransInfo *t, short around)
transform modes used by different operators.
static void transdata_elem_to_sphere_fn(void *__restrict iter_data_v, const int iter, const TaskParallelTLS *__restrict UNUSED(tls))
static void transdata_elem_to_sphere(const TransInfo *UNUSED(t), const TransDataContainer *tc, TransData *td, const float ratio, const struct ToSphereInfo *to_sphere_info, const bool is_local_center, const bool is_data_space)
void initToSphere(TransInfo *t)
static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
static void to_sphere_radius_update(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)