Blender  V2.93
transform_mode_tosphere.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 #include "BLI_string.h"
28 
29 #include "MEM_guardedalloc.h"
30 
31 #include "BKE_context.h"
32 #include "BKE_unit.h"
33 
34 #include "ED_screen.h"
35 
36 #include "UI_interface.h"
37 
38 #include "BLT_translation.h"
39 
40 #include "transform.h"
41 #include "transform_mode.h"
42 #include "transform_snap.h"
43 
44 /* -------------------------------------------------------------------- */
48 struct ToSphereInfo {
50  float radius;
51 };
52 
55 {
56  struct ToSphereInfo *data = t->custom.mode.data;
57  float radius = 0.0f;
58 
59  const bool is_local_center = transdata_check_local_center(t, t->around);
60 
61  if (t->flag & T_PROP_EDIT_ALL) {
62  int factor_accum = 0.0f;
64  TransData *td = tc->data;
65  for (int i = 0; i < tc->data_len; i++, td++) {
66  if (td->factor == 0.0f) {
67  continue;
68  }
69  const float *center = is_local_center ? td->center : tc->center_local;
70  radius += td->factor * len_v3v3(center, td->iloc);
71  factor_accum += td->factor;
72  }
73  }
74  if (factor_accum != 0.0f) {
75  radius /= factor_accum;
76  }
77  }
78  else {
80  TransData *td = tc->data;
81  for (int i = 0; i < tc->data_len; i++, td++) {
82  const float *center = is_local_center ? td->center : tc->center_local;
83  radius += len_v3v3(center, td->iloc);
84  }
85  }
86  radius /= (float)t->data_len_all;
87  }
88 
89  data->prop_size_prev = t->prop_size;
90  data->radius = radius;
91 }
92 
95 /* -------------------------------------------------------------------- */
99 static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
100 {
101  const bool is_local_center = transdata_check_local_center(t, t->around);
102 
103  float vec[3];
104  float ratio, radius;
105  int i;
106  char str[UI_MAX_DRAW_STR];
107 
108  ratio = t->values[0];
109 
110  transform_snap_increment(t, &ratio);
111 
112  applyNumInput(&t->num, &ratio);
113 
114  CLAMP(ratio, 0.0f, 1.0f);
115 
116  t->values_final[0] = ratio;
117 
118  /* header print for NumInput */
119  if (hasNumInput(&t->num)) {
120  char c[NUM_STR_REP_LEN];
121 
122  outputNumInput(&(t->num), c, &t->scene->unit);
123 
124  BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %s %s"), c, t->proptext);
125  }
126  else {
127  /* default header print */
128  BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %.4f %s"), ratio, t->proptext);
129  }
130 
131  const struct ToSphereInfo *data = t->custom.mode.data;
132  if (data->prop_size_prev != t->prop_size) {
134  }
135 
137  TransData *td = tc->data;
138  for (i = 0; i < tc->data_len; i++, td++) {
139  float tratio;
140  if (td->flag & TD_SKIP) {
141  continue;
142  }
143 
144  const float *center = is_local_center ? td->center : tc->center_local;
145 
146  sub_v3_v3v3(vec, td->iloc, center);
147 
148  radius = normalize_v3(vec);
149 
150  tratio = ratio * td->factor;
151 
152  mul_v3_fl(vec, radius * (1.0f - tratio) + data->radius * tratio);
153 
154  add_v3_v3v3(td->loc, center, vec);
155  }
156  }
157 
158  recalcData(t);
159 
160  ED_area_status_text(t->area, str);
161 }
162 
164 {
165  t->mode = TFM_TOSPHERE;
166  t->transform = applyToSphere;
167 
169 
170  t->idx_max = 0;
171  t->num.idx_max = 0;
172  t->snap[0] = 0.1f;
173  t->snap[1] = t->snap[0] * 0.1f;
174 
175  copy_v3_fl(t->num.val_inc, t->snap[0]);
176  t->num.unit_sys = t->scene->unit.system;
177  t->num.unit_type[0] = B_UNIT_NONE;
178 
179  t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
180  t->flag |= T_NO_CONSTRAINT;
181 
182  struct ToSphereInfo *data = MEM_callocN(sizeof(*data), __func__);
183  t->custom.mode.data = data;
184  t->custom.mode.use_free = true;
185 
187 }
typedef float(TangentPoint)[2]
@ B_UNIT_NONE
Definition: BKE_unit.h:78
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
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)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNUSED(x)
#define TIP_(msgid)
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:102
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:27
@ NUM_NO_NEGATIVE
Definition: ED_numinput.h:70
@ NUM_NULL_ONE
Definition: ED_numinput.h:69
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:207
bool hasNumInput(const NumInput *n)
Definition: numinput.c:185
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:815
@ TFM_TOSPHERE
Definition: ED_transform.h:50
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 RGB to Bright Vector Camera CLAMP
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:90
#define str(s)
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static unsigned c
Definition: RandGen.cpp:97
@ INPUT_HORIZONTAL_RATIO
Definition: transform.h:735
void recalcData(TransInfo *t)
@ T_PROP_EDIT_ALL
Definition: transform.h:114
@ T_NO_CONSTRAINT
Definition: transform.h:106
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
@ TD_SKIP
bool transdata_check_local_center(TransInfo *t, short around)
transform modes used by different operators.
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(TransInfo *t, float *r_val)