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:
Diffstat (limited to 'intern/mantaflow/intern')
-rw-r--r--intern/mantaflow/intern/MANTA_main.cpp543
-rw-r--r--intern/mantaflow/intern/MANTA_main.h170
-rw-r--r--intern/mantaflow/intern/manta_fluid_API.cpp229
-rw-r--r--intern/mantaflow/intern/strings/fluid_script.h23
-rw-r--r--intern/mantaflow/intern/strings/liquid_script.h6
-rw-r--r--intern/mantaflow/intern/strings/smoke_script.h8
6 files changed, 459 insertions, 520 deletions
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 43121f08f2d..586c413b044 100644
--- a/intern/mantaflow/intern/MANTA_main.cpp
+++ b/intern/mantaflow/intern/MANTA_main.cpp
@@ -27,10 +27,6 @@
#include <sstream>
#include <zlib.h>
-#if OPENVDB == 1
-# include "openvdb/openvdb.h"
-#endif
-
#include "MANTA_main.h"
#include "Python.h"
#include "fluid_script.h"
@@ -60,13 +56,6 @@ using std::to_string;
atomic<int> MANTA::solverID(0);
int MANTA::with_debug(0);
-/* Number of particles that the cache reads at once (with zlib). */
-#define PARTICLE_CHUNK 20000
-/* Number of mesh nodes that the cache reads at once (with zlib). */
-#define NODE_CHUNK 20000
-/* Number of mesh triangles that the cache reads at once (with zlib). */
-#define TRIANGLE_CHUNK 20000
-
MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
{
if (with_debug)
@@ -96,8 +85,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mUsingInvel = (fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL);
mUsingOutflow = (fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW);
- // Simulation constants
- mTempAmb = 0; // TODO: Maybe use this later for buoyancy calculation
+ /* Simulation constants. */
mResX = res[0];
mResY = res[1];
mResZ = res[2];
@@ -105,7 +93,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mTotalCells = mResX * mResY * mResZ;
mResGuiding = fds->res;
- // Smoke low res grids
+ /* Smoke low res grids. */
mDensity = nullptr;
mShadow = nullptr;
mHeat = nullptr;
@@ -131,7 +119,7 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mReactIn = nullptr;
mEmissionIn = nullptr;
- // Smoke high res grids
+ /* Smoke high res grids. */
mDensityHigh = nullptr;
mFlameHigh = nullptr;
mFuelHigh = nullptr;
@@ -146,19 +134,19 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mTextureV2 = nullptr;
mTextureW2 = nullptr;
- // Fluid low res grids
+ /* Fluid low res grids. */
mPhiIn = nullptr;
mPhiStaticIn = nullptr;
mPhiOutIn = nullptr;
mPhiOutStaticIn = nullptr;
mPhi = nullptr;
- // Mesh
+ /* Mesh. */
mMeshNodes = nullptr;
mMeshTriangles = nullptr;
mMeshVelocities = nullptr;
- // Fluid obstacle
+ /* Fluid obstacle. */
mPhiObsIn = nullptr;
mPhiObsStaticIn = nullptr;
mNumObstacle = nullptr;
@@ -166,47 +154,48 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mObVelocityY = nullptr;
mObVelocityZ = nullptr;
- // Fluid guiding
+ /* Fluid guiding. */
mPhiGuideIn = nullptr;
mNumGuide = nullptr;
mGuideVelocityX = nullptr;
mGuideVelocityY = nullptr;
mGuideVelocityZ = nullptr;
- // Fluid initial velocity
+ /* Fluid initial velocity. */
mInVelocityX = nullptr;
mInVelocityY = nullptr;
mInVelocityZ = nullptr;
- // Secondary particles
+ /* Secondary particles. */
mFlipParticleData = nullptr;
mFlipParticleVelocity = nullptr;
- mSndParticleData = nullptr;
- mSndParticleVelocity = nullptr;
- mSndParticleLife = nullptr;
+ mParticleData = nullptr;
+ mParticleVelocity = nullptr;
+ mParticleLife = nullptr;
- // Cache read success indicators
+ /* Cache read success indicators. */
mFlipFromFile = false;
mMeshFromFile = false;
mParticlesFromFile = false;
- // Setup Mantaflow in Python
+ /* Setup Mantaflow in Python. */
initializeMantaflow();
- // Initializa RNA map with values that Python will need
+ /* Initializa RNA map with values that Python will need. */
initializeRNAMap(fmd);
- // Initialize Mantaflow variables in Python
- // Liquid
+ bool initSuccess = true;
+ /* Initialize Mantaflow variables in Python. */
+ /* Liquid. */
if (mUsingLiquid) {
- initDomain();
- initLiquid();
+ initSuccess &= initDomain();
+ initSuccess &= initLiquid();
if (mUsingObstacle)
- initObstacle();
+ initSuccess &= initObstacle();
if (mUsingInvel)
- initInVelocity();
+ initSuccess &= initInVelocity();
if (mUsingOutflow)
- initOutflow();
+ initSuccess &= initOutflow();
if (mUsingDrops || mUsingBubbles || mUsingFloats || mUsingTracers) {
mUpresParticle = fds->particle_scale;
@@ -215,8 +204,8 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mResZParticle = mUpresParticle * mResZ;
mTotalCellsParticles = mResXParticle * mResYParticle * mResZParticle;
- initSndParts();
- initLiquidSndParts();
+ initSuccess &= initSndParts();
+ initSuccess &= initLiquidSndParts();
}
if (mUsingMesh) {
@@ -226,44 +215,44 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mResZMesh = mUpresMesh * mResZ;
mTotalCellsMesh = mResXMesh * mResYMesh * mResZMesh;
- // Initialize Mantaflow variables in Python
- initMesh();
- initLiquidMesh();
+ /* Initialize Mantaflow variables in Python. */
+ initSuccess &= initMesh();
+ initSuccess &= initLiquidMesh();
}
if (mUsingDiffusion) {
- initCurvature();
+ initSuccess &= initCurvature();
}
if (mUsingGuiding) {
mResGuiding = (fds->guide_parent) ? fds->guide_res : fds->res;
- initGuiding();
+ initSuccess &= initGuiding();
}
if (mUsingFractions) {
- initFractions();
+ initSuccess &= initFractions();
}
}
- // Smoke
+ /* Smoke. */
if (mUsingSmoke) {
- initDomain();
- initSmoke();
+ initSuccess &= initDomain();
+ initSuccess &= initSmoke();
if (mUsingHeat)
- initHeat();
+ initSuccess &= initHeat();
if (mUsingFire)
- initFire();
+ initSuccess &= initFire();
if (mUsingColors)
- initColors();
+ initSuccess &= initColors();
if (mUsingObstacle)
- initObstacle();
+ initSuccess &= initObstacle();
if (mUsingInvel)
- initInVelocity();
+ initSuccess &= initInVelocity();
if (mUsingOutflow)
- initOutflow();
+ initSuccess &= initOutflow();
if (mUsingGuiding) {
mResGuiding = (fds->guide_parent) ? fds->guide_res : fds->res;
- initGuiding();
+ initSuccess &= initGuiding();
}
if (mUsingNoise) {
@@ -273,31 +262,33 @@ MANTA::MANTA(int *res, FluidModifierData *fmd) : mCurrentID(++solverID)
mResZNoise = amplify * mResZ;
mTotalCellsHigh = mResXNoise * mResYNoise * mResZNoise;
- // Initialize Mantaflow variables in Python
- initNoise();
- initSmokeNoise();
+ /* Initialize Mantaflow variables in Python. */
+ initSuccess &= initNoise();
+ initSuccess &= initSmokeNoise();
if (mUsingFire)
- initFireHigh();
+ initSuccess &= initFireHigh();
if (mUsingColors)
- initColorsHigh();
+ initSuccess &= initColorsHigh();
}
}
- updatePointers();
+ /* All requested initializations must not fail in constructor. */
+ BLI_assert(initSuccess);
+ updatePointers(fmd);
}
-void MANTA::initDomain(FluidModifierData *fmd)
+bool MANTA::initDomain(FluidModifierData *fmd)
{
- // Vector will hold all python commands that are to be executed
+ /* Vector will hold all python commands that are to be executed. */
vector<string> pythonCommands;
- // Set manta debug level first
+ /* Set manta debug level first. */
pythonCommands.push_back(manta_import + manta_debuglevel);
ostringstream ss;
ss << "set_manta_debuglevel(" << with_debug << ")";
pythonCommands.push_back(ss.str());
- // Now init basic fluid domain
+ /* Now init basic fluid domain. */
string tmpString = fluid_variables + fluid_solver + fluid_alloc + fluid_cache_helper +
fluid_bake_multiprocessing + fluid_bake_data + fluid_bake_noise +
fluid_bake_mesh + fluid_bake_particles + fluid_bake_guiding +
@@ -305,20 +296,20 @@ void MANTA::initDomain(FluidModifierData *fmd)
fluid_adapt_time_step + fluid_time_stepping;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
+ return runPythonString(pythonCommands);
}
-void MANTA::initNoise(FluidModifierData *fmd)
+bool MANTA::initNoise(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = fluid_variables_noise + fluid_solver_noise;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
+ return runPythonString(pythonCommands);
}
-void MANTA::initSmoke(FluidModifierData *fmd)
+bool MANTA::initSmoke(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = smoke_variables + smoke_alloc + smoke_adaptive_step + smoke_save_data +
@@ -326,10 +317,10 @@ void MANTA::initSmoke(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
+ return runPythonString(pythonCommands);
}
-void MANTA::initSmokeNoise(FluidModifierData *fmd)
+bool MANTA::initSmokeNoise(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = smoke_variables_noise + smoke_alloc_noise + smoke_wavelet_noise +
@@ -337,11 +328,11 @@ void MANTA::initSmokeNoise(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingNoise = true;
+ return runPythonString(pythonCommands);
}
-void MANTA::initHeat(FluidModifierData *fmd)
+bool MANTA::initHeat(FluidModifierData *fmd)
{
if (!mHeat) {
vector<string> pythonCommands;
@@ -349,12 +340,13 @@ void MANTA::initHeat(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingHeat = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initFire(FluidModifierData *fmd)
+bool MANTA::initFire(FluidModifierData *fmd)
{
if (!mFuel) {
vector<string> pythonCommands;
@@ -362,12 +354,13 @@ void MANTA::initFire(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingFire = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initFireHigh(FluidModifierData *fmd)
+bool MANTA::initFireHigh(FluidModifierData *fmd)
{
if (!mFuelHigh) {
vector<string> pythonCommands;
@@ -375,12 +368,13 @@ void MANTA::initFireHigh(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingFire = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initColors(FluidModifierData *fmd)
+bool MANTA::initColors(FluidModifierData *fmd)
{
if (!mColorR) {
vector<string> pythonCommands;
@@ -388,12 +382,13 @@ void MANTA::initColors(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingColors = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initColorsHigh(FluidModifierData *fmd)
+bool MANTA::initColorsHigh(FluidModifierData *fmd)
{
if (!mColorRHigh) {
vector<string> pythonCommands;
@@ -401,12 +396,13 @@ void MANTA::initColorsHigh(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingColors = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initLiquid(FluidModifierData *fmd)
+bool MANTA::initLiquid(FluidModifierData *fmd)
{
if (!mPhiIn) {
vector<string> pythonCommands;
@@ -415,44 +411,45 @@ void MANTA::initLiquid(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingLiquid = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initMesh(FluidModifierData *fmd)
+bool MANTA::initMesh(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = fluid_variables_mesh + fluid_solver_mesh + liquid_load_mesh;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingMesh = true;
+ return runPythonString(pythonCommands);
}
-void MANTA::initLiquidMesh(FluidModifierData *fmd)
+bool MANTA::initLiquidMesh(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = liquid_alloc_mesh + liquid_step_mesh + liquid_save_mesh;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingMesh = true;
+ return runPythonString(pythonCommands);
}
-void MANTA::initCurvature(FluidModifierData *fmd)
+bool MANTA::initCurvature(FluidModifierData *fmd)
{
std::vector<std::string> pythonCommands;
std::string finalString = parseScript(liquid_alloc_curvature, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingDiffusion = true;
+ return runPythonString(pythonCommands);
}
-void MANTA::initObstacle(FluidModifierData *fmd)
+bool MANTA::initObstacle(FluidModifierData *fmd)
{
if (!mPhiObsIn) {
vector<string> pythonCommands;
@@ -460,12 +457,13 @@ void MANTA::initObstacle(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingObstacle = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initGuiding(FluidModifierData *fmd)
+bool MANTA::initGuiding(FluidModifierData *fmd)
{
if (!mPhiGuideIn) {
vector<string> pythonCommands;
@@ -474,23 +472,24 @@ void MANTA::initGuiding(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingGuiding = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initFractions(FluidModifierData *fmd)
+bool MANTA::initFractions(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = fluid_alloc_fractions + fluid_with_fractions;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingFractions = true;
+ return runPythonString(pythonCommands);
}
-void MANTA::initInVelocity(FluidModifierData *fmd)
+bool MANTA::initInVelocity(FluidModifierData *fmd)
{
if (!mInVelocityX) {
vector<string> pythonCommands;
@@ -498,12 +497,13 @@ void MANTA::initInVelocity(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingInvel = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initOutflow(FluidModifierData *fmd)
+bool MANTA::initOutflow(FluidModifierData *fmd)
{
if (!mPhiOutIn) {
vector<string> pythonCommands;
@@ -511,24 +511,25 @@ void MANTA::initOutflow(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
mUsingOutflow = true;
+ return runPythonString(pythonCommands);
}
+ return false;
}
-void MANTA::initSndParts(FluidModifierData *fmd)
+bool MANTA::initSndParts(FluidModifierData *fmd)
{
vector<string> pythonCommands;
string tmpString = fluid_variables_particles + fluid_solver_particles;
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
+ return runPythonString(pythonCommands);
}
-void MANTA::initLiquidSndParts(FluidModifierData *fmd)
+bool MANTA::initLiquidSndParts(FluidModifierData *fmd)
{
- if (!mSndParticleData) {
+ if (!mParticleData) {
vector<string> pythonCommands;
string tmpString = liquid_alloc_particles + liquid_variables_particles +
liquid_step_particles + fluid_with_sndparts + liquid_load_particles +
@@ -536,8 +537,9 @@ void MANTA::initLiquidSndParts(FluidModifierData *fmd)
string finalString = parseScript(tmpString, fmd);
pythonCommands.push_back(finalString);
- runPythonString(pythonCommands);
+ return runPythonString(pythonCommands);
}
+ return false;
}
MANTA::~MANTA()
@@ -546,7 +548,7 @@ MANTA::~MANTA()
cout << "~FLUID: " << mCurrentID << " with res(" << mResX << ", " << mResY << ", " << mResZ
<< ")" << endl;
- // Destruction string for Python
+ /* Destruction string for Python. */
string tmpString = "";
vector<string> pythonCommands;
bool result = false;
@@ -554,10 +556,10 @@ MANTA::~MANTA()
tmpString += manta_import;
tmpString += fluid_delete_all;
- // Initializa RNA map with values that Python will need
+ /* Initializa RNA map with values that Python will need. */
initializeRNAMap();
- // Leave out fmd argument in parseScript since only looking up IDs
+ /* Leave out fmd argument in parseScript since only looking up IDs. */
string finalString = parseScript(tmpString);
pythonCommands.push_back(finalString);
result = runPythonString(pythonCommands);
@@ -619,10 +621,10 @@ void MANTA::initializeMantaflow()
string filename = "manta_scene_" + to_string(mCurrentID) + ".py";
vector<string> fill = vector<string>();
- // Initialize extension classes and wrappers
+ /* Initialize extension classes and wrappers. */
srand(0);
PyGILState_STATE gilstate = PyGILState_Ensure();
- Pb::setup(filename, fill); // Namespace from Mantaflow (registry)
+ Pb::setup(filename, fill); /* Namespace from Mantaflow (registry). */
PyGILState_Release(gilstate);
}
@@ -632,7 +634,7 @@ void MANTA::terminateMantaflow()
cout << "Fluid: Releasing Mantaflow framework" << endl;
PyGILState_STATE gilstate = PyGILState_Ensure();
- Pb::finalize(); // Namespace from Mantaflow (registry)
+ Pb::finalize(); /* Namespace from Mantaflow (registry). */
PyGILState_Release(gilstate);
}
@@ -870,12 +872,13 @@ void MANTA::initializeRNAMap(FluidModifierData *fmd)
mRNAMap["GUIDING_ALPHA"] = to_string(fds->guide_alpha);
mRNAMap["GUIDING_BETA"] = to_string(fds->guide_beta);
mRNAMap["GUIDING_FACTOR"] = to_string(fds->guide_vel_factor);
- mRNAMap["GRAVITY_X"] = to_string(fds->gravity[0]);
- mRNAMap["GRAVITY_Y"] = to_string(fds->gravity[1]);
- mRNAMap["GRAVITY_Z"] = to_string(fds->gravity[2]);
+ mRNAMap["GRAVITY_X"] = to_string(fds->gravity_final[0]);
+ mRNAMap["GRAVITY_Y"] = to_string(fds->gravity_final[1]);
+ mRNAMap["GRAVITY_Z"] = to_string(fds->gravity_final[2]);
mRNAMap["CACHE_DIR"] = cacheDirectory;
mRNAMap["COMPRESSION_OPENVDB"] = vdbCompressionMethod;
mRNAMap["PRECISION_OPENVDB"] = vdbPrecisionHalf;
+ mRNAMap["PP_PARTICLE_MAXIMUM"] = to_string(fds->sys_particle_maximum);
/* Fluid object names. */
mRNAMap["NAME_FLAGS"] = FLUID_NAME_FLAGS;
@@ -1072,7 +1075,7 @@ string MANTA::parseScript(const string &setup_string, FluidModifierData *fmd)
ostringstream res;
string line = "";
- // Update RNA map if modifier data is handed over
+ /* Update RNA map if modifier data is handed over. */
if (fmd) {
initializeRNAMap(fmd);
}
@@ -1110,7 +1113,8 @@ bool MANTA::writeConfiguration(FluidModifierData *fmd, int framenr)
/* Create 'config' subdir if it does not exist already. */
BLI_dir_create_recursive(directory.c_str());
- gzFile gzf = (gzFile)BLI_gzopen(file.c_str(), "wb1"); // do some compression
+ /* Open new file with some compression. */
+ gzFile gzf = (gzFile)BLI_gzopen(file.c_str(), "wb1");
if (!gzf) {
cerr << "Fluid Error -- Cannot open file " << file << endl;
return false;
@@ -1256,6 +1260,7 @@ bool MANTA::readData(FluidModifierData *fmd, int framenr, bool resumable)
<< ", '" << volume_format << "', " << resumable_cache << ")";
pythonCommands.push_back(ss.str());
result &= runPythonString(pythonCommands);
+ return (mSmokeFromFile = result);
}
if (mUsingLiquid) {
ss.str("");
@@ -1263,6 +1268,7 @@ bool MANTA::readData(FluidModifierData *fmd, int framenr, bool resumable)
<< ", '" << volume_format << "', " << resumable_cache << ")";
pythonCommands.push_back(ss.str());
result &= runPythonString(pythonCommands);
+ return (mFlipFromFile = result);
}
return result;
}
@@ -1296,7 +1302,7 @@ bool MANTA::readNoise(FluidModifierData *fmd, int framenr, bool resumable)
<< ", '" << volume_format << "', " << resumable_cache << ")";
pythonCommands.push_back(ss.str());
- return runPythonString(pythonCommands);
+ return (mNoiseFromFile = runPythonString(pythonCommands));
}
bool MANTA::readMesh(FluidModifierData *fmd, int framenr)
@@ -1331,7 +1337,7 @@ bool MANTA::readMesh(FluidModifierData *fmd, int framenr)
pythonCommands.push_back(ss.str());
}
- return runPythonString(pythonCommands);
+ return (mMeshFromFile = runPythonString(pythonCommands));
}
bool MANTA::readParticles(FluidModifierData *fmd, int framenr, bool resumable)
@@ -1365,7 +1371,7 @@ bool MANTA::readParticles(FluidModifierData *fmd, int framenr, bool resumable)
<< framenr << ", '" << volume_format << "', " << resumable_cache << ")";
pythonCommands.push_back(ss.str());
- return runPythonString(pythonCommands);
+ return (mParticlesFromFile = runPythonString(pythonCommands));
}
bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain)
@@ -1612,10 +1618,10 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd)
string manta_script;
- // Libraries
+ /* Libraries. */
manta_script += header_libraries + manta_import;
- // Variables
+ /* Variables. */
manta_script += header_variables + fluid_variables + smoke_variables;
if (noise) {
manta_script += fluid_variables_noise + smoke_variables_noise;
@@ -1623,14 +1629,14 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd)
if (guiding)
manta_script += fluid_variables_guiding;
- // Solvers
+ /* Solvers. */
manta_script += header_solvers + fluid_solver;
if (noise)
manta_script += fluid_solver_noise;
if (guiding)
manta_script += fluid_solver_guiding;
- // Grids
+ /* Grids. */
manta_script += header_grids + fluid_alloc + smoke_alloc;
if (noise) {
manta_script += smoke_alloc_noise;
@@ -1654,36 +1660,36 @@ void MANTA::exportSmokeScript(FluidModifierData *fmd)
if (outflow)
manta_script += fluid_alloc_outflow;
- // Noise field
+ /* Noise field. */
if (noise)
manta_script += smoke_wavelet_noise;
- // Time
+ /* Time. */
manta_script += header_time + fluid_time_stepping + fluid_adapt_time_step;
- // Import
+ /* Import. */
manta_script += header_import + fluid_file_import + fluid_cache_helper + smoke_load_data;
if (noise)
manta_script += smoke_load_noise;
if (guiding)
manta_script += fluid_load_guiding;
- // Pre/Post Steps
+ /* Pre/Post Steps. */
manta_script += header_prepost + fluid_pre_step + fluid_post_step;
- // Steps
+ /* Steps. */
manta_script += header_steps + smoke_adaptive_step + smoke_step;
if (noise) {
manta_script += smoke_step_noise;
}
- // Main
+ /* Main. */
manta_script += header_main + smoke_standalone + fluid_standalone;
- // Fill in missing variables in script
+ /* Fill in missing variables in script. */
string final_script = MANTA::parseScript(manta_script, fmd);
- // Write script
+ /* Write script. */
ofstream myfile;
myfile.open(cacheDirScript);
myfile << final_script;
@@ -1722,10 +1728,10 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd)
string manta_script;
- // Libraries
+ /* Libraries. */
manta_script += header_libraries + manta_import;
- // Variables
+ /* Variables. */
manta_script += header_variables + fluid_variables + liquid_variables;
if (mesh)
manta_script += fluid_variables_mesh;
@@ -1734,7 +1740,7 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd)
if (guiding)
manta_script += fluid_variables_guiding;
- // Solvers
+ /* Solvers. */
manta_script += header_solvers + fluid_solver;
if (mesh)
manta_script += fluid_solver_mesh;
@@ -1743,7 +1749,7 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd)
if (guiding)
manta_script += fluid_solver_guiding;
- // Grids
+ /* Grids. */
manta_script += header_grids + fluid_alloc + liquid_alloc;
if (mesh)
manta_script += liquid_alloc_mesh;
@@ -1760,13 +1766,13 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd)
if (outflow)
manta_script += fluid_alloc_outflow;
- // Domain init
+ /* Domain init. */
manta_script += header_gridinit + liquid_init_phi;
- // Time
+ /* Time. */
manta_script += header_time + fluid_time_stepping + fluid_adapt_time_step;
- // Import
+ /* Import. */
manta_script += header_import + fluid_file_import + fluid_cache_helper + liquid_load_data;
if (mesh)
manta_script += liquid_load_mesh;
@@ -1775,23 +1781,23 @@ void MANTA::exportLiquidScript(FluidModifierData *fmd)
if (guiding)
manta_script += fluid_load_guiding;
- // Pre/Post Steps
+ /* Pre/Post Steps. */
manta_script += header_prepost + fluid_pre_step + fluid_post_step;
- // Steps
+ /* Steps. */
manta_script += header_steps + liquid_adaptive_step + liquid_step;
if (mesh)
manta_script += liquid_step_mesh;
if (drops || bubble || floater || tracer)
manta_script += liquid_step_particles;
- // Main
+ /* Main. */
manta_script += header_main + liquid_standalone + fluid_standalone;
- // Fill in missing variables in script
+ /* Fill in missing variables in script. */
string final_script = MANTA::parseScript(manta_script, fmd);
- // Write script
+ /* Write script. */
ofstream myfile;
myfile.open(cacheDirScript);
myfile << final_script;
@@ -1820,12 +1826,18 @@ static PyObject *callPythonFunction(string varName, string functionName, bool is
/* Be sure to initialize Python before using it. */
Py_Initialize();
- // Get pyobject that holds result value
+ /* Get pyobject that holds result value. */
if (!manta_main_module) {
PyGILState_Release(gilstate);
return nullptr;
}
+ /* Ensure that requested variable is present in module - avoid attribute errors later on. */
+ if (!PyObject_HasAttrString(manta_main_module, varName.c_str())) {
+ PyGILState_Release(gilstate);
+ return nullptr;
+ }
+
var = PyObject_GetAttrString(manta_main_module, varName.c_str());
if (!var) {
PyGILState_Release(gilstate);
@@ -1908,6 +1920,11 @@ static long pyObjectToLong(PyObject *inputObject)
return result;
}
+template<class T> static T *getPointer(string pyObjectName, string pyFunctionName)
+{
+ return static_cast<T *>(pyObjectToPointer(callPythonFunction(pyObjectName, pyFunctionName)));
+}
+
int MANTA::getFrame()
{
if (with_debug)
@@ -1952,137 +1969,137 @@ void MANTA::adaptTimestep()
runPythonString(pythonCommands);
}
-void MANTA::updatePointers()
+void MANTA::updatePointers(FluidModifierData *fmd, bool flush)
{
if (with_debug)
cout << "MANTA::updatePointers()" << endl;
+ FluidDomainSettings *fds = fmd->domain;
+
+ bool liquid = !flush && (fds->type == FLUID_DOMAIN_TYPE_LIQUID);
+ bool smoke = !flush && (fds->type == FLUID_DOMAIN_TYPE_GAS);
+ bool noise = !flush && smoke && fds->flags & FLUID_DOMAIN_USE_NOISE;
+ bool heat = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_HEAT;
+ bool colors = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_COLORS;
+ bool fire = !flush && smoke && fds->active_fields & FLUID_DOMAIN_ACTIVE_FIRE;
+ bool obstacle = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OBSTACLE;
+ bool guiding = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_GUIDE;
+ bool invel = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_INVEL;
+ bool outflow = !flush && fds->active_fields & FLUID_DOMAIN_ACTIVE_OUTFLOW;
+ bool drops = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_SPRAY;
+ bool bubble = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_BUBBLE;
+ bool floater = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_FOAM;
+ bool tracer = !flush && liquid && fds->particle_type & FLUID_DOMAIN_PARTICLE_TRACER;
+ bool parts = !flush && liquid && (drops | bubble | floater | tracer);
+ bool mesh = !flush && liquid && fds->flags & FLUID_DOMAIN_USE_MESH;
+ bool meshvel = !flush && liquid && mesh && fds->flags & FLUID_DOMAIN_USE_SPEED_VECTORS;
+
string func = "getDataPointer";
string funcNodes = "getNodesDataPointer";
string funcTris = "getTrisDataPointer";
string id = to_string(mCurrentID);
- string solver = "s" + id;
- string parts = "pp" + id;
- string snd = "sp" + id;
- string mesh = "sm" + id;
- string mesh2 = "mesh" + id;
- string noise = "sn" + id;
- string solver_ext = "_" + solver;
- string parts_ext = "_" + parts;
- string snd_ext = "_" + snd;
- string mesh_ext = "_" + mesh;
- string mesh_ext2 = "_" + mesh2;
- string noise_ext = "_" + noise;
-
- mFlags = (int *)pyObjectToPointer(callPythonFunction("flags" + solver_ext, func));
- mPhiIn = (float *)pyObjectToPointer(callPythonFunction("phiIn" + solver_ext, func));
- mPhiStaticIn = (float *)pyObjectToPointer(callPythonFunction("phiSIn" + solver_ext, func));
- mVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_vel" + solver_ext, func));
- mVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_vel" + solver_ext, func));
- mVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_vel" + solver_ext, func));
- mForceX = (float *)pyObjectToPointer(callPythonFunction("x_force" + solver_ext, func));
- mForceY = (float *)pyObjectToPointer(callPythonFunction("y_force" + solver_ext, func));
- mForceZ = (float *)pyObjectToPointer(callPythonFunction("z_force" + solver_ext, func));
-
- if (mUsingOutflow) {
- mPhiOutIn = (float *)pyObjectToPointer(callPythonFunction("phiOutIn" + solver_ext, func));
- mPhiOutStaticIn = (float *)pyObjectToPointer(
- callPythonFunction("phiOutSIn" + solver_ext, func));
- }
- if (mUsingObstacle) {
- mPhiObsIn = (float *)pyObjectToPointer(callPythonFunction("phiObsIn" + solver_ext, func));
- mPhiObsStaticIn = (float *)pyObjectToPointer(
- callPythonFunction("phiObsSIn" + solver_ext, func));
- mObVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_obvel" + solver_ext, func));
- mObVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_obvel" + solver_ext, func));
- mObVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_obvel" + solver_ext, func));
- mNumObstacle = (float *)pyObjectToPointer(callPythonFunction("numObs" + solver_ext, func));
- }
- if (mUsingGuiding) {
- mPhiGuideIn = (float *)pyObjectToPointer(callPythonFunction("phiGuideIn" + solver_ext, func));
- mGuideVelocityX = (float *)pyObjectToPointer(
- callPythonFunction("x_guidevel" + solver_ext, func));
- mGuideVelocityY = (float *)pyObjectToPointer(
- callPythonFunction("y_guidevel" + solver_ext, func));
- mGuideVelocityZ = (float *)pyObjectToPointer(
- callPythonFunction("z_guidevel" + solver_ext, func));
- mNumGuide = (float *)pyObjectToPointer(callPythonFunction("numGuides" + solver_ext, func));
- }
- if (mUsingInvel) {
- mInVelocityX = (float *)pyObjectToPointer(callPythonFunction("x_invel" + solver_ext, func));
- mInVelocityY = (float *)pyObjectToPointer(callPythonFunction("y_invel" + solver_ext, func));
- mInVelocityZ = (float *)pyObjectToPointer(callPythonFunction("z_invel" + solver_ext, func));
- }
- if (mUsingSmoke) {
- mDensity = (float *)pyObjectToPointer(callPythonFunction("density" + solver_ext, func));
- mDensityIn = (float *)pyObjectToPointer(callPythonFunction("densityIn" + solver_ext, func));
- mShadow = (float *)pyObjectToPointer(callPythonFunction("shadow" + solver_ext, func));
- mEmissionIn = (float *)pyObjectToPointer(callPythonFunction("emissionIn" + solver_ext, func));
- }
- if (mUsingSmoke && mUsingHeat) {
- mHeat = (float *)pyObjectToPointer(callPythonFunction("heat" + solver_ext, func));
- mHeatIn = (float *)pyObjectToPointer(callPythonFunction("heatIn" + solver_ext, func));
- }
- if (mUsingSmoke && mUsingFire) {
- mFlame = (float *)pyObjectToPointer(callPythonFunction("flame" + solver_ext, func));
- mFuel = (float *)pyObjectToPointer(callPythonFunction("fuel" + solver_ext, func));
- mReact = (float *)pyObjectToPointer(callPythonFunction("react" + solver_ext, func));
- mFuelIn = (float *)pyObjectToPointer(callPythonFunction("fuelIn" + solver_ext, func));
- mReactIn = (float *)pyObjectToPointer(callPythonFunction("reactIn" + solver_ext, func));
- }
- if (mUsingSmoke && mUsingColors) {
- mColorR = (float *)pyObjectToPointer(callPythonFunction("color_r" + solver_ext, func));
- mColorG = (float *)pyObjectToPointer(callPythonFunction("color_g" + solver_ext, func));
- mColorB = (float *)pyObjectToPointer(callPythonFunction("color_b" + solver_ext, func));
- mColorRIn = (float *)pyObjectToPointer(callPythonFunction("color_r_in" + solver_ext, func));
- mColorGIn = (float *)pyObjectToPointer(callPythonFunction("color_g_in" + solver_ext, func));
- mColorBIn = (float *)pyObjectToPointer(callPythonFunction("color_b_in" + solver_ext, func));
- }
- if (mUsingSmoke && mUsingNoise) {
- mDensityHigh = (float *)pyObjectToPointer(callPythonFunction("density" + noise_ext, func));
- mTextureU = (float *)pyObjectToPointer(callPythonFunction("texture_u" + solver_ext, func));
- mTextureV = (float *)pyObjectToPointer(callPythonFunction("texture_v" + solver_ext, func));
- mTextureW = (float *)pyObjectToPointer(callPythonFunction("texture_w" + solver_ext, func));
- mTextureU2 = (float *)pyObjectToPointer(callPythonFunction("texture_u2" + solver_ext, func));
- mTextureV2 = (float *)pyObjectToPointer(callPythonFunction("texture_v2" + solver_ext, func));
- mTextureW2 = (float *)pyObjectToPointer(callPythonFunction("texture_w2" + solver_ext, func));
- }
- if (mUsingSmoke && mUsingNoise && mUsingFire) {
- mFlameHigh = (float *)pyObjectToPointer(callPythonFunction("flame" + noise_ext, func));
- mFuelHigh = (float *)pyObjectToPointer(callPythonFunction("fuel" + noise_ext, func));
- mReactHigh = (float *)pyObjectToPointer(callPythonFunction("react" + noise_ext, func));
- }
- if (mUsingSmoke && mUsingNoise && mUsingColors) {
- mColorRHigh = (float *)pyObjectToPointer(callPythonFunction("color_r" + noise_ext, func));
- mColorGHigh = (float *)pyObjectToPointer(callPythonFunction("color_g" + noise_ext, func));
- mColorBHigh = (float *)pyObjectToPointer(callPythonFunction("color_b" + noise_ext, func));
- }
- if (mUsingLiquid) {
- mPhi = (float *)pyObjectToPointer(callPythonFunction("phi" + solver_ext, func));
- mFlipParticleData = (vector<pData> *)pyObjectToPointer(
- callPythonFunction("pp" + solver_ext, func));
- mFlipParticleVelocity = (vector<pVel> *)pyObjectToPointer(
- callPythonFunction("pVel" + parts_ext, func));
- }
- if (mUsingLiquid && mUsingMesh) {
- mMeshNodes = (vector<Node> *)pyObjectToPointer(
- callPythonFunction("mesh" + mesh_ext, funcNodes));
- mMeshTriangles = (vector<Triangle> *)pyObjectToPointer(
- callPythonFunction("mesh" + mesh_ext, funcTris));
- }
- if (mUsingLiquid && mUsingMVel) {
- mMeshVelocities = (vector<pVel> *)pyObjectToPointer(
- callPythonFunction("mVel" + mesh_ext2, func));
- }
- if (mUsingLiquid && (mUsingDrops | mUsingBubbles | mUsingFloats | mUsingTracers)) {
- mSndParticleData = (vector<pData> *)pyObjectToPointer(
- callPythonFunction("ppSnd" + snd_ext, func));
- mSndParticleVelocity = (vector<pVel> *)pyObjectToPointer(
- callPythonFunction("pVelSnd" + parts_ext, func));
- mSndParticleLife = (vector<float> *)pyObjectToPointer(
- callPythonFunction("pLifeSnd" + parts_ext, func));
- }
+ string s_ext = "_s" + id;
+ string pp_ext = "_pp" + id;
+ string snd_ext = "_sp" + id;
+ string sm_ext = "_sm" + id;
+ string mesh_ext = "_mesh" + id;
+ string sn_ext = "_sn" + id;
+
+ mFlags = (smoke || liquid) ? getPointer<int>("flags" + s_ext, func) : nullptr;
+ mPhiIn = (smoke || liquid) ? getPointer<float>("phiIn" + s_ext, func) : nullptr;
+ mPhiStaticIn = (smoke || liquid) ? getPointer<float>("phiSIn" + s_ext, func) : nullptr;
+ mVelocityX = (smoke || liquid) ? getPointer<float>("x_vel" + s_ext, func) : nullptr;
+ mVelocityY = (smoke || liquid) ? getPointer<float>("y_vel" + s_ext, func) : nullptr;
+ mVelocityZ = (smoke || liquid) ? getPointer<float>("z_vel" + s_ext, func) : nullptr;
+ mForceX = (smoke || liquid) ? getPointer<float>("x_force" + s_ext, func) : nullptr;
+ mForceY = (smoke || liquid) ? getPointer<float>("y_force" + s_ext, func) : nullptr;
+ mForceZ = (smoke || liquid) ? getPointer<float>("z_force" + s_ext, func) : nullptr;
+
+ /* Outflow. */
+ mPhiOutIn = (outflow) ? getPointer<float>("phiOutIn" + s_ext, func) : nullptr;
+ mPhiOutStaticIn = (outflow) ? getPointer<float>("phiOutSIn" + s_ext, func) : nullptr;
+
+ /* Obstacles. */
+ mPhiObsIn = (obstacle) ? getPointer<float>("phiObsIn" + s_ext, func) : nullptr;
+ mPhiObsStaticIn = (obstacle) ? getPointer<float>("phiObsSIn" + s_ext, func) : nullptr;
+ mObVelocityX = (obstacle) ? getPointer<float>("x_obvel" + s_ext, func) : nullptr;
+ mObVelocityY = (obstacle) ? getPointer<float>("y_obvel" + s_ext, func) : nullptr;
+ mObVelocityZ = (obstacle) ? getPointer<float>("z_obvel" + s_ext, func) : nullptr;
+ mNumObstacle = (obstacle) ? getPointer<float>("numObs" + s_ext, func) : nullptr;
+
+ /* Guiding. */
+ mPhiGuideIn = (guiding) ? getPointer<float>("phiGuideIn" + s_ext, func) : nullptr;
+ mGuideVelocityX = (guiding) ? getPointer<float>("x_guidevel" + s_ext, func) : nullptr;
+ mGuideVelocityY = (guiding) ? getPointer<float>("y_guidevel" + s_ext, func) : nullptr;
+ mGuideVelocityZ = (guiding) ? getPointer<float>("z_guidevel" + s_ext, func) : nullptr;
+ mNumGuide = (guiding) ? getPointer<float>("numGuides" + s_ext, func) : nullptr;
+
+ /* Initial velocities. */
+ mInVelocityX = (invel) ? getPointer<float>("x_invel" + s_ext, func) : nullptr;
+ mInVelocityY = (invel) ? getPointer<float>("y_invel" + s_ext, func) : nullptr;
+ mInVelocityZ = (invel) ? getPointer<float>("z_invel" + s_ext, func) : nullptr;
+
+ /* Smoke. */
+ mDensity = (smoke) ? getPointer<float>("density" + s_ext, func) : nullptr;
+ mDensityIn = (smoke) ? getPointer<float>("densityIn" + s_ext, func) : nullptr;
+ mShadow = (smoke) ? getPointer<float>("shadow" + s_ext, func) : nullptr;
+ mEmissionIn = (smoke) ? getPointer<float>("emissionIn" + s_ext, func) : nullptr;
+
+ /* Heat. */
+ mHeat = (heat) ? getPointer<float>("heat" + s_ext, func) : nullptr;
+ mHeatIn = (heat) ? getPointer<float>("heatIn" + s_ext, func) : nullptr;
+
+ /* Fire. */
+ mFlame = (fire) ? getPointer<float>("flame" + s_ext, func) : nullptr;
+ mFuel = (fire) ? getPointer<float>("fuel" + s_ext, func) : nullptr;
+ mReact = (fire) ? getPointer<float>("react" + s_ext, func) : nullptr;
+ mFuelIn = (fire) ? getPointer<float>("fuelIn" + s_ext, func) : nullptr;
+ mReactIn = (fire) ? getPointer<float>("reactIn" + s_ext, func) : nullptr;
+
+ /* Colors. */
+ mColorR = (colors) ? getPointer<float>("color_r" + s_ext, func) : nullptr;
+ mColorG = (colors) ? getPointer<float>("color_g" + s_ext, func) : nullptr;
+ mColorB = (colors) ? getPointer<float>("color_b" + s_ext, func) : nullptr;
+ mColorRIn = (colors) ? getPointer<float>("color_r_in" + s_ext, func) : nullptr;
+ mColorGIn = (colors) ? getPointer<float>("color_g_in" + s_ext, func) : nullptr;
+ mColorBIn = (colors) ? getPointer<float>("color_b_in" + s_ext, func) : nullptr;
+
+ /* Noise. */
+ mDensityHigh = (noise) ? getPointer<float>("density" + sn_ext, func) : nullptr;
+ mTextureU = (noise) ? getPointer<float>("texture_u" + s_ext, func) : nullptr;
+ mTextureV = (noise) ? getPointer<float>("texture_v" + s_ext, func) : nullptr;
+ mTextureW = (noise) ? getPointer<float>("texture_w" + s_ext, func) : nullptr;
+ mTextureU2 = (noise) ? getPointer<float>("texture_u2" + s_ext, func) : nullptr;
+ mTextureV2 = (noise) ? getPointer<float>("texture_v2" + s_ext, func) : nullptr;
+ mTextureW2 = (noise) ? getPointer<float>("texture_w2" + s_ext, func) : nullptr;
+
+ /* Fire with noise. */
+ mFlameHigh = (noise && fire) ? getPointer<float>("flame" + sn_ext, func) : nullptr;
+ mFuelHigh = (noise && fire) ? getPointer<float>("fuel" + sn_ext, func) : nullptr;
+ mReactHigh = (noise && fire) ? getPointer<float>("react" + sn_ext, func) : nullptr;
+
+ /* Colors with noise. */
+ mColorRHigh = (noise && colors) ? getPointer<float>("color_r" + sn_ext, func) : nullptr;
+ mColorGHigh = (noise && colors) ? getPointer<float>("color_g" + sn_ext, func) : nullptr;
+ mColorBHigh = (noise && colors) ? getPointer<float>("color_b" + sn_ext, func) : nullptr;
+
+ /* Liquid. */
+ mPhi = (liquid) ? getPointer<float>("phi" + s_ext, func) : nullptr;
+ mFlipParticleData = (liquid) ? getPointer<vector<pData>>("pp" + s_ext, func) : nullptr;
+ mFlipParticleVelocity = (liquid) ? getPointer<vector<pVel>>("pVel" + pp_ext, func) : nullptr;
+
+ /* Mesh. */
+ mMeshNodes = (mesh) ? getPointer<vector<Node>>("mesh" + sm_ext, funcNodes) : nullptr;
+ mMeshTriangles = (mesh) ? getPointer<vector<Triangle>>("mesh" + sm_ext, funcTris) : nullptr;
+
+ /* Mesh velocities. */
+ mMeshVelocities = (meshvel) ? getPointer<vector<pVel>>("mVel" + mesh_ext, func) : nullptr;
+
+ /* Secondary particles. */
+ mParticleData = (parts) ? getPointer<vector<pData>>("ppSnd" + snd_ext, func) : nullptr;
+ mParticleVelocity = (parts) ? getPointer<vector<pVel>>("pVelSnd" + pp_ext, func) : nullptr;
+ mParticleLife = (parts) ? getPointer<vector<float>>("pLifeSnd" + pp_ext, func) : nullptr;
mFlipFromFile = false;
mMeshFromFile = false;
diff --git a/intern/mantaflow/intern/MANTA_main.h b/intern/mantaflow/intern/MANTA_main.h
index dae2aea4e08..5fd94ca01bc 100644
--- a/intern/mantaflow/intern/MANTA_main.h
+++ b/intern/mantaflow/intern/MANTA_main.h
@@ -41,7 +41,7 @@ struct MANTA {
MANTA(){};
virtual ~MANTA();
- // Mirroring Mantaflow structures for particle data (pVel also used for mesh vert vels)
+ /* Mirroring Mantaflow structures for particle data (pVel also used for mesh vert vels). */
typedef struct PData {
float pos[3];
int flag;
@@ -50,7 +50,7 @@ struct MANTA {
float pos[3];
} pVel;
- // Mirroring Mantaflow structures for meshes
+ /* Mirroring Mantaflow structures for meshes. */
typedef struct Node {
int flags;
float pos[3], normal[3];
@@ -60,36 +60,33 @@ struct MANTA {
int flags;
} Triangle;
- // Manta step, handling everything
- void step(struct FluidModifierData *fmd, int startFrame);
-
- // Grid initialization functions
- void initHeat(struct FluidModifierData *fmd = NULL);
- void initFire(struct FluidModifierData *fmd = NULL);
- void initColors(struct FluidModifierData *fmd = NULL);
- void initFireHigh(struct FluidModifierData *fmd = NULL);
- void initColorsHigh(struct FluidModifierData *fmd = NULL);
- void initLiquid(FluidModifierData *fmd = NULL);
- void initLiquidMesh(FluidModifierData *fmd = NULL);
- void initObstacle(FluidModifierData *fmd = NULL);
- void initCurvature(FluidModifierData *fmd = NULL);
- void initGuiding(FluidModifierData *fmd = NULL);
- void initFractions(FluidModifierData *fmd = NULL);
- void initInVelocity(FluidModifierData *fmd = NULL);
- void initOutflow(FluidModifierData *fmd = NULL);
- void initSndParts(FluidModifierData *fmd = NULL);
- void initLiquidSndParts(FluidModifierData *fmd = NULL);
-
- // Pointer transfer: Mantaflow -> Blender
- void updatePointers();
-
- // Write cache
+ /* Grid initialization functions. */
+ bool initHeat(struct FluidModifierData *fmd = nullptr);
+ bool initFire(struct FluidModifierData *fmd = nullptr);
+ bool initColors(struct FluidModifierData *fmd = nullptr);
+ bool initFireHigh(struct FluidModifierData *fmd = nullptr);
+ bool initColorsHigh(struct FluidModifierData *fmd = nullptr);
+ bool initLiquid(FluidModifierData *fmd = nullptr);
+ bool initLiquidMesh(FluidModifierData *fmd = nullptr);
+ bool initObstacle(FluidModifierData *fmd = nullptr);
+ bool initCurvature(FluidModifierData *fmd = nullptr);
+ bool initGuiding(FluidModifierData *fmd = nullptr);
+ bool initFractions(FluidModifierData *fmd = nullptr);
+ bool initInVelocity(FluidModifierData *fmd = nullptr);
+ bool initOutflow(FluidModifierData *fmd = nullptr);
+ bool initSndParts(FluidModifierData *fmd = nullptr);
+ bool initLiquidSndParts(FluidModifierData *fmd = nullptr);
+
+ /* Pointer transfer: Mantaflow -> Blender. Use flush to reset all pointers to nullptr. */
+ void updatePointers(FluidModifierData *fmd, bool flush = false);
+
+ /* Write cache. */
bool writeConfiguration(FluidModifierData *fmd, int framenr);
bool writeData(FluidModifierData *fmd, int framenr);
bool writeNoise(FluidModifierData *fmd, int framenr);
- // write calls for mesh and particles were left in bake calls for now
+ /* Write calls for mesh and particles were left in bake calls for now. */
- // Read cache (via Manta save/load)
+ /* Read cache (via Python). */
bool readConfiguration(FluidModifierData *fmd, int framenr);
bool readData(FluidModifierData *fmd, int framenr, bool resumable);
bool readNoise(FluidModifierData *fmd, int framenr, bool resumable);
@@ -97,26 +94,21 @@ struct MANTA {
bool readParticles(FluidModifierData *fmd, int framenr, bool resumable);
bool readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain);
- // Read cache (via file read functions in MANTA - e.g. read .bobj.gz meshes, .uni particles)
- bool updateMeshStructures(FluidModifierData *fmd, int framenr);
- bool updateFlipStructures(FluidModifierData *fmd, int framenr);
- bool updateParticleStructures(FluidModifierData *fmd, int framenr);
- bool updateSmokeStructures(FluidModifierData *fmd, int framenr);
- bool updateNoiseStructures(FluidModifierData *fmd, int framenr);
+ /* Propagate variable changes from RNA to Python. */
bool updateVariables(FluidModifierData *fmd);
- // Bake cache
+ /* Bake cache. */
bool bakeData(FluidModifierData *fmd, int framenr);
bool bakeNoise(FluidModifierData *fmd, int framenr);
bool bakeMesh(FluidModifierData *fmd, int framenr);
bool bakeParticles(FluidModifierData *fmd, int framenr);
bool bakeGuiding(FluidModifierData *fmd, int framenr);
- // IO for Mantaflow scene script
+ /* IO for Mantaflow scene script. */
void exportSmokeScript(struct FluidModifierData *fmd);
void exportLiquidScript(struct FluidModifierData *fmd);
- // Check cache status by frame
+ /* Check cache status by frame. */
bool hasConfig(FluidModifierData *fmd, int framenr);
bool hasData(FluidModifierData *fmd, int framenr);
bool hasNoise(FluidModifierData *fmd, int framenr);
@@ -193,7 +185,7 @@ struct MANTA {
return mUpresParticle;
}
- // Smoke getters
+ /* Smoke getters. */
inline float *getDensity()
{
return mDensity;
@@ -422,9 +414,9 @@ struct MANTA {
}
static atomic<int> solverID;
- static int with_debug; // on or off (1 or 0), also sets manta debug level
+ static int with_debug; /* On or off (1 or 0), also sets manta debug level. */
- // Mesh getters
+ /* Mesh getters. */
inline int getNumVertices()
{
return (mMeshNodes && !mMeshNodes->empty()) ? mMeshNodes->size() : 0;
@@ -563,9 +555,9 @@ struct MANTA {
inline int getSndParticleFlagAt(int i)
{
assert(i >= 0);
- if (mSndParticleData && !mSndParticleData->empty()) {
- assert(i < mSndParticleData->size());
- return (*mSndParticleData)[i].flag;
+ if (mParticleData && !mParticleData->empty()) {
+ assert(i < mParticleData->size());
+ return (*mParticleData)[i].flag;
}
return 0;
}
@@ -601,27 +593,27 @@ struct MANTA {
inline float getSndParticlePositionXAt(int i)
{
assert(i >= 0);
- if (mSndParticleData && !mSndParticleData->empty()) {
- assert(i < mSndParticleData->size());
- return (*mSndParticleData)[i].pos[0];
+ if (mParticleData && !mParticleData->empty()) {
+ assert(i < mParticleData->size());
+ return (*mParticleData)[i].pos[0];
}
return 0.0f;
}
inline float getSndParticlePositionYAt(int i)
{
assert(i >= 0);
- if (mSndParticleData && !mSndParticleData->empty()) {
- assert(i < mSndParticleData->size());
- return (*mSndParticleData)[i].pos[1];
+ if (mParticleData && !mParticleData->empty()) {
+ assert(i < mParticleData->size());
+ return (*mParticleData)[i].pos[1];
}
return 0.0f;
}
inline float getSndParticlePositionZAt(int i)
{
assert(i >= 0);
- if (mSndParticleData && !mSndParticleData->empty()) {
- assert(i < mSndParticleData->size());
- return (*mSndParticleData)[i].pos[2];
+ if (mParticleData && !mParticleData->empty()) {
+ assert(i < mParticleData->size());
+ return (*mParticleData)[i].pos[2];
}
return 0.0f;
}
@@ -657,27 +649,27 @@ struct MANTA {
inline float getSndParticleVelocityXAt(int i)
{
assert(i >= 0);
- if (mSndParticleVelocity && !mSndParticleVelocity->empty()) {
- assert(i < mSndParticleVelocity->size());
- return (*mSndParticleVelocity)[i].pos[0];
+ if (mParticleVelocity && !mParticleVelocity->empty()) {
+ assert(i < mParticleVelocity->size());
+ return (*mParticleVelocity)[i].pos[0];
}
return 0.0f;
}
inline float getSndParticleVelocityYAt(int i)
{
assert(i >= 0);
- if (mSndParticleVelocity && !mSndParticleVelocity->empty()) {
- assert(i < mSndParticleVelocity->size());
- return (*mSndParticleVelocity)[i].pos[1];
+ if (mParticleVelocity && !mParticleVelocity->empty()) {
+ assert(i < mParticleVelocity->size());
+ return (*mParticleVelocity)[i].pos[1];
}
return 0.0f;
}
inline float getSndParticleVelocityZAt(int i)
{
assert(i >= 0);
- if (mSndParticleVelocity && !mSndParticleVelocity->empty()) {
- assert(i < mSndParticleVelocity->size());
- return (*mSndParticleVelocity)[i].pos[2];
+ if (mParticleVelocity && !mParticleVelocity->empty()) {
+ assert(i < mParticleVelocity->size());
+ return (*mParticleVelocity)[i].pos[2];
}
return 0.0f;
}
@@ -686,30 +678,28 @@ struct MANTA {
{
return (mFlipParticleData && !mFlipParticleData->empty()) ?
(float *)&mFlipParticleData->front() :
- NULL;
+ nullptr;
}
inline float *getSndParticleData()
{
- return (mSndParticleData && !mSndParticleData->empty()) ? (float *)&mSndParticleData->front() :
- NULL;
+ return (mParticleData && !mParticleData->empty()) ? (float *)&mParticleData->front() : nullptr;
}
inline float *getFlipParticleVelocity()
{
return (mFlipParticleVelocity && !mFlipParticleVelocity->empty()) ?
(float *)&mFlipParticleVelocity->front() :
- NULL;
+ nullptr;
}
inline float *getSndParticleVelocity()
{
- return (mSndParticleVelocity && !mSndParticleVelocity->empty()) ?
- (float *)&mSndParticleVelocity->front() :
- NULL;
+ return (mParticleVelocity && !mParticleVelocity->empty()) ?
+ (float *)&mParticleVelocity->front() :
+ nullptr;
}
inline float *getSndParticleLife()
{
- return (mSndParticleLife && !mSndParticleLife->empty()) ? (float *)&mSndParticleLife->front() :
- NULL;
+ return (mParticleLife && !mParticleLife->empty()) ? (float *)&mParticleLife->front() : nullptr;
}
inline int getNumFlipParticles()
@@ -718,7 +708,7 @@ struct MANTA {
}
inline int getNumSndParticles()
{
- return (mSndParticleData && !mSndParticleData->empty()) ? mSndParticleData->size() : 0;
+ return (mParticleData && !mParticleData->empty()) ? mParticleData->size() : 0;
}
inline bool usingFlipFromFile()
@@ -734,7 +724,7 @@ struct MANTA {
return mParticlesFromFile;
}
- // Direct access to solver time attributes
+ /* Direct access to solver time attributes. */
int getFrame();
float getTimestep();
void adaptTimestep();
@@ -742,7 +732,7 @@ struct MANTA {
bool needsRealloc(FluidModifierData *fmd);
private:
- // simulation constants
+ /* Simulation constants. */
size_t mTotalCells;
size_t mTotalCellsHigh;
size_t mTotalCellsMesh;
@@ -750,6 +740,7 @@ struct MANTA {
unordered_map<string, string> mRNAMap;
+ /* The ID of the solver objects will be incremented for every new object. */
int mCurrentID;
bool mUsingHeat;
@@ -796,10 +787,7 @@ struct MANTA {
int mUpresMesh;
int mUpresParticle;
- float mTempAmb; /* ambient temperature */
- float mConstantScaling;
-
- // Fluid grids
+ /* Fluid grids. */
float *mVelocityX;
float *mVelocityY;
float *mVelocityZ;
@@ -819,7 +807,7 @@ struct MANTA {
float *mNumObstacle;
float *mNumGuide;
- // Smoke grids
+ /* Smoke grids. */
float *mDensity;
float *mHeat;
float *mFlame;
@@ -851,7 +839,7 @@ struct MANTA {
float *mTextureV2;
float *mTextureW2;
- // Liquid grids
+ /* Liquid grids. */
float *mPhiIn;
float *mPhiStaticIn;
float *mPhiObsIn;
@@ -861,31 +849,31 @@ struct MANTA {
float *mPhiOutStaticIn;
float *mPhi;
- // Mesh fields
+ /* Mesh fields. */
vector<Node> *mMeshNodes;
vector<Triangle> *mMeshTriangles;
vector<pVel> *mMeshVelocities;
- // Particle fields
+ /* Particle fields. */
vector<pData> *mFlipParticleData;
vector<pVel> *mFlipParticleVelocity;
- vector<pData> *mSndParticleData;
- vector<pVel> *mSndParticleVelocity;
- vector<float> *mSndParticleLife;
+ vector<pData> *mParticleData;
+ vector<pVel> *mParticleVelocity;
+ vector<float> *mParticleLife;
- void initializeRNAMap(struct FluidModifierData *fmd = NULL);
- void initDomain(struct FluidModifierData *fmd = NULL);
- void initNoise(struct FluidModifierData *fmd = NULL);
- void initMesh(struct FluidModifierData *fmd = NULL);
- void initSmoke(struct FluidModifierData *fmd = NULL);
- void initSmokeNoise(struct FluidModifierData *fmd = NULL);
+ void initializeRNAMap(struct FluidModifierData *doRnaRefresh = nullptr);
+ bool initDomain(struct FluidModifierData *doRnaRefresh = nullptr);
+ bool initNoise(struct FluidModifierData *doRnaRefresh = nullptr);
+ bool initMesh(struct FluidModifierData *doRnaRefresh = nullptr);
+ bool initSmoke(struct FluidModifierData *doRnaRefresh = nullptr);
+ bool initSmokeNoise(struct FluidModifierData *doRnaRefresh = nullptr);
void initializeMantaflow();
void terminateMantaflow();
bool runPythonString(vector<string> commands);
string getRealValue(const string &varName);
string parseLine(const string &line);
- string parseScript(const string &setup_string, FluidModifierData *fmd = NULL);
+ string parseScript(const string &setup_string, FluidModifierData *fmd = nullptr);
string getDirectory(struct FluidModifierData *fmd, string subdirectory);
string getFile(struct FluidModifierData *fmd,
string subdirectory,
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 1db3da63ecc..530dbd49b7c 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -37,33 +37,29 @@ void manta_free(MANTA *fluid)
fluid = nullptr;
}
-void manta_ensure_obstacle(MANTA *fluid, struct FluidModifierData *fmd)
+int manta_ensure_obstacle(MANTA *fluid, struct FluidModifierData *fmd)
{
- if (!fluid)
- return;
- fluid->initObstacle(fmd);
- fluid->updatePointers();
+ if (!fluid || !fmd)
+ return 0;
+ return fluid->initObstacle(fmd);
}
-void manta_ensure_guiding(MANTA *fluid, struct FluidModifierData *fmd)
+int manta_ensure_guiding(MANTA *fluid, struct FluidModifierData *fmd)
{
- if (!fluid)
- return;
- fluid->initGuiding(fmd);
- fluid->updatePointers();
+ if (!fluid || !fmd)
+ return 0;
+ return fluid->initGuiding(fmd);
}
-void manta_ensure_invelocity(MANTA *fluid, struct FluidModifierData *fmd)
+int manta_ensure_invelocity(MANTA *fluid, struct FluidModifierData *fmd)
{
- if (!fluid)
- return;
- fluid->initInVelocity(fmd);
- fluid->updatePointers();
+ if (!fluid || !fmd)
+ return 0;
+ return fluid->initInVelocity(fmd);
}
-void manta_ensure_outflow(MANTA *fluid, struct FluidModifierData *fmd)
+int manta_ensure_outflow(MANTA *fluid, struct FluidModifierData *fmd)
{
- if (!fluid)
- return;
- fluid->initOutflow(fmd);
- fluid->updatePointers();
+ if (!fluid || !fmd)
+ return 0;
+ return fluid->initOutflow(fmd);
}
int manta_write_config(MANTA *fluid, FluidModifierData *fmd, int framenr)
@@ -229,11 +225,18 @@ void manta_adapt_timestep(MANTA *fluid)
bool manta_needs_realloc(MANTA *fluid, FluidModifierData *fmd)
{
- if (!fluid)
+ if (!fluid || !fmd)
return false;
return fluid->needsRealloc(fmd);
}
+void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush)
+{
+ if (!fluid || !fmd)
+ return;
+ fluid->updatePointers(fmd, flush);
+}
+
/* Fluid accessors */
size_t manta_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */)
{
@@ -368,89 +371,6 @@ void manta_smoke_export_script(MANTA *smoke, FluidModifierData *fmd)
smoke->exportSmokeScript(fmd);
}
-void manta_smoke_export(MANTA *smoke,
- float *dt,
- float *dx,
- float **dens,
- float **react,
- float **flame,
- float **fuel,
- float **heat,
- float **vx,
- float **vy,
- float **vz,
- float **r,
- float **g,
- float **b,
- int **flags,
- float **shadow)
-{
- if (dens)
- *dens = smoke->getDensity();
- if (fuel)
- *fuel = smoke->getFuel();
- if (react)
- *react = smoke->getReact();
- if (flame)
- *flame = smoke->getFlame();
- if (heat)
- *heat = smoke->getHeat();
- *vx = smoke->getVelocityX();
- *vy = smoke->getVelocityY();
- *vz = smoke->getVelocityZ();
- if (r)
- *r = smoke->getColorR();
- if (g)
- *g = smoke->getColorG();
- if (b)
- *b = smoke->getColorB();
- *flags = smoke->getFlags();
- if (shadow)
- *shadow = smoke->getShadow();
- *dt = 1; // dummy value, not needed for smoke
- *dx = 1; // dummy value, not needed for smoke
-}
-
-void manta_smoke_turbulence_export(MANTA *smoke,
- float **dens,
- float **react,
- float **flame,
- float **fuel,
- float **r,
- float **g,
- float **b,
- float **tcu,
- float **tcv,
- float **tcw,
- float **tcu2,
- float **tcv2,
- float **tcw2)
-{
- if (!smoke && !(smoke->usingNoise()))
- return;
-
- *dens = smoke->getDensityHigh();
- if (fuel)
- *fuel = smoke->getFuelHigh();
- if (react)
- *react = smoke->getReactHigh();
- if (flame)
- *flame = smoke->getFlameHigh();
- if (r)
- *r = smoke->getColorRHigh();
- if (g)
- *g = smoke->getColorGHigh();
- if (b)
- *b = smoke->getColorBHigh();
- *tcu = smoke->getTextureU();
- *tcv = smoke->getTextureV();
- *tcw = smoke->getTextureW();
-
- *tcu2 = smoke->getTextureU2();
- *tcv2 = smoke->getTextureV2();
- *tcw2 = smoke->getTextureW2();
-}
-
static void get_rgba(
float *r, float *g, float *b, float *a, int total_cells, float *data, int sequential)
{
@@ -484,7 +404,7 @@ void manta_smoke_get_rgba(MANTA *smoke, float *data, int sequential)
sequential);
}
-void manta_smoke_turbulence_get_rgba(MANTA *smoke, float *data, int sequential)
+void manta_noise_get_rgba(MANTA *smoke, float *data, int sequential)
{
get_rgba(smoke->getColorRHigh(),
smoke->getColorGHigh(),
@@ -519,42 +439,40 @@ void manta_smoke_get_rgba_fixed_color(MANTA *smoke, float color[3], float *data,
get_rgba_fixed_color(color, smoke->getTotalCells(), data, sequential);
}
-void manta_smoke_turbulence_get_rgba_fixed_color(MANTA *smoke,
- float color[3],
- float *data,
- int sequential)
+void manta_noise_get_rgba_fixed_color(MANTA *smoke, float color[3], float *data, int sequential)
{
get_rgba_fixed_color(color, smoke->getTotalCellsHigh(), data, sequential);
}
-void manta_smoke_ensure_heat(MANTA *smoke, struct FluidModifierData *fmd)
+int manta_smoke_ensure_heat(MANTA *smoke, struct FluidModifierData *fmd)
{
- if (smoke) {
- smoke->initHeat(fmd);
- smoke->updatePointers();
- }
+ if (!smoke || !fmd)
+ return 0;
+ return smoke->initHeat(fmd);
}
-void manta_smoke_ensure_fire(MANTA *smoke, struct FluidModifierData *fmd)
+int manta_smoke_ensure_fire(MANTA *smoke, struct FluidModifierData *fmd)
{
- if (smoke) {
- smoke->initFire(fmd);
- if (smoke->usingNoise()) {
- smoke->initFireHigh(fmd);
- }
- smoke->updatePointers();
+ if (!smoke || !fmd)
+ return 0;
+
+ int result = smoke->initFire(fmd);
+ if (smoke->usingNoise()) {
+ result &= smoke->initFireHigh(fmd);
}
+ return result;
}
-void manta_smoke_ensure_colors(MANTA *smoke, struct FluidModifierData *fmd)
+int manta_smoke_ensure_colors(MANTA *smoke, struct FluidModifierData *fmd)
{
- if (smoke) {
- smoke->initColors(fmd);
- if (smoke->usingNoise()) {
- smoke->initColorsHigh(fmd);
- }
- smoke->updatePointers();
+ if (!smoke || !fmd)
+ return 0;
+
+ int result = smoke->initColors(fmd);
+ if (smoke->usingNoise()) {
+ result &= smoke->initColorsHigh(fmd);
}
+ return result;
}
/* Smoke accessors */
@@ -647,45 +565,69 @@ int manta_smoke_has_colors(MANTA *smoke)
return (smoke->getColorR() && smoke->getColorG() && smoke->getColorB()) ? 1 : 0;
}
-float *manta_smoke_turbulence_get_density(MANTA *smoke)
+float *manta_noise_get_density(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getDensityHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_fuel(MANTA *smoke)
+float *manta_noise_get_fuel(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getFuelHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_react(MANTA *smoke)
+float *manta_noise_get_react(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getReactHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_color_r(MANTA *smoke)
+float *manta_noise_get_color_r(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getColorRHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_color_g(MANTA *smoke)
+float *manta_noise_get_color_g(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getColorGHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_color_b(MANTA *smoke)
+float *manta_noise_get_color_b(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getColorBHigh() : nullptr;
}
-float *manta_smoke_turbulence_get_flame(MANTA *smoke)
+float *manta_noise_get_flame(MANTA *smoke)
{
return (smoke && smoke->usingNoise()) ? smoke->getFlameHigh() : nullptr;
}
+float *manta_noise_get_texture_u(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureU() : nullptr;
+}
+float *manta_noise_get_texture_v(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureV() : nullptr;
+}
+float *manta_noise_get_texture_w(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureW() : nullptr;
+}
+float *manta_noise_get_texture_u2(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureU2() : nullptr;
+}
+float *manta_noise_get_texture_v2(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureV2() : nullptr;
+}
+float *manta_noise_get_texture_w2(MANTA *smoke)
+{
+ return (smoke && smoke->usingNoise()) ? smoke->getTextureW2() : nullptr;
+}
-int manta_smoke_turbulence_has_fuel(MANTA *smoke)
+int manta_noise_has_fuel(MANTA *smoke)
{
return (smoke->getFuelHigh()) ? 1 : 0;
}
-int manta_smoke_turbulence_has_colors(MANTA *smoke)
+int manta_noise_has_colors(MANTA *smoke)
{
return (smoke->getColorRHigh() && smoke->getColorGHigh() && smoke->getColorBHigh()) ? 1 : 0;
}
-void manta_smoke_turbulence_get_res(MANTA *smoke, int *res)
+void manta_noise_get_res(MANTA *smoke, int *res)
{
if (smoke && smoke->usingNoise()) {
res[0] = smoke->getResXHigh();
@@ -693,7 +635,7 @@ void manta_smoke_turbulence_get_res(MANTA *smoke, int *res)
res[2] = smoke->getResZHigh();
}
}
-int manta_smoke_turbulence_get_cells(MANTA *smoke)
+int manta_noise_get_cells(MANTA *smoke)
{
int total_cells_high = smoke->getResXHigh() * smoke->getResYHigh() * smoke->getResZHigh();
return (smoke && smoke->usingNoise()) ? total_cells_high : 0;
@@ -707,12 +649,11 @@ void manta_liquid_export_script(MANTA *liquid, FluidModifierData *fmd)
liquid->exportLiquidScript(fmd);
}
-void manta_liquid_ensure_sndparts(MANTA *liquid, struct FluidModifierData *fmd)
+int manta_liquid_ensure_sndparts(MANTA *liquid, struct FluidModifierData *fmd)
{
- if (liquid) {
- liquid->initLiquidSndParts(fmd);
- liquid->updatePointers();
- }
+ if (!liquid || !fmd)
+ return 0;
+ return liquid->initLiquidSndParts(fmd);
}
/* Liquid accessors */
diff --git a/intern/mantaflow/intern/strings/fluid_script.h b/intern/mantaflow/intern/strings/fluid_script.h
index 977b99e7759..a01e333ab5e 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -146,19 +146,19 @@ mantaMsg('1 Mantaflow cell is ' + str(ratioMetersToRes_s$ID$) + ' Blender length
ratioResToBLength_s$ID$ = float(res_s$ID$) / float(domainSize_s$ID$) # [cells / blength] (blength: cm, m, or km, ... )\n\
mantaMsg('1 Blender length unit is ' + str(ratioResToBLength_s$ID$) + ' Mantaflow cells long.')\n\
\n\
-ratioBTimeToTimstep_s$ID$ = float(1) / float(frameLengthRaw_s$ID$) # the time within 1 blender time unit, see also fluid.c\n\
-mantaMsg('1 Blender time unit is ' + str(ratioBTimeToTimstep_s$ID$) + ' Mantaflow time units long.')\n\
+ratioBTimeToTimestep_s$ID$ = float(1) / float(frameLengthRaw_s$ID$) # the time within 1 blender time unit, see also fluid.c\n\
+mantaMsg('1 Blender time unit is ' + str(ratioBTimeToTimestep_s$ID$) + ' Mantaflow time units long.')\n\
\n\
ratioFrameToFramelength_s$ID$ = float(1) / float(frameLengthUnscaled_s$ID$ ) # the time within 1 frame\n\
mantaMsg('frame / frameLength is ' + str(ratioFrameToFramelength_s$ID$) + ' Mantaflow time units long.')\n\
\n\
-scaleAcceleration_s$ID$ = ratioResToBLength_s$ID$ * (ratioBTimeToTimstep_s$ID$**2)# [meters/btime^2] to [cells/timestep^2] (btime: sec, min, or h, ...)\n\
+scaleAcceleration_s$ID$ = ratioResToBLength_s$ID$ * (ratioBTimeToTimestep_s$ID$**2)# [meters/btime^2] to [cells/timestep^2] (btime: sec, min, or h, ...)\n\
mantaMsg('scaleAcceleration is ' + str(scaleAcceleration_s$ID$))\n\
\n\
scaleSpeedFrames_s$ID$ = ratioResToBLength_s$ID$ * ratioFrameToFramelength_s$ID$ # [blength/frame] to [cells/frameLength]\n\
mantaMsg('scaleSpeed is ' + str(scaleSpeedFrames_s$ID$))\n\
\n\
-scaleSpeedTime_s$ID$ = ratioResToBLength_s$ID$ * ratioBTimeToTimstep_s$ID$ # [blength/btime] to [cells/frameLength]\n\
+scaleSpeedTime_s$ID$ = ratioResToBLength_s$ID$ * ratioBTimeToTimestep_s$ID$ # [blength/btime] to [cells/frameLength]\n\
mantaMsg('scaleSpeedTime is ' + str(scaleSpeedTime_s$ID$))\n\
\n\
gravity_s$ID$ *= scaleAcceleration_s$ID$ # scale from world acceleration to cell based acceleration\n\
@@ -418,19 +418,6 @@ const std::string fluid_post_step =
"\n\
def fluid_post_step_$ID$():\n\
mantaMsg('Fluid post step')\n\
- forces_s$ID$.clear()\n\
- x_force_s$ID$.clear()\n\
- y_force_s$ID$.clear()\n\
- z_force_s$ID$.clear()\n\
- \n\
- if using_guiding_s$ID$:\n\
- weightGuide_s$ID$.clear()\n\
- if using_invel_s$ID$:\n\
- x_invel_s$ID$.clear()\n\
- y_invel_s$ID$.clear()\n\
- z_invel_s$ID$.clear()\n\
- invel_s$ID$.clear()\n\
- invelC_s$ID$.clear()\n\
\n\
# Copy vel grid to reals grids (which Blender internal will in turn use for vel access)\n\
copyVec3ToReal(source=vel_s$ID$, targetX=x_vel_s$ID$, targetY=y_vel_s$ID$, targetZ=z_vel_s$ID$)\n";
@@ -770,8 +757,6 @@ if (GUI):\n\
cache_resumable = $CACHE_RESUMABLE$\n\
cache_dir = '$CACHE_DIR$'\n\
file_format_data = '$CACHE_DATA_FORMAT$'\n\
-file_format_noise = '$CACHE_NOISE_FORMAT$'\n\
-file_format_particles = '$CACHE_PARTICLE_FORMAT$'\n\
file_format_mesh = '$CACHE_MESH_FORMAT$'\n\
\n\
# How many frame to load from cache\n\
diff --git a/intern/mantaflow/intern/strings/liquid_script.h b/intern/mantaflow/intern/strings/liquid_script.h
index 04505206601..08d8dcd7de3 100644
--- a/intern/mantaflow/intern/strings/liquid_script.h
+++ b/intern/mantaflow/intern/strings/liquid_script.h
@@ -48,7 +48,8 @@ meshRadiusFactor_s$ID$ = $MESH_PARTICLE_RADIUS$\n\
smoothenPos_s$ID$ = $MESH_SMOOTHEN_POS$\n\
smoothenNeg_s$ID$ = $MESH_SMOOTHEN_NEG$\n\
randomness_s$ID$ = $PARTICLE_RANDOMNESS$\n\
-surfaceTension_s$ID$ = $LIQUID_SURFACE_TENSION$\n";
+surfaceTension_s$ID$ = $LIQUID_SURFACE_TENSION$\n\
+maxSysParticles_s$ID$ = $PP_PARTICLE_MAXIMUM$\n";
const std::string liquid_variables_particles =
"\n\
@@ -216,6 +217,7 @@ def liquid_adaptive_step_$ID$(framenr):\n\
else:\n\
pVel_pp$ID$.setSource(grid=None, isMAC=False)\n\
\n\
+ pp_s$ID$.maxParticles = maxSysParticles_s$ID$ # remember, 0 means no particle cap\n\
sampleLevelsetWithParticles(phi=phiIn_s$ID$, flags=flags_s$ID$, parts=pp_s$ID$, discretization=particleNumber_s$ID$, randomness=randomness_s$ID$)\n\
flags_s$ID$.updateFromLevelset(phi_s$ID$)\n\
\n\
@@ -477,7 +479,7 @@ const std::string liquid_standalone =
def load(frame, cache_resumable):\n\
liquid_load_data_$ID$(os.path.join(cache_dir, 'data'), frame, file_format_data, cache_resumable)\n\
if using_sndparts_s$ID$:\n\
- liquid_load_particles_$ID$(os.path.join(cache_dir, 'particles'), frame, file_format_particles, cache_resumable)\n\
+ liquid_load_particles_$ID$(os.path.join(cache_dir, 'particles'), frame, file_format_data, cache_resumable)\n\
if using_mesh_s$ID$:\n\
liquid_load_mesh_$ID$(os.path.join(cache_dir, 'mesh'), frame, file_format_mesh)\n\
if using_guiding_s$ID$:\n\
diff --git a/intern/mantaflow/intern/strings/smoke_script.h b/intern/mantaflow/intern/strings/smoke_script.h
index 612d01b85ef..f81259115c5 100644
--- a/intern/mantaflow/intern/strings/smoke_script.h
+++ b/intern/mantaflow/intern/strings/smoke_script.h
@@ -100,6 +100,9 @@ color_r_in_s$ID$ = None\n\
color_g_in_s$ID$ = None\n\
color_b_in_s$ID$ = None\n\
\n\
+# Set some initial values\n\
+shadow_s$ID$.setConst(-1)\n\
+\n\
# Keep track of important objects in dict to load them later on\n\
smoke_data_dict_final_s$ID$ = { 'density' : density_s$ID$, 'shadow' : shadow_s$ID$ }\n\
smoke_data_dict_resume_s$ID$ = { 'densityIn' : densityIn_s$ID$, 'emission' : emission_s$ID$ }\n";
@@ -490,6 +493,9 @@ def step_noise_$ID$():\n\
advectSemiLagrange(flags=flags_s$ID$, vel=vel_s$ID$, grid=uvGrid1_s$ID$, order=2)\n\
updateUvWeight(resetTime=sn$ID$.timestep*10.0 , index=1, numUvs=uvs_s$ID$, uv=uvGrid1_s$ID$, offset=uvs_offset_s$ID$)\n\
\n\
+ if not domainClosed_s$ID$ or using_outflow_s$ID$:\n\
+ resetOutflow(flags=flags_sn$ID$, real=density_sn$ID$)\n\
+ \n\
mantaMsg('Energy')\n\
computeEnergy(flags=flags_s$ID$, vel=vel_s$ID$, energy=energy_s$ID$)\n\
\n\
@@ -595,7 +601,7 @@ const std::string smoke_standalone =
def load(frame, cache_resumable):\n\
smoke_load_data_$ID$(os.path.join(cache_dir, 'data'), frame, file_format_data, cache_resumable)\n\
if using_noise_s$ID$:\n\
- smoke_load_noise_$ID$(os.path.join(cache_dir, 'noise'), frame, file_format_noise, cache_resumable)\n\
+ smoke_load_noise_$ID$(os.path.join(cache_dir, 'noise'), frame, file_format_data, cache_resumable)\n\
if using_guiding_s$ID$:\n\
fluid_load_guiding_$ID$(os.path.join(cache_dir, 'guiding'), frame, file_format_data)\n\
\n\