1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*/
/** \file
* \ingroup edtransform
*/
#include "DNA_particle_types.h"
#include "DNA_modifier_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_math.h"
#include "BKE_context.h"
#include "BKE_report.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "ED_particle.h"
#include "transform.h"
#include "transform_convert.h"
/* -------------------------------------------------------------------- */
/** \name Particle Edit Transform Creation
*
* \{ */
void createTransParticleVerts(bContext *C, TransInfo *t)
{
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
TransData *td = NULL;
TransDataExtension *tx;
Object *ob = CTX_data_active_object(C);
ParticleEditSettings *pset = PE_settings(t->scene);
PTCacheEdit *edit = PE_get_current(t->depsgraph, t->scene, ob);
ParticleSystem *psys = NULL;
PTCacheEditPoint *point;
PTCacheEditKey *key;
float mat[4][4];
int i, k, transformparticle;
int count = 0, hasselected = 0;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) {
return;
}
psys = edit->psys;
for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
point->flag &= ~PEP_TRANSFORM;
transformparticle = 0;
if ((point->flag & PEP_HIDE) == 0) {
for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
if ((key->flag & PEK_HIDE) == 0) {
if (key->flag & PEK_SELECT) {
hasselected = 1;
transformparticle = 1;
}
else if (is_prop_edit) {
transformparticle = 1;
}
}
}
}
if (transformparticle) {
count += point->totkey;
point->flag |= PEP_TRANSFORM;
}
}
/* note: in prop mode we need at least 1 selected */
if (hasselected == 0) {
return;
}
tc->data_len = count;
td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)");
if (t->mode == TFM_BAKE_TIME) {
tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension),
"Particle_TransExtension");
}
else {
tx = tc->data_ext = NULL;
}
unit_m4(mat);
invert_m4_m4(ob->imat, ob->obmat);
for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
TransData *head, *tail;
head = tail = td;
if (!(point->flag & PEP_TRANSFORM)) {
continue;
}
if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
psys_mat_hair_to_global(
ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
}
for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
if (key->flag & PEK_USE_WCO) {
copy_v3_v3(key->world_co, key->co);
mul_m4_v3(mat, key->world_co);
td->loc = key->world_co;
}
else {
td->loc = key->co;
}
copy_v3_v3(td->iloc, td->loc);
copy_v3_v3(td->center, td->loc);
if (key->flag & PEK_SELECT) {
td->flag |= TD_SELECTED;
}
else if (!is_prop_edit) {
td->flag |= TD_SKIP;
}
unit_m3(td->mtx);
unit_m3(td->smtx);
/* don't allow moving roots */
if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR))) {
td->protectflag |= OB_LOCK_LOC;
}
td->ob = ob;
td->ext = tx;
if (t->mode == TFM_BAKE_TIME) {
td->val = key->time;
td->ival = *(key->time);
/* abuse size and quat for min/max values */
td->flag |= TD_NO_EXT;
if (k == 0) {
tx->size = NULL;
}
else {
tx->size = (key - 1)->time;
}
if (k == point->totkey - 1) {
tx->quat = NULL;
}
else {
tx->quat = (key + 1)->time;
}
}
td++;
if (tx) {
tx++;
}
tail++;
}
if (is_prop_edit && head != tail) {
calc_distanceCurveVerts(head, tail - 1);
}
}
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Node Transform Creation
*
* \{ */
void flushTransParticles(TransInfo *t)
{
FOREACH_TRANS_DATA_CONTAINER (t, tc) {
Scene *scene = t->scene;
ViewLayer *view_layer = t->view_layer;
Object *ob = OBACT(view_layer);
PTCacheEdit *edit = PE_get_current(t->depsgraph, scene, ob);
ParticleSystem *psys = edit->psys;
PTCacheEditPoint *point;
PTCacheEditKey *key;
TransData *td;
float mat[4][4], imat[4][4], co[3];
int i, k;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
/* we do transform in world space, so flush world space position
* back to particle local space (only for hair particles) */
td = tc->data;
for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) {
if (!(point->flag & PEP_TRANSFORM)) {
continue;
}
if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
ParticleSystemModifierData *psmd_eval = edit->psmd_eval;
psys_mat_hair_to_global(
ob, psmd_eval->mesh_final, psys->part->from, psys->particles + i, mat);
invert_m4_m4(imat, mat);
for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
copy_v3_v3(co, key->world_co);
mul_m4_v3(imat, co);
/* optimization for proportional edit */
if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) {
copy_v3_v3(key->co, co);
point->flag |= PEP_EDIT_RECALC;
}
}
}
else {
point->flag |= PEP_EDIT_RECALC;
}
}
PE_update_object(t->depsgraph, scene, OBACT(view_layer), 1);
BKE_particle_batch_cache_dirty_tag(psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
DEG_id_tag_update(&ob->id, ID_RECALC_PSYS_REDO);
}
}
/** \} */
|