Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastián Barschkis <sebbas@sebbas.org>2020-02-09 19:09:00 +0300
committerSebastián Barschkis <sebbas@sebbas.org>2020-02-09 19:09:00 +0300
commit4a08eb0707fc17e4e97430ffa33eb7d3e36db712 (patch)
tree5139566839e9544077f203eccfb2e7f58da0e332 /extern/mantaflow/preprocessed/fileio
parent68221b7ebafe58a2bbf612ad8c59e24569489be5 (diff)
Fluid: Updated manta pp files
Includes the OpenVDB read/write functions for int grids. This essential for the resume bake functionality in modular fluid caches.
Diffstat (limited to 'extern/mantaflow/preprocessed/fileio')
-rw-r--r--extern/mantaflow/preprocessed/fileio/iogrids.cpp73
-rw-r--r--extern/mantaflow/preprocessed/fileio/ioparticles.cpp2
2 files changed, 75 insertions, 0 deletions
diff --git a/extern/mantaflow/preprocessed/fileio/iogrids.cpp b/extern/mantaflow/preprocessed/fileio/iogrids.cpp
index 2f6cdaa6209..2b8ee905f99 100644
--- a/extern/mantaflow/preprocessed/fileio/iogrids.cpp
+++ b/extern/mantaflow/preprocessed/fileio/iogrids.cpp
@@ -954,6 +954,79 @@ template<class T> void readGridVDB(const string &name, Grid<T> *grid)
1);
}
+template<> void writeGridVDB(const string &name, Grid<int> *grid)
+{
+ debMsg("Writing int grid " << grid->getName() << " to vdb file " << name, 1);
+
+ // Create an empty int32-point grid with background value 0.
+ openvdb::initialize();
+ openvdb::Int32Grid::Ptr gridVDB = openvdb::Int32Grid::create();
+ gridVDB->setTransform(
+ openvdb::math::Transform::createLinearTransform(1. / grid->getSizeX())); // voxel size
+
+ // Get an accessor for coordinate-based access to voxels.
+ openvdb::Int32Grid::Accessor accessor = gridVDB->getAccessor();
+
+ gridVDB->setGridClass(openvdb::GRID_UNKNOWN);
+
+ // Name the grid "density".
+ gridVDB->setName(grid->getName());
+
+ openvdb::io::File file(name);
+
+ FOR_IJK(*grid)
+ {
+ openvdb::Coord xyz(i, j, k);
+ accessor.setValue(xyz, (*grid)(i, j, k));
+ }
+
+ // Add the grid pointer to a container.
+ openvdb::GridPtrVec gridsVDB;
+ gridsVDB.push_back(gridVDB);
+
+ // Write out the contents of the container.
+ file.write(gridsVDB);
+ file.close();
+}
+
+template<> void readGridVDB(const string &name, Grid<int> *grid)
+{
+ debMsg("Reading int grid " << grid->getName() << " from vdb file " << name, 1);
+
+ openvdb::initialize();
+ openvdb::io::File file(name);
+ file.open();
+
+ openvdb::GridBase::Ptr baseGrid;
+ for (openvdb::io::File::NameIterator nameIter = file.beginName(); nameIter != file.endName();
+ ++nameIter) {
+# ifndef BLENDER
+ // Read in only the grid we are interested in.
+ if (nameIter.gridName() == grid->getName()) {
+ baseGrid = file.readGrid(nameIter.gridName());
+ }
+ else {
+ debMsg("skipping grid " << nameIter.gridName(), 1);
+ }
+# else
+ // For Blender, skip name check and pick first grid from loop
+ baseGrid = file.readGrid(nameIter.gridName());
+ break;
+# endif
+ }
+ file.close();
+ openvdb::Int32Grid::Ptr gridVDB = openvdb::gridPtrCast<openvdb::Int32Grid>(baseGrid);
+
+ openvdb::Int32Grid::Accessor accessor = gridVDB->getAccessor();
+
+ FOR_IJK(*grid)
+ {
+ openvdb::Coord xyz(i, j, k);
+ int v = accessor.getValue(xyz);
+ (*grid)(i, j, k) = v;
+ }
+}
+
template<> void writeGridVDB(const string &name, Grid<Real> *grid)
{
debMsg("Writing real grid " << grid->getName() << " to vdb file " << name, 1);
diff --git a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
index 432cbc9f100..a6cc7583327 100644
--- a/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
+++ b/extern/mantaflow/preprocessed/fileio/ioparticles.cpp
@@ -310,6 +310,8 @@ template<class T> void readPdataUni(const std::string &name, ParticleDataImpl<T>
UniPartHeader head;
assertMsg(gzread(gzf, &head, sizeof(UniPartHeader)) == sizeof(UniPartHeader),
"can't read file, no header present");
+ pdata->resize(head.dim);
+
assertMsg(head.dim == pdata->size(), "pdata size doesn't match");
# if FLOATINGPOINT_PRECISION != 1
ParticleDataImpl<T> temp(pdata->getParent());