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