Smoke: expose empty space clipping property to the UI.
authorKévin Dietrich <kevin.dietrich@mailoo.org>
Thu, 22 Feb 2018 15:26:50 +0000 (16:26 +0100)
committerKévin Dietrich <kevin.dietrich@mailoo.org>
Sat, 24 Feb 2018 12:37:58 +0000 (13:37 +0100)
This is used to determine which voxels are to be considered empty space.

Previously it was hardcoded for converting dense grids to OpenVDB grids
to reduce disk space usage.

This value is also useful for rendering engines to know, i.e. to
optimize ray marching.

intern/openvdb/intern/openvdb_dense_convert.cc
intern/openvdb/intern/openvdb_dense_convert.h
intern/openvdb/openvdb_capi.cc
intern/openvdb/openvdb_capi.h
release/scripts/startup/bl_ui/properties_physics_smoke.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenkernel/intern/pointcache.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenloader/intern/versioning_270.c
source/blender/makesdna/DNA_smoke_types.h
source/blender/makesrna/intern/rna_smoke.c

index 10d5fb6..76fbbf8 100644 (file)
@@ -79,7 +79,8 @@ openvdb::GridBase *OpenVDB_export_vector_grid(
         const int res[3],
         float fluid_mat[4][4],
         openvdb::VecType vec_type,
-        const bool is_color,
+               const bool is_color,
+               const float clipping,
         const openvdb::FloatGrid *mask)
 {
        using namespace openvdb;
@@ -92,15 +93,15 @@ openvdb::GridBase *OpenVDB_export_vector_grid(
 
        grid[0] = FloatGrid::create(0.0f);
        tools::Dense<const float, tools::LayoutXYZ> dense_grid_x(bbox, data_x);
-       tools::copyFromDense(dense_grid_x, grid[0]->tree(), TOLERANCE);
+       tools::copyFromDense(dense_grid_x, grid[0]->tree(), clipping);
 
        grid[1] = FloatGrid::create(0.0f);
        tools::Dense<const float, tools::LayoutXYZ> dense_grid_y(bbox, data_y);
-       tools::copyFromDense(dense_grid_y, grid[1]->tree(), TOLERANCE);
+       tools::copyFromDense(dense_grid_y, grid[1]->tree(), clipping);
 
        grid[2] = FloatGrid::create(0.0f);
        tools::Dense<const float, tools::LayoutXYZ> dense_grid_z(bbox, data_z);
-       tools::copyFromDense(dense_grid_z, grid[2]->tree(), TOLERANCE);
+       tools::copyFromDense(dense_grid_z, grid[2]->tree(), clipping);
 
        Vec3SGrid::Ptr vecgrid = Vec3SGrid::create(Vec3s(0.0f));
 
index 7882caf..e5e2965 100644 (file)
@@ -36,8 +36,6 @@
 
 #include <cstdio>
 
-#define TOLERANCE 1e-3f
-
 namespace internal {
 
 /* Verify that the name does not correspond to the old format, in which case we
@@ -52,7 +50,8 @@ GridType *OpenVDB_export_grid(
         const openvdb::Name &name,
         const T *data,
         const int res[3],
-        float fluid_mat[4][4],
+               float fluid_mat[4][4],
+               const float clipping,
         const openvdb::FloatGrid *mask)
 {
        using namespace openvdb;
@@ -64,7 +63,7 @@ GridType *OpenVDB_export_grid(
        typename GridType::Ptr grid = GridType::create(T(0));
 
        tools::Dense<const T, openvdb::tools::LayoutXYZ> dense_grid(bbox, data);
-       tools::copyFromDense(dense_grid, grid->tree(), (T)TOLERANCE);
+       tools::copyFromDense(dense_grid, grid->tree(), static_cast<T>(clipping));
 
        grid->setTransform(transform);
 
@@ -119,15 +118,15 @@ void OpenVDB_import_grid(
        }
 }
 
-openvdb::GridBase *OpenVDB_export_vector_grid(
-        OpenVDBWriter *writer,
-        const openvdb::Name &name,
-        const float *data_x, const float *data_y, const float *data_z,
-        const int res[3],
-        float fluid_mat[4][4],
-        openvdb::VecType vec_type,
-        const bool is_color,
-        const openvdb::FloatGrid *mask);
+openvdb::GridBase *OpenVDB_export_vector_grid(OpenVDBWriter *writer,
+               const openvdb::Name &name,
+               const float *data_x, const float *data_y, const float *data_z,
+               const int res[3],
+               float fluid_mat[4][4],
+               openvdb::VecType vec_type,
+               const bool is_color,
+               const float clipping,
+               const openvdb::FloatGrid *mask);
 
 
 void OpenVDB_import_grid_vector(
index ef4f8c8..1c8b51a 100644 (file)
@@ -39,7 +39,7 @@ int OpenVDB_getVersionHex()
 OpenVDBFloatGrid *OpenVDB_export_grid_fl(
         OpenVDBWriter *writer,
         const char *name, float *data,
-        const int res[3], float matrix[4][4],
+               const int res[3], float matrix[4][4], const float clipping,
         OpenVDBFloatGrid *mask)
 {
        Timer(__func__);
@@ -53,6 +53,7 @@ OpenVDBFloatGrid *OpenVDB_export_grid_fl(
                data,
                res,
                matrix,
+                       clipping,
                mask_grid);
 
        return reinterpret_cast<OpenVDBFloatGrid *>(grid);
@@ -61,7 +62,7 @@ OpenVDBFloatGrid *OpenVDB_export_grid_fl(
 OpenVDBIntGrid *OpenVDB_export_grid_ch(
         OpenVDBWriter *writer,
         const char *name, unsigned char *data,
-        const int res[3], float matrix[4][4],
+               const int res[3], float matrix[4][4], const float clipping,
         OpenVDBFloatGrid *mask)
 {
        Timer(__func__);
@@ -76,17 +77,17 @@ OpenVDBIntGrid *OpenVDB_export_grid_ch(
                data,
                res,
                matrix,
+                       clipping,
                mask_grid);
 
        return reinterpret_cast<OpenVDBIntGrid *>(grid);
 }
 
-OpenVDBVectorGrid *OpenVDB_export_grid_vec(
-        struct OpenVDBWriter *writer,
-        const char *name,
-        const float *data_x, const float *data_y, const float *data_z,
-        const int res[3], float matrix[4][4], short vec_type,
-        const bool is_color, OpenVDBFloatGrid *mask)
+OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
+               const char *name,
+               const float *data_x, const float *data_y, const float *data_z,
+               const int res[3], float matrix[4][4], short vec_type, const float clipping,
+               const bool is_color, OpenVDBFloatGrid *mask)
 {
        Timer(__func__);
 
@@ -105,6 +106,7 @@ OpenVDBVectorGrid *OpenVDB_export_grid_vec(
                matrix,
                static_cast<VecType>(vec_type),
                is_color,
+                       clipping,
                mask_grid);
 
        return reinterpret_cast<OpenVDBVectorGrid *>(grid);
index 2d2feea..fe7af82 100644 (file)
@@ -49,22 +49,20 @@ enum {
 struct OpenVDBFloatGrid *OpenVDB_export_grid_fl(
         struct OpenVDBWriter *writer,
         const char *name, float *data,
-        const int res[3], float matrix[4][4],
+               const int res[3], float matrix[4][4], const float clipping,
         struct OpenVDBFloatGrid *mask);
 
-struct OpenVDBIntGrid *OpenVDB_export_grid_ch(
-        struct OpenVDBWriter *writer,
-        const char *name, unsigned char *data,
-        const int res[3], float matrix[4][4],
-        struct OpenVDBFloatGrid *mask);
+struct OpenVDBIntGrid *OpenVDB_export_grid_ch(struct OpenVDBWriter *writer,
+               const char *name, unsigned char *data,
+               const int res[3], float matrix[4][4], const float clipping,
+               struct OpenVDBFloatGrid *mask);
 
-struct OpenVDBVectorGrid *OpenVDB_export_grid_vec(
-        struct OpenVDBWriter *writer,
-        const char *name,
-        const float *data_x, const float *data_y, const float *data_z,
-        const int res[3], float matrix[4][4], short vec_type,
-        const bool is_color,
-        struct OpenVDBFloatGrid *mask);
+struct OpenVDBVectorGrid *OpenVDB_export_grid_vec(struct OpenVDBWriter *writer,
+               const char *name,
+               const float *data_x, const float *data_y, const float *data_z,
+               const int res[3], float matrix[4][4], short vec_type, const float clipping,
+               const bool is_color,
+               struct OpenVDBFloatGrid *mask);
 
 void OpenVDB_import_grid_fl(
         struct OpenVDBReader *reader,
index 01144fa..9489fb7 100644 (file)
@@ -68,6 +68,8 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel, Panel):
             col.prop(domain, "time_scale", text="Scale")
             col.label(text="Border Collisions:")
             col.prop(domain, "collision_extents", text="")
+            col.label(text="Empty Space:")
+            col.prop(domain, "clipping")
 
             col = split.column()
             col.label(text="Behavior:")
index c99da72..6cd93e1 100644 (file)
@@ -28,7 +28,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         279
-#define BLENDER_SUBVERSION      2
+#define BLENDER_SUBVERSION      3
 /* Several breakages with 270, e.g. constraint deg vs rad */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   6
index a84dc05..5b36b0f 100644 (file)
@@ -972,20 +972,20 @@ static int ptcache_smoke_openvdb_write(struct OpenVDBWriter *writer, void *smoke
 
                smoke_turbulence_export(sds->wt, &dens, &react, &flame, &fuel, &r, &g, &b, &tcu, &tcv, &tcw);
 
-               wt_density_grid = OpenVDB_export_grid_fl(writer, "density", dens, sds->res_wt, sds->fluidmat_wt, NULL);
+               wt_density_grid = OpenVDB_export_grid_fl(writer, "density", dens, sds->res_wt, sds->fluidmat_wt, sds->clipping, NULL);
                clip_grid = wt_density_grid;
 
                if (fluid_fields & SM_ACTIVE_FIRE) {
-                       OpenVDB_export_grid_fl(writer, "flame", flame, sds->res_wt, sds->fluidmat_wt, wt_density_grid);
-                       OpenVDB_export_grid_fl(writer, "fuel", fuel, sds->res_wt, sds->fluidmat_wt, wt_density_grid);
-                       OpenVDB_export_grid_fl(writer, "react", react, sds->res_wt, sds->fluidmat_wt, wt_density_grid);
+                       OpenVDB_export_grid_fl(writer, "flame", flame, sds->res_wt, sds->fluidmat_wt, sds->clipping, wt_density_grid);
+                       OpenVDB_export_grid_fl(writer, "fuel", fuel, sds->res_wt, sds->fluidmat_wt, sds->clipping, wt_density_grid);
+                       OpenVDB_export_grid_fl(writer, "react", react, sds->res_wt, sds->fluidmat_wt, sds->clipping, wt_density_grid);
                }
 
                if (fluid_fields & SM_ACTIVE_COLORS) {
-                       OpenVDB_export_grid_vec(writer, "color", r, g, b, sds->res_wt, sds->fluidmat_wt, VEC_INVARIANT, true, wt_density_grid);
+                       OpenVDB_export_grid_vec(writer, "color", r, g, b, sds->res_wt, sds->fluidmat_wt, VEC_INVARIANT, true, sds->clipping, wt_density_grid);
                }
 
-               OpenVDB_export_grid_vec(writer, "texture coordinates", tcu, tcv, tcw, sds->res, sds->fluidmat, VEC_INVARIANT, false, wt_density_grid);
+               OpenVDB_export_grid_vec(writer, "texture coordinates", tcu, tcv, tcw, sds->res, sds->fluidmat, VEC_INVARIANT, false, sds->clipping, wt_density_grid);
        }
 
        if (sds->fluid) {
@@ -1000,32 +1000,32 @@ static int ptcache_smoke_openvdb_write(struct OpenVDBWriter *writer, void *smoke
                OpenVDBWriter_add_meta_fl(writer, "blender/smoke/dt", dt);
 
                const char *name = (!sds->wt) ? "density" : "density_low";
-               density_grid = OpenVDB_export_grid_fl(writer, name, dens, sds->res, sds->fluidmat, NULL);
+               density_grid = OpenVDB_export_grid_fl(writer, name, dens, sds->res, sds->fluidmat, sds->clipping, NULL);
                clip_grid = sds->wt ? clip_grid : density_grid;
 
-               OpenVDB_export_grid_fl(writer, "shadow", sds->shadow, sds->res, sds->fluidmat, NULL);
+               OpenVDB_export_grid_fl(writer, "shadow", sds->shadow, sds->res, sds->fluidmat, sds->clipping, NULL);
 
                if (fluid_fields & SM_ACTIVE_HEAT) {
-                       OpenVDB_export_grid_fl(writer, "heat", heat, sds->res, sds->fluidmat, clip_grid);
-                       OpenVDB_export_grid_fl(writer, "heat_old", heatold, sds->res, sds->fluidmat, clip_grid);
+                       OpenVDB_export_grid_fl(writer, "heat", heat, sds->res, sds->fluidmat, sds->clipping, clip_grid);
+                       OpenVDB_export_grid_fl(writer, "heat_old", heatold, sds->res, sds->fluidmat, sds->clipping, clip_grid);
                }
 
                if (fluid_fields & SM_ACTIVE_FIRE) {
                        name = (!sds->wt) ? "flame" : "flame_low";
-                       OpenVDB_export_grid_fl(writer, name, flame, sds->res, sds->fluidmat, density_grid);
+                       OpenVDB_export_grid_fl(writer, name, flame, sds->res, sds->fluidmat, sds->clipping, density_grid);
                        name = (!sds->wt) ? "fuel" : "fuel_low";
-                       OpenVDB_export_grid_fl(writer, name, fuel, sds->res, sds->fluidmat, density_grid);
+                       OpenVDB_export_grid_fl(writer, name, fuel, sds->res, sds->fluidmat, sds->clipping, density_grid);
                        name = (!sds->wt) ? "react" : "react_low";
-                       OpenVDB_export_grid_fl(writer, name, react, sds->res, sds->fluidmat, density_grid);
+                       OpenVDB_export_grid_fl(writer, name, react, sds->res, sds->fluidmat, sds->clipping, density_grid);
                }
 
                if (fluid_fields & SM_ACTIVE_COLORS) {
                        name = (!sds->wt) ? "color" : "color_low";
-                       OpenVDB_export_grid_vec(writer, name, r, g, b, sds->res, sds->fluidmat, VEC_INVARIANT, true, density_grid);
+                       OpenVDB_export_grid_vec(writer, name, r, g, b, sds->res, sds->fluidmat, VEC_INVARIANT, true, sds->clipping, density_grid);
                }
 
-               OpenVDB_export_grid_vec(writer, "velocity", vx, vy, vz, sds->res, sds->fluidmat, VEC_CONTRAVARIANT_RELATIVE, false, clip_grid);
-               OpenVDB_export_grid_ch(writer, "obstacles", obstacles, sds->res, sds->fluidmat, NULL);
+               OpenVDB_export_grid_vec(writer, "velocity", vx, vy, vz, sds->res, sds->fluidmat, VEC_CONTRAVARIANT_RELATIVE, false, sds->clipping, clip_grid);
+               OpenVDB_export_grid_ch(writer, "obstacles", obstacles, sds->res, sds->fluidmat, sds->clipping, NULL);
        }
 
        return 1;
index 86e69e6..bf47360 100644 (file)
@@ -551,6 +551,8 @@ void smokeModifier_createType(struct SmokeModifierData *smd)
 
                        smd->domain->coba = NULL;
                        smd->domain->coba_field = FLUID_FIELD_DENSITY;
+
+                       smd->domain->clipping = 1e-3f;
                }
                else if (smd->type & MOD_SMOKE_TYPE_FLOW)
                {
index d27c1ce..f1c40aa 100644 (file)
@@ -1735,6 +1735,24 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
                }
        }
 
+       if (!MAIN_VERSION_ATLEAST(main, 279, 3)) {
+               if (!DNA_struct_elem_find(fd->filesdna, "SmokeDomainSettings", "float", "clipping")) {
+                       Object *ob;
+                       ModifierData *md;
+
+                       for (ob = main->object.first; ob; ob = ob->id.next) {
+                               for (md = ob->modifiers.first; md; md = md->next) {
+                                       if (md->type == eModifierType_Smoke) {
+                                               SmokeModifierData *smd = (SmokeModifierData *)md;
+                                               if (smd->domain) {
+                                                       smd->domain->clipping = 1e-3f;
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+
        {
                /* Fix for invalid state of screen due to bug in older versions. */
                for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
index 9932e16..c1565bd 100644 (file)
@@ -217,6 +217,9 @@ typedef struct SmokeDomainSettings {
        char use_coba;
        char coba_field;  /* simulation field used for the color mapping */
        char pad2;
+
+       float clipping;
+       float pad3;
 } SmokeDomainSettings;
 
 
index 1db6410..54daba7 100644 (file)
@@ -898,6 +898,14 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
        RNA_def_property_struct_type(prop, "ColorRamp");
        RNA_def_property_ui_text(prop, "Color Ramp", "");
        RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+
+       prop = RNA_def_property(srna, "clipping", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "clipping");
+       RNA_def_property_range(prop, 0.0, 1.0);
+       RNA_def_property_ui_range(prop, 0.0, 1.0, 0.1, 3);
+       RNA_def_property_ui_text(prop, "Clipping",
+                                                        "Value under which voxels are considered empty space to optimize caching or rendering");
+       RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
 }
 
 static void rna_def_smoke_flow_settings(BlenderRNA *brna)