Blender V4.3
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
10#include "BLI_utildefines.h"
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16struct Collection;
17struct Depsgraph;
18struct ListBase;
19struct RNG;
20struct Object;
21struct ParticleData;
22struct ParticleKey;
24struct Scene;
25struct ViewLayer;
26
27struct EffectorWeights *BKE_effector_add_weights(struct Collection *collection);
28
29/* Input to effector code */
30typedef struct EffectedPoint {
31 float *loc;
32 float *vel;
33 float *ave; /* angular velocity for particles with dynamic rotation */
34 float *rot; /* rotation quaternion for particles with dynamic rotation */
37
38 /* only for particles */
39 float size, charge;
40
41 unsigned int flag;
42 int index;
43
44 struct ParticleSystem *psys; /* particle system the point belongs to */
46
51
52typedef struct EffectorData {
53 /* Effector point */
54 float loc[3];
55 float nor[3];
56 float vel[3];
57
58 float vec_to_point[3];
60
61 /* only for effector particles */
62 float size, charge;
63
64 /* only for vortex effector with surface falloff */
65 float nor2[3], vec_to_point2[3];
66
67 int *index; /* point index */
69
70/* used for calculating the effector force */
71typedef struct EffectorCache {
73
74 struct Depsgraph *depsgraph;
75 struct Scene *scene;
76 struct Object *ob;
79
80 struct PartDeflect *pd;
81
83 struct RNG *rng;
84
85 /* precalculated for guides */
88
89 float frame;
90 int flag;
92
100
101struct PartDeflect *BKE_partdeflect_new(int type);
102struct PartDeflect *BKE_partdeflect_copy(const struct PartDeflect *pd_src);
103void BKE_partdeflect_free(struct PartDeflect *pd);
104
111 const struct Scene *scene,
112 struct ViewLayer *view_layer,
113 struct Collection *collection);
115
119struct ListBase *BKE_effectors_create(struct Depsgraph *depsgraph,
120 struct Object *ob_src,
121 struct ParticleSystem *psys_src,
122 struct EffectorWeights *weights,
123 bool use_rotation);
127void BKE_effectors_apply(struct ListBase *effectors,
128 struct ListBase *colliders,
129 struct EffectorWeights *weights,
130 struct EffectedPoint *point,
131 float *force,
132 float *wind_force,
133 float *impulse);
134void BKE_effectors_free(struct ListBase *lb);
135
137 struct ParticleData *pa,
138 struct ParticleKey *state,
139 struct EffectedPoint *point);
141 struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
143 struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point);
144
145/* needed for boids */
146float effector_falloff(struct EffectorCache *eff,
147 struct EffectorData *efd,
148 struct EffectedPoint *point,
149 struct EffectorWeights *weights);
151 const float co[3],
152 float surface_co[3],
153 float surface_nor[3],
154 float surface_vel[3]);
155bool get_effector_data(struct EffectorCache *eff,
156 struct EffectorData *efd,
157 struct EffectedPoint *point,
158 int real_velocity);
159
160/* Required for `particle_system.cc`. */
161#if 0
162void do_physical_effector(struct EffectorData *eff,
163 struct EffectorPoint *point,
164 float *total_force);
165float effector_falloff(struct EffectorData *eff,
166 struct EffectorPoint *point,
167 struct EffectorWeights *weights);
168#endif
169
170/* EffectedPoint->flag */
171#define PE_WIND_AS_SPEED 1
172#define PE_USE_NORMAL_DATA 4
173
174/* EffectorData->flag */
175#define PE_VELOCITY_TO_IMPULSE 1
176
177/* ======== Simulation Debugging ======== */
178
179unsigned int BKE_sim_debug_data_hash(int i);
180unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky);
181
182/* _VA_SIM_DEBUG_HASH#(i, ...): combined hash value of multiple integers */
183/* Internal helpers. */
184#define _VA_SIM_DEBUG_HASH1(a) (BKE_sim_debug_data_hash(a))
185#define _VA_SIM_DEBUG_HASH2(a, b) \
186 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH1(b)))
187#define _VA_SIM_DEBUG_HASH3(a, b, c) \
188 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH2(b, c)))
189#define _VA_SIM_DEBUG_HASH4(a, b, c, d) \
190 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH3(b, c, d)))
191#define _VA_SIM_DEBUG_HASH5(a, b, c, d, e) \
192 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH4(b, c, d, e)))
193#define _VA_SIM_DEBUG_HASH6(a, b, c, d, e, f) \
194 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), _VA_SIM_DEBUG_HASH5(b, c, d, e, f)))
195#define _VA_SIM_DEBUG_HASH7(a, b, c, d, e, f, g) \
196 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), \
197 _VA_SIM_DEBUG_HASH6(b, c, d, e, f, g)))
198#define _VA_SIM_DEBUG_HASH8(a, b, c, d, e, f, g, h) \
199 (BKE_sim_debug_data_hash_combine(BKE_sim_debug_data_hash(a), \
200 _VA_SIM_DEBUG_HASH7(b, c, d, e, f, g, h)))
201
202#define SIM_DEBUG_HASH(...) VA_NARGS_CALL_OVERLOAD(_VA_SIM_DEBUG_HASH, __VA_ARGS__)
203
204typedef struct SimDebugElement {
205 unsigned int category_hash;
206 unsigned int hash;
207
208 int type;
209 float color[3];
210
211 float v1[3], v2[3];
212 char str[64];
214
222
223typedef struct SimDebugData {
224 struct GHash *gh;
226
228
229void BKE_sim_debug_data_set_enabled(bool enable);
231void BKE_sim_debug_data_free(void);
232
234 const float v1[3],
235 const float v2[3],
236 const char *str,
237 float r,
238 float g,
239 float b,
240 const char *category,
241 unsigned int hash);
242void BKE_sim_debug_data_remove_element(unsigned int hash);
243
244#define BKE_sim_debug_data_add_dot(p, r, g, b, category, ...) \
245 { \
246 const float v2[3] = {0.0f, 0.0f, 0.0f}; \
247 BKE_sim_debug_data_add_element( \
248 SIM_DEBUG_ELEM_DOT, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
249 }
250
251#define BKE_sim_debug_data_add_circle(p, radius, r, g, b, category, ...) \
252 { \
253 const float v2[3] = {radius, 0.0f, 0.0f}; \
254 BKE_sim_debug_data_add_element( \
255 SIM_DEBUG_ELEM_CIRCLE, p, v2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
256 }
257
258#define BKE_sim_debug_data_add_line(p1, p2, r, g, b, category, ...) \
259 { \
260 BKE_sim_debug_data_add_element( \
261 SIM_DEBUG_ELEM_LINE, p1, p2, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
262 }
263
264#define BKE_sim_debug_data_add_vector(p, d, r, g, b, category, ...) \
265 { \
266 BKE_sim_debug_data_add_element( \
267 SIM_DEBUG_ELEM_VECTOR, p, d, NULL, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
268 }
269
270#define BKE_sim_debug_data_add_string(p, str, r, g, b, category, ...) \
271 { \
272 BKE_sim_debug_data_add_element( \
273 SIM_DEBUG_ELEM_STRING, p, NULL, str, r, g, b, category, SIM_DEBUG_HASH(__VA_ARGS__)); \
274 }
275
276#define BKE_sim_debug_data_remove(...) \
277 BKE_sim_debug_data_remove_element(SIM_DEBUG_HASH(__VA_ARGS__))
278
279void BKE_sim_debug_data_clear(void);
280void BKE_sim_debug_data_clear_category(const char *category);
281
282#ifdef __cplusplus
283}
284#endif
unsigned int BKE_sim_debug_data_hash_combine(unsigned int kx, unsigned int ky)
Definition effect.cc:1208
eSimDebugElement_Type
Definition BKE_effect.h:215
@ SIM_DEBUG_ELEM_VECTOR
Definition BKE_effect.h:219
@ SIM_DEBUG_ELEM_LINE
Definition BKE_effect.h:218
@ SIM_DEBUG_ELEM_CIRCLE
Definition BKE_effect.h:217
@ SIM_DEBUG_ELEM_STRING
Definition BKE_effect.h:220
@ SIM_DEBUG_ELEM_DOT
Definition BKE_effect.h:216
void BKE_sim_debug_data_clear_category(const char *category)
Definition effect.cc:1376
void BKE_partdeflect_free(struct PartDeflect *pd)
Definition effect.cc:119
SimDebugData * _sim_debug_data
Definition effect.cc:1201
struct GuideEffectorData GuideEffectorData
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:57
struct SimDebugElement SimDebugElement
bool BKE_sim_debug_data_get_enabled(void)
Definition effect.cc:1276
float effector_falloff(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, struct EffectorWeights *weights)
Definition effect.cc:589
void BKE_effectors_free(struct ListBase *lb)
Definition effect.cc:364
struct EffectorCache EffectorCache
struct EffectedPoint EffectedPoint
void BKE_sim_debug_data_remove_element(unsigned int hash)
Definition effect.cc:1356
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:1110
void BKE_sim_debug_data_set_enabled(bool enable)
Definition effect.cc:1261
void pd_point_from_soft(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:432
bool get_effector_data(struct EffectorCache *eff, struct EffectorData *efd, struct EffectedPoint *point, int real_velocity)
Definition effect.cc:674
void BKE_sim_debug_data_clear(void)
Definition effect.cc:1366
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:638
void BKE_sim_debug_data_free(void)
Definition effect.cc:1281
void BKE_effector_relations_free(struct ListBase *lb)
Definition effect.cc:242
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:309
unsigned int BKE_sim_debug_data_hash(int i)
Definition effect.cc:1203
struct EffectorRelation EffectorRelation
struct EffectorData EffectorData
struct SimDebugData SimDebugData
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:1304
void pd_point_from_loc(struct Scene *scene, float *loc, float *vel, int index, struct EffectedPoint *point)
Definition effect.cc:417
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:381
ATTR_WARN_UNUSED_RESULT const BMVert * v2
local_group_size(16, 16) .push_constant(Type b
const Depsgraph * depsgraph
static void do_physical_effector(EffectorCache *eff, EffectorData *efd, EffectedPoint *point, float *total_force)
Definition effect.cc:950
#define str(s)
static ulong state[N]
#define hash
Definition noise.c:154
float vel_to_sec
Definition BKE_effect.h:36
float * vel
Definition BKE_effect.h:32
struct ParticleSystem * psys
Definition BKE_effect.h:44
float vel_to_frame
Definition BKE_effect.h:35
float * loc
Definition BKE_effect.h:31
unsigned int flag
Definition BKE_effect.h:41
float * rot
Definition BKE_effect.h:34
float * ave
Definition BKE_effect.h:33
struct ParticleSystem * psys
Definition BKE_effect.h:77
struct RNG * rng
Definition BKE_effect.h:83
struct EffectorCache * prev
Definition BKE_effect.h:72
struct SurfaceModifierData * surmd
Definition BKE_effect.h:78
float guide_dir[3]
Definition BKE_effect.h:87
float guide_loc[4]
Definition BKE_effect.h:87
float guide_radius
Definition BKE_effect.h:87
struct Scene * scene
Definition BKE_effect.h:75
struct GuideEffectorData * guide_data
Definition BKE_effect.h:86
struct PartDeflect * pd
Definition BKE_effect.h:80
struct EffectorCache * next
Definition BKE_effect.h:72
struct Object * ob
Definition BKE_effect.h:76
struct Depsgraph * depsgraph
Definition BKE_effect.h:74
float loc[3]
Definition BKE_effect.h:54
float distance
Definition BKE_effect.h:59
float vec_to_point[3]
Definition BKE_effect.h:58
float vec_to_point2[3]
Definition BKE_effect.h:65
float nor[3]
Definition BKE_effect.h:55
float falloff
Definition BKE_effect.h:59
float vel[3]
Definition BKE_effect.h:56
float nor2[3]
Definition BKE_effect.h:65
struct EffectorRelation * next
Definition BKE_effect.h:94
struct ParticleSystem * psys
Definition BKE_effect.h:97
struct PartDeflect * pd
Definition BKE_effect.h:98
struct Object * ob
Definition BKE_effect.h:96
struct EffectorRelation * prev
Definition BKE_effect.h:94
float vec_to_point[3]
Definition BKE_effect.h:48
Definition rand.cc:33
struct GHash * gh
Definition BKE_effect.h:224
unsigned int category_hash
Definition BKE_effect.h:205
unsigned int hash
Definition BKE_effect.h:206