Commit: 8c8b54b60187cd846283f6a4c00453fdc2c2acec
Author: Kévin Dietrich
Date:   Thu May 28 02:41:10 2015 +0200
Branches: openvdb
https://developer.blender.org/rB8c8b54b60187cd846283f6a4c00453fdc2c2acec

Import grids for playback now works.

It is still commented out due to the need of a good cache (reading)
system.

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

M       intern/openvdb/intern/openvdb_dense_convert.cpp
M       intern/openvdb/intern/openvdb_dense_convert.h
M       source/blender/blenkernel/intern/smoke.c

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

diff --git a/intern/openvdb/intern/openvdb_dense_convert.cpp 
b/intern/openvdb/intern/openvdb_dense_convert.cpp
index e095d46..c299679 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.cpp
+++ b/intern/openvdb/intern/openvdb_dense_convert.cpp
@@ -168,11 +168,11 @@ void OpenVDB_import_grid_vector(OpenVDBReader *reader,
 {
        Vec3SGrid::Ptr vgrid = gridPtrCast<Vec3SGrid>(reader->getGrid(name));
 
+#if 0
        SplitVectorGrid vector_split;
        vector_split(vgrid);
 
        FloatGrid::Ptr grid[3];
-
        math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 
1));
 
        grid[0] = vector_split.grid_x();
@@ -189,6 +189,23 @@ void OpenVDB_import_grid_vector(OpenVDBReader *reader,
        tools::Dense<float, tools::LayoutXYZ> dense_grid_z(bbox);
        tools::copyToDense(*grid[2], dense_grid_z);
        *data_z = dense_grid_z.data();
+#else
+       Vec3SGrid::Accessor acc = vgrid->getAccessor();
+       math::Coord xyz;
+       int &x = xyz[0], &y = xyz[1], &z = xyz[2];
+
+       int index = 0;
+       for (z = 0; z < res[2]; ++z) {
+               for (y = 0; y < res[1]; ++y) {
+                       for (x = 0; x < res[0]; ++x, ++index) {
+                               math::Vec3s value = acc.getValue(xyz);
+                               (*data_x)[index] = value.x();
+                               (*data_y)[index] = value.y();
+                               (*data_z)[index] = value.z();
+                       }
+               }
+       }
+#endif
 }
 
 void OpenVDB_update_fluid_transform(const char *filename, float matrix[4][4], 
float matrix_high[4][4])
diff --git a/intern/openvdb/intern/openvdb_dense_convert.h 
b/intern/openvdb/intern/openvdb_dense_convert.h
index 4102498..ee55a33 100644
--- a/intern/openvdb/intern/openvdb_dense_convert.h
+++ b/intern/openvdb/intern/openvdb_dense_convert.h
@@ -78,24 +78,26 @@ void OpenVDB_import_grid(OpenVDBReader *reader,
        using namespace openvdb;
 
        typename GridType::Ptr grid_tmp = 
gridPtrCast<GridType>(reader->getGrid(name));
-//     typename GridType::Accessor acc = grid_tmp->getAccessor();
-
+#if 0
        math::CoordBBox bbox(Coord(0), Coord(res[0] - 1, res[1] - 1, res[2] - 
1));
 
        tools::Dense<T, tools::LayoutXYZ> dense_grid(bbox);
        tools::copyToDense(*grid_tmp, dense_grid);
-
-       *data = dense_grid.data();
-
-//     int index = 0;
-//     for (int z = 0; z <= res.z(); ++z) {
-//             for (int y = 0; y <= res.y(); ++y) {
-//                     for (int x = 0; x <= res.x(); ++x, ++index) {
-//                             math::Coord xyz(x, y, z);
-//                             data[index] = acc.getValue(xyz);
-//                     }
-//             }
-//     }
+       memcpy(*data, dense_grid.data(), sizeof(T) * res[0] * res[1] * res[2]);
+#else
+       typename GridType::Accessor acc = grid_tmp->getAccessor();
+       math::Coord xyz;
+       int &x = xyz[0], &y = xyz[1], &z = xyz[2];
+
+       int index = 0;
+       for (z = 0; z < res[2]; ++z) {
+               for (y = 0; y < res[1]; ++y) {
+                       for (x = 0; x < res[0]; ++x, ++index) {
+                               (*data)[index] = acc.getValue(xyz);
+                       }
+               }
+       }
+#endif
 }
 
 void OpenVDB_export_vector_grid(OpenVDBWriter *writer,
diff --git a/source/blender/blenkernel/intern/smoke.c 
b/source/blender/blenkernel/intern/smoke.c
index 20f8322..fbc14ee 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -2714,7 +2714,7 @@ static void smokeModifier_process(SmokeModifierData *smd, 
Scene *scene, Object *
                }
 
                /* try to read from openvdb cache */
-//             if (sds->use_openvdb && (sds->flags & 
MOD_SMOKE_OPENVDB_EXPORTED) == 0) {
+//             if (sds->use_openvdb && (sds->flags & 
MOD_SMOKE_OPENVDB_EXPORTED)) {
 //                     smokeModifier_OpenVDB_import(smd, scene, ob);
 //                     smd->time = framenr;
 //                     return;
@@ -3082,8 +3082,6 @@ static void compute_fluid_matrices(SmokeDomainSettings 
*sds)
 
 static void OpenVDB_read_fluid_settings(SmokeDomainSettings *sds, struct 
OpenVDBReader *reader)
 {
-       OpenVDBReader_get_meta_int(reader, "active_fields", 
&sds->active_fields);
-       OpenVDBReader_get_meta_v3_int(reader, "resolution", sds->res);
        OpenVDBReader_get_meta_v3_int(reader, "min_resolution", sds->res_min);
        OpenVDBReader_get_meta_v3_int(reader, "max_resolution", sds->res_max);
        OpenVDBReader_get_meta_v3_int(reader, "base_resolution", sds->base_res);
@@ -3205,7 +3203,47 @@ static void OpenVDB_export_smoke(SmokeDomainSettings 
*sds, struct OpenVDBWriter
 
 static void OpenVDB_import_smoke(SmokeDomainSettings *sds, struct 
OpenVDBReader *reader)
 {
-       int fluid_fields;
+       int fluid_fields = smoke_get_data_flags(sds);
+       int active_fields, cache_fields = 0;
+       int cache_res[3];
+       float cache_dx;
+       bool reallocate = false;
+
+       OpenVDBReader_get_meta_int(reader, "fluid_fields", &cache_fields);
+       OpenVDBReader_get_meta_int(reader, "active_fields", &active_fields);
+       OpenVDBReader_get_meta_fl(reader, "dx", &cache_dx);
+       OpenVDBReader_get_meta_v3_int(reader, "resolution", cache_res);
+
+       /* check if resolution has changed */
+       if (sds->res[0] != cache_res[0] ||
+               sds->res[1] != cache_res[1] ||
+               sds->res[2] != cache_res[2])
+       {
+               if (sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN) {
+                       reallocate = true;
+               }
+               else {
+                       return;
+               }
+       }
+
+       /* reallocate fluid if needed*/
+       if (reallocate) {
+               sds->active_fields = active_fields | cache_fields;
+               smoke_reallocate_fluid(sds, cache_dx, cache_res, 1);
+               sds->dx = cache_dx;
+               copy_v3_v3_int(sds->res, cache_res);
+               sds->total_cells = cache_res[0] * cache_res[1] * cache_res[2];
+
+               if (sds->flags & MOD_SMOKE_HIGHRES) {
+                       smoke_reallocate_highres_fluid(sds, cache_dx, 
cache_res, 1);
+               }
+       }
+
+       /* check if active fields have changed */
+       if ((fluid_fields != cache_fields) || (active_fields != 
sds->active_fields)) {
+               reallocate = true;
+       }
 
        if (sds->fluid) {
                float dt, dx, *dens, *react, *fuel, *flame, *heat, *heatold, 
*vx, *vy, *vz, *r, *g, *b;
@@ -3214,8 +3252,6 @@ static void OpenVDB_import_smoke(SmokeDomainSettings 
*sds, struct OpenVDBReader
                smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, 
&fuel, &heat,
                             &heatold, &vx, &vy, &vz, &r, &g, &b, &obstacles);
 
-               OpenVDBReader_get_meta_int(reader, "fluid_fields", 
&fluid_fields);
-               OpenVDBReader_get_meta_fl(reader, "dx", &dx);
                OpenVDBReader_get_meta_fl(reader, "dt", &dt);
 
                OpenVDB_import_grid_fl(reader, "Shadow", &sds->shadow, 
sds->res);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to