Commit: b63074492d9bfe6ca00f2f721af255564a608c66 Author: Roman Pogribnyi Date: Thu Nov 6 00:31:09 2014 +0100 Branches: soc-2014-fluid https://developer.blender.org/rBb63074492d9bfe6ca00f2f721af255564a608c66
low- and highres colored smoke =================================================================== M intern/smoke/intern/FLUID_3D.cpp M intern/smoke/intern/FLUID_3D.h M intern/smoke/intern/MANTA.cpp M intern/smoke/intern/MANTA.h M intern/smoke/intern/WTURBULENCE.cpp M intern/smoke/intern/WTURBULENCE.h M intern/smoke/intern/scenarios/smoke.h M source/blender/blenkernel/intern/smoke.c =================================================================== diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp index 2b286c8..5dcf781 100644 --- a/intern/smoke/intern/FLUID_3D.cpp +++ b/intern/smoke/intern/FLUID_3D.cpp @@ -1741,7 +1741,9 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) _color_r = _color_rOld = _color_rTemp = NULL; _color_g = _color_gOld = _color_gTemp = NULL; _color_b = _color_bOld = _color_bTemp = NULL; + using_colors = false; if (init_colors) { + using_colors =true; initColors(0.0f, 0.0f, 0.0f); } @@ -1762,8 +1764,7 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) vector<string> a; a.push_back("manta_scene.py"); runMantaScript(final_script,a); /*need this to delete previous solvers and grids*/ - Manta_API::updatePointers(this); - + Manta_API::updatePointers(this, using_colors); } void FLUID_3D::initHeat() @@ -1778,7 +1779,18 @@ void FLUID_3D::initFire() void FLUID_3D::initColors(float init_r, float init_g, float init_b) { - + if (!_color_r){ + using_colors = true; + PyGILState_STATE gilstate = PyGILState_Ensure(); + stringstream ss; + ss << "manta_color_r = " << init_r << endl; + ss << "manta_color_g = " << init_g << endl; + ss << "manta_color_b = " << init_b << endl; + PyRun_SimpleString(ss.str().c_str()); + PyRun_SimpleString(smoke_init_colors_low.c_str()); + PyGILState_Release(gilstate); + Manta_API::updatePointers(this, true); + } } void FLUID_3D::setBorderObstacles() @@ -1861,12 +1873,10 @@ void FLUID_3D::step(float dt, float gravity[3]) std::string frame_str = static_cast<ostringstream*>( &(ostringstream() << sim_frame) )->str(); std::string py_string_0 = string("sim_step_low(").append(frame_str); std::string py_string_1 = py_string_0.append(")\0"); - cout << "Debug C++: densityPointer:" << Manta_API::getGridPointer("density", "s")<<endl; - PyRun_SimpleString("print ('pyhton density pointer:' + density.getDataPointer())"); PyRun_SimpleString(py_string_1.c_str()); cout<< "done"<<manta_sim_running<<endl; PyGILState_Release(gilstate); - Manta_API::updatePointers(this); + Manta_API::updatePointers(this,using_colors); } diff --git a/intern/smoke/intern/FLUID_3D.h b/intern/smoke/intern/FLUID_3D.h index cb9c0d6..6ca837e 100644 --- a/intern/smoke/intern/FLUID_3D.h +++ b/intern/smoke/intern/FLUID_3D.h @@ -139,6 +139,7 @@ struct FLUID_3D float *_color_b; float *_color_bOld; float *_color_bTemp; + bool using_colors; // CG fields diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp index 63579bc..f9fad8d 100644 --- a/intern/smoke/intern/MANTA.cpp +++ b/intern/smoke/intern/MANTA.cpp @@ -394,7 +394,7 @@ void Manta_API::run_manta_sim_highRes(WTURBULENCE *wt) PyRun_SimpleString(py_string_1.c_str()); cout<< "done"<<manta_sim_running<<endl; PyGILState_Release(gilstate); - updateHighResPointers(wt); + updateHighResPointers(wt,false); } void Manta_API::generate_manta_sim_file_highRes(SmokeModifierData *smd) @@ -530,16 +530,16 @@ string Manta_API::getGridPointer(std::string gridName, std::string solverName) PyGILState_STATE gilstate = PyGILState_Ensure(); PyObject *main = PyImport_AddModule("__main__"); - if (main == NULL){cout << "null" << 1 << endl;} + if (main == NULL){cout << "null" << 1 << endl;return "";} PyObject *globals = PyModule_GetDict(main); - if (globals == NULL){cout << "null" << 12 << endl;} + if (globals == NULL){cout << "null" << 12 << endl;return "";} PyObject *grid_object = PyDict_GetItemString(globals, gridName.c_str()); - if (grid_object == NULL){cout << "null" << 13 << endl;} + if (grid_object == NULL){cout << "null" << 13 << endl;return "";} PyObject* func = PyObject_GetAttrString(grid_object,(char*)"getDataPointer"); - if (func == NULL){cout << "null" << 14 << endl;} + if (func == NULL){cout << "null" << 14 << endl;return "";} PyObject* retured_value = PyObject_CallObject(func, NULL); PyObject* encoded = PyUnicode_AsUTF8String(retured_value); - if (retured_value == NULL){cout << "null" << 15 << endl;} + if (retured_value == NULL){cout << "null" << 15 << endl;return "";} std::string res = strdup(PyBytes_AsString(encoded)); cout << "RESRES" << res << "___" << endl; PyGILState_Release(gilstate); @@ -563,23 +563,36 @@ void Manta_API::initBlenderRNA(float *alpha, float *beta, float *dt_factor, floa _max_temp = flame_max_temp; } - -void Manta_API::updatePointers(FLUID_3D *fluid) -{ - stringstream ss(getGridPointer("density", "s")); +void * Manta_API::pointerFromString(const std::string& s){ + stringstream ss(s); void *gridPointer = NULL; ss >> gridPointer; - fluid->_density = (float* )gridPointer; - ss.str(""); + return gridPointer; } -void Manta_API::updateHighResPointers(WTURBULENCE *wt) + +void Manta_API::updatePointers(FLUID_3D *fluid, bool updateColor) { - stringstream ss(getGridPointer("xl_density", "xl")); - void *gridPointer = NULL; - ss >> gridPointer; - wt->_densityBig = (float* )gridPointer; - ss.str(""); + fluid->_density = (float* )pointerFromString(getGridPointer("density", "s")); + if (updateColor){ + cout<< "POINTER FOR R_LOW" << fluid->_color_r<< endl; + fluid->_color_r = (float* )pointerFromString(getGridPointer("color_r_low", "s")); + cout<< "POINTER FOR R_LOW" << fluid->_color_r<< endl; + fluid->_color_g = (float* )pointerFromString(getGridPointer("color_g_low", "s")); + fluid->_color_b = (float* )pointerFromString(getGridPointer("color_b_low", "s")); + } +} + +void Manta_API::updateHighResPointers(WTURBULENCE *wt, bool updateColor) +{ + wt->_densityBig = (float* )pointerFromString(getGridPointer("xl_density", "xl"));; + if (updateColor){ + cout<< "POINTER FOR R_HIGH" << wt->_color_rBig << endl; + wt->_color_rBig = (float* )pointerFromString(getGridPointer("color_r_high", "xl")); + cout<< "POINTER FOR R_HIGH" << wt->_color_rBig << endl; + wt->_color_gBig = (float* )pointerFromString(getGridPointer("color_g_high", "xl")); + wt->_color_bBig = (float* )pointerFromString(getGridPointer("color_b_high", "xl")); + } } Manta_API::Manta_API(int *res, float dx, float dtdef, int init_heat, int init_fire, int init_colors,SmokeDomainSettings *sds): _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f) diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h index fd341d9..d0981bd 100644 --- a/intern/smoke/intern/MANTA.h +++ b/intern/smoke/intern/MANTA.h @@ -117,14 +117,16 @@ public: pthread_t manta_thread; + static void * pointerFromString(const std::string& s); + static string gridNameFromType(const string& type); static void addGrid(void * data,string name, string type, int x, int y, int z); static void addAdaptiveGrid(void * data, string gridName, string solverName, string type,int minX, int minY, int minZ, int maxX, int maxY, int maxZ); static void export_obstacles(float *data, int x, int y, int z); static std::string getGridPointer(string gridName, string solverName); - static void updatePointers(FLUID_3D *fluid); - static void updateHighResPointers(WTURBULENCE *wt); + static void updatePointers(FLUID_3D *fluid, bool updateColor); + static void updateHighResPointers(WTURBULENCE *wt,bool updateColor); }; diff --git a/intern/smoke/intern/WTURBULENCE.cpp b/intern/smoke/intern/WTURBULENCE.cpp index 11ab1b1..000a78e 100644 --- a/intern/smoke/intern/WTURBULENCE.cpp +++ b/intern/smoke/intern/WTURBULENCE.cpp @@ -37,6 +37,7 @@ #include "SPHERE.h" #include <zlib.h> #include <math.h> +#include "scenarios/smoke.h" // needed to access static advection functions #include "FLUID_3D.h" @@ -1262,7 +1263,9 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no _color_rBig = _color_rBigOld = NULL; _color_gBig = _color_gBigOld = NULL; _color_bBig = _color_bBigOld = NULL; + using_colors = false; if (init_colors) { + using_colors = true; initColors(0.0f, 0.0f, 0.0f); } @@ -1292,7 +1295,7 @@ WTURBULENCE::WTURBULENCE(int xResSm, int yResSm, int zResSm, int amplify, int no setNoise(noisetype, noisefile_path); sds->smd->domain->wt = this; Manta_API::generate_manta_sim_file_highRes(sds->smd); - Manta_API::updateHighResPointers(this); + Manta_API::updateHighResPointers(this,using_colors); } /// destructor WTURBULENCE::~WTURBULENCE() @@ -1321,7 +1324,21 @@ WTURBULENCE::~WTURBULENCE() } void WTURBULENCE::initFire(){} -void WTURBULENCE::initColors(float init_r, float init_g, float init_b){} +void WTURBULENCE::initColors(float init_r, float init_g, float init_b) +{ + if (!_color_rBig){ + using_colors = true; + PyGILState_STATE gilstate = PyGILState_Ensure(); + stringstream ss; + ss << "manta_color_r = " << init_r << endl; + ss << "manta_color_g = " << init_g << endl; + ss << "manta_color_b = " << init_b << endl; + PyRun_SimpleString(ss.str().c_str()); + PyRun_SimpleString(smoke_init_colors_high.c_str()); + PyGILState_Release(gilstate); + Manta_API::updateHighResPointers(this,true); + } +} void WTURBULENCE::setNoise(int type, const char *noisefile_path){} void WTURBULENCE::initBlenderRNA(float *strength){} @@ -1336,7 +1353,7 @@ void WTURBULENCE::stepTurbulenceReadable(float dt, float* xvel, float* yvel, flo std::string py_string_1 = py_string_0.append(")\0"); PyRun_SimpleString(py_string_1.c_str()); PyGILState_Release(gilstate); - Manta_API::updateHighResPointers(this); + Manta_API::updateHighResPointers(this,using_colors); } // step more complete version -- include rotation correction @@ -1350,7 +1367,7 @@ void WTURBULENCE::stepTurbulenceFull(float dt, float* xvel, float* yvel, float* std::string py_string_1 = py_string_0.append(")\0"); PyRun_SimpleString(py_string_1.c_str()); PyGILState_Release(gilstate); - Manta_API::updateHighResPointers(this); + Manta_API::updateHighResPointers(this,using_colors); } // texcoord functions diff --git a/intern/smoke/intern/WTURBULENCE.h b/intern/smoke/intern/WTURBULENCE.h index 31e809f..787177b 100644 --- a/intern/smoke/intern/WTURBULENCE.h +++ b/intern/smoke/intern/WTURBULENCE.h @@ -128,7 +128,8 @@ struct WTURBULENCE float* _color_gBigOld; float* _color_bBig; float* _color_bBigOld; - + bool using_colors; + // texture coordinates for noise float* _tcU; float* _tcV; di @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs