OpenVDB : use underscores instead of spaces in grid names.
authorKévin Dietrich <kevin.dietrich@mailoo.org>
Mon, 29 Jan 2018 17:37:35 +0000 (18:37 +0100)
committerKévin Dietrich <kevin.dietrich@mailoo.org>
Sat, 24 Feb 2018 12:37:08 +0000 (13:37 +0100)
Some other software cannot handle grid names with spaces in them. We still check for names with spaces so as to not break old
files.

This fixes T53802.

intern/openvdb/intern/openvdb_dense_convert.cc
intern/openvdb/intern/openvdb_dense_convert.h
source/blender/blenkernel/intern/pointcache.c

index ef52408..10d5fb6 100644 (file)
@@ -165,4 +165,19 @@ void OpenVDB_import_grid_vector(
        }
 }
 
+openvdb::Name do_name_versionning(const openvdb::Name &name)
+{
+       openvdb::Name temp_name = name;
+
+       if (temp_name.find("_low", temp_name.size() - 4, 4) == temp_name.size() - 4) {
+               return temp_name.replace(temp_name.size() - 4, 4, " low");
+       }
+
+       if (temp_name.find("_old", temp_name.size() - 4, 4) == temp_name.size() - 4) {
+               return temp_name.replace(temp_name.size() - 4, 4, " old");
+       }
+
+       return temp_name;
+}
+
 }  /* namespace internal */
index 284fd1c..7882caf 100644 (file)
 
 namespace internal {
 
+/* Verify that the name does not correspond to the old format, in which case we
+ * need to replace the '_low' ending with ' low'. See T53802. */
+openvdb::Name do_name_versionning(const openvdb::Name &name);
+
 openvdb::Mat4R convertMatrix(const float mat[4][4]);
 
 template <typename GridType, typename T>
@@ -87,13 +91,19 @@ void OpenVDB_import_grid(
 {
        using namespace openvdb;
 
-       if (!reader->hasGrid(name)) {
-               std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", name.c_str());
-               memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
-               return;
+       openvdb::Name temp_name = name;
+
+       if (!reader->hasGrid(temp_name)) {
+               temp_name = do_name_versionning(temp_name);
+
+               if (!reader->hasGrid(temp_name)) {
+                       std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", temp_name.c_str());
+                       memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
+                       return;
+               }
        }
 
-       typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(name));
+       typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(temp_name));
        typename GridType::ConstAccessor acc = grid->getConstAccessor();
 
        math::Coord xyz;
index dc1c0da..a84dc05 100644 (file)
@@ -999,7 +999,7 @@ static int ptcache_smoke_openvdb_write(struct OpenVDBWriter *writer, void *smoke
                OpenVDBWriter_add_meta_fl(writer, "blender/smoke/dx", dx);
                OpenVDBWriter_add_meta_fl(writer, "blender/smoke/dt", dt);
 
-               const char *name = (!sds->wt) ? "density" : "density low";
+               const char *name = (!sds->wt) ? "density" : "density_low";
                density_grid = OpenVDB_export_grid_fl(writer, name, dens, sds->res, sds->fluidmat, NULL);
                clip_grid = sds->wt ? clip_grid : density_grid;
 
@@ -1007,20 +1007,20 @@ static int ptcache_smoke_openvdb_write(struct OpenVDBWriter *writer, void *smoke
 
                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_old", heatold, sds->res, sds->fluidmat, clip_grid);
                }
 
                if (fluid_fields & SM_ACTIVE_FIRE) {
-                       name = (!sds->wt) ? "flame" : "flame low";
+                       name = (!sds->wt) ? "flame" : "flame_low";
                        OpenVDB_export_grid_fl(writer, name, flame, sds->res, sds->fluidmat, density_grid);
-                       name = (!sds->wt) ? "fuel" : "fuel low";
+                       name = (!sds->wt) ? "fuel" : "fuel_low";
                        OpenVDB_export_grid_fl(writer, name, fuel, sds->res, sds->fluidmat, density_grid);
-                       name = (!sds->wt) ? "react" : "react low";
+                       name = (!sds->wt) ? "react" : "react_low";
                        OpenVDB_export_grid_fl(writer, name, react, sds->res, sds->fluidmat, density_grid);
                }
 
                if (fluid_fields & SM_ACTIVE_COLORS) {
-                       name = (!sds->wt) ? "color" : "color low";
+                       name = (!sds->wt) ? "color" : "color_low";
                        OpenVDB_export_grid_vec(writer, name, r, g, b, sds->res, sds->fluidmat, VEC_INVARIANT, true, density_grid);
                }
 
@@ -1104,25 +1104,25 @@ static int ptcache_smoke_openvdb_read(struct OpenVDBReader *reader, void *smoke_
 
                OpenVDB_import_grid_fl(reader, "shadow", &sds->shadow, sds->res);
 
-               const char *name = (!sds->wt) ? "density" : "density low";
+               const char *name = (!sds->wt) ? "density" : "density_low";
                OpenVDB_import_grid_fl(reader, name, &dens, sds->res);
 
                if (cache_fields & SM_ACTIVE_HEAT) {
                        OpenVDB_import_grid_fl(reader, "heat", &heat, sds->res);
-                       OpenVDB_import_grid_fl(reader, "heat old", &heatold, sds->res);
+                       OpenVDB_import_grid_fl(reader, "heat_old", &heatold, sds->res);
                }
 
                if (cache_fields & SM_ACTIVE_FIRE) {
-                       name = (!sds->wt) ? "flame" : "flame low";
+                       name = (!sds->wt) ? "flame" : "flame_low";
                        OpenVDB_import_grid_fl(reader, name, &flame, sds->res);
-                       name = (!sds->wt) ? "fuel" : "fuel low";
+                       name = (!sds->wt) ? "fuel" : "fuel_low";
                        OpenVDB_import_grid_fl(reader, name, &fuel, sds->res);
-                       name = (!sds->wt) ? "react" : "react low";
+                       name = (!sds->wt) ? "react" : "react_low";
                        OpenVDB_import_grid_fl(reader, name, &react, sds->res);
                }
 
                if (cache_fields & SM_ACTIVE_COLORS) {
-                       name = (!sds->wt) ? "color" : "color low";
+                       name = (!sds->wt) ? "color" : "color_low";
                        OpenVDB_import_grid_vec(reader, name, &r, &g, &b, sds->res);
                }