diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h index 9b4d9c83f0b..3c7c6e6bc01 100644 --- a/extern/mantaflow/helper/util/vectorbase.h +++ b/extern/mantaflow/helper/util/vectorbase.h @@ -664,6 +664,11 @@ template inline Vec3i toVec3iRound(T v) return Vec3i((int)round(v[0]), (int)round(v[1]), (int)round(v[2])); } +template inline Vec3i toVec3iFloor(T v) +{ + return Vec3i((int)floor(v[0]), (int)floor(v[1]), (int)floor(v[2])); +} + //! convert to int Vector if values are close enough to an int template inline Vec3i toVec3iChecked(T v) { diff --git a/extern/mantaflow/preprocessed/fileio/iovdb.cpp b/extern/mantaflow/preprocessed/fileio/iovdb.cpp index cc2d0aa508d..e615741e0f7 100644 --- a/extern/mantaflow/preprocessed/fileio/iovdb.cpp +++ b/extern/mantaflow/preprocessed/fileio/iovdb.cpp @@ -209,11 +209,11 @@ typename GridType::Ptr exportVDB(Grid *from, float clip, openvdb::FloatGrid:: openvdb::Coord(from->getSizeX() - 1, from->getSizeY() - 1, from->getSizeZ() - 1)); openvdb::tools::Dense dense(bbox, data); - // Trick: Set clip value to very small / negative value in order to copy all values of dense - // grids - float tmpClip = (from->saveSparse()) ? clip : -std::numeric_limits::max(); + // Use clip value, or (when not exporting in sparse mode) clear it in order to copy all values + // of dense grid + ValueT tmpClip = (from->saveSparse()) ? ValueT(clip) : ValueT(0); // Copy from dense to sparse grid structure considering clip value - openvdb::tools::copyFromDense(dense, *to, ValueT(tmpClip)); + openvdb::tools::copyFromDense(dense, *to, tmpClip); // If present, use clip grid to trim down current vdb grid even more if (from->saveSparse() && clipGrid && !clipGrid->empty()) { @@ -245,10 +245,10 @@ void exportVDB(ParticleDataImpl *from, std::vector vdbValues; std::string name = from->getName(); + BasicParticleSystem *pp = dynamic_cast(from->getParticleSys()); FOR_PARTS(*from) { // Optionally, skip exporting particles that have been marked as deleted - BasicParticleSystem *pp = dynamic_cast(from->getParticleSys()); if (skipDeletedParts && !pp->isActive(idx)) { continue; } diff --git a/extern/mantaflow/preprocessed/gitinfo.h b/extern/mantaflow/preprocessed/gitinfo.h index ddc644db724..1bb96fe3baa 100644 --- a/extern/mantaflow/preprocessed/gitinfo.h +++ b/extern/mantaflow/preprocessed/gitinfo.h @@ -1,3 +1,3 @@ -#define MANTA_GIT_VERSION "commit 1c86d86496e7f7473c36248d12ef07bf4d9d2840" +#define MANTA_GIT_VERSION "commit 39b7a415721ecbf6643612a24e8eadd221aeb934" diff --git a/extern/mantaflow/preprocessed/grid.h b/extern/mantaflow/preprocessed/grid.h index 3d6f8558b8f..9c3d954771e 100644 --- a/extern/mantaflow/preprocessed/grid.h +++ b/extern/mantaflow/preprocessed/grid.h @@ -204,14 +204,12 @@ class GridBase : public PbClass { inline void checkIndex(int i, int j, int k) const; //! Check if indices are within bounds, otherwise error (should only be called when debugging) inline void checkIndex(IndexInt idx) const; - //! Check if index is within given boundaries - inline bool isInBounds(const Vec3i &p, int bnd) const; - //! Check if index is within given boundaries - inline bool isInBounds(const Vec3i &p) const; - //! Check if index is within given boundaries + //! Check if vector int is within given boundaries + inline bool isInBounds(const Vec3i &p, int bnd = 0) const; + //! Check if vector real is within given boundaries inline bool isInBounds(const Vec3 &p, int bnd = 0) const { - return isInBounds(toVec3i(p), bnd); + return isInBounds(toVec3iFloor(p), bnd); } //! Check if linear index is in the range of the array inline bool isInBounds(IndexInt idx) const; @@ -1785,11 +1783,6 @@ inline void GridBase::checkIndex(IndexInt idx) const } } -bool GridBase::isInBounds(const Vec3i &p) const -{ - return (p.x >= 0 && p.y >= 0 && p.z >= 0 && p.x < mSize.x && p.y < mSize.y && p.z < mSize.z); -} - bool GridBase::isInBounds(const Vec3i &p, int bnd) const { bool ret = (p.x >= bnd && p.y >= bnd && p.x < mSize.x - bnd && p.y < mSize.y - bnd); diff --git a/extern/mantaflow/preprocessed/plugin/flip.cpp b/extern/mantaflow/preprocessed/plugin/flip.cpp index eaa1ebe45d5..d6fd3437959 100644 --- a/extern/mantaflow/preprocessed/plugin/flip.cpp +++ b/extern/mantaflow/preprocessed/plugin/flip.cpp @@ -429,7 +429,7 @@ void markFluidCells(const BasicParticleSystem &parts, for (IndexInt idx = 0; idx < parts.size(); idx++) { if (!parts.isActive(idx) || (ptype && ((*ptype)[idx] & exclude))) continue; - Vec3i p = toVec3i(parts.getPos(idx)); + Vec3i p = toVec3iFloor(parts.getPos(idx)); if (flags.isInBounds(p) && flags.isEmpty(p)) flags(p) = (flags(p) | FlagGrid::TypeFluid) & ~FlagGrid::TypeEmpty; } @@ -544,7 +544,7 @@ void adjustNumber(BasicParticleSystem &parts, // count particles in cells, and delete excess particles for (IndexInt idx = 0; idx < (int)parts.size(); idx++) { if (parts.isActive(idx)) { - Vec3i p = toVec3i(parts.getPos(idx)); + Vec3i p = toVec3iFloor(parts.getPos(idx)); if (!tmp.isInBounds(p)) { parts.kill(idx); // out of domain, remove continue; @@ -711,7 +711,7 @@ void gridParticleIndex(const BasicParticleSystem &parts, for (IndexInt idx = 0; idx < (IndexInt)parts.size(); idx++) { if (parts.isActive(idx)) { // check index for validity... - Vec3i p = toVec3i(parts.getPos(idx)); + Vec3i p = toVec3iFloor(parts.getPos(idx)); if (!index.isInBounds(p)) { inactive++; continue; @@ -740,7 +740,7 @@ void gridParticleIndex(const BasicParticleSystem &parts, for (IndexInt idx = 0; idx < (IndexInt)parts.size(); idx++) { if (!parts.isActive(idx)) continue; - Vec3i p = toVec3i(parts.getPos(idx)); + Vec3i p = toVec3iFloor(parts.getPos(idx)); if (!index.isInBounds(p)) { continue; } @@ -1636,7 +1636,7 @@ struct knPushOutofObs : public KernelBase { { if (!parts.isActive(idx) || (ptype && ((*ptype)[idx] & exclude))) return; - Vec3i p = toVec3i(parts.getPos(idx)); + Vec3i p = toVec3iFloor(parts.getPos(idx)); if (!flags.isInBounds(p)) return; diff --git a/extern/mantaflow/preprocessed/plugin/initplugins.cpp b/extern/mantaflow/preprocessed/plugin/initplugins.cpp index dce7b72de6c..a0cc2761dab 100644 --- a/extern/mantaflow/preprocessed/plugin/initplugins.cpp +++ b/extern/mantaflow/preprocessed/plugin/initplugins.cpp @@ -2278,7 +2278,7 @@ T convolveGrid(Grid &originGrid, GaussianKernelCreator &gkSigma, Vec3 pos, in step = Vec3(0.0, 0.0, 1.0); T pxResult(0); for (int i = 0; i < gkSigma.mDim; ++i) { - Vec3i curpos = toVec3i(pos - step * (i - gkSigma.mDim / 2)); + Vec3i curpos = toVec3iFloor(pos - step * (i - gkSigma.mDim / 2)); if (originGrid.isInBounds(curpos)) pxResult += gkSigma.get1DKernelValue(i) * originGrid.get(curpos); else { // TODO , improve... @@ -2423,7 +2423,7 @@ struct KnBlurMACGridGauss : public KernelBase { Vec3 pxResult(0.0f); for (int di = 0; di < gkSigma.mDim; ++di) { - Vec3i curpos = toVec3i(pos - step * (di - gkSigma.mDim / 2)); + Vec3i curpos = toVec3iFloor(pos - step * (di - gkSigma.mDim / 2)); if (!originGrid.isInBounds(curpos)) { if (curpos.x < 0) curpos.x = 0; diff --git a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp index 8ebc239e8fc..7a1d8224d94 100644 --- a/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp +++ b/extern/mantaflow/preprocessed/plugin/secondaryparticles.cpp @@ -1214,8 +1214,8 @@ struct knFlipUpdateSecondaryParticlesLinear : public KernelBase { // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + - ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + + ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1234,8 +1234,8 @@ struct knFlipUpdateSecondaryParticlesLinear : public KernelBase { // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + - ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + + ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1252,7 +1252,7 @@ struct knFlipUpdateSecondaryParticlesLinear : public KernelBase { const Vec3 vj = v.getInterpolated(pts_sec[idx].pos); // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + ct * (1 / Real(antitunneling)) * dt * vj); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + ct * (1 / Real(antitunneling)) * dt * vj); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1474,8 +1474,8 @@ struct knFlipUpdateSecondaryParticlesCubic : public KernelBase { // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + - ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + + ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1515,8 +1515,8 @@ struct knFlipUpdateSecondaryParticlesCubic : public KernelBase { // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + - ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + + ct * (1 / Real(antitunneling)) * dt * v_sec[idx]); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1554,8 +1554,8 @@ struct knFlipUpdateSecondaryParticlesCubic : public KernelBase { // anti tunneling for small obstacles for (int ct = 1; ct < antitunneling; ct++) { - Vec3i tempPos = toVec3i(pts_sec[idx].pos + ct * (1 / Real(antitunneling)) * dt * - (sumNumerator / sumDenominator)); + Vec3i tempPos = toVec3iFloor(pts_sec[idx].pos + ct * (1 / Real(antitunneling)) * dt * + (sumNumerator / sumDenominator)); if (!flags.isInBounds(tempPos) || flags(tempPos) & FlagGrid::TypeObstacle) { pts_sec.kill(idx); return; @@ -1863,7 +1863,7 @@ struct knFlipDeleteParticlesInObstacle : public KernelBase { return; const Vec3 &xi = pts[idx].pos; - const Vec3i xidx = toVec3i(xi); + const Vec3i xidx = toVec3iFloor(xi); // remove particles that completely left the bounds if (!flags.isInBounds(xidx)) { pts.kill(idx); diff --git a/extern/mantaflow/preprocessed/plugin/surfaceturbulence.cpp b/extern/mantaflow/preprocessed/plugin/surfaceturbulence.cpp index aa04b551e1e..e5aa09117ea 100644 --- a/extern/mantaflow/preprocessed/plugin/surfaceturbulence.cpp +++ b/extern/mantaflow/preprocessed/plugin/surfaceturbulence.cpp @@ -2145,8 +2145,7 @@ void PbRegister_particleSurfaceTurbulence() void debugCheckParts(const BasicParticleSystem &parts, const FlagGrid &flags) { for (int idx = 0; idx < parts.size(); idx++) { - Vec3i p = toVec3i(parts.getPos(idx)); - if (!flags.isInBounds(p)) { + if (!flags.isInBounds(parts.getPos(idx))) { debMsg("bad position??? " << idx << " " << parts.getPos(idx), 1); exit(1); }