Blender  V3.3
transform_convert_particle.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 "DNA_modifier_types.h"
9 #include "DNA_particle_types.h"
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "BLI_math.h"
14 
15 #include "BKE_context.h"
16 #include "BKE_particle.h"
17 #include "BKE_pointcache.h"
18 
19 #include "ED_particle.h"
20 
21 #include "transform.h"
22 #include "transform_snap.h"
23 
24 /* Own include. */
25 #include "transform_convert.h"
26 
27 /* -------------------------------------------------------------------- */
32 {
34 
35  TransData *td = NULL;
37  Object *ob = OBACT(t->view_layer);
38  ParticleEditSettings *pset = PE_settings(t->scene);
39  PTCacheEdit *edit = PE_get_current(t->depsgraph, t->scene, ob);
40  ParticleSystem *psys = NULL;
42  PTCacheEditKey *key;
43  float mat[4][4];
44  int i, k, transformparticle;
45  int count = 0, hasselected = 0;
46  const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
47 
48  if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) {
49  return;
50  }
51 
52  psys = edit->psys;
53 
54  for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
55  point->flag &= ~PEP_TRANSFORM;
56  transformparticle = 0;
57 
58  if ((point->flag & PEP_HIDE) == 0) {
59  for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
60  if ((key->flag & PEK_HIDE) == 0) {
61  if (key->flag & PEK_SELECT) {
62  hasselected = 1;
63  transformparticle = 1;
64  }
65  else if (is_prop_edit) {
66  transformparticle = 1;
67  }
68  }
69  }
70  }
71 
72  if (transformparticle) {
73  count += point->totkey;
74  point->flag |= PEP_TRANSFORM;
75  }
76  }
77 
78  /* NOTE: in prop mode we need at least 1 selected. */
79  if (hasselected == 0) {
80  return;
81  }
82 
83  tc->data_len = count;
84  td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)");
85 
86  if (t->mode == TFM_BAKE_TIME) {
87  tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension),
88  "Particle_TransExtension");
89  }
90  else {
91  tx = tc->data_ext = NULL;
92  }
93 
94  unit_m4(mat);
95 
96  invert_m4_m4(ob->imat, ob->obmat);
97 
98  for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
99  TransData *head, *tail;
100  head = tail = td;
101 
102  if (!(point->flag & PEP_TRANSFORM)) {
103  continue;
104  }
105 
106  if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
107  ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
109  ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
110  }
111 
112  for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
113  if (key->flag & PEK_USE_WCO) {
114  copy_v3_v3(key->world_co, key->co);
115  mul_m4_v3(mat, key->world_co);
116  td->loc = key->world_co;
117  }
118  else {
119  td->loc = key->co;
120  }
121 
122  copy_v3_v3(td->iloc, td->loc);
123  copy_v3_v3(td->center, td->loc);
124 
125  if (key->flag & PEK_SELECT) {
126  td->flag |= TD_SELECTED;
127  }
128  else if (!is_prop_edit) {
129  td->flag |= TD_SKIP;
130  }
131 
132  unit_m3(td->mtx);
133  unit_m3(td->smtx);
134 
135  /* don't allow moving roots */
136  if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) {
137  td->protectflag |= OB_LOCK_LOC;
138  }
139 
140  td->ob = ob;
141  td->ext = tx;
142  if (t->mode == TFM_BAKE_TIME) {
143  td->val = key->time;
144  td->ival = *(key->time);
145  /* abuse size and quat for min/max values */
146  td->flag |= TD_NO_EXT;
147  if (k == 0) {
148  tx->size = NULL;
149  }
150  else {
151  tx->size = (key - 1)->time;
152  }
153 
154  if (k == point->totkey - 1) {
155  tx->quat = NULL;
156  }
157  else {
158  tx->quat = (key + 1)->time;
159  }
160  }
161 
162  td++;
163  if (tx) {
164  tx++;
165  }
166  tail++;
167  }
168  if (is_prop_edit && head != tail) {
169  calc_distanceCurveVerts(head, tail - 1, false);
170  }
171  }
172  }
173 }
174 
177 /* -------------------------------------------------------------------- */
182 {
184  Scene *scene = t->scene;
185  ViewLayer *view_layer = t->view_layer;
186  Object *ob = OBACT(view_layer);
187  PTCacheEdit *edit = PE_get_current(t->depsgraph, scene, ob);
188  ParticleSystem *psys = edit->psys;
190  PTCacheEditKey *key;
191  TransData *td;
192  float mat[4][4], imat[4][4], co[3];
193  int i, k;
194  const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
195 
196  /* we do transform in world space, so flush world space position
197  * back to particle local space (only for hair particles) */
198  td = tc->data;
199  for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) {
200  if (!(point->flag & PEP_TRANSFORM)) {
201  continue;
202  }
203 
204  if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
205  ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
207  ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
208  invert_m4_m4(imat, mat);
209 
210  for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
211  copy_v3_v3(co, key->world_co);
212  mul_m4_v3(imat, co);
213 
214  /* optimization for proportional edit */
215  if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) {
216  copy_v3_v3(key->co, co);
217  point->flag |= PEP_EDIT_RECALC;
218  }
219  }
220  }
221  else {
222  point->flag |= PEP_EDIT_RECALC;
223  }
224  }
225 
226  PE_update_object(t->depsgraph, scene, OBACT(view_layer), 1);
229  }
230 }
231 
234 /* -------------------------------------------------------------------- */
239 {
240  if (t->state != TRANS_CANCEL) {
242  }
244 }
245 
249  /* flags */ T_POINTS,
250  /* createTransData */ createTransParticleVerts,
251  /* recalcData */ recalcData_particles,
252  /* special_aftertrans_update */ NULL,
253 };
void psys_mat_hair_to_global(struct Object *ob, struct Mesh *mesh, short from, struct ParticleData *pa, float hairmat[4][4])
Definition: particle.c:3935
@ BKE_PARTICLE_BATCH_DIRTY_ALL
Definition: BKE_particle.h:686
void BKE_particle_batch_cache_dirty_tag(struct ParticleSystem *psys, int mode)
Definition: particle.c:5274
#define PEK_HIDE
#define PEP_EDIT_RECALC
#define PEP_TRANSFORM
#define PEP_HIDE
#define PEK_SELECT
#define PEK_USE_WCO
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
void unit_m4(float m[4][4])
Definition: rct.c:1090
bool invert_m4_m4(float R[4][4], const float A[4][4])
Definition: math_matrix.c:1287
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
MINLINE bool compare_v3v3(const float a[3], const float b[3], float limit) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_PSYS_REDO
Definition: DNA_ID.h:798
@ OB_LOCK_LOC
#define PSYS_GLOBAL_HAIR
#define SCE_SELECT_PATH
#define OBACT(_view_layer)
#define PE_LOCK_FIRST
struct ParticleEditSettings * PE_settings(struct Scene *scene)
void PE_update_object(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int useflag)
struct PTCacheEdit * PE_get_current(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
@ TFM_BAKE_TIME
Definition: ED_transform.h:55
_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.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a point
#define C
Definition: RandGen.cpp:25
double time
Scene scene
int count
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
float imat[4][4]
float obmat[4][4]
PTCacheEditPoint * points
struct ParticleSystem * psys
struct ParticleSystemModifierData * psmd_eval
ParticleData * particles
ParticleSettings * part
float smtx[3][3]
short protectflag
float mtx[3][3]
TransDataExtension * ext
float * val
struct Object * ob
void calc_distanceCurveVerts(TransData *head, TransData *tail, bool cyclic)
conversion and adaptation of different datablocks to a common struct.
static void recalcData_particles(TransInfo *t)
TransConvertTypeInfo TransConvertType_Particle
static void flushTransParticles(TransInfo *t)
static void createTransParticleVerts(bContext *UNUSED(C), TransInfo *t)
@ TD_NO_EXT
@ TD_SELECTED
@ TD_SKIP
void applySnappingIndividual(TransInfo *t)