Blender V5.3
transform_convert_particle.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
8
10#include "DNA_particle_types.h"
11
12#include "MEM_guardedalloc.h"
13
14#include "BLI_math_matrix_c.hh"
15#include "BLI_math_vector_c.hh"
16
17#include "BKE_layer.hh"
18#include "BKE_object_types.hh"
19#include "BKE_particle.h"
20#include "BKE_pointcache.h"
21
22#include "ED_particle.hh"
23
24#include "transform.hh"
25#include "transform_snap.hh"
26
27/* Own include. */
28#include "transform_convert.hh"
29
30namespace blender::ed::transform {
31
32/* -------------------------------------------------------------------- */
35
37{
39
40 TransData *td = nullptr;
44 PTCacheEdit *edit = PE_get_current(t->depsgraph, t->scene, ob);
45 ParticleSystem *psys = nullptr;
46 PTCacheEditPoint *point;
47 PTCacheEditKey *key;
48 float mat[4][4];
49 int i, k, transformparticle;
50 int count = 0, hasselected = 0;
51 const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
52
53 if (edit == nullptr || t->settings->particle.selectmode == SCE_SELECT_PATH) {
54 return;
55 }
56
57 psys = edit->psys;
58
59 for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
60 point->flag &= ~PEP_TRANSFORM;
61 transformparticle = 0;
62
63 if ((point->flag & PEP_HIDE) == 0) {
64 for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
65 if ((key->flag & PEK_HIDE) == 0) {
66 if (key->flag & PEK_SELECT) {
67 hasselected = 1;
68 transformparticle = 1;
69 }
70 else if (is_prop_edit) {
71 transformparticle = 1;
72 }
73 }
74 }
75 }
76
77 if (transformparticle) {
78 count += point->totkey;
79 point->flag |= PEP_TRANSFORM;
80 }
81 }
82
83 /* NOTE: in prop mode we need at least 1 selected. */
84 if (hasselected == 0) {
85 return;
86 }
87
88 tc->data_len = count;
89 td = tc->data = MEM_new_array_zeroed<TransData>(tc->data_len, "TransObData(Particle Mode)");
90
91 unit_m4(mat);
92
93 invert_m4_m4(ob->runtime->world_to_object.ptr(), ob->object_to_world().ptr());
94
95 for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
96 TransData *head, *tail;
97 head = tail = td;
98
99 if (!(point->flag & PEP_TRANSFORM)) {
100 continue;
101 }
102
103 if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
104 ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
106 ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
107 }
108
109 for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
110 if (key->flag & PEK_USE_WCO) {
111 copy_v3_v3(key->world_co, key->co);
112 mul_m4_v3(mat, key->world_co);
113 td->loc = key->world_co;
114 }
115 else {
116 td->loc = key->co;
117 }
118
119 copy_v3_v3(td->iloc, td->loc);
120 copy_v3_v3(td->center, td->loc);
121
122 if (key->flag & PEK_SELECT) {
123 td->flag |= TD_SELECTED;
124 }
125 else if (!is_prop_edit) {
126 td->flag |= TD_SKIP;
127 }
128
129 unit_m3(td->mtx);
130 unit_m3(td->smtx);
131
132 /* Don't allow moving roots. */
133 if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) {
135 }
136
137 td++;
138 tail++;
139 }
140 if (is_prop_edit && head != tail) {
141 calc_distanceCurveVerts(head, tail - 1, false);
142 }
143 }
144 }
145}
146
148
149/* -------------------------------------------------------------------- */
152
154{
156 Scene *scene = t->scene;
157 ViewLayer *view_layer = t->view_layer;
158 BKE_view_layer_synced_ensure(*t->bmain, scene, view_layer);
160 PTCacheEdit *edit = PE_get_current(t->depsgraph, scene, ob);
161 ParticleSystem *psys = edit->psys;
162 PTCacheEditPoint *point;
163 PTCacheEditKey *key;
164 float mat[4][4], imat[4][4], co[3];
165 int i, k;
166 const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
167
168 /* We do transform in world space, so flush world space position
169 * back to particle local space (only for hair particles). */
170 for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
171 if (!(point->flag & PEP_TRANSFORM)) {
172 continue;
173 }
174
175 if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
176 ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
178 ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
179 invert_m4_m4(imat, mat);
180
181 for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
182 copy_v3_v3(co, key->world_co);
183 mul_m4_v3(imat, co);
184
185 /* Optimization for proportional edit. */
186 if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) {
187 copy_v3_v3(key->co, co);
188 point->flag |= PEP_EDIT_RECALC;
189 }
190 }
191 }
192 else {
193 point->flag |= PEP_EDIT_RECALC;
194 }
195 }
196
197 PE_update_object(t->depsgraph, scene, ob, 1);
200 }
201}
202
204
205/* -------------------------------------------------------------------- */
208
216
218
220 /*flags*/ T_POINTS,
221 /*create_trans_data*/ createTransParticleVerts,
222 /*recalc_data*/ recalcData_particles,
223 /*special_aftertrans_update*/ nullptr,
224};
225
226} // namespace blender::ed::transform
#define PEK_HIDE
#define PEP_EDIT_RECALC
#define PEP_TRANSFORM
#define PEP_HIDE
#define PEK_SELECT
#define PEK_USE_WCO
Read Blender memory allocation and freeing.
void transform_snap_project_individual_apply(TransInfo *t)
static void recalcData_particles(TransInfo *t)
TransConvertTypeInfo TransConvertType_Particle
static void createTransParticleVerts(bContext *, TransInfo *t)
static void flushTransParticles(TransInfo *t)
void calc_distanceCurveVerts(TransData *head, TransData *tail, bool cyclic)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BKE_particle_batch_cache_dirty_tag(struct ParticleSystem *psys, int mode)
Definition particle.cc:5580
MINLINE void copy_v3_v3(float r[3], const float a[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
void mul_m4_v3(const float M[4][4], float r[3])
PTCacheEdit * PE_get_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
void DEG_id_tag_update(ID *id, unsigned int flags)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void unit_m4(float m[4][4])
MINLINE bool compare_v3v3(const float v1[3], const float v2[3], float limit) ATTR_WARN_UNUSED_RESULT
void psys_mat_hair_to_global(struct Object *ob, struct Mesh *mesh, short from, struct ParticleData *pa, float hairmat[4][4])
Definition particle.cc:3944
void unit_m3(float m[3][3])
@ ID_RECALC_PSYS_REDO
Definition DNA_ID.h:1081
@ BKE_PARTICLE_BATCH_DIRTY_ALL
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
ParticleEditSettings * PE_settings(Scene *scene)
const c_style_mat & ptr() const
bke::ObjectRuntime * runtime
struct PTCacheEditKey * keys
PTCacheEditPoint * points
struct ParticleSystem * psys
struct ParticleSystemModifierData * psmd_eval
eParticleSystem_Flag flag
struct ParticleEditSettings particle
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:48
conversion and adaptation of different datablocks to a common struct.