Blender V5.0
BKE_effect.h
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#pragma once
5
9
10struct Collection;
11struct Depsgraph;
12struct ListBase;
13struct RNG;
14struct Object;
15struct ParticleData;
16struct ParticleKey;
18struct Scene;
19struct ViewLayer;
20
21struct EffectorWeights *BKE_effector_add_weights(struct Collection *collection);
22
23/* Input to effector code */
24typedef struct EffectedPoint {
25 float *loc;
26 float *vel;
27 float *ave; /* angular velocity for particles with dynamic rotation */
28 float *rot; /* rotation quaternion for particles with dynamic rotation */
31
32 /* only for particles */
33 float size, charge;
34
35 unsigned int flag;
36 int index;
37
38 struct ParticleSystem *psys; /* particle system the point belongs to */
40
45
46typedef struct EffectorData {
47 /* Effector point */
48 float loc[3];
49 float nor[3];
50 float vel[3];
51
52 float vec_to_point[3];
54
55 /* only for effector particles */
56 float size, charge;
57
58 /* only for vortex effector with surface falloff */
59 float nor2[3], vec_to_point2[3];
60
61 int *index; /* point index */
63
64/* used for calculating the effector force */
65typedef struct EffectorCache {
67
68 struct Depsgraph *depsgraph;
69 struct Scene *scene;
70 struct Object *ob;
73
74 struct PartDeflect *pd;
75
77 struct RNG *rng;
78
79 /* precalculated for guides */
82
83 float frame;
84 int flag;
86
94
95struct PartDeflect *BKE_partdeflect_new(int type);
96struct PartDeflect *BKE_partdeflect_copy(const struct PartDeflect *pd_src);
97void BKE_partdeflect_free(struct PartDeflect *pd);
98
105 const struct Scene *scene,
106 struct ViewLayer *view_layer,
107 struct Collection *collection);
109
113struct ListBase *BKE_effectors_create(struct Depsgraph *depsgraph,
114 struct Object *ob_src,
115 struct ParticleSystem *psys_src,
116 struct EffectorWeights *weights,
117 bool use_rotation);
121void BKE_effectors_apply(struct ListBase *effectors,
122 struct ListBase *colliders,
123 struct EffectorWeights *weights,
124 struct EffectedPoint *point,
125 float *force,
126 float *wind_force,
127 float *impulse);
128void BKE_effectors_free(struct ListBase *lb);
129
131 struct ParticleData *pa,
132 struct ParticleKey *state,
133 struct EffectedPoint *point);
135 struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
137 struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
138
139/* needed for boids */
140float effector_falloff(struct EffectorCache *eff,
141 struct EffectorData *efd,
142 struct EffectedPoint *point,
143 struct EffectorWeights *weights);
145 const float co[3],
146 float surface_co[3],
147 float surface_nor[3],
148 float surface_vel[3]);
149bool get_effector_data(struct EffectorCache *eff,
150 struct EffectorData *efd,
151 struct EffectedPoint *point,
152 int real_velocity);
153
154/* Required for `particle_system.cc`. */
155#if 0
156void do_physical_effector(struct EffectorData *eff,
157 struct EffectorPoint *point,
158 float *total_force);
159float effector_falloff(struct EffectorData *eff,
160 struct EffectorPoint *point,
161 struct EffectorWeights *weights);
162#endif
163
164/* EffectedPoint->flag */
165#define PE_WIND_AS_SPEED 1
166#define PE_USE_NORMAL_DATA 4
167
168/* EffectorData->flag */
169#define PE_VELOCITY_TO_IMPULSE 1
170
171/* ======== Simulation Debugging ======== */
172
173unsigned int BKE_sim_debug_data_hash(int i);
174unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky);
175
176/* _VA_SIM_DEBUG_HASH#(i, ...): combined hash value of multiple integers */
177/* Internal helpers. */
178#define _VA_SIM_DEBUG_HASH1(a) (BKE_sim_debug_data_hash(a))
179#define _VA_SIM_DEBUG_HASH2(a, b) \
180 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH1(b)))
181#define _VA_SIM_DEBUG_HASH3(a, b, c) \
182 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH2(b, c)))
183#define _VA_SIM_DEBUG_HASH4(a, b, c, d) \
184 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH3(b, c, d)))
185#define _VA_SIM_DEBUG_HASH5(a, b, c, d, e) \
186 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH4(b, c, d, e)))
187#define _VA_SIM_DEBUG_HASH6(a, b, c, d, e, f) \
188 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH5(b, c, d, e, f)))
189#define _VA_SIM_DEBUG_HASH7(a, b, c, d, e, f, g) \
190 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), \
191 _VA_SIM_DEBUG_HASH6(b, c, d, e, f, g)))
192#define _VA_SIM_DEBUG_HASH8(a, b, c, d, e, f, g, h) \
193 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), \
194 _VA_SIM_DEBUG_HASH7(b, c, d, e, f, g, h)))
195
196#define SIM_DEBUG_HASH(...) VA_NARGS_CALL_OVERLOAD(_VA_SIM_DEBUG_HASH, __VA_ARGS__)
197
198typedef struct SimDebugElement {
199 unsigned int category_hash;
200 unsigned int hash;
201
202 int type;
203 float color[3];
204
205 float v1[3], v2[3];
206 char str[64];
208
216
217typedef struct SimDebugData {
218 struct GHash *gh;
220
222
223void BKE_sim_debug_data_set_enabled(bool enable);
225void BKE_sim_debug_data_free(void);
226
228 const float v1[3],
229 const float v2[3],
230 const char *str,
231 float r,
232 float g,
233 float b,
234 const char *category,
235 unsigned int hash);
236void BKE_sim_debug_data_remove_element(unsigned int hash);
237
238#define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) \
239 { \
240 const float v2[3] = {0.0f, 0.0f, 0.0f}; \
241 BKE_sim_debug_data_add_element( \
242 SIM_DEBUG_ELEM_DOT, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
243 }
244
245#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) \
246 { \
247 const float v2[3] = {radius, 0.0f, 0.0f}; \
248 BKE_sim_debug_data_add_element( \
249 SIM_DEBUG_ELEM_CIRCLE, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
250 }
251
252#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) \
253 { \
254 BKE_sim_debug_data_add_element( \
255 SIM_DEBUG_ELEM_LINE, p1, p2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
256 }
257
258#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) \
259 { \
260 BKE_sim_debug_data_add_element( \
261 SIM_DEBUG_ELEM_VECTOR, p, d, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
262 }
263
264#define BKE_sim_debug_data_add_string(p, str, r, g, b, category, ...) \
265 { \
266 BKE_sim_debug_data_add_element( \
267 SIM_DEBUG_ELEM_STRING, p, NULL, str, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
268 }
269
270#define BKE_sim_debug_data_remove(...) \
271 BKE_sim_debug_data_remove_element(SIM_DEBUG_HASH(__VA_ARGS__))
272
273void BKE_sim_debug_data_clear(void);
274void BKE_sim_debug_data_clear_category(const char *category);
unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky)
Definition effect.cc:1204
eSimDebugElement_Type
Definition BKE_effect.h:209
@ SIM_DEBUG_ELEM_VECTOR
Definition BKE_effect.h:213
@ SIM_DEBUG_ELEM_LINE
Definition BKE_effect.h:212
@ SIM_DEBUG_ELEM_CIRCLE
Definition BKE_effect.h:211
@ SIM_DEBUG_ELEM_STRING
Definition BKE_effect.h:214
@ SIM_DEBUG_ELEM_DOT
Definition BKE_effect.h:210
void BKE_sim_debug_data_clear_category(const char *category)
Definition effect.cc:1370
void BKE_partdeflect_free(struct PartDeflect *pd)
Definition effect.cc:119
SimDebugData * _sim_debug_data
Definition effect.cc:1197
struct ListBase * BKE_effector_relations_create(struct Depsgraph *depsgraph, const struct Scene *scene, struct ViewLayer *view_layer, struct Collection *collection)
struct PartDeflect * BKE_partdeflect_new(int type)
Definition effect.cc:71
struct EffectorWeights * BKE_effector_add_weights(struct Collection *collection)
Definition effect.cc:58
bool BKE_sim_debug_data_get_enabled(void)
Definition effect.cc:1271
float effector_falloff(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, struct EffectorWeights *weights)
Definition effect.cc:586
void BKE_effectors_free(struct ListBase *lb)
Definition effect.cc:361
void BKE_sim_debug_data_remove_element(unsigned int hash)
Definition effect.cc:1350
void BKE_effectors_apply(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *wind_force, float *impulse)
Definition effect.cc:1106
void BKE_sim_debug_data_set_enabled(bool enable)
Definition effect.cc:1257
void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:429
bool get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, int real_velocity)
Definition effect.cc:671
void BKE_sim_debug_data_clear(void)
Definition effect.cc:1360
bool closest_point_on_surface(struct SurfaceModifierData *surmd, const float co[3], float surface_co[3], float surface_nor[3], float surface_vel[3])
Definition effect.cc:635
void BKE_sim_debug_data_free(void)
Definition effect.cc:1276
void BKE_effector_relations_free(struct ListBase *lb)
Definition effect.cc:239
struct ListBase * BKE_effectors_create(struct Depsgraph *depsgraph, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool use_rotation)
Definition effect.cc:306
unsigned int BKE_sim_debug_data_hash(int i)
Definition effect.cc:1199
void BKE_sim_debug_data_add_element(int type, const float v1[3], const float v2[3], const char *str, float r, float g, float b, const char *category, unsigned int hash)
Definition effect.cc:1299
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:414
struct PartDeflect * BKE_partdeflect_copy(const struct PartDeflect *pd_src)
void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point)
Definition effect.cc:378
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BPy_StructRNA * depsgraph
static void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
Definition effect.cc:946
#define str(s)
static ulong state[N]
#define hash
Definition noise_c.cc:154
float vel_to_sec
Definition BKE_effect.h:30
float * vel
Definition BKE_effect.h:26
struct ParticleSystem * psys
Definition BKE_effect.h:38
float vel_to_frame
Definition BKE_effect.h:29
float * loc
Definition BKE_effect.h:25
unsigned int flag
Definition BKE_effect.h:35
float * rot
Definition BKE_effect.h:28
float * ave
Definition BKE_effect.h:27
struct ParticleSystem * psys
Definition BKE_effect.h:71
struct RNG * rng
Definition BKE_effect.h:77
struct EffectorCache * prev
Definition BKE_effect.h:66
struct SurfaceModifierData * surmd
Definition BKE_effect.h:72
float guide_dir[3]
Definition BKE_effect.h:81
float guide_loc[4]
Definition BKE_effect.h:81
float guide_radius
Definition BKE_effect.h:81
struct Scene * scene
Definition BKE_effect.h:69
struct GuideEffectorData * guide_data
Definition BKE_effect.h:80
struct PartDeflect * pd
Definition BKE_effect.h:74
struct EffectorCache * next
Definition BKE_effect.h:66
struct Object * ob
Definition BKE_effect.h:70
struct Depsgraph * depsgraph
Definition BKE_effect.h:68
float loc[3]
Definition BKE_effect.h:48
float distance
Definition BKE_effect.h:53
float vec_to_point[3]
Definition BKE_effect.h:52
float vec_to_point2[3]
Definition BKE_effect.h:59
float nor[3]
Definition BKE_effect.h:49
float falloff
Definition BKE_effect.h:53
float vel[3]
Definition BKE_effect.h:50
float nor2[3]
Definition BKE_effect.h:59
struct EffectorRelation * next
Definition BKE_effect.h:88
struct ParticleSystem * psys
Definition BKE_effect.h:91
struct PartDeflect * pd
Definition BKE_effect.h:92
struct Object * ob
Definition BKE_effect.h:90
struct EffectorRelation * prev
Definition BKE_effect.h:88
float vec_to_point[3]
Definition BKE_effect.h:42
Definition rand.cc:33
struct GHash * gh
Definition BKE_effect.h:218
unsigned int category_hash
Definition BKE_effect.h:199
unsigned int hash
Definition BKE_effect.h:200
i
Definition text_draw.cc:230