Smoke:
authorDaniel Genrich <daniel.genrich@gmx.net>
Tue, 25 Aug 2009 23:39:49 +0000 (23:39 +0000)
committerDaniel Genrich <daniel.genrich@gmx.net>
Tue, 25 Aug 2009 23:39:49 +0000 (23:39 +0000)
*Bugfix for crash on using a plane as smoke domain (reported by DingTo)
* Bringing slowly high res back, not yet working

source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/editors/space_view3d/drawobject.c
source/blender/makesdna/DNA_smoke_types.h
source/blender/makesrna/intern/rna_smoke.c

index d9740091912e838fb6d100efb6bf026cac72b2ef..42bea26045069661d77b4001f163e1065a67a34f 100644 (file)
@@ -703,11 +703,44 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
        pid->calldata= smd;
        
        pid->type= PTCACHE_TYPE_SMOKE_DOMAIN;
-       pid->stack_index= sds->point_cache->index;
+       pid->stack_index= sds->point_cache[0]->index;
 
-       pid->cache= sds->point_cache;
-       pid->cache_ptr= &sds->point_cache;
-       pid->ptcaches= &sds->ptcaches;
+       pid->cache= sds->point_cache[0];
+       pid->cache_ptr= &(sds->point_cache[0]);
+       pid->ptcaches= &(sds->ptcaches[0]);
+
+       pid->totpoint= pid->totwrite= ptcache_totpoint_smoke;
+
+       pid->write_elem= NULL;
+       pid->read_elem= NULL;
+
+       pid->read_stream = ptcache_read_smoke;
+       pid->write_stream = ptcache_write_smoke;
+       
+       pid->interpolate_elem= NULL;
+
+       pid->write_header= ptcache_write_basic_header;
+       pid->read_header= ptcache_read_basic_header;
+
+       pid->data_types= (1<<BPHYS_DATA_LOCATION); // bogus values tot make pointcache happy
+       pid->info_types= 0;
+}
+
+void BKE_ptcache_id_from_smoke_turbulence(PTCacheID *pid, struct Object *ob, struct SmokeModifierData *smd)
+{
+       SmokeDomainSettings *sds = smd->domain;
+
+       memset(pid, 0, sizeof(PTCacheID));
+
+       pid->ob= ob;
+       pid->calldata= smd;
+       
+       pid->type= PTCACHE_TYPE_SMOKE_HIGHRES;
+       pid->stack_index= sds->point_cache[1]->index;
+
+       pid->cache= sds->point_cache[1];
+       pid->cache_ptr= &sds->point_cache[1];
+       pid->ptcaches= &sds->ptcaches[1];
 
        pid->totpoint= pid->totwrite= ptcache_totpoint_smoke;
 
@@ -1792,10 +1825,7 @@ int BKE_ptcache_id_reset(Scene *scene, PTCacheID *pid, int mode)
                else if(pid->type == PTCACHE_TYPE_PARTICLES)
                        psys_reset(pid->calldata, PSYS_RESET_DEPSGRAPH);
                else if(pid->type == PTCACHE_TYPE_SMOKE_DOMAIN)
-               {
                        smokeModifier_reset(pid->calldata);
-                       printf("reset PTCACHE_TYPE_SMOKE_DOMAIN\n");
-               }
        }
        if(clear)
                BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
index 28d1c264376af34269eca6b13cfbe37ff19b66f2..cd9679be4863981570d47667947956a0d05e1156 100644 (file)
@@ -166,6 +166,10 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
 
                // calc other res with max_res provided
                VECSUB(size, max, min);
+
+               if((size[0] < FLT_EPSILON) || (size[1] < FLT_EPSILON) || (size[2] < FLT_EPSILON))
+                       return 0;
+
                if(size[0] > size[1])
                {
                        if(size[0] > size[1])
@@ -213,13 +217,11 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
                smd->time = scene->r.cfra;
                smd->domain->firstframe = smd->time;
 
-               /*
-               if(!smd->domain->wt)
+               if(!smd->domain->wt && (smd->domain->flags & MOD_SMOKE_HIGHRES))
                {
-                       smd->domain->wt = smoke_turbulence_init(sds->res,  smd->domain->amplify + 1, smd->domain->noise);
+                       smd->domain->wt = smoke_turbulence_init(smd->domain->res,  smd->domain->amplify + 1, smd->domain->noise);
                        smoke_turbulence_initBlenderRNA(smd->domain->wt, &smd->domain->strength);
                }
-               */
 
                if(!smd->domain->view3d)
                {
@@ -409,10 +411,10 @@ int smokeModifier_init (SmokeModifierData *smd, Object *ob, Scene *scene, Derive
                {
                        smd->coll->bvhtree = NULL; // bvhtree_build_from_smoke ( ob->obmat, dm->getFaceArray(dm), dm->getNumFaces(dm), dm->getVertArray(dm), dm->getNumVerts(dm), 0.0 );
                }
-
+               return 1;
        }
 
-       return 0;
+       return 1;
 }
 
 /*! init triangle divisions */
@@ -529,8 +531,10 @@ void smokeModifier_freeDomain(SmokeModifierData *smd)
                if(smd->domain->wt)
                        smoke_turbulence_free(smd->domain->wt);
 
-               BKE_ptcache_free_list(&smd->domain->ptcaches);
-               smd->domain->point_cache = NULL;
+               BKE_ptcache_free_list(&(smd->domain->ptcaches[0]));
+               smd->domain->point_cache[0] = NULL;
+               BKE_ptcache_free_list(&(smd->domain->ptcaches[1]));
+               smd->domain->point_cache[1] = NULL;
 
                MEM_freeN(smd->domain);
                smd->domain = NULL;
@@ -603,10 +607,15 @@ void smokeModifier_reset(struct SmokeModifierData *smd)
                                smd->domain->wt = NULL;
                        }
                
-                       smd->domain->point_cache->flag &= ~PTCACHE_SIMULATION_VALID;
-                       smd->domain->point_cache->flag |= PTCACHE_OUTDATED;
-                       smd->domain->point_cache->simframe= 0;
-                       smd->domain->point_cache->last_exact= 0;
+                       smd->domain->point_cache[0]->flag &= ~PTCACHE_SIMULATION_VALID;
+                       smd->domain->point_cache[0]->flag |= PTCACHE_OUTDATED;
+                       smd->domain->point_cache[0]->simframe= 0;
+                       smd->domain->point_cache[0]->last_exact= 0;
+
+                       smd->domain->point_cache[1]->flag &= ~PTCACHE_SIMULATION_VALID;
+                       smd->domain->point_cache[1]->flag |= PTCACHE_OUTDATED;
+                       smd->domain->point_cache[1]->simframe= 0;
+                       smd->domain->point_cache[1]->last_exact= 0;
 
                        // printf("reset_domain\n");
                }
@@ -666,9 +675,13 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 
                        smd->domain->smd = smd;
 
-                       smd->domain->point_cache = BKE_ptcache_add(&smd->domain->ptcaches);
-                       smd->domain->point_cache->flag |= PTCACHE_DISK_CACHE;
-                       smd->domain->point_cache->step = 1;
+                       smd->domain->point_cache[0] = BKE_ptcache_add(&(smd->domain->ptcaches[0]));
+                       smd->domain->point_cache[0]->flag |= PTCACHE_DISK_CACHE;
+                       smd->domain->point_cache[0]->step = 1;
+
+                       smd->domain->point_cache[1] = BKE_ptcache_add(&(smd->domain->ptcaches[1]));
+                       smd->domain->point_cache[1]->flag |= PTCACHE_DISK_CACHE;
+                       smd->domain->point_cache[1]->step = 1;
 
                        /* set some standard values */
                        smd->domain->fluid = NULL;
@@ -775,8 +788,9 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
        }
        else if(smd->type & MOD_SMOKE_TYPE_DOMAIN)
        {
-               PointCache *cache;
+               PointCache *cache, *cache_wt;
                PTCacheID pid;
+               PTCacheID pid_wt;
                float timescale;
                int cache_result = 0;
                int startframe, endframe, framenr;
@@ -788,7 +802,7 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
 
                framenr = scene->r.cfra;
 
-               cache = sds->point_cache;
+               cache = sds->point_cache[0];
 
                BKE_ptcache_id_from_smoke(&pid, ob, smd);
                BKE_ptcache_id_time(&pid, scene, framenr, &startframe, &endframe, &timescale);
@@ -800,12 +814,15 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
                        cache->simframe= 0;
                        cache->last_exact= 0;
 
-                       smokeModifier_init(smd, ob, scene, dm);
+                       if(!smokeModifier_init(smd, ob, scene, dm))
+                               return;
+
+                       if(!smd->domain->fluid)
+                               return;
 
                        smoke_simulate_domain(smd, scene, ob, dm);
 
                        {
-                               // float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg
                                Base *base_tmp = NULL;
 
                                for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next) 
@@ -852,7 +869,11 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
                        BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
                }
        
-               smokeModifier_init(smd, ob, scene, dm);
+               if(!smokeModifier_init(smd, ob, scene, dm))
+                       return;
+
+               if(!smd->domain->fluid)
+                               return;
 
                /* try to read from cache */
                cache_result = BKE_ptcache_read_cache(&pid, (float)framenr, scene->r.frs_sec);
@@ -904,8 +925,10 @@ void smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedM
 
                smoke_simulate_domain(smd, scene, ob, dm);
 
+               if(sds->wt)
+                       smoke_turbulence_step(sds->wt, sds->fluid);
+
                {
-                       // float light[3] = {0.0,0.0,0.0}; // TODO: take real LAMP coordinates - dg
                        Base *base_tmp = NULL;
 
                        for(base_tmp = scene->base.first; base_tmp; base_tmp= base_tmp->next) 
index 26e3d5bf6f1138816221a090e6707c54c565148b..aaba65b21af068d22628a0e6bf3229ed66abfa8c 100644 (file)
@@ -3695,7 +3695,8 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
                                smd->domain->view3d = NULL;
                                smd->domain->tex = NULL;
 
-                               direct_link_pointcache_list(fd, &smd->domain->ptcaches, &smd->domain->point_cache);
+                               direct_link_pointcache_list(fd, &(smd->domain->ptcaches[0]), &(smd->domain->point_cache[0]));
+                               direct_link_pointcache_list(fd, &(smd->domain->ptcaches[1]), &(smd->domain->point_cache[1]));
                        }
                        else if(smd->type==MOD_SMOKE_TYPE_FLOW)
                        {
index eb3f17f368ce94e7b8dff7b0289e80ada02e6d04..26fd0cf6af636a594af9ef122d3ad25eaffb5912 100644 (file)
@@ -1136,7 +1136,10 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
                        */
 
                        if((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
-                               write_pointcaches(wd, &smd->domain->ptcaches);
+                       {
+                               write_pointcaches(wd, &(smd->domain->ptcaches[0]));
+                               write_pointcaches(wd, &(smd->domain->ptcaches[1]));
+                       }
                } 
                else if(md->type==eModifierType_Fluidsim) {
                        FluidsimModifierData *fluidmd = (FluidsimModifierData*) md;
index bcb962bdcd72ae1fbfb51dbc2d9d7c751006d2ef..6cf229ead31e3bf68d065784697575ccdbade2fe 100644 (file)
@@ -5316,7 +5316,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                md = modifiers_findByType(ob, eModifierType_Smoke);
                if (md) {
                        SmokeModifierData *smd = (SmokeModifierData *)md;
-                       if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
+                       if(smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain && smd->domain->fluid) {
                                GPU_create_smoke(smd);
                                draw_volume(scene, ar, v3d, base, smd->domain->tex, smd->domain->res);
                                GPU_free_smoke(smd);
index 542281e1960044157a374d650f9c85362f26e310..a8ab4734af07a2725a7cbfc18934b3a87ac51b28 100644 (file)
@@ -67,8 +67,8 @@ typedef struct SmokeDomainSettings {
        short diss_percent; 
        short pad;
        int diss_speed;/* in frames */
-       struct PointCache *point_cache; /* definition is in DNA_object_force.h */
-       struct ListBase ptcaches;
+       struct PointCache *point_cache[2];      /* definition is in DNA_object_force.h */
+       struct ListBase ptcaches[2];
        struct WTURBULENCE *wt; // WTURBULENCE object, if active
        int pad3;
        float strength;
index e671665bd177ff6703196927265a3e2cfab5861e..5ef25edacf7c7b033a21dbba0d555250a14f0c7d 100644 (file)
@@ -177,7 +177,7 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
        RNA_def_property_range(prop, 1.0, 100.0);
        RNA_def_property_ui_range(prop, 1.0, 1000.0, 1, 0);
        RNA_def_property_ui_text(prop, "Dissolve Speed", "Dissolve Speed");
-       RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, NULL);
+       RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
 
        prop= RNA_def_property(srna, "highres", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_SMOKE_HIGHRES);
@@ -195,7 +195,7 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
 
        prop= RNA_def_property(srna, "point_cache", PROP_POINTER, PROP_NEVER_NULL);
-       RNA_def_property_pointer_sdna(prop, NULL, "point_cache");
+       RNA_def_property_pointer_sdna(prop, NULL, "point_cache[0]");
        RNA_def_property_struct_type(prop, "PointCache");
        RNA_def_property_ui_text(prop, "Point Cache", "");
 
@@ -224,12 +224,10 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Strength", "Strength of wavelet noise");
        RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_Smoke_reset");
 
-       /*
-       prop= RNA_def_property(srna, "point_cache_hr", PROP_POINTER, PROP_NEVER_NULL);
-       RNA_def_property_pointer_sdna(prop, NULL, "point_cache");
+       prop= RNA_def_property(srna, "point_cache_turbulence", PROP_POINTER, PROP_NEVER_NULL);
+       RNA_def_property_pointer_sdna(prop, NULL, "point_cache[1]");
        RNA_def_property_struct_type(prop, "PointCache");
        RNA_def_property_ui_text(prop, "Point Cache", "");
-       */
 }
 
 static void rna_def_smoke_flow_settings(BlenderRNA *brna)