|
Blender
V2.59
|
00001 /* 00002 * $Id: BKE_particle.h 37760 2011-06-23 18:59:47Z lukastoenne $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2007 by Janne Karhu. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00030 #ifndef BKE_PARTICLE_H 00031 #define BKE_PARTICLE_H 00032 00037 #include "DNA_particle_types.h" 00038 #include "DNA_object_types.h" 00039 00040 struct ParticleSystemModifierData; 00041 struct ParticleSystem; 00042 struct ParticleKey; 00043 struct ParticleSettings; 00044 struct HairKey; 00045 00046 struct Main; 00047 struct Group; 00048 struct Object; 00049 struct Scene; 00050 struct DerivedMesh; 00051 struct ModifierData; 00052 struct MTFace; 00053 struct MCol; 00054 struct MFace; 00055 struct MVert; 00056 struct IpoCurve; 00057 struct LinkNode; 00058 struct KDTree; 00059 struct RNG; 00060 struct SurfaceModifierData; 00061 struct BVHTreeRay; 00062 struct BVHTreeRayHit; 00063 00064 #define PARTICLE_P ParticleData *pa; int p 00065 #define LOOP_PARTICLES for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++) 00066 #define LOOP_EXISTING_PARTICLES for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++) if(!(pa->flag & PARS_UNEXIST)) 00067 #define LOOP_SHOWN_PARTICLES for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++) if(!(pa->flag & (PARS_UNEXIST|PARS_NO_DISP))) 00068 #define LOOP_DYNAMIC_PARTICLES for(p=0, pa=psys->particles; p<psys->totpart; p++, pa++) if(pa->state.time > 0.f) 00069 00070 #define PSYS_FRAND_COUNT 1024 00071 #define PSYS_FRAND(seed) psys->frand[(seed) % PSYS_FRAND_COUNT] 00072 00073 /* fast but sure way to get the modifier*/ 00074 #define PARTICLE_PSMD ParticleSystemModifierData *psmd = sim->psmd ? sim->psmd : psys_get_modifier(sim->ob, sim->psys) 00075 00076 /* common stuff that many particle functions need */ 00077 typedef struct ParticleSimulationData { 00078 struct Scene *scene; 00079 struct Object *ob; 00080 struct ParticleSystem *psys; 00081 struct ParticleSystemModifierData *psmd; 00082 struct ListBase *colliders; 00083 } ParticleSimulationData; 00084 00085 typedef struct ParticleTexture{ 00086 float ivel; /* used in reset */ 00087 float time, life, exist, size; /* used in init */ 00088 float damp, gravity, field; /* used in physics */ 00089 float length, clump, kink, effector;/* used in path caching */ 00090 float rough1, rough2, roughe; /* used in path caching */ 00091 } ParticleTexture; 00092 00093 typedef struct ParticleSeam{ 00094 float v0[3], v1[3]; 00095 float nor[3], dir[3], tan[3]; 00096 float length2; 00097 } ParticleSeam; 00098 00099 typedef struct ParticleCacheKey{ 00100 float co[3]; 00101 float vel[3]; 00102 float rot[4]; 00103 float col[3]; 00104 float time; 00105 int steps; 00106 } ParticleCacheKey; 00107 00108 typedef struct ParticleThreadContext { 00109 /* shared */ 00110 struct ParticleSimulationData sim; 00111 struct DerivedMesh *dm; 00112 struct Material *ma; 00113 00114 /* distribution */ 00115 struct KDTree *tree; 00116 00117 struct ParticleSeam *seams; 00118 int totseam; 00119 00120 float *jit, *jitoff, *weight; 00121 float maxweight; 00122 int *index, *skip, jitlevel; 00123 00124 int from, cfrom, distr; 00125 00126 struct ParticleData *tpars; 00127 00128 /* path caching */ 00129 int editupdate, between, steps; 00130 int totchild, totparent, parent_pass; 00131 00132 float cfra; 00133 00134 float *vg_length, *vg_clump, *vg_kink; 00135 float *vg_rough1, *vg_rough2, *vg_roughe; 00136 float *vg_effector; 00137 } ParticleThreadContext; 00138 00139 typedef struct ParticleThread { 00140 ParticleThreadContext *ctx; 00141 struct RNG *rng, *rng_path; 00142 int num, tot; 00143 } ParticleThread; 00144 00145 typedef struct ParticleBillboardData 00146 { 00147 struct Object *ob; 00148 float vec[3], vel[3]; 00149 float offset[2]; 00150 float size[2]; 00151 float tilt, random, time; 00152 int uv[3]; 00153 int lock, num; 00154 int totnum; 00155 int lifetime; 00156 short align, uv_split, anim, split_offset; 00157 } ParticleBillboardData; 00158 00159 typedef struct ParticleCollisionElement 00160 { 00161 /* pointers to original data */ 00162 float *x[4], *v[4]; 00163 00164 /* values interpolated from original data*/ 00165 float x0[3], x1[3], x2[3], p[3]; 00166 00167 /* results for found intersection point */ 00168 float nor[3], vel[3], uv[2]; 00169 00170 /* count of original data (1-4) */ 00171 int tot; 00172 00173 /* index of the collision face */ 00174 int index; 00175 00176 /* flags for inversed normal / particle already inside element at start */ 00177 short inv_nor, inside; 00178 } ParticleCollisionElement; 00179 00180 /* container for moving data between deflet_particle and particle_intersect_face */ 00181 typedef struct ParticleCollision 00182 { 00183 struct Object *current; 00184 struct Object *hit; 00185 struct Object *prev; 00186 struct Object *skip; 00187 struct Object *emitter; 00188 00189 struct CollisionModifierData *md; // collision modifier for current object; 00190 00191 float f; // time factor of previous collision, needed for substracting face velocity 00192 float fac1, fac2; 00193 00194 float cfra, old_cfra; 00195 00196 float original_ray_length; //original length of co2-co1, needed for collision time evaluation 00197 00198 int prev_index; 00199 00200 ParticleCollisionElement pce; 00201 00202 float total_time, inv_timestep; 00203 00204 float radius; 00205 float co1[3], co2[3]; 00206 float ve1[3], ve2[3]; 00207 00208 float acc[3], boid_z; 00209 00210 int boid; 00211 } ParticleCollision; 00212 00213 typedef struct ParticleDrawData { 00214 float *vdata, *vd; /* vertice data */ 00215 float *ndata, *nd; /* normal data */ 00216 float *cdata, *cd; /* color data */ 00217 float *vedata, *ved; /* velocity data */ 00218 float *ma_r, *ma_g, *ma_b; 00219 int tot_vec_size, flag; 00220 int totpoint, totve; 00221 } ParticleDrawData; 00222 00223 #define PARTICLE_DRAW_DATA_UPDATED 1 00224 00225 /* ----------- functions needed outside particlesystem ---------------- */ 00226 /* particle.c */ 00227 int count_particles(struct ParticleSystem *psys); 00228 int count_particles_mod(struct ParticleSystem *psys, int totgr, int cur); 00229 00230 struct ParticleSystem *psys_get_current(struct Object *ob); 00231 /* for rna */ 00232 short psys_get_current_num(struct Object *ob); 00233 void psys_set_current_num(Object *ob, int index); 00234 struct Object *psys_find_object(struct Scene *scene, struct ParticleSystem *psys); 00235 00236 struct Object *psys_get_lattice(struct ParticleSimulationData *sim); 00237 00238 int psys_in_edit_mode(struct Scene *scene, struct ParticleSystem *psys); 00239 int psys_check_enabled(struct Object *ob, struct ParticleSystem *psys); 00240 int psys_check_edited(struct ParticleSystem *psys); 00241 00242 void psys_check_group_weights(struct ParticleSettings *part); 00243 int psys_uses_gravity(struct ParticleSimulationData *sim); 00244 00245 /* free */ 00246 void psys_free_settings(struct ParticleSettings *part); 00247 void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit); 00248 void psys_free(struct Object * ob, struct ParticleSystem * psys); 00249 00250 void psys_render_set(struct Object *ob, struct ParticleSystem *psys, float viewmat[][4], float winmat[][4], int winx, int winy, int timeoffset); 00251 void psys_render_restore(struct Object *ob, struct ParticleSystem *psys); 00252 int psys_render_simplify_distribution(struct ParticleThreadContext *ctx, int tot); 00253 int psys_render_simplify_params(struct ParticleSystem *psys, struct ChildParticle *cpa, float *params); 00254 00255 void psys_interpolate_uvs(struct MTFace *tface, int quad, float *uv, float *uvco); 00256 void psys_interpolate_mcol(struct MCol *mcol, int quad, float *uv, struct MCol *mc); 00257 00258 void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int time); 00259 00260 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); 00261 struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys); 00262 00263 struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name); 00264 void object_remove_particle_system(struct Scene *scene, struct Object *ob); 00265 struct ParticleSettings *psys_new_settings(const char *name, struct Main *main); 00266 struct ParticleSettings *psys_copy_settings(struct ParticleSettings *part); 00267 void make_local_particlesettings(struct ParticleSettings *part); 00268 00269 void psys_reset(struct ParticleSystem *psys, int mode); 00270 00271 void psys_find_parents(struct ParticleSimulationData *sim); 00272 00273 void psys_cache_paths(struct ParticleSimulationData *sim, float cfra); 00274 void psys_cache_edit_paths(struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra); 00275 void psys_cache_child_paths(struct ParticleSimulationData *sim, float cfra, int editupdate); 00276 int do_guides(struct ListBase *effectors, ParticleKey *state, int pa_num, float time); 00277 void precalc_guides(struct ParticleSimulationData *sim, struct ListBase *effectors); 00278 float psys_get_timestep(struct ParticleSimulationData *sim); 00279 float psys_get_child_time(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *birthtime, float *dietime); 00280 float psys_get_child_size(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *pa_time); 00281 void psys_get_particle_on_path(struct ParticleSimulationData *sim, int pa_num, struct ParticleKey *state, int vel); 00282 int psys_get_particle_state(struct ParticleSimulationData *sim, int p, struct ParticleKey *state, int always); 00283 00284 /* for anim.c */ 00285 void psys_get_dupli_texture(struct ParticleSystem *psys, struct ParticleSettings *part, struct ParticleSystemModifierData *psmd, struct ParticleData *pa, struct ChildParticle *cpa, float *uv, float *orco); 00286 void psys_get_dupli_path_transform(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ChildParticle *cpa, struct ParticleCacheKey *cache, float mat[][4], float *scale); 00287 00288 ParticleThread *psys_threads_create(struct ParticleSimulationData *sim); 00289 void psys_threads_free(ParticleThread *threads); 00290 00291 void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]); 00292 void psys_apply_hair_lattice(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); 00293 00294 /* particle_system.c */ 00295 struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt); 00296 void psys_count_keyed_targets(struct ParticleSimulationData *sim); 00297 void psys_update_particle_tree(struct ParticleSystem *psys, float cfra); 00298 00299 void psys_make_temp_pointcache(struct Object *ob, struct ParticleSystem *psys); 00300 void psys_get_pointcache_start_end(struct Scene *scene, ParticleSystem *psys, int *sfra, int *efra); 00301 00302 void psys_check_boid_data(struct ParticleSystem *psys); 00303 00304 void psys_get_birth_coordinates(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, float dtime, float cfra); 00305 00306 void particle_system_update(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys); 00307 00308 /* ----------- functions needed only inside particlesystem ------------ */ 00309 /* particle.c */ 00310 void psys_disable_all(struct Object *ob); 00311 void psys_enable_all(struct Object *ob); 00312 00313 void free_hair(struct Object *ob, struct ParticleSystem *psys, int dynamics); 00314 void free_keyed_keys(struct ParticleSystem *psys); 00315 void psys_free_particles(struct ParticleSystem *psys); 00316 void psys_free_children(struct ParticleSystem *psys); 00317 00318 void psys_interpolate_particle(short type, struct ParticleKey keys[4], float dt, struct ParticleKey *result, int velocity); 00319 void psys_vec_rot_to_face(struct DerivedMesh *dm, struct ParticleData *pa, float *vec); 00320 void psys_mat_hair_to_object(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]); 00321 void psys_mat_hair_to_global(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]); 00322 void psys_mat_hair_to_orco(struct Object *ob, struct DerivedMesh *dm, short from, struct ParticleData *pa, float hairmat[][4]); 00323 00324 float psys_get_dietime_from_cache(struct PointCache *cache, int index); 00325 00326 void psys_free_pdd(struct ParticleSystem *psys); 00327 00328 float *psys_cache_vgroup(struct DerivedMesh *dm, struct ParticleSystem *psys, int vgroup); 00329 void psys_get_texture(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleTexture *ptex, int event, float cfra); 00330 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); 00331 float psys_particle_value_from_verts(struct DerivedMesh *dm, short from, struct ParticleData *pa, float *values); 00332 void psys_get_from_key(struct ParticleKey *key, float *loc, float *vel, float *rot, float *time); 00333 00334 /* BLI_bvhtree_ray_cast callback */ 00335 void BKE_psys_collision_neartest_cb(void *userdata, int index, const struct BVHTreeRay *ray, struct BVHTreeRayHit *hit); 00336 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); 00337 00338 /* particle_system.c */ 00339 void initialize_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, int p); 00340 void psys_calc_dmcache(struct Object *ob, struct DerivedMesh *dm, struct ParticleSystem *psys); 00341 int psys_particle_dm_face_lookup(struct Object *ob, struct DerivedMesh *dm, int index, float *fw, struct LinkNode *node); 00342 00343 void reset_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, float dtime, float cfra); 00344 00345 /* psys_reset */ 00346 #define PSYS_RESET_ALL 1 00347 #define PSYS_RESET_DEPSGRAPH 2 00348 /* #define PSYS_RESET_CHILDREN 3 */ /*UNUSED*/ 00349 #define PSYS_RESET_CACHE_MISS 4 00350 00351 /* index_dmcache */ 00352 #define DMCACHE_NOTFOUND -1 00353 #define DMCACHE_ISCHILD -2 00354 00355 #endif