Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJanne Karhu <jhkarh@gmail.com>2011-03-12 15:38:11 +0300
committerJanne Karhu <jhkarh@gmail.com>2011-03-12 15:38:11 +0300
commit5b75593c239f9db213c07804f41a130751245cb6 (patch)
tree58b0af98cc1b74be556a966e2c9fbba9fb136f49 /source/blender/editors
parent60fe23b10006095a53bc9dc845ea09bf05168d2c (diff)
Completely refactored sph fluid particles. Only the very core of the algorithm remains
the same, but big changes have happened both on the outside and on the inside. New UI: * The old parameters were quite true to the underlying algorithm, but were quite obscure from a users point of view. Now there are only a few intuitive basic parameters that define the basic fluid behavior. ** By default particle size is now used to determine the interaction radius, rest density and spring rest lengths so that it's easy to get stable simulations by simply emitting particles for a few frames and adjusting the particle size (easy when the particle size is drawn) so that the fluid appears continuous (particles are touching eachother). ** Stiffness - in reality most fluids are very incompressible, but this is a very hard problem to solve with particle based fluid simulation so some compromises have to be made. So the bigger the stiffness parameter is the less the fluid will compress under stress, but the more substeps are needed for stable simulation. ** Viscosity - how much internal friction there is in the fluid. Large viscosities also smooth out instabilities, so less viscous fluids again need more substeps to remain stable. ** Buoancy - with high buoancy low pressure areas inside the fluid start to rise against gravity, and high pressure areas start to come down. * In addition to these basic parameters there are separate advanced parameters that can either be tweaked relative to the basic parameters (or particle size) or defined independently. ** Repulsion - the stiffness parameter tries to keep the fluid density constant, but this can lead to small clumps of particles, so the repulsion keeps the particles better separated. ** Stiff viscosity - the normal viscosity only applies when particles are moving closer to eachother to allow free flowing fluids. Stiff viscosity also applies smoothing to particles that are moving away from eachother. ** Interaction radius - by default this is 4 * particle size. ** Rest density - by default this is a density that the particles have when they're packed densely next to eachother. ** Spring rest length - by default this is 2 * particle size. * There are also new options for 3d view particle coloring in the display panel to show particle velocity and acceleration. These make it easier to see what's happening in the fluid simulations, but can of course be used with other particles as well. * Viscoelastic springs have some new options too. The plasticity can now be set to much higher values for instant deletion of springs as the elastic limit is exeeded. In addition to that there is an option to only create springs for a certain number of frames when a particle is born. These options give new possibilities for breaking viscoelastic fluids. New in the code: * Most of the fluids code is now thread safe, so when particle dynamics go threaded there will be a nice speed boost to fluids as well. * Fluids now use a bvh-tree instead of a kd-tree for the neighbor lookups. The bvh-tree implementation makes the code quite a bit cleaner and should also give a slight speed boost to the simulation too. * Previously only force fields were calculated with the different integration methods, but now the fluid calculations are also done using the selected integration method, so there are again more choices in effecting simulation accuracy and stability. This change also included a nice cleanup of the whole particle integration code. As the internals are pretty stirred up old particle fluid simulations will probably not work correctly straight away, but with some tweaking the same level of control is still available by not using the "relative versions" of the advanced parameters (by default these are not used when loading old files).
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/space_view3d/drawobject.c81
1 files changed, 23 insertions, 58 deletions
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index bd3c140c647..4979c3c2a2a 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -3465,7 +3465,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
Material *ma;
float vel[3], imat[4][4];
float timestep, pixsize=1.0, pa_size, r_tilt, r_length;
- float pa_time, pa_birthtime, pa_dietime, pa_health;
+ float pa_time, pa_birthtime, pa_dietime, pa_health, intensity;
float cfra;
float ma_r=0.0f, ma_g=0.0f, ma_b=0.0f;
int a, totpart, totpoint=0, totve=0, drawn, draw_as, totchild=0;
@@ -3529,7 +3529,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(v3d->zbuf) glDepthMask(1);
- if((ma) && (part->draw&PART_DRAW_MAT_COL)) {
+ if((ma) && (part->draw_col == PART_DRAW_COL_MAT)) {
rgb_float_to_byte(&(ma->r), tcol);
ma_r = ma->r;
@@ -3630,6 +3630,10 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
normalize_v3(imat[1]);
}
+ if(ELEM3(draw_as, PART_DRAW_DOT, PART_DRAW_CROSS, PART_DRAW_LINE)
+ && part->draw_col > PART_DRAW_COL_MAT)
+ create_cdata = 1;
+
if(!create_cdata && pdd && pdd->cdata) {
MEM_freeN(pdd->cdata);
pdd->cdata = pdd->cd = NULL;
@@ -3672,7 +3676,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(create_cdata && !pdd->cdata)
pdd->cdata = MEM_callocN(tot_vec_size, "particle_cdata");
if(create_ndata && !pdd->ndata)
- pdd->ndata = MEM_callocN(tot_vec_size, "particle_vdata");
+ pdd->ndata = MEM_callocN(tot_vec_size, "particle_ndata");
if(part->draw & PART_DRAW_VEL && draw_as != PART_DRAW_LINE) {
if(!pdd->vedata)
@@ -3727,65 +3731,26 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
else
pa_health = -1.0;
-#if 0 // XXX old animation system
- if((part->flag&PART_ABS_TIME)==0){
- if(ma && ma->ipo){
- IpoCurve *icu;
-
- /* correction for lifetime */
- calc_ipo(ma->ipo, 100.0f*pa_time);
-
- for(icu = ma->ipo->curve.first; icu; icu=icu->next) {
- if(icu->adrcode == MA_COL_R)
- ma_r = icu->curval;
- else if(icu->adrcode == MA_COL_G)
- ma_g = icu->curval;
- else if(icu->adrcode == MA_COL_B)
- ma_b = icu->curval;
- }
- }
- if(part->ipo) {
- IpoCurve *icu;
-
- /* correction for lifetime */
- calc_ipo(part->ipo, 100*pa_time);
+ r_tilt = 2.0f*(PSYS_FRAND(a + 21) - 0.5f);
+ r_length = PSYS_FRAND(a + 22);
- for(icu = part->ipo->curve.first; icu; icu=icu->next) {
- if(icu->adrcode == PART_SIZE)
- pa_size = icu->curval;
- }
+ if(part->draw_col > PART_DRAW_COL_MAT) {
+ switch(part->draw_col) {
+ case PART_DRAW_COL_VEL:
+ intensity = len_v3(pa->state.vel)/part->color_vec_max;
+ break;
+ case PART_DRAW_COL_ACC:
+ intensity = len_v3v3(pa->state.vel, pa->prev_state.vel)/((pa->state.time-pa->prev_state.time)*part->color_vec_max);
+ break;
}
+ CLAMP(intensity, 0.f, 1.f);
+ weight_to_rgb(intensity, &ma_r, &ma_g, &ma_b);
}
-#endif // XXX old animation system
-
- r_tilt = 2.0f*(PSYS_FRAND(a + 21) - 0.5f);
- r_length = PSYS_FRAND(a + 22);
}
else{
ChildParticle *cpa= &psys->child[a-totpart];
pa_time=psys_get_child_time(psys,cpa,cfra,&pa_birthtime,&pa_dietime);
-
-#if 0 // XXX old animation system
- if((part->flag&PART_ABS_TIME)==0) {
- if(ma && ma->ipo){
- IpoCurve *icu;
-
- /* correction for lifetime */
- calc_ipo(ma->ipo, 100.0f*pa_time);
-
- for(icu = ma->ipo->curve.first; icu; icu=icu->next) {
- if(icu->adrcode == MA_COL_R)
- ma_r = icu->curval;
- else if(icu->adrcode == MA_COL_G)
- ma_g = icu->curval;
- else if(icu->adrcode == MA_COL_B)
- ma_b = icu->curval;
- }
- }
- }
-#endif // XXX old animation system
-
pa_size=psys_get_child_size(psys,cpa,cfra,NULL);
pa_health = -1.0;
@@ -3911,7 +3876,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if (1) { //ob_dt > OB_WIRE) {
glEnableClientState(GL_NORMAL_ARRAY);
- if(part->draw&PART_DRAW_MAT_COL)
+ if(part->draw_col == PART_DRAW_COL_MAT)
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_LIGHTING);
@@ -3940,7 +3905,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(1) { //ob_dt > OB_WIRE) {
glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
- if(part->draw&PART_DRAW_MAT_COL)
+ if(part->draw_col == PART_DRAW_COL_MAT)
glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
}
@@ -3956,7 +3921,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
if(1) { //ob_dt > OB_WIRE) {
glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
- if(part->draw&PART_DRAW_MAT_COL)
+ if(part->draw_col == PART_DRAW_COL_MAT)
glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
}
@@ -3966,7 +3931,7 @@ static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv
/* restore & clean up */
if(1) { //ob_dt > OB_WIRE) {
- if(part->draw&PART_DRAW_MAT_COL)
+ if(part->draw_col == PART_DRAW_COL_MAT)
glDisable(GL_COLOR_ARRAY);
glDisable(GL_COLOR_MATERIAL);
}