Add Chromium-only Blender WebEngine parity work

This commit is contained in:
mes123456
2026-08-12 04:47:48 -04:00
commit 9fd26010f6
18225 changed files with 11622124 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
diff --git a/extern/mantaflow/helper/util/vectorbase.h b/extern/mantaflow/helper/util/vectorbase.h
index b05f90939d4..fbdfd8a4851 100644
--- a/extern/mantaflow/helper/util/vectorbase.h
+++ b/extern/mantaflow/helper/util/vectorbase.h
@@ -402,10 +402,10 @@ inline const Vector3D<S> &projectNormalTo(const Vector3D<S> &v, const Vector3D<S
//! (clamps to 0 and 1 with VECTOR_EPSILON)
template<class S> inline S norm(const Vector3D<S> &v)
{
- S l = v.x * v.x + v.y * v.y + v.z * v.z;
- if (l <= VECTOR_EPSILON * VECTOR_EPSILON)
+ S l = std::hypot(v.x, v.y, v.z);
+ if (l <= VECTOR_EPSILON)
return (0.);
- return (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) ? 1. : sqrt(l);
+ return (fabs(l - 1.) < VECTOR_EPSILON) ? 1. : l;
}
//! Compute squared magnitude
@@ -465,11 +465,11 @@ template<class S> inline Vector3D<S> abs(const Vector3D<S> &v)
//! Returns a normalized vector
template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v)
{
- S l = v.x * v.x + v.y * v.y + v.z * v.z;
- if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON)
+ S l = std::hypot(v.x, v.y, v.z);
+ if (fabs(l - 1.) < VECTOR_EPSILON)
return v; /* normalized "enough"... */
- else if (l > VECTOR_EPSILON * VECTOR_EPSILON) {
- S fac = 1. / sqrt(l);
+ else if (l > VECTOR_EPSILON) {
+ S fac = 1. / l;
return Vector3D<S>(v.x * fac, v.y * fac, v.z * fac);
}
else
@@ -481,13 +481,13 @@ template<class S> inline Vector3D<S> getNormalized(const Vector3D<S> &v)
template<class S> inline S normalize(Vector3D<S> &v)
{
S norm;
- S l = v.x * v.x + v.y * v.y + v.z * v.z;
- if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) {
+ S l = std::hypot(v.x, v.y, v.z);
+ if (fabs(l - 1.) < VECTOR_EPSILON) {
norm = 1.;
}
- else if (l > VECTOR_EPSILON * VECTOR_EPSILON) {
- norm = sqrt(l);
- v *= 1. / norm;
+ else if (l > VECTOR_EPSILON) {
+ norm = l;
+ v *= 1. / l;
}
else {
v = Vector3D<S>::Zero;

View File

@@ -0,0 +1,62 @@
diff --git a/extern/mantaflow/preprocessed/plugin/pressure.cpp b/extern/mantaflow/preprocessed/plugin/pressure.cpp
index 593aeb16859..75118a4402a 100644
--- a/extern/mantaflow/preprocessed/plugin/pressure.cpp
+++ b/extern/mantaflow/preprocessed/plugin/pressure.cpp
@@ -1181,7 +1181,27 @@ void solvePressureSystem(Grid<Real> &rhs,
gcg->setMGPreconditioner(GridCgInterface::PC_MGP, pmg);
}
+ auto cleanup = [&](){
+ // Cleanup
+ if (gcg)
+ delete gcg;
+ if (pca0)
+ delete pca0;
+ if (pca1)
+ delete pca1;
+ if (pca2)
+ delete pca2;
+ if (pca3)
+ delete pca3;
+
+ // PcMGDynamic: always delete multigrid solver after use
+ // PcMGStatic: keep multigrid solver for next solve
+ if (pmg && preconditioner == PcMGDynamic)
+ releaseMG(parent);
+ };
+
// CG solve
+ try {
for (int iter = 0; iter < maxIter; iter++) {
if (!gcg->iterate())
iter = maxIter;
@@ -1193,23 +1213,13 @@ void solvePressureSystem(Grid<Real> &rhs,
debMsg("FluidSolver::solvePressure done. Iterations:" << gcg->getIterations()
<< ", residual:" << gcg->getResNorm(),
2);
+ }
+ catch (const Manta::Error &e) {
+ cleanup();
+ throw e;
+ }
- // Cleanup
- if (gcg)
- delete gcg;
- if (pca0)
- delete pca0;
- if (pca1)
- delete pca1;
- if (pca2)
- delete pca2;
- if (pca3)
- delete pca3;
-
- // PcMGDynamic: always delete multigrid solver after use
- // PcMGStatic: keep multigrid solver for next solve
- if (pmg && preconditioner == PcMGDynamic)
- releaseMG(parent);
+ cleanup();
}
static PyObject *_W_2(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{

View File

@@ -0,0 +1,179 @@
commit 8052900a3b2ce243e1273bec5ab55a8af7c1dc9f
Author: Brecht Van Lommel <brecht@blender.org>
Date: Tue Mar 31 14:04:50 2026 +0200
Fix: Mantaflow memory leak in PbArgs temporary storage
diff --git a/extern/mantaflow/helper/pwrapper/pconvert.cpp b/extern/mantaflow/helper/pwrapper/pconvert.cpp
index 5a7a32c5a73..7978032001b 100644
--- a/extern/mantaflow/helper/pwrapper/pconvert.cpp
+++ b/extern/mantaflow/helper/pwrapper/pconvert.cpp
@@ -324,53 +324,53 @@ template<> PbTypeVec fromPy<PbTypeVec>(PyObject *obj)
return vec;
}
-template<class T> T *tmpAlloc(PyObject *obj, std::vector<void *> *tmp)
+template<class T> T *tmpAlloc(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
if (!tmp)
throw Error("dynamic de-ref not supported for this type");
T *ptr = new T(fromPy<T>(obj));
- tmp->push_back(ptr);
+ tmp->push_back([ptr]() { delete ptr; });
return ptr;
}
-template<> float *fromPyPtr<float>(PyObject *obj, std::vector<void *> *tmp)
+template<> float *fromPyPtr<float>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<float>(obj, tmp);
}
-template<> double *fromPyPtr<double>(PyObject *obj, std::vector<void *> *tmp)
+template<> double *fromPyPtr<double>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<double>(obj, tmp);
}
-template<> int *fromPyPtr<int>(PyObject *obj, std::vector<void *> *tmp)
+template<> int *fromPyPtr<int>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<int>(obj, tmp);
}
-template<> std::string *fromPyPtr<std::string>(PyObject *obj, std::vector<void *> *tmp)
+template<> std::string *fromPyPtr<std::string>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<std::string>(obj, tmp);
}
-template<> bool *fromPyPtr<bool>(PyObject *obj, std::vector<void *> *tmp)
+template<> bool *fromPyPtr<bool>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<bool>(obj, tmp);
}
-template<> Vec3 *fromPyPtr<Vec3>(PyObject *obj, std::vector<void *> *tmp)
+template<> Vec3 *fromPyPtr<Vec3>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<Vec3>(obj, tmp);
}
-template<> Vec3i *fromPyPtr<Vec3i>(PyObject *obj, std::vector<void *> *tmp)
+template<> Vec3i *fromPyPtr<Vec3i>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<Vec3i>(obj, tmp);
}
-template<> Vec4 *fromPyPtr<Vec4>(PyObject *obj, std::vector<void *> *tmp)
+template<> Vec4 *fromPyPtr<Vec4>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<Vec4>(obj, tmp);
}
-template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<void *> *tmp)
+template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<Vec4i>(obj, tmp);
}
template<>
-std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<void *> *tmp)
+std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
return tmpAlloc<std::vector<PbClass *>>(obj, tmp);
}
@@ -501,9 +501,9 @@ PbArgs::PbArgs(PyObject *linarg, PyObject *dict) : mLinArgs(0), mKwds(0)
}
PbArgs::~PbArgs()
{
- for (int i = 0; i < (int)mTmpStorage.size(); i++)
- operator delete(mTmpStorage[i]);
- mTmpStorage.clear();
+ for (auto &fn : mTmpStorageCleanup)
+ fn();
+ mTmpStorageCleanup.clear();
}
void PbArgs::copy(PbArgs &a)
diff --git a/extern/mantaflow/helper/pwrapper/pconvert.h b/extern/mantaflow/helper/pwrapper/pconvert.h
index eda2f5b9632..857c306f586 100644
--- a/extern/mantaflow/helper/pwrapper/pconvert.h
+++ b/extern/mantaflow/helper/pwrapper/pconvert.h
@@ -20,6 +20,7 @@
# ifndef _PCONVERT_H
# define _PCONVERT_H
+# include <functional>
# include <string>
# include <map>
# include <vector>
@@ -36,8 +37,10 @@ struct ArgLocker {
PyObject *getPyNone();
+using TmpCleanupFn = std::function<void()>;
+
// for PbClass-derived classes
-template<class T> T *fromPyPtr(PyObject *obj, std::vector<void *> *tmp)
+template<class T> T *fromPyPtr(PyObject *obj, std::vector<TmpCleanupFn> *tmp)
{
if (PbClass::isNullRef(obj) || PbClass::isNoneRef(obj))
return 0;
@@ -48,19 +51,19 @@ template<class T> T *fromPyPtr(PyObject *obj, std::vector<void *> *tmp)
return (T *)(pbo);
}
-template<> float *fromPyPtr<float>(PyObject *obj, std::vector<void *> *tmp);
-template<> double *fromPyPtr<double>(PyObject *obj, std::vector<void *> *tmp);
-template<> int *fromPyPtr<int>(PyObject *obj, std::vector<void *> *tmp);
-template<> std::string *fromPyPtr<std::string>(PyObject *obj, std::vector<void *> *tmp);
-template<> bool *fromPyPtr<bool>(PyObject *obj, std::vector<void *> *tmp);
-template<> Vec3 *fromPyPtr<Vec3>(PyObject *obj, std::vector<void *> *tmp);
-template<> Vec3i *fromPyPtr<Vec3i>(PyObject *obj, std::vector<void *> *tmp);
-template<> Vec4 *fromPyPtr<Vec4>(PyObject *obj, std::vector<void *> *tmp);
-template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<void *> *tmp);
+template<> float *fromPyPtr<float>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> double *fromPyPtr<double>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> int *fromPyPtr<int>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> std::string *fromPyPtr<std::string>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> bool *fromPyPtr<bool>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> Vec3 *fromPyPtr<Vec3>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> Vec3i *fromPyPtr<Vec3i>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> Vec4 *fromPyPtr<Vec4>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
+template<> Vec4i *fromPyPtr<Vec4i>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
template<>
-std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<void *> *tmp);
+std::vector<PbClass *> *fromPyPtr<std::vector<PbClass *>>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
template<>
-std::vector<float> *fromPyPtr<std::vector<float>>(PyObject *obj, std::vector<void *> *tmp);
+std::vector<float> *fromPyPtr<std::vector<float>>(PyObject *obj, std::vector<TmpCleanupFn> *tmp);
PyObject *incref(PyObject *obj);
template<class T> PyObject *toPy(const T &v)
@@ -205,10 +208,10 @@ class PbArgs {
visit(number, key);
PyObject *o = getItem(key, false, lk);
if (o)
- return fromPyPtr<T>(o, &mTmpStorage);
+ return fromPyPtr<T>(o, &mTmpStorageCleanup);
if (number >= 0)
o = getItem(number, false, lk);
- return o ? fromPyPtr<T>(o, &mTmpStorage) : defarg;
+ return o ? fromPyPtr<T>(o, &mTmpStorageCleanup) : defarg;
}
template<class T>
inline T *getPtr(const std::string &key, int number = -1, ArgLocker *lk = nullptr)
@@ -216,10 +219,10 @@ class PbArgs {
visit(number, key);
PyObject *o = getItem(key, false, lk);
if (o)
- return fromPyPtr<T>(o, &mTmpStorage);
+ return fromPyPtr<T>(o, &mTmpStorageCleanup);
o = getItem(number, false, lk);
if (o)
- return fromPyPtr<T>(o, &mTmpStorage);
+ return fromPyPtr<T>(o, &mTmpStorageCleanup);
errMsg("Argument '" + key + "' is not defined.");
}
@@ -250,7 +253,7 @@ class PbArgs {
std::map<std::string, DataElement> mData;
std::vector<DataElement> mLinData;
PyObject *mLinArgs, *mKwds;
- std::vector<void *> mTmpStorage;
+ std::vector<TmpCleanupFn> mTmpStorageCleanup;
};
} // namespace Manta

View File

@@ -0,0 +1,134 @@
commit bfc0169a74b80dc9eafd5390a4680f05c3e22f8a
Author: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Sun May 4 22:33:40 2025 +0200
Physics: Improve fluid viscosity performance by 2.5%
diff --git a/extern/mantaflow/preprocessed/conjugategrad.h b/extern/mantaflow/preprocessed/conjugategrad.h
index 35cb3960656..e5edf2e6040 100644
--- a/extern/mantaflow/preprocessed/conjugategrad.h
+++ b/extern/mantaflow/preprocessed/conjugategrad.h
@@ -169,8 +169,6 @@ struct ApplyMatrix : public KernelBase {
{
unusedParameter(vecRhs); // Not needed in this matrix application
- if (matrixA.size() != 4)
- errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Ai = *matrixA[1];
Grid<Real> &Aj = *matrixA[2];
@@ -219,6 +217,8 @@ struct ApplyMatrix : public KernelBase {
};
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
+ if (matrixA.size() != 4)
+ errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
op(idx, flags, dst, src, matrixA, vecRhs);
}
@@ -255,8 +255,6 @@ struct ApplyMatrix2D : public KernelBase {
{
unusedParameter(vecRhs); // Not needed in this matrix application
- if (matrixA.size() != 3)
- errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Ai = *matrixA[1];
Grid<Real> &Aj = *matrixA[2];
@@ -303,6 +301,8 @@ struct ApplyMatrix2D : public KernelBase {
};
void operator()(const tbb::blocked_range<IndexInt> &__r) const
{
+ if (matrixA.size() != 3)
+ errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
op(idx, flags, dst, src, matrixA, vecRhs);
}
@@ -337,8 +337,6 @@ struct ApplyMatrixViscosityU : public KernelBase {
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
- if (matrixA.size() != 15)
- errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
@@ -347,8 +345,6 @@ struct ApplyMatrixViscosityU : public KernelBase {
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
- if (vecRhs.size() != 2)
- errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcV = *vecRhs[0];
Grid<Real> &srcW = *vecRhs[1];
@@ -402,6 +398,10 @@ struct ApplyMatrixViscosityU : public KernelBase {
{
const int _maxX = maxX;
const int _maxY = maxY;
+ if (matrixA.size() != 15)
+ errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
+ if (vecRhs.size() != 2)
+ errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)
@@ -449,8 +449,6 @@ struct ApplyMatrixViscosityV : public KernelBase {
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
- if (matrixA.size() != 15)
- errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
@@ -459,8 +457,6 @@ struct ApplyMatrixViscosityV : public KernelBase {
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
- if (vecRhs.size() != 2)
- errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcU = *vecRhs[0];
Grid<Real> &srcW = *vecRhs[1];
@@ -514,6 +510,10 @@ struct ApplyMatrixViscosityV : public KernelBase {
{
const int _maxX = maxX;
const int _maxY = maxY;
+ if (matrixA.size() != 15)
+ errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
+ if (vecRhs.size() != 2)
+ errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)
@@ -561,8 +561,6 @@ struct ApplyMatrixViscosityW : public KernelBase {
const std::vector<Grid<Real> *> matrixA,
const std::vector<Grid<Real> *> vecRhs) const
{
- if (matrixA.size() != 15)
- errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
Grid<Real> &A0 = *matrixA[0];
Grid<Real> &Aplusi = *matrixA[1];
Grid<Real> &Aplusj = *matrixA[2];
@@ -571,8 +569,6 @@ struct ApplyMatrixViscosityW : public KernelBase {
Grid<Real> &Aminusj = *matrixA[5];
Grid<Real> &Aminusk = *matrixA[6];
- if (vecRhs.size() != 2)
- errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
Grid<Real> &srcU = *vecRhs[0];
Grid<Real> &srcV = *vecRhs[1];
@@ -626,6 +622,11 @@ struct ApplyMatrixViscosityW : public KernelBase {
{
const int _maxX = maxX;
const int _maxY = maxY;
+
+ if (matrixA.size() != 15)
+ errMsg("ConjugateGrad: Invalid A matrix in apply matrix step");
+ if (vecRhs.size() != 2)
+ errMsg("ConjugateGrad: Invalid rhs vector in apply matrix step");
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 1; j < _maxY; j++)

View File

@@ -0,0 +1,46 @@
commit 725df6eb883dadf2225938baecf97c005da5b549
Author: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Wed May 21 22:44:01 2025 +0200
Physics: Fix OpenVDB import visual glitches, by copying full 8x8x8 nodes
If grid has 8x8x8 block with the same value, it is stored as Tile with single value.
We need to iterate over the bounding box and copy such value to all voxels in 8x8x8 node.
Fixes: #91174 #124064
diff --git a/extern/mantaflow/preprocessed/fileio/iovdb.cpp b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
index 4b7463782da..85ab3781e5a 100644
--- a/extern/mantaflow/preprocessed/fileio/iovdb.cpp
+++ b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
@@ -54,14 +54,28 @@ template<class GridType, class T> void importVDB(typename GridType::Ptr from, Gr
using ValueT = typename GridType::ValueType;
// Check if current grid is to be read as a sparse grid, active voxels (only) will be copied
+
if (to->saveSparse()) {
to->clear(); // Ensure that destination grid is empty before writing
for (typename GridType::ValueOnCIter iter = from->cbeginValueOn(); iter.test(); ++iter) {
ValueT vdbValue = *iter;
- openvdb::Coord coord = iter.getCoord();
T toMantaValue;
convertFrom(vdbValue, &toMantaValue);
- to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ // #91174 #124064 - Check if iteration is Voxel or Tile
+ if (iter.isVoxelValue()) {
+ openvdb::Coord coord = iter.getCoord();
+ to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ }
+ else {
+ openvdb::CoordBBox bbox;
+ iter.getBoundingBox(bbox);
+ // If grid has 8x8x8 block with the same value, it is stored as Tile with single value.
+ // We need to iterate over the bounding box and copy such value to all voxels in 8x8x8 node.
+ for (openvdb::CoordBBox::Iterator<true> ijk(bbox); ijk; ++ijk) {
+ openvdb::Coord coord = *ijk;
+ to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ }
+ }
}
}
// When importing all grid cells, using a grid accessor is usually faster than a value iterator

View File

@@ -0,0 +1,43 @@
diff --git a/extern/mantaflow/preprocessed/plugin/flip.cpp b/extern/mantaflow/preprocessed/plugin/flip.cpp
index 8757958d4b0..f5d7147c34f 100644
--- a/extern/mantaflow/preprocessed/plugin/flip.cpp
+++ b/extern/mantaflow/preprocessed/plugin/flip.cpp
@@ -1012,6 +1012,7 @@ struct ComputeAveragedLevelsetWeight : public KernelBase {
const ParticleIndexSystem &indexSys,
LevelsetGrid &phi,
const Real radius,
+ const Real sradiusInv,
const ParticleDataImpl<int> *ptype,
const int exclude,
Grid<Vec3> *save_pAcc = nullptr,
@@ -1020,8 +1021,6 @@ struct ComputeAveragedLevelsetWeight : public KernelBase {
const Vec3 gridPos = Vec3(i, j, k) + Vec3(0.5); // shifted by half cell
Real phiv = radius * 1.0; // outside
- // loop over neighborhood, similar to ComputeUnionLevelsetPindex
- const Real sradiusInv = 1. / (4. * radius * radius);
const int r = int(radius) + 1;
// accumulators
Real wacc = 0.;
@@ -1120,17 +1119,19 @@ struct ComputeAveragedLevelsetWeight : public KernelBase {
{
const int _maxX = maxX;
const int _maxY = maxY;
+ // loop over neighborhood, similar to ComputeUnionLevelsetPindex
+ const Real sradiusInv = 1. / (4. * radius * radius);
if (maxZ > 1) {
for (int k = __r.begin(); k != (int)__r.end(); k++)
for (int j = 0; j < _maxY; j++)
for (int i = 0; i < _maxX; i++)
- op(i, j, k, parts, index, indexSys, phi, radius, ptype, exclude, save_pAcc, save_rAcc);
+ op(i, j, k, parts, index, indexSys, phi, radius, sradiusInv, ptype, exclude, save_pAcc, save_rAcc);
}
else {
const int k = 0;
for (int j = __r.begin(); j != (int)__r.end(); j++)
for (int i = 0; i < _maxX; i++)
- op(i, j, k, parts, index, indexSys, phi, radius, ptype, exclude, save_pAcc, save_rAcc);
+ op(i, j, k, parts, index, indexSys, phi, radius, sradiusInv, ptype, exclude, save_pAcc, save_rAcc);
}
}
void run()

View File

@@ -0,0 +1,73 @@
diff --git a/extern/mantaflow/preprocessed/fastmarch.cpp b/extern/mantaflow/preprocessed/fastmarch.cpp
index 31e43483b49..9856d84a8b1 100644
--- a/extern/mantaflow/preprocessed/fastmarch.cpp
+++ b/extern/mantaflow/preprocessed/fastmarch.cpp
@@ -306,25 +306,24 @@ struct knExtrapolateMACSimple : public KernelBase {
const int d,
const int c) const
{
- static const Vec3i nb[6] = {Vec3i(1, 0, 0),
- Vec3i(-1, 0, 0),
- Vec3i(0, 1, 0),
- Vec3i(0, -1, 0),
- Vec3i(0, 0, 1),
- Vec3i(0, 0, -1)};
- const int dim = (vel.is3D() ? 3 : 2);
-
if (tmp(i, j, k) != 0)
return;
+ const Vec3i nb[6] = {Vec3i(i+1, j, k),
+ Vec3i(i-1, j, k),
+ Vec3i(i, j+1, k),
+ Vec3i(i, j-1, k),
+ Vec3i(i, j, k+1),
+ Vec3i(i, j, k-1)};
+ const int dim = (vel.is3D() ? 3 : 2);
// copy from initialized neighbors
Vec3i p(i, j, k);
int nbs = 0;
Real avgVel = 0.;
for (int n = 0; n < 2 * dim; ++n) {
- if (tmp(p + nb[n]) == d) {
+ if (tmp(nb[n]) == d) {
// vel(p)[c] = (c+1.)*0.1;
- avgVel += vel(p + nb[n])[c];
+ avgVel += vel(nb[n])[c];
nbs++;
}
}
@@ -714,24 +713,23 @@ struct knExtrapolateMACFromWeight : public KernelBase {
const int d,
const int c) const
{
- static const Vec3i nb[6] = {Vec3i(1, 0, 0),
- Vec3i(-1, 0, 0),
- Vec3i(0, 1, 0),
- Vec3i(0, -1, 0),
- Vec3i(0, 0, 1),
- Vec3i(0, 0, -1)};
- const int dim = (vel.is3D() ? 3 : 2);
-
if (weight(i, j, k)[c] != 0)
return;
+ const Vec3i nb[6] = {Vec3i(i+1, j, k),
+ Vec3i(i-1, j, k),
+ Vec3i(i, j+1, k),
+ Vec3i(i, j-1, k),
+ Vec3i(i, j, k+1),
+ Vec3i(i, j, k-1)};
+ const int dim = (vel.is3D() ? 3 : 2);
// copy from initialized neighbors
Vec3i p(i, j, k);
int nbs = 0;
Real avgVel = 0.;
for (int n = 0; n < 2 * dim; ++n) {
- if (weight(p + nb[n])[c] == d) {
- avgVel += vel(p + nb[n])[c];
+ if (weight(nb[n])[c] == d) {
+ avgVel += vel(nb[n])[c];
nbs++;
}
}

View File

@@ -0,0 +1,86 @@
diff --git a/extern/mantaflow/helper/pwrapper/registry.cpp b/extern/mantaflow/helper/pwrapper/registry.cpp
index 5196c0409f8..b4206a41dea 100644
--- a/extern/mantaflow/helper/pwrapper/registry.cpp
+++ b/extern/mantaflow/helper/pwrapper/registry.cpp
@@ -115,7 +115,7 @@ class WrapperRegistry {
void construct(const std::string &scriptname, const vector<string> &args);
void cleanup();
void renameObjects();
- void runPreInit();
+ void runPreInit(PyObject *name_space);
PyObject *initModule();
ClassData *lookup(const std::string &name);
bool canConvert(ClassData *from, ClassData *to);
@@ -505,7 +505,7 @@ void WrapperRegistry::addConstants(PyObject *module)
}
}
-void WrapperRegistry::runPreInit()
+void WrapperRegistry::runPreInit(PyObject *name_space)
{
// add python directories to path
PyObject *sys_path = PySys_GetObject((char *)"path");
@@ -518,7 +518,15 @@ void WrapperRegistry::runPreInit()
}
if (!mCode.empty()) {
mCode = "from manta import *\n" + mCode;
- PyRun_SimpleString(mCode.c_str());
+ PyObject *return_value = PyRun_String(mCode.c_str(), Py_file_input, name_space, name_space);
+ if (return_value == nullptr) {
+ if (PyErr_Occurred()) {
+ PyErr_Print();
+ }
+ }
+ else {
+ Py_DECREF(return_value);
+ }
}
}
@@ -698,16 +706,23 @@ PyObject *WrapperRegistry::initModule()
//******************************************************
// Register members and exposed functions
-void setup(const std::string &filename, const std::vector<std::string> &args)
+void setup(const bool python_lifecycle,
+ const std::string &filename,
+ const std::vector<std::string> &args,
+ PyObject *name_space)
{
WrapperRegistry::instance().construct(filename, args);
- Py_Initialize();
- WrapperRegistry::instance().runPreInit();
+ if (python_lifecycle) {
+ Py_Initialize();
+ }
+ WrapperRegistry::instance().runPreInit(name_space);
}
-void finalize()
+void finalize(const bool python_lifecycle)
{
- Py_Finalize();
+ if (python_lifecycle) {
+ Py_Finalize();
+ }
WrapperRegistry::instance().cleanup();
}
diff --git a/extern/mantaflow/helper/pwrapper/registry.h b/extern/mantaflow/helper/pwrapper/registry.h
index d9d2bbb624b..2273d0b9bb1 100644
--- a/extern/mantaflow/helper/pwrapper/registry.h
+++ b/extern/mantaflow/helper/pwrapper/registry.h
@@ -48,8 +48,11 @@ template<class T> struct Namify {
namespace Pb {
// internal registry access
-void setup(const std::string &filename, const std::vector<std::string> &args);
-void finalize();
+void setup(bool python_lifecycle,
+ const std::string &filename,
+ const std::vector<std::string> &args,
+ PyObject *name_space);
+void finalize(bool python_lifecycle);
bool canConvert(PyObject *obj, const std::string &to);
Manta::PbClass *objFromPy(PyObject *obj);
Manta::PbClass *createPy(const std::string &classname,

View File

@@ -0,0 +1,83 @@
diff --git a/extern/mantaflow/helper/util/vector4d.h b/extern/mantaflow/helper/util/vector4d.h
index c3d72ac8aff..69cb96ff1ff 100644
--- a/extern/mantaflow/helper/util/vector4d.h
+++ b/extern/mantaflow/helper/util/vector4d.h
@@ -287,6 +287,34 @@ template<class S> inline S dot(const Vector4D<S> &t, const Vector4D<S> &v)
return t.x * v.x + t.y * v.y + t.z * v.z + t.t * v.t;
}
+/* Based on libstdc++ implementation from:
+ https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/c_global/cmath#L3769
+*/
+template<typename _Tp>
+inline _Tp
+__hypot4(_Tp __x, _Tp __y, _Tp __z, _Tp __t)
+{
+ __x = std::abs(__x);
+ __y = std::abs(__y);
+ __z = std::abs(__z);
+ __t = std::abs(__t);
+ if (_Tp __a = __x < __y ? (__y < __z ? (__z < __t ? __t : __z ) : (__y < __t ? __t : __y )) : __x < __z ? (__z < __t ? __t : __z ) : (__x < __t ? __t : __x ))
+ return __a * std::sqrt((__x / __a) * (__x / __a)
+ + (__y / __a) * (__y / __a)
+ + (__z / __a) * (__z / __a)
+ + (__t / __a) * (__t / __a));
+ else
+ return {};
+}
+
+inline float
+hypot4(float __x, float __y, float __z, float __t)
+{ return __hypot4<float>(__x, __y, __z, __t); }
+
+inline double
+hypot4(double __x, double __y, double __z, double __t)
+{ return __hypot4<double>(__x, __y, __z, __t); }
+
//! Cross product
/*template<class S>
inline Vector4D<S> cross ( const Vector4D<S> &t, const Vector4D<S> &v ) {
@@ -300,8 +328,8 @@ inline Vector4D<S> cross ( const Vector4D<S> &t, const Vector4D<S> &v ) {
//! Compute the magnitude (length) of the vector
template<class S> inline S norm(const Vector4D<S> &v)
{
- S l = v.x * v.x + v.y * v.y + v.z * v.z + v.t * v.t;
- return (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) ? 1. : sqrt(l);
+ S l = hypot4(v.x, v.y, v.z, v.t);
+ return (fabs(l - 1.) < VECTOR_EPSILON) ? 1. : l;
}
//! Compute squared magnitude
@@ -313,11 +341,11 @@ template<class S> inline S normSquare(const Vector4D<S> &v)
//! Returns a normalized vector
template<class S> inline Vector4D<S> getNormalized(const Vector4D<S> &v)
{
- S l = v.x * v.x + v.y * v.y + v.z * v.z + v.t * v.t;
- if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON)
+ S l = hypot4(v.x, v.y, v.z, v.t);
+ if (fabs(l - 1.) < VECTOR_EPSILON)
return v; /* normalized "enough"... */
- else if (l > VECTOR_EPSILON * VECTOR_EPSILON) {
- S fac = 1. / sqrt(l);
+ else if (l > VECTOR_EPSILON) {
+ S fac = 1. / l;
return Vector4D<S>(v.x * fac, v.y * fac, v.z * fac, v.t * fac);
}
else
@@ -329,12 +357,12 @@ template<class S> inline Vector4D<S> getNormalized(const Vector4D<S> &v)
template<class S> inline S normalize(Vector4D<S> &v)
{
S norm;
- S l = v.x * v.x + v.y * v.y + v.z * v.z + v.t * v.t;
- if (fabs(l - 1.) < VECTOR_EPSILON * VECTOR_EPSILON) {
+ S l = hypot4(v.x, v.y, v.z, v.t);
+ if (fabs(l - 1.) < VECTOR_EPSILON) {
norm = 1.;
}
- else if (l > VECTOR_EPSILON * VECTOR_EPSILON) {
- norm = sqrt(l);
+ else if (l > VECTOR_EPSILON) {
+ norm = l;
v *= 1. / norm;
}
else {

View File

@@ -0,0 +1,38 @@
commit 4a2c116053be7d445f061bee074796dc87529b3f
Author: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Fri May 2 19:59:49 2025 +0200
Physics: Dissolve smoke independently from number of timesteps in Frame
Fixes: 80529
diff --git a/extern/mantaflow/preprocessed/plugin/extforces.cpp b/extern/mantaflow/preprocessed/plugin/extforces.cpp
index 88935fa7ae9..eaf3e7d39f4 100644
--- a/extern/mantaflow/preprocessed/plugin/extforces.cpp
+++ b/extern/mantaflow/preprocessed/plugin/extforces.cpp
@@ -1652,10 +1652,11 @@ void dissolveSmoke(const FlagGrid &flags,
Grid<Real> *green = nullptr,
Grid<Real> *blue = nullptr,
int speed = 5,
- bool logFalloff = true)
+ bool logFalloff = true,
+ const float dissolveScale = 1.0)
{
- float dydx = 1.0f / (float)speed; // max density/speed = dydx
- float fac = 1.0f - dydx;
+ const float dydx = dissolveScale / (float)speed; // max density (1.0) * scale / speed = dydx
+ const float fac = 1.0f - dydx;
KnDissolveSmoke(flags, density, heat, red, green, blue, speed, logFalloff, dydx, fac);
}
static PyObject *_W_11(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
@@ -1676,8 +1677,9 @@ static PyObject *_W_11(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
Grid<Real> *blue = _args.getPtrOpt<Grid<Real>>("blue", 5, nullptr, &_lock);
int speed = _args.getOpt<int>("speed", 6, 5, &_lock);
bool logFalloff = _args.getOpt<bool>("logFalloff", 7, true, &_lock);
+ const float dissolveScale = _args.getOpt<float>("dissolveScale", 8, 1.0, &_lock);
_retval = getPyNone();
- dissolveSmoke(flags, density, heat, red, green, blue, speed, logFalloff);
+ dissolveSmoke(flags, density, heat, red, green, blue, speed, logFalloff, dissolveScale);
_args.check();
}
pbFinalizePlugin(parent, "dissolveSmoke", !noTiming);