[Bf-blender-cvs] [2ec07dfa182] master: Fluid: Update Mantaflow source files
Sebastián Barschkis
noreply at git.blender.org
Wed Oct 14 00:37:33 CEST 2020
Commit: 2ec07dfa182d4503ccf3930406e8c7b239751e18
Author: Sebastián Barschkis
Date: Tue Oct 13 21:36:14 2020 +0200
Branches: master
https://developer.blender.org/rB2ec07dfa182d4503ccf3930406e8c7b239751e18
Fluid: Update Mantaflow source files
Updated files includes:
- Fix for smoke / fire emission from particles
- Custom precision for liquid particles when saving in OpenVDB format
===================================================================
M extern/mantaflow/preprocessed/fileio/iovdb.cpp
M extern/mantaflow/preprocessed/fileio/mantaio.cpp
M extern/mantaflow/preprocessed/fileio/mantaio.h
M extern/mantaflow/preprocessed/gitinfo.h
M extern/mantaflow/preprocessed/plugin/initplugins.cpp
M extern/mantaflow/preprocessed/python/defines.py.reg.cpp
===================================================================
diff --git a/extern/mantaflow/preprocessed/fileio/iovdb.cpp b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
index b990274e1c4..287c78f0608 100644
--- a/extern/mantaflow/preprocessed/fileio/iovdb.cpp
+++ b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
@@ -60,7 +60,7 @@ template<class GridType, class T> void importVDB(typename GridType::Ptr from, Gr
template<class VDBType, class T>
void importVDB(VDBType vdbValue, ParticleDataImpl<T> *to, int index, float voxelSize)
{
- (void)voxelSize; // Unused
+ unusedParameter(voxelSize); // Unused for now
T toMantaValue;
convertFrom(vdbValue, &toMantaValue);
to->set(index, toMantaValue);
@@ -165,12 +165,12 @@ static void setGridOptions(typename GridType::Ptr grid,
string name,
openvdb::GridClass cls,
float voxelSize,
- bool precisionHalf)
+ int precision)
{
grid->setTransform(openvdb::math::Transform::createLinearTransform(voxelSize));
grid->setGridClass(cls);
grid->setName(name);
- grid->setSaveFloatAsHalf(precisionHalf);
+ grid->setSaveFloatAsHalf(precision == PRECISION_MINI || precision == PRECISION_HALF);
}
template<class T, class GridType> typename GridType::Ptr exportVDB(Grid<T> *from)
@@ -194,7 +194,8 @@ template<class MantaType, class VDBType>
void exportVDB(ParticleDataImpl<MantaType> *from,
openvdb::points::PointDataGrid::Ptr to,
openvdb::tools::PointIndexGrid::Ptr pIndex,
- bool skipDeletedParts)
+ bool skipDeletedParts,
+ int precision)
{
std::vector<VDBType> vdbValues;
std::string name = from->getName();
@@ -212,8 +213,21 @@ void exportVDB(ParticleDataImpl<MantaType> *from,
vdbValues.push_back(vdbValue);
}
- openvdb::NamePair attribute =
- openvdb::points::TypedAttributeArray<VDBType, openvdb::points::NullCodec>::attributeType();
+ // Use custom codec for precision of the attribute
+ openvdb::NamePair attribute;
+ if (precision == PRECISION_FULL) {
+ attribute =
+ openvdb::points::TypedAttributeArray<VDBType, openvdb::points::NullCodec>::attributeType();
+ }
+ else if (precision == PRECISION_HALF ||
+ precision == PRECISION_MINI) { // Mini uses same precision as half for now
+ attribute =
+ openvdb::points::TypedAttributeArray<VDBType,
+ openvdb::points::TruncateCodec>::attributeType();
+ }
+ else {
+ errMsg("exportVDB: invalid precision level");
+ }
openvdb::points::appendAttribute(to->tree(), name, attribute);
// Create a wrapper around the vdb values vector.
@@ -229,7 +243,8 @@ void exportVDB(ParticleDataImpl<MantaType> *from,
openvdb::points::PointDataGrid::Ptr exportVDB(BasicParticleSystem *from,
std::vector<ParticleDataBase *> &fromPData,
bool skipDeletedParts,
- float voxelSize)
+ float voxelSize,
+ int precision)
{
std::vector<openvdb::Vec3s> positions;
std::vector<int> flags;
@@ -257,16 +272,34 @@ openvdb::points::PointDataGrid::Ptr exportVDB(BasicParticleSystem *from,
openvdb::tools::createPointIndexGrid<openvdb::tools::PointIndexGrid>(positionsWrapper,
*transform);
- // TODO (sebbas): Use custom codec for attributes?
- // using Codec = openvdb::points::FixedPointCodec</*1-byte=*/false, openvdb::points::UnitRange>;
- openvdb::points::PointDataGrid::Ptr to =
- openvdb::points::createPointDataGrid<openvdb::points::NullCodec /*Codec*/,
- openvdb::points::PointDataGrid>(
- *pointIndexGrid, positionsWrapper, *transform);
+ openvdb::points::PointDataGrid::Ptr to;
+ openvdb::NamePair flagAttribute;
+
+ using CodecNull = openvdb::points::NullCodec;
+ using CodecTrunc = openvdb::points::TruncateCodec;
+ using CodecFixPoint = openvdb::points::FixedPointCodec<true, openvdb::points::PositionRange>;
+
+ // Use custom codec for precision of the particle position and the flag attribute
+ if (precision == PRECISION_FULL) {
+ to = openvdb::points::createPointDataGrid<CodecNull, openvdb::points::PointDataGrid>(
+ *pointIndexGrid, positionsWrapper, *transform);
+ flagAttribute = openvdb::points::TypedAttributeArray<int, CodecNull>::attributeType();
+ }
+ else if (precision == PRECISION_HALF) {
+ to = openvdb::points::createPointDataGrid<CodecTrunc, openvdb::points::PointDataGrid>(
+ *pointIndexGrid, positionsWrapper, *transform);
+ flagAttribute = openvdb::points::TypedAttributeArray<int, CodecTrunc>::attributeType();
+ }
+ else if (precision == PRECISION_MINI) {
+ to = openvdb::points::createPointDataGrid<CodecFixPoint, openvdb::points::PointDataGrid>(
+ *pointIndexGrid, positionsWrapper, *transform);
+ flagAttribute = openvdb::points::TypedAttributeArray<int, CodecTrunc>::
+ attributeType(); // Use 16 bit trunc for flag for now
+ }
+ else {
+ errMsg("exportVDB: invalid precision level");
+ }
- openvdb::NamePair flagAttribute =
- openvdb::points::TypedAttributeArray<int,
- openvdb::points::NullCodec /*Codec*/>::attributeType();
openvdb::points::appendAttribute(to->tree(), FLAG_NAME, flagAttribute);
// Create a wrapper around the flag vector.
openvdb::points::PointAttributeVector<int> flagWrapper(flags);
@@ -281,17 +314,17 @@ openvdb::points::PointDataGrid::Ptr exportVDB(BasicParticleSystem *from,
if (pdb->getType() == ParticleDataBase::TypeInt) {
debMsg("Writing int particle data '" << pdb->getName() << "'", 1);
ParticleDataImpl<int> *pdi = dynamic_cast<ParticleDataImpl<int> *>(pdb);
- exportVDB<int, int>(pdi, to, pointIndexGrid, skipDeletedParts);
+ exportVDB<int, int>(pdi, to, pointIndexGrid, skipDeletedParts, precision);
}
else if (pdb->getType() == ParticleDataBase::TypeReal) {
debMsg("Writing real particle data '" << pdb->getName() << "'", 1);
ParticleDataImpl<Real> *pdi = dynamic_cast<ParticleDataImpl<Real> *>(pdb);
- exportVDB<Real, float>(pdi, to, pointIndexGrid, skipDeletedParts);
+ exportVDB<Real, float>(pdi, to, pointIndexGrid, skipDeletedParts, precision);
}
else if (pdb->getType() == ParticleDataBase::TypeVec3) {
debMsg("Writing Vec3 particle data '" << pdb->getName() << "'", 1);
ParticleDataImpl<Vec3> *pdi = dynamic_cast<ParticleDataImpl<Vec3> *>(pdb);
- exportVDB<Vec3, openvdb::Vec3s>(pdi, to, pointIndexGrid, skipDeletedParts);
+ exportVDB<Vec3, openvdb::Vec3s>(pdi, to, pointIndexGrid, skipDeletedParts, precision);
}
else {
errMsg("exportVDB: unknown ParticleDataBase type");
@@ -302,8 +335,10 @@ openvdb::points::PointDataGrid::Ptr exportVDB(BasicParticleSystem *from,
static void registerCustomCodecs()
{
- using Codec = openvdb::points::FixedPointCodec</*1-byte=*/false, openvdb::points::UnitRange>;
- openvdb::points::TypedAttributeArray<int, Codec>::registerType();
+ openvdb::points::TypedAttributeArray<int, openvdb::points::TruncateCodec>::registerType();
+ openvdb::points::TypedAttributeArray<float, openvdb::points::TruncateCodec>::registerType();
+ openvdb::points::TypedAttributeArray<openvdb::Vec3s,
+ openvdb::points::TruncateCodec>::registerType();
}
int writeObjectsVDB(const string &filename,
@@ -311,15 +346,14 @@ int writeObjectsVDB(const string &filename,
float worldSize,
bool skipDeletedParts,
int compression,
- bool precisionHalf)
+ int precision)
{
openvdb::initialize();
openvdb::io::File file(filename);
openvdb::GridPtrVec gridsVDB;
- // TODO (sebbas): Use custom codec for flag attribute?
- // Register codecs one, this makes sure custom attributes can be read
- // registerCustomCodecs();
+ // Register custom codecs, this makes sure custom attributes can be read
+ registerCustomCodecs();
std::vector<ParticleDataBase *> pdbBuffer;
@@ -365,7 +399,7 @@ int writeObjectsVDB(const string &filename,
debMsg("Writing particle system '" << mantaPP->getName()
<< "' (and buffered pData) to vdb file " << filename,
1);
- vdbGrid = exportVDB(mantaPP, pdbBuffer, skipDeletedParts, voxelSize);
+ vdbGrid = exportVDB(mantaPP, pdbBuffer, skipDeletedParts, voxelSize, precision);
gridsVDB.push_back(vdbGrid);
pdbBuffer.clear();
}
@@ -382,7 +416,7 @@ int writeObjectsVDB(const string &filename,
// Set additional grid attributes, e.g. name, grid class, compression level, etc.
if (vdbGrid) {
- setGridOptions<openvdb::GridBase>(vdbGrid, objectName, gClass, voxelSize, precisionHalf);
+ setGridOptions<openvdb::GridBase>(vdbGrid, objectName, gClass, voxelSize, precision);
}
}
@@ -434,19 +468,18 @@ int readObjectsVDB(const string &filename, std::vector<PbClass *> *objects, floa
openvdb::io::File file(filename);
openvdb::GridPtrVec gridsVDB;
- // TODO (sebbas): Use custom codec for flag attribute?
- // Register codecs one, this makes sure custom attributes can be read
- // registerCustomCodecs();
+ // Register custom codecs, this makes sure custom attributes can be read
+ registerCustomCodecs();
try {
file.setCopyMaxBytes(0);
file.open();
gridsVDB = *(file.getGrids());
openvdb::MetaMap::Ptr metadata = file.getMetadata();
- (void)metadata; // Unused for now
+ unusedParameter(metadata); // Unused for now
}
catch (const openvdb::IoError &e) {
- (void)e; // Unused for now
+ unusedParameter(e); // Unused for now
debMsg("readObjectsVDB: Could not open vdb file " << filename, 1);
file.close();
return 0;
@@ -494,27 +527,36 @@ int readObjectsVDB(const string &filename, std::vector<PbClass *>
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list