Changeset View
Changeset View
Standalone View
Standalone View
intern/mantaflow/intern/MANTA_main.cpp
| Show First 20 Lines • Show All 1,080 Lines • ▼ Show 20 Lines | string MANTA::parseScript(const string &setup_string, FluidModifierData *fmd) | ||||
| } | } | ||||
| while (getline(f, line)) { | while (getline(f, line)) { | ||||
| res << parseLine(line) << "\n"; | res << parseLine(line) << "\n"; | ||||
| } | } | ||||
| return res.str(); | return res.str(); | ||||
| } | } | ||||
| /* Dirty hack: Needed to format paths from python code that is run via PyRun_SimpleString */ | /* Dirty hack: Needed to format paths from python code that is run via PyRun_SimpleString */ | ||||
| static string escapeSlashes(string const &s) | static string escapePath(string const &s) | ||||
| { | { | ||||
| string result = ""; | string result = ""; | ||||
| for (string::const_iterator i = s.begin(), end = s.end(); i != end; ++i) { | for (char c : s) { | ||||
| unsigned char c = *i; | if (c == '\\') { | ||||
| if (c == '\\') | |||||
| result += "\\\\"; | result += "\\\\"; | ||||
| else | } | ||||
| else if (c == '\'') { | |||||
| result += "\\\'"; | |||||
| } | |||||
| else { | |||||
| result += c; | result += c; | ||||
| } | } | ||||
| } | |||||
| return result; | return result; | ||||
| } | } | ||||
| bool MANTA::writeConfiguration(FluidModifierData *fmd, int framenr) | bool MANTA::writeConfiguration(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| if (with_debug) | if (with_debug) | ||||
| cout << "MANTA::writeConfiguration()" << endl; | cout << "MANTA::writeConfiguration()" << endl; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | bool MANTA::writeData(FluidModifierData *fmd, int framenr) | ||||
| FluidDomainSettings *fds = fmd->domain; | FluidDomainSettings *fds = fmd->domain; | ||||
| string directory = getDirectory(fmd, FLUID_DOMAIN_DIR_DATA); | string directory = getDirectory(fmd, FLUID_DOMAIN_DIR_DATA); | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| string resumable_cache = !(fds->flags & FLUID_DOMAIN_USE_RESUMABLE_CACHE) ? "False" : "True"; | string resumable_cache = !(fds->flags & FLUID_DOMAIN_USE_RESUMABLE_CACHE) ? "False" : "True"; | ||||
| if (mUsingSmoke) { | if (mUsingSmoke) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "smoke_save_data_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "smoke_save_data_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| } | } | ||||
| if (mUsingLiquid) { | if (mUsingLiquid) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "liquid_save_data_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "liquid_save_data_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| } | } | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::writeNoise(FluidModifierData *fmd, int framenr) | bool MANTA::writeNoise(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| if (with_debug) | if (with_debug) | ||||
| cout << "MANTA::writeNoise()" << endl; | cout << "MANTA::writeNoise()" << endl; | ||||
| ostringstream ss; | ostringstream ss; | ||||
| vector<string> pythonCommands; | vector<string> pythonCommands; | ||||
| FluidDomainSettings *fds = fmd->domain; | FluidDomainSettings *fds = fmd->domain; | ||||
| string directory = getDirectory(fmd, FLUID_DOMAIN_DIR_NOISE); | string directory = getDirectory(fmd, FLUID_DOMAIN_DIR_NOISE); | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| string resumable_cache = !(fds->flags & FLUID_DOMAIN_USE_RESUMABLE_CACHE) ? "False" : "True"; | string resumable_cache = !(fds->flags & FLUID_DOMAIN_USE_RESUMABLE_CACHE) ? "False" : "True"; | ||||
| if (mUsingSmoke && mUsingNoise) { | if (mUsingSmoke && mUsingNoise) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "smoke_save_noise_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "smoke_save_noise_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| } | } | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::readConfiguration(FluidModifierData *fmd, int framenr) | bool MANTA::readConfiguration(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | bool MANTA::readData(FluidModifierData *fmd, int framenr, bool resumable) | ||||
| string resumable_cache = (!resumable) ? "False" : "True"; | string resumable_cache = (!resumable) ? "False" : "True"; | ||||
| /* Sanity check: Are cache files present? */ | /* Sanity check: Are cache files present? */ | ||||
| if (!hasData(fmd, framenr)) | if (!hasData(fmd, framenr)) | ||||
| return false; | return false; | ||||
| if (mUsingSmoke) { | if (mUsingSmoke) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "smoke_load_data_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "smoke_load_data_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| result &= runPythonString(pythonCommands); | result &= runPythonString(pythonCommands); | ||||
| return (mSmokeFromFile = result); | return (mSmokeFromFile = result); | ||||
| } | } | ||||
| if (mUsingLiquid) { | if (mUsingLiquid) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "liquid_load_data_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "liquid_load_data_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| result &= runPythonString(pythonCommands); | result &= runPythonString(pythonCommands); | ||||
| return (mFlipFromFile = result); | return (mFlipFromFile = result); | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| Show All 17 Lines | char format = (!strcmp(fds->cache_id, FLUID_CACHE_VERSION)) ? fds->cache_data_format : | ||||
| fds->cache_noise_format; | fds->cache_noise_format; | ||||
| string volume_format = getCacheFileEnding(format); | string volume_format = getCacheFileEnding(format); | ||||
| /* Sanity check: Are cache files present? */ | /* Sanity check: Are cache files present? */ | ||||
| if (!hasNoise(fmd, framenr)) | if (!hasNoise(fmd, framenr)) | ||||
| return false; | return false; | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "smoke_load_noise_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "smoke_load_noise_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return (mNoiseFromFile = runPythonString(pythonCommands)); | return (mNoiseFromFile = runPythonString(pythonCommands)); | ||||
| } | } | ||||
| bool MANTA::readMesh(FluidModifierData *fmd, int framenr) | bool MANTA::readMesh(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| Show All 11 Lines | bool MANTA::readMesh(FluidModifierData *fmd, int framenr) | ||||
| string mesh_format = getCacheFileEnding(fds->cache_mesh_format); | string mesh_format = getCacheFileEnding(fds->cache_mesh_format); | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| /* Sanity check: Are cache files present? */ | /* Sanity check: Are cache files present? */ | ||||
| if (!hasMesh(fmd, framenr)) | if (!hasMesh(fmd, framenr)) | ||||
| return false; | return false; | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "liquid_load_mesh_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "liquid_load_mesh_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << mesh_format << "')"; | << ", '" << mesh_format << "')"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| if (mUsingMVel) { | if (mUsingMVel) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "liquid_load_meshvel_" << mCurrentID << "('" << escapeSlashes(directory) << "', " | ss << "liquid_load_meshvel_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << framenr << ", '" << volume_format << "')"; | << ", '" << volume_format << "')"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| } | } | ||||
| return (mMeshFromFile = runPythonString(pythonCommands)); | return (mMeshFromFile = runPythonString(pythonCommands)); | ||||
| } | } | ||||
| bool MANTA::readParticles(FluidModifierData *fmd, int framenr, bool resumable) | bool MANTA::readParticles(FluidModifierData *fmd, int framenr, bool resumable) | ||||
| { | { | ||||
| Show All 17 Lines | char format = (!strcmp(fds->cache_id, FLUID_CACHE_VERSION)) ? fds->cache_data_format : | ||||
| fds->cache_particle_format; | fds->cache_particle_format; | ||||
| string volume_format = getCacheFileEnding(format); | string volume_format = getCacheFileEnding(format); | ||||
| /* Sanity check: Are cache files present? */ | /* Sanity check: Are cache files present? */ | ||||
| if (!hasParticles(fmd, framenr)) | if (!hasParticles(fmd, framenr)) | ||||
| return false; | return false; | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "liquid_load_particles_" << mCurrentID << "('" << escapeSlashes(directory) << "', " | ss << "liquid_load_particles_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << framenr << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return (mParticlesFromFile = runPythonString(pythonCommands)); | return (mParticlesFromFile = runPythonString(pythonCommands)); | ||||
| } | } | ||||
| bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain) | bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain) | ||||
| { | { | ||||
| if (with_debug) | if (with_debug) | ||||
| Show All 14 Lines | bool MANTA::readGuiding(FluidModifierData *fmd, int framenr, bool sourceDomain) | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| /* Sanity check: Are cache files present? */ | /* Sanity check: Are cache files present? */ | ||||
| if (!hasGuiding(fmd, framenr, sourceDomain)) | if (!hasGuiding(fmd, framenr, sourceDomain)) | ||||
| return false; | return false; | ||||
| if (sourceDomain) { | if (sourceDomain) { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "fluid_load_vel_" << mCurrentID << "('" << escapeSlashes(directory) << "', " << framenr | ss << "fluid_load_vel_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << ", '" << volume_format << "')"; | << ", '" << volume_format << "')"; | ||||
| } | } | ||||
| else { | else { | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "fluid_load_guiding_" << mCurrentID << "('" << escapeSlashes(directory) << "', " | ss << "fluid_load_guiding_" << mCurrentID << "('" << escapePath(directory) << "', " << framenr | ||||
| << framenr << ", '" << volume_format << "')"; | << ", '" << volume_format << "')"; | ||||
| } | } | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::bakeData(FluidModifierData *fmd, int framenr) | bool MANTA::bakeData(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| Show All 17 Lines | BLI_path_join(cacheDirGuiding, | ||||
| sizeof(cacheDirGuiding), | sizeof(cacheDirGuiding), | ||||
| fds->cache_directory, | fds->cache_directory, | ||||
| FLUID_DOMAIN_DIR_GUIDE, | FLUID_DOMAIN_DIR_GUIDE, | ||||
| nullptr); | nullptr); | ||||
| BLI_path_make_safe(cacheDirData); | BLI_path_make_safe(cacheDirData); | ||||
| BLI_path_make_safe(cacheDirGuiding); | BLI_path_make_safe(cacheDirGuiding); | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "bake_fluid_data_" << mCurrentID << "('" << escapeSlashes(cacheDirData) << "', " << framenr | ss << "bake_fluid_data_" << mCurrentID << "('" << escapePath(cacheDirData) << "', " << framenr | ||||
| << ", '" << volume_format << "')"; | << ", '" << volume_format << "')"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::bakeNoise(FluidModifierData *fmd, int framenr) | bool MANTA::bakeNoise(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| Show All 9 Lines | bool MANTA::bakeNoise(FluidModifierData *fmd, int framenr) | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| BLI_path_join( | BLI_path_join( | ||||
| cacheDirNoise, sizeof(cacheDirNoise), fds->cache_directory, FLUID_DOMAIN_DIR_NOISE, nullptr); | cacheDirNoise, sizeof(cacheDirNoise), fds->cache_directory, FLUID_DOMAIN_DIR_NOISE, nullptr); | ||||
| BLI_path_make_safe(cacheDirNoise); | BLI_path_make_safe(cacheDirNoise); | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "bake_noise_" << mCurrentID << "('" << escapeSlashes(cacheDirNoise) << "', " << framenr | ss << "bake_noise_" << mCurrentID << "('" << escapePath(cacheDirNoise) << "', " << framenr | ||||
| << ", '" << volume_format << "')"; | << ", '" << volume_format << "')"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::bakeMesh(FluidModifierData *fmd, int framenr) | bool MANTA::bakeMesh(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| Show All 10 Lines | bool MANTA::bakeMesh(FluidModifierData *fmd, int framenr) | ||||
| string volume_format = getCacheFileEnding(fds->cache_data_format); | string volume_format = getCacheFileEnding(fds->cache_data_format); | ||||
| string mesh_format = getCacheFileEnding(fds->cache_mesh_format); | string mesh_format = getCacheFileEnding(fds->cache_mesh_format); | ||||
| BLI_path_join( | BLI_path_join( | ||||
| cacheDirMesh, sizeof(cacheDirMesh), fds->cache_directory, FLUID_DOMAIN_DIR_MESH, nullptr); | cacheDirMesh, sizeof(cacheDirMesh), fds->cache_directory, FLUID_DOMAIN_DIR_MESH, nullptr); | ||||
| BLI_path_make_safe(cacheDirMesh); | BLI_path_make_safe(cacheDirMesh); | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "bake_mesh_" << mCurrentID << "('" << escapeSlashes(cacheDirMesh) << "', " << framenr | ss << "bake_mesh_" << mCurrentID << "('" << escapePath(cacheDirMesh) << "', " << framenr << ", '" | ||||
| << ", '" << volume_format << "', '" << mesh_format << "')"; | << volume_format << "', '" << mesh_format << "')"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::bakeParticles(FluidModifierData *fmd, int framenr) | bool MANTA::bakeParticles(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| if (with_debug) | if (with_debug) | ||||
| Show All 12 Lines | bool MANTA::bakeParticles(FluidModifierData *fmd, int framenr) | ||||
| BLI_path_join(cacheDirParticles, | BLI_path_join(cacheDirParticles, | ||||
| sizeof(cacheDirParticles), | sizeof(cacheDirParticles), | ||||
| fds->cache_directory, | fds->cache_directory, | ||||
| FLUID_DOMAIN_DIR_PARTICLES, | FLUID_DOMAIN_DIR_PARTICLES, | ||||
| nullptr); | nullptr); | ||||
| BLI_path_make_safe(cacheDirParticles); | BLI_path_make_safe(cacheDirParticles); | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "bake_particles_" << mCurrentID << "('" << escapeSlashes(cacheDirParticles) << "', " | ss << "bake_particles_" << mCurrentID << "('" << escapePath(cacheDirParticles) << "', " | ||||
| << framenr << ", '" << volume_format << "', " << resumable_cache << ")"; | << framenr << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::bakeGuiding(FluidModifierData *fmd, int framenr) | bool MANTA::bakeGuiding(FluidModifierData *fmd, int framenr) | ||||
| { | { | ||||
| Show All 13 Lines | bool MANTA::bakeGuiding(FluidModifierData *fmd, int framenr) | ||||
| BLI_path_join(cacheDirGuiding, | BLI_path_join(cacheDirGuiding, | ||||
| sizeof(cacheDirGuiding), | sizeof(cacheDirGuiding), | ||||
| fds->cache_directory, | fds->cache_directory, | ||||
| FLUID_DOMAIN_DIR_GUIDE, | FLUID_DOMAIN_DIR_GUIDE, | ||||
| nullptr); | nullptr); | ||||
| BLI_path_make_safe(cacheDirGuiding); | BLI_path_make_safe(cacheDirGuiding); | ||||
| ss.str(""); | ss.str(""); | ||||
| ss << "bake_guiding_" << mCurrentID << "('" << escapeSlashes(cacheDirGuiding) << "', " << framenr | ss << "bake_guiding_" << mCurrentID << "('" << escapePath(cacheDirGuiding) << "', " << framenr | ||||
| << ", '" << volume_format << "', " << resumable_cache << ")"; | << ", '" << volume_format << "', " << resumable_cache << ")"; | ||||
| pythonCommands.push_back(ss.str()); | pythonCommands.push_back(ss.str()); | ||||
| return runPythonString(pythonCommands); | return runPythonString(pythonCommands); | ||||
| } | } | ||||
| bool MANTA::updateVariables(FluidModifierData *fmd) | bool MANTA::updateVariables(FluidModifierData *fmd) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 679 Lines • Show Last 20 Lines | |||||