Commit: 43fcc9207a11baf1d02f0fba2ccb00c3f7106e4a
Author: Sebastián Barschkis
Date:   Thu Jan 7 21:01:19 2016 +0100
Branches: fluid-mantaflow
https://developer.blender.org/rB43fcc9207a11baf1d02f0fba2ccb00c3f7106e4a

some manta api refactoring

===================================================================

M       intern/smoke/intern/FLUID_3D.cpp
M       intern/smoke/intern/MANTA.cpp
M       intern/smoke/intern/MANTA.h
M       intern/smoke/intern/WTURBULENCE.cpp
M       intern/smoke/intern/scenarios/smoke.h

===================================================================

diff --git a/intern/smoke/intern/FLUID_3D.cpp b/intern/smoke/intern/FLUID_3D.cpp
index d7f927a..fcf0a4e 100644
--- a/intern/smoke/intern/FLUID_3D.cpp
+++ b/intern/smoke/intern/FLUID_3D.cpp
@@ -589,38 +589,35 @@ _xRes(res[0]), _yRes(res[1]), _zRes(res[2]), _res(0.0f)
                _obstacles[x]    = false;
        }
        
-       /* heat */
        _heat = NULL;
        using_heat = false;
+       
+       _flame = _fuel = _react = NULL;
+       using_fire = false;
+       
+       _color_r = _color_g = _color_b = NULL;
+       using_colors = false;
+       
+       smd->domain->fluid = this;
+//     vector<string> args;
+//     args.push_back("manta_scene.py");
+//     initializeMantaflow(args); /*need this to delete previous solvers and 
grids*/
+       Manta_API::start_mantaflow();
+       Manta_API::run_manta_sim_file_lowRes(smd);
+       
+       // Heat grids
        if (init_heat) {
                initHeat();
        }
-       // Fire simulation
-       _flame = _fuel = NULL;
-       _react = NULL;
-       using_fire = false;
+       // Fire grids
        if (init_fire) {
                initFire();
        }
-       // Smoke color
-       _color_r = NULL;
-       _color_g = NULL;
-       _color_b = NULL;
-       using_colors = false;
+       // Smoke color grids
        if (init_colors) {
                initColors(0.0f, 0.0f, 0.0f);
        }
        
-//     PyGILState_STATE gilstate = PyGILState_Ensure();
-//     PyRun_SimpleString(clean_code_low.c_str());
-//     PyGILState_Release(gilstate);
-       
-       smd->domain->fluid = this;
-       vector<string> args;
-       args.push_back("manta_scene.py");
-       initializeMantaflow(args); /*need this to delete previous solvers and 
grids*/
-       
-       Manta_API::run_manta_sim_file_lowRes(smd);
        Manta_API::updatePointers(this);
 }
 
@@ -666,6 +663,11 @@ FLUID_3D::~FLUID_3D()
 {
        cout << "~FLUID_3D" << endl;
 
+       if (using_heat) Manta_API::delete_heat_low();
+       if (using_fire) Manta_API::delete_fire_low();
+       if (using_colors) Manta_API::delete_colors_low();
+       Manta_API::delete_base_grids_low();
+
 //     if (_xVelocity) delete[] _xVelocity;
 //     if (_yVelocity) delete[] _yVelocity;
 //     if (_zVelocity) delete[] _zVelocity;
diff --git a/intern/smoke/intern/MANTA.cpp b/intern/smoke/intern/MANTA.cpp
index 93419e9..71e0f99 100644
--- a/intern/smoke/intern/MANTA.cpp
+++ b/intern/smoke/intern/MANTA.cpp
@@ -1,6 +1,7 @@
 #include "MANTA.h"
 #include "WTURBULENCE.h"
 #include "scenarios/smoke.h"
+#include "../../../source/blender/python/manta_pp/pwrapper/manta.h"
 
 extern "C" bool manta_check_grid_size(struct FLUID_3D *fluid, int dimX, int 
dimY, int dimZ)
 {
@@ -418,6 +419,51 @@ void 
Manta_API::run_manta_sim_file_highRes(SmokeModifierData *smd)
        PyGILState_Release(gilstate);
 }
 
+void Manta_API::delete_colors_low()
+{
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       PyRun_SimpleString(del_colors_low.c_str());
+       PyGILState_Release(gilstate);
+}
+
+void Manta_API::delete_fire_low()
+{
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       PyRun_SimpleString(del_fire_low.c_str());
+       PyGILState_Release(gilstate);
+}
+
+void Manta_API::delete_heat_low()
+{
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       PyRun_SimpleString(del_heat_low.c_str());
+       PyGILState_Release(gilstate);
+}
+
+void Manta_API::delete_base_grids_low()
+{
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       PyRun_SimpleString(del_base_grids_low.c_str());
+       PyGILState_Release(gilstate);
+}
+
+void Manta_API::start_mantaflow()
+{
+       string filename = "manta_scene.py";
+       std::vector<std::string> fill = std::vector<std::string>();
+       
+       // Initialize extension classes and wrappers
+       srand(0);
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       
+       if (!manta_initialized)
+       {       
+               Pb::setup(filename, fill);
+               manta_initialized = true;
+       }
+       PyGILState_Release(gilstate);
+}
+
 std::string Manta_API::getRealValue( const std::string& varName, 
SmokeModifierData *smd)
 {
        ostringstream ss;
diff --git a/intern/smoke/intern/MANTA.h b/intern/smoke/intern/MANTA.h
index 98384d0..a133ec8 100644
--- a/intern/smoke/intern/MANTA.h
+++ b/intern/smoke/intern/MANTA.h
@@ -31,7 +31,8 @@ struct manta_arg_struct {
        SmokeModifierData smd;
 };
 
-static bool manta_sim_running=true;
+static bool manta_sim_running = true;
+static bool manta_initialized = false;
 
 extern "C" bool manta_check_grid_size(struct FLUID_3D *fluid, int dimX, int 
dimY, int dimZ);
 
@@ -94,23 +95,21 @@ public:
        /*blender transforms obj coords to [-1,1]. This method transforms them 
back*/
        void add_mesh_transform_method(stringstream& ss);
        
-       void manta_cache_path(char *filepath);
+       void stop_manta_sim();
        
-       void create_manta_folder();
+       static void run_manta_sim_file_lowRes(SmokeModifierData *smd);
        
-       void *run_manta_scene_thread(void *threadid);
+       static void run_manta_sim_file_highRes(SmokeModifierData *smd);
        
-       void run_manta_sim_highRes(WTURBULENCE *wt);
+       static void delete_colors_low();
        
-       void run_manta_scene(Manta_API * fluid);
+       static void delete_fire_low();
        
-       void stop_manta_sim();
+       static void delete_heat_low();
        
-       static void run_manta_sim_file_lowRes(SmokeModifierData *smd);
-       
-       static void run_manta_sim_file_highRes(SmokeModifierData *smd);
+       static void delete_base_grids_low();
        
-       void manta_sim_step(int frame);
+       static void start_mantaflow();
        
        static std::string getRealValue(const string& varName, 
SmokeModifierData *sds);
        
diff --git a/intern/smoke/intern/WTURBULENCE.cpp 
b/intern/smoke/intern/WTURBULENCE.cpp
index 59b799a..a55c16d 100644
--- a/intern/smoke/intern/WTURBULENCE.cpp
+++ b/intern/smoke/intern/WTURBULENCE.cpp
@@ -1423,4 +1423,4 @@ void WTURBULENCE::updateFlame()
        Manta_API::updateHighResPointers(this);
 }
 
-#endif
+#endif /* WITH_MANTA */
diff --git a/intern/smoke/intern/scenarios/smoke.h 
b/intern/smoke/intern/scenarios/smoke.h
index d9c824c..7149fb3 100644
--- a/intern/smoke/intern/scenarios/smoke.h
+++ b/intern/smoke/intern/scenarios/smoke.h
@@ -1,41 +1,8 @@
 #include <string>
 using namespace std;
-const string smoke_clean = "";
 
 /* SETUPS */
 
-const string clean_code_low = "\
-del res\n\
-del solver_dim\n\
-del gs\n\
-del doOpen\n\
-del boundConditions\n\
-del s\n\
-del timings\n\
-del flags\n\
-del vel\n\
-del x_vel\n\
-del y_vel\n\
-del z_vel\n\
-del density\n\
-del pressure\n\
-del color_r_low\n\
-del color_g_low\n\
-del color_b_low\n\
-del heat_low\n\
-del flame_low\n\
-del fuel_low\n\
-del react_low\n\
-del forces\n\
-del inflow_grid\n\
-del fuel_inflow\n\
-del noise\n\
-del using_colors\n\
-del using_heat\n\
-del using_fire\n\
-del low_flags_updated\n\
-";
-
 const string smoke_setup_low = "\
 from manta import *\n\
 import os, shutil, math, sys\n\
@@ -90,10 +57,6 @@ low_flags_updated = False\n\
 ";
 
 const string smoke_setup_high = "\
-from manta import *\n\
-import os, shutil, math, sys\n\
-\n\
-s = FluidSolver(name='main2', gridSize = vec3(21,21,32), dim = 3)\n\
 xl_gs = vec3($HRESX$, $HRESY$, $HRESZ$)\n\
 xl = Solver(name = 'larger', gridSize = xl_gs)\n\
 uvs = $UVS_CNT$\n\
@@ -167,36 +130,69 @@ color_b_high.copyFrom(xl_density) \n\
 color_b_high.multConst(manta_color_b) \n\
 using_colors = True\n";
 
-const string smoke_del_colors_low = "\n\
+const string del_colors_low = "\n\
 del color_r_low \n\
 del color_g_low \n\
 del color_b_low \n\
 using_colors = False";
 
-const string smoke_del_colors_high = "\n\
+const string del_colors_high = "\n\
 del color_r_high \n\
 del color_g_high \n\
 del color_b_high \n\
 using_colors = False";
 
+const string del_fire_low = "\n\
+del flame_low \n\
+del fuel_low \n\
+del react_low \n\
+using_fire = False";
+
+const string del_heat_low = "\n\
+del heat_low \n\
+using_heat = False";
+
+const string del_base_grids_low = "\n\
+del res\n\
+del solver_dim\n\
+del gs\n\
+del doOpen\n\
+del boundConditions\n\
+del s\n\
+del timings\n\
+del using_colors\n\
+del using_heat\n\
+del using_fire\n\
+del flags\n\
+del vel\n\
+del x_vel\n\
+del y_vel\n\
+del z_vel\n\
+del density\n\
+del pressure\n\
+del forces\n\
+del inflow_grid\n\
+del fuel_inflow\n\
+del noise";
+
 const string smoke_init_heat_low = "\
 print(\"Initializing heat lowres\")\n\
 heat_low = s.create(RealGrid)\n\
-using_heat = True\n";
+using_heat = True";
 
 const string smoke_init_fire_low = "\
 print(\"Initializing fire lowres\")\n\
 flame_low = s.create(RealGrid)\n\
 fuel_low = s.create(RealGrid)\n\
 react_low = s.create(RealGrid)\n\
-using_fire = True\n";
+using_fire = True";
 
 const string smoke_init_fire_high = "\
 print(\"Initializing fire highres\")\n\
 flame_high = xl.create(RealGrid)\n\
 fuel_high = xl.create(RealGrid)\n\
 react_high = xl.create(RealGrid)\n\
-using_fire = True\n";
+using_fire = True";
 
 const string standalone_low = "\n\
 if (GUI):\n\
@@ -291,7 +287,7 @@ def step_low():\n\
   s.step()\n\
 \n\
 def process_burn_low():\n\
-  if (color_r_low and color_g_low and color_b_low):\n\
+  if (using_colors):\n\
     processBurn(fuel=fuel_low, density=density, react=react_low, 
red=color_r_low, green=color_g_low, blue=color_b_low, heat=heat_low, 
burningRate=$BURNING_RATE$, flameSmoke=$FLAME_SMOKE$, 
ignitionTemp=$IGNITION_TEMP$, maxTemp=$MAX_TEMP$, dt=$DT$, 
flameSmokeColor=vec3($FLAME_SMOKE_COLOR_X$,$FLAME_SMOKE_COLOR_Y$,$FLAME_SMOKE_COLOR_Z$))\n\
   else:\n\
     processBurn(fuel=fuel_low, density=density, react=react_low, 
heat=heat_low, burningRate=$BURNING_RATE$, flameSmoke=$FLAME_SMOKE$, 
ignitionTemp=$IGNITION_TEMP$, maxTemp=$MAX_TEMP$, dt=$DT$, 
flameSmokeColor=vec3($FLAME_SMOKE_COLOR_X$,$FLAME_SMOKE_COLOR_Y$,$FLAME_SMOKE_COLOR_Z$))\n\

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to