Commit: 61e194757bc5afb8a9ab52703f981144db8a2349
Author: Sebastián Barschkis
Date:   Fri Aug 24 00:25:27 2018 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rB61e194757bc5afb8a9ab52703f981144db8a2349

improved cache directory handling

===================================================================

M       intern/mantaflow/intern/FLUID.cpp
M       source/blender/blenkernel/intern/smoke.c
M       source/blender/editors/physics/physics_fluid.c

===================================================================

diff --git a/intern/mantaflow/intern/FLUID.cpp 
b/intern/mantaflow/intern/FLUID.cpp
index ada723cc893..7c67df19d0c 100644
--- a/intern/mantaflow/intern/FLUID.cpp
+++ b/intern/mantaflow/intern/FLUID.cpp
@@ -896,6 +896,7 @@ int FLUID::updateFlipStructures(SmokeModifierData *smd, int 
framenr)
                std::cout << "FLUID::updateFlipStructures()" << std::endl;
 
        if (!mUsingLiquid) return 0;
+       if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
        std::ostringstream ss;
        char cacheDir[FILE_MAX], targetFile[FILE_MAX];
@@ -932,6 +933,7 @@ int FLUID::updateMeshStructures(SmokeModifierData *smd, int 
framenr)
                std::cout << "FLUID::updateMeshStructures()" << std::endl;
 
        if (!mUsingMesh) return 0;
+       if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
        std::ostringstream ss;
        char cacheDir[FILE_MAX], targetFile[FILE_MAX];
@@ -969,6 +971,7 @@ int FLUID::updateParticleStructures(SmokeModifierData *smd, 
int framenr)
                std::cout << "FLUID::updateParticleStructures()" << std::endl;
 
        if (!mUsingDrops && !mUsingBubbles && !mUsingFloats && !mUsingTracers) 
return 0;
+       if (BLI_path_is_rel(smd->domain->cache_directory)) return 0;
 
        std::ostringstream ss;
        char cacheDir[FILE_MAX], targetFile[FILE_MAX];
diff --git a/source/blender/blenkernel/intern/smoke.c 
b/source/blender/blenkernel/intern/smoke.c
index f840ec5e2e3..e8b830a11f4 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -549,7 +549,7 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
                        smd->domain->particle_tracer_amount = 0.5f;
                        smd->domain->particle_tracer_life = 250.0f;
                        smd->domain->particle_tracer_max = 2;
-                       smd->domain->particle_type = 0;
+                       smd->domain->particle_type = FLUID_DOMAIN_PARTICLE_FLIP;
                        smd->domain->particle_scale = 1;
 
                        /* fluid guiding options */
@@ -798,6 +798,7 @@ void smokeModifier_copy(const struct SmokeModifierData 
*smd, struct SmokeModifie
                tsmd->domain->cache_data_format = 
smd->domain->cache_data_format;
                tsmd->domain->cache_particle_format = 
smd->domain->cache_particle_format;
                tsmd->domain->cache_noise_format = 
smd->domain->cache_noise_format;
+               BLI_strncpy(tsmd->domain->cache_directory, 
smd->domain->cache_directory, sizeof(tsmd->domain->cache_directory));
 
                /* viewport display options */
                tsmd->domain->viewport_display_mode = 
smd->domain->viewport_display_mode;
diff --git a/source/blender/editors/physics/physics_fluid.c 
b/source/blender/editors/physics/physics_fluid.c
index 70d381694c9..635a9315cee 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -1178,6 +1178,51 @@ static bool fluid_manta_initjob(bContext *C, 
FluidMantaflowJob *job, wmOperator
 
        return true;
 }
+
+static bool fluid_manta_initpaths(FluidMantaflowJob *job, ReportList *reports)
+{
+       SmokeDomainSettings *sds = job->smd->domain;
+       char tmpDir[FILE_MAX];
+       tmpDir[0] = '\0';
+
+       const char *relbase = modifier_path_relbase(job->bmain, job->ob);
+
+       /* We do not accept empty paths, they can end in random places 
silently, see T51176. */
+       if (sds->cache_directory[0] == '\0') {
+               modifier_path_init(sds->cache_directory, 
sizeof(sds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
+               BKE_reportf(reports, RPT_WARNING, "Fluid Mantaflow: Empty cache 
path, reset to default '%s'", sds->cache_directory);
+       }
+
+       BLI_strncpy(tmpDir, sds->cache_directory, FILE_MAXDIR);
+       BLI_path_abs(tmpDir, relbase);
+
+       /* Ensure whole path exists */
+       const bool dir_exists = BLI_dir_create_recursive(tmpDir);
+
+       /* We change path to some presumably valid default value, but do not 
allow bake process to continue,
+        * this gives user chance to set manually another path. */
+       if (!dir_exists) {
+               modifier_path_init(sds->cache_directory, 
sizeof(sds->cache_directory), FLUID_DOMAIN_DIR_DEFAULT);
+
+               BKE_reportf(reports, RPT_ERROR, "Fluid Mantaflow: Could not 
create cache directory '%s', reset to default '%s'",
+                                   tmpDir, sds->cache_directory);
+
+               BLI_strncpy(tmpDir, sds->cache_directory, FILE_MAXDIR);
+               BLI_path_abs(tmpDir, relbase);
+
+               /* Ensure whole path exists and is wirtable. */
+               if (!BLI_dir_create_recursive(tmpDir)) {
+                       BKE_reportf(reports, RPT_ERROR, "Fluid Mantaflow: Could 
not use default cache directory '%s', "
+                                                       "please define a valid 
cache path manually", tmpDir);
+               }
+               return false;
+       }
+
+       /* Copy final dir back into domain settings */
+       BLI_strncpy(sds->cache_directory, tmpDir, FILE_MAXDIR);
+       return true;
+}
+
 static void fluid_manta_bake_free(void *customdata)
 {
        FluidMantaflowJob *job = customdata;
@@ -1391,6 +1436,7 @@ static int fluid_manta_bake_exec(bContext *C, wmOperator 
*op)
                fluid_manta_bake_free(job);
                return OPERATOR_CANCELLED;
        }
+       fluid_manta_initpaths(job, op->reports);
        fluid_manta_bake_startjob(job, NULL, NULL, NULL);
        fluid_manta_bake_endjob(job);
        fluid_manta_bake_free(job);
@@ -1412,6 +1458,8 @@ static int fluid_manta_bake_invoke(struct bContext *C, 
struct wmOperator *op, co
                return OPERATOR_CANCELLED;
        }
 
+       fluid_manta_initpaths(job, op->reports);
+
        wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene,
                                                                "Fluid 
Mantaflow Bake", WM_JOB_PROGRESS,
                                                                
WM_JOB_TYPE_OBJECT_SIM_MANTA);
@@ -1580,6 +1628,8 @@ static int fluid_manta_free_exec(struct bContext *C, 
struct wmOperator *op)
        job->type = op->type->idname;
        job->name = op->type->name;
 
+       fluid_manta_initpaths(job, op->reports);
+
        wmJob *wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene,
                                                                "Fluid 
Mantaflow Free", WM_JOB_PROGRESS,
                                                                
WM_JOB_TYPE_OBJECT_SIM_MANTA);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to