Fluid: Updated Mantaflow source files

This updates fixes the following issues (critical for 2.92):

- Issue that prevented dense 'int' grids from being exported (incorrect clip value)
- Issue with particles outside out of domain bounds (position between -1 and 0) not being deleted
This commit is contained in:
Sebastián Barschkis 2021-02-05 16:23:02 +01:00
parent 4212ea7b7d
commit a563775649
Notes: blender-bot 2023-02-14 11:34:30 +01:00
Referenced by issue #85423, Crash on toggle bone layer
8 changed files with 35 additions and 38 deletions

View File

@ -664,6 +664,11 @@ template<class T> inline Vec3i toVec3iRound(T v)
return Vec3i((int)round(v[0]), (int)round(v[1]), (int)round(v[2]));
}
template<class T> 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<class T> inline Vec3i toVec3iChecked(T v)
{

View File

@ -209,11 +209,11 @@ typename GridType::Ptr exportVDB(Grid<T> *from, float clip, openvdb::FloatGrid::
openvdb::Coord(from->getSizeX() - 1, from->getSizeY() - 1, from->getSizeZ() - 1));
openvdb::tools::Dense<ValueT, openvdb::tools::MemoryLayout::LayoutXYZ> 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<Real>::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<MantaType> *from,
std::vector<VDBType> vdbValues;
std::string name = from->getName();
BasicParticleSystem *pp = dynamic_cast<BasicParticleSystem *>(from->getParticleSys());
FOR_PARTS(*from)
{
// Optionally, skip exporting particles that have been marked as deleted
BasicParticleSystem *pp = dynamic_cast<BasicParticleSystem *>(from->getParticleSys());
if (skipDeletedParts && !pp->isActive(idx)) {
continue;
}

View File

@ -1,3 +1,3 @@
#define MANTA_GIT_VERSION "commit 1c86d86496e7f7473c36248d12ef07bf4d9d2840"
#define MANTA_GIT_VERSION "commit 39b7a415721ecbf6643612a24e8eadd221aeb934"

View File

@ -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);

View File

@ -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;

View File

@ -2278,7 +2278,7 @@ T convolveGrid(Grid<T> &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;

View File

@ -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);

View File

@ -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);
}