6 * ***** BEGIN GPL LICENSE BLOCK *****
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2007 by Janne Karhu.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL LICENSE BLOCK *****
32 #ifndef BKE_PARTICLE_H
33 #define BKE_PARTICLE_H
35 #include "DNA_particle_types.h"
36 #include "DNA_object_types.h"
38 struct ParticleSystemModifierData;
39 struct ParticleSystem;
41 struct ParticleSettings;
59 typedef struct ParticleEffectorCache {
60 struct ParticleEffectorCache *next, *prev;
63 /* precalculated variables for guides */
64 float firstloc[4], firstdir[3];
67 /* precalculated variables for deflection */
71 /* precalculated variables for boids */
76 struct Object obcopy; /* for restoring transformation data */
77 struct RNG *rng; /* random noise generator for e.g. wind */
78 } ParticleEffectorCache;
80 typedef struct ParticleReactEvent {
81 struct ParticleReactEvent *next, *prev;
84 struct ParticleSystem *psys;
85 struct ParticleKey state;
90 typedef struct ParticleTexture{
91 float ivel; /* used in reset */
92 float time, life, exist, size; /* used in init */
93 float pvel[3]; /* used in physics */
94 float length, clump, kink, rough; /* used in path caching */
97 typedef struct BoidVecFunc{
98 void (*Addf)(float *v, float *v1, float *v2);
99 void (*Subf)(float *v, float *v1, float *v2);
100 void (*Mulf)(float *v, float f);
101 float (*Length)(float *v);
102 float (*Normalize)(float *v);
103 float (*Inpf)(float *v1, float *v2);
104 void (*Copyf)(float *v1, float *v2);
107 typedef struct ParticleSeam{
109 float nor[3], dir[3], tan[3];
113 typedef struct ParticleCacheKey{
121 typedef struct ParticleEditKey{
132 typedef struct ParticleUndo {
133 struct ParticleUndo *next, *prev;
134 struct ParticleEditKey **keys;
135 struct KDTree *emitter_field;
136 struct ParticleData *particles;
137 float *emitter_cosnos;
138 int totpart, totkeys;
142 typedef struct ParticleEdit {
144 struct ParticleUndo *curundo;
146 ParticleEditKey **keys;
151 struct KDTree *emitter_field;
152 float *emitter_cosnos;
158 typedef struct ParticleThreadContext {
162 struct DerivedMesh *dm;
163 struct ParticleSystemModifierData *psmd;
164 struct ParticleSystem *psys;
170 struct ParticleSeam *seams;
173 float *jit, *jitoff, *weight;
175 int *index, *skip, jitlevel;
177 int from, cfrom, distr;
179 struct ParticleData *tpars;
182 int editupdate, between, steps;
183 int totchild, totparent, parent_pass;
187 float *vg_length, *vg_clump, *vg_kink;
188 float *vg_rough1, *vg_rough2, *vg_roughe;
190 } ParticleThreadContext;
192 typedef struct ParticleThread {
193 ParticleThreadContext *ctx;
194 struct RNG *rng, *rng_path;
198 typedef struct ParticleBillboardData
201 float vec[3], vel[3];
203 float size, tilt, random, time;
207 short align, uv_split, anim, split_offset;
209 ParticleBillboardData;
211 /* ----------- functions needed outside particlesystem ---------------- */
213 int count_particles(struct ParticleSystem *psys);
214 int count_particles_mod(struct ParticleSystem *psys, int totgr, int cur);
215 int psys_count_keys(struct ParticleSystem *psys);
216 char *psys_menu_string(struct Object *ob, int for_sb);
218 struct ParticleSystem *psys_get_current(struct Object *ob);
219 short psys_get_current_num(struct Object *ob);
220 struct Object *psys_find_object(struct Scene *scene, struct ParticleSystem *psys);
221 //struct ParticleSystem *psys_get(struct Object *ob, int index);
222 struct ParticleData *psys_get_selected_particle(struct ParticleSystem *psys, int *index);
223 struct ParticleKey *psys_get_selected_key(struct ParticleSystem *psys, int pa_index, int *key_index);
224 void psys_change_act(void *ob_v, void *act_v);
225 struct Object *psys_get_lattice(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
226 void psys_disable_all(struct Object *ob);
227 void psys_enable_all(struct Object *ob);
228 int psys_ob_has_hair(struct Object *ob);
229 int psys_in_edit_mode(struct Scene *scene, struct ParticleSystem *psys);
230 int psys_check_enabled(struct Object *ob, struct ParticleSystem *psys);
232 void psys_free_settings(struct ParticleSettings *part);
233 void free_child_path_cache(struct ParticleSystem *psys);
234 void psys_free_path_cache(struct ParticleSystem *psys);
235 void free_hair(struct ParticleSystem *psys, int softbody);
236 void free_keyed_keys(struct ParticleSystem *psys);
237 void psys_free(struct Object * ob, struct ParticleSystem * psys);
238 void psys_free_children(struct ParticleSystem *psys);
240 void psys_render_set(struct Object *ob, struct ParticleSystem *psys, float viewmat[][4], float winmat[][4], int winx, int winy, int timeoffset);
241 void psys_render_restore(struct Object *ob, struct ParticleSystem *psys);
242 int psys_render_simplify_distribution(struct ParticleThreadContext *ctx, int tot);
243 int psys_render_simplify_params(struct ParticleSystem *psys, struct ChildParticle *cpa, float *params);
245 void psys_interpolate_uvs(struct MTFace *tface, int quad, float *uv, float *uvco);
246 void psys_interpolate_mcol(struct MCol *mcol, int quad, float *uv, struct MCol *mc);
248 void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int time);
250 void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr, int index, int index_dmcache, float *fuv, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
251 struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys);
253 struct ParticleSettings *psys_new_settings(char *name, struct Main *main);
254 struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part);
255 void psys_flush_particle_settings(struct Scene *scene, struct ParticleSettings *part, int recalc);
256 void make_local_particlesettings(struct ParticleSettings *part);
258 struct LinkNode *psys_using_settings(struct Scene *scene, struct ParticleSettings *part, int flush_update);
259 void psys_changed_type(struct ParticleSystem *psys);
260 void psys_reset(struct ParticleSystem *psys, int mode);
262 void psys_find_parents(struct Object *ob, struct ParticleSystemModifierData *psmd, struct ParticleSystem *psys);
264 void psys_cache_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
265 void psys_cache_child_paths(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float cfra, int editupdate);
266 void psys_update_world_cos(struct Object *ob, struct ParticleSystem *psys);
267 int do_guide(struct Scene *scene, struct ParticleKey *state, int pa_num, float time, struct ListBase *lb);
268 float psys_get_size(struct Object *ob, struct Material *ma, struct ParticleSystemModifierData *psmd, struct IpoCurve *icu_size, struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleData *pa, float *vg_size);
269 float psys_get_timestep(struct ParticleSettings *part);
270 float psys_get_child_time(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra);
271 float psys_get_child_size(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *pa_time);
272 void psys_get_particle_on_path(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, int pa_num, struct ParticleKey *state, int vel);
273 int psys_get_particle_state(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, int p, struct ParticleKey *state, int always);
274 void psys_get_dupli_texture(struct Object *ob, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float *uv, float *orco);
275 void psys_get_dupli_path_transform(struct Object *ob, struct ParticleSystem *psys, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, struct ParticleCacheKey *cache, float mat[][4], float *scale);
277 ParticleThread *psys_threads_create(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
278 int psys_threads_init_distribution(ParticleThread *threads, struct Scene *scene, struct DerivedMesh *dm, int from);
279 int psys_threads_init_path(ParticleThread *threads, struct Scene *scene, float cfra, int editupdate);
280 void psys_threads_free(ParticleThread *threads);
282 void psys_thread_distribute_particle(ParticleThread *thread, struct ParticleData *pa, struct ChildParticle *cpa, int p);
283 void psys_thread_create_path(ParticleThread *thread, struct ChildParticle *cpa, ParticleCacheKey *keys, int i);
285 void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]);
287 /* particle_system.c */
288 int psys_count_keyed_targets(struct Object *ob, struct ParticleSystem *psys);
289 void psys_get_reactor_target(struct Object *ob, struct ParticleSystem *psys, struct Object **target_ob, struct ParticleSystem **target_psys);
291 void psys_init_effectors(struct Scene *scene, struct Object *obsrc, struct Group *group, struct ParticleSystem *psys);
292 void psys_end_effectors(struct ParticleSystem *psys);
294 void psys_get_pointcache_start_end(struct Scene *scene, struct ParticleSystem *psys, int *sfra, int *efra);
296 void particle_system_update(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
298 /* ----------- functions needed only inside particlesystem ------------ */
300 void psys_interpolate_particle(short type, struct ParticleKey keys[4], float dt, struct ParticleKey *result, int velocity);
301 void psys_key_to_object(struct Object *ob, struct ParticleKey *key, float imat[][4]);
302 //void psys_key_to_geometry(struct DerivedMesh *dm, struct ParticleData *pa, struct ParticleKey *key);
303 //void psys_key_from_geometry(struct DerivedMesh *dm, struct ParticleData *pa, struct ParticleKey *key);
304 //void psys_face_mat(struct DerivedMesh *dm, struct ParticleData *pa, float mat[][4]);
305 void psys_vec_rot_to_face(struct DerivedMesh *dm, struct ParticleData *pa, float *vec);
306 //void psys_vec_rot_from_face(struct DerivedMesh *dm, struct ParticleData *pa, float *vec);
307 void psys_mat_hair_to_object(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]);
308 void psys_mat_hair_to_global(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]);
309 void psys_mat_hair_to_orco(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]);
311 float *psys_cache_vgroup(struct DerivedMesh *dm, struct ParticleSystem *psys, int vgroup);
312 void psys_get_texture(struct Object *ob, struct Material *ma, struct ParticleSystemModifierData *psmd, struct ParticleSystem *psys, struct ParticleData *pa, struct ParticleTexture *ptex, int event);
313 void psys_interpolate_face(struct MVert *mvert, struct MFace *mface, struct MTFace *tface, float (*orcodata)[3], float *uv, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
314 float psys_particle_value_from_verts(struct DerivedMesh *dm, short from, struct ParticleData *pa, float *values);
315 float psys_interpolate_value_from_verts(struct DerivedMesh *dm, short from, int index, float *fw, float *values);
316 void psys_get_from_key(struct ParticleKey *key, float *loc, float *vel, float *rot, float *time);
318 int psys_intersect_dm(struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float *vert_cos, float *co1, float* co2, float *min_d, int *min_face, float *min_uv, float *face_minmax, float *pa_minmax, float radius, float *ipoint);
319 void psys_particle_on_dm(struct DerivedMesh *dm, int from, int index, int index_dmcache, float *fw, float foffset, float *vec, float *nor, float *utan, float *vtan, float *orco, float *ornor);
321 /* particle_system.c */
322 void initialize_particle(struct ParticleData *pa, int p, struct Object *ob, struct ParticleSystem *psys, struct ParticleSystemModifierData *psmd);
324 void do_effectors(int pa_no, struct ParticleData *pa, struct ParticleKey *state, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, float *texco, float *force_field, float *vel,float framestep, float cfra);
326 void psys_calc_dmcache(struct Object *ob, struct DerivedMesh *dm, struct ParticleSystem *psys);
327 int psys_particle_dm_face_lookup(struct Object *ob, struct DerivedMesh *dm, int index, float *fw, struct LinkNode *node);
329 void reset_particle(struct Scene *scene, struct ParticleData *pa, struct ParticleSystem *psys, struct ParticleSystemModifierData *psmd, struct Object *ob,
330 float dtime, float cfra, float *vg_vel, float *vg_tan, float *vg_rot);
334 #define PSYS_RESET_ALL 1
335 #define PSYS_RESET_DEPSGRAPH 2
336 #define PSYS_RESET_CHILDREN 3
337 #define PSYS_RESET_CACHE_MISS 4
339 /* ParticleEffectorCache->type */
340 #define PSYS_EC_EFFECTOR 1
341 #define PSYS_EC_DEFLECT 2
342 #define PSYS_EC_PARTICLE 4
343 #define PSYS_EC_REACTOR 8
345 /* ParticleEditKey->flag */
347 #define PEK_TO_SELECT 2
352 #define DMCACHE_NOTFOUND -1
353 #define DMCACHE_ISCHILD -2