Commit: c5051412a153d7ab8d1429aec9cbd0e02759bcfe
Author: Sebastián Barschkis
Date:   Sat May 7 16:35:03 2016 +0200
Branches: fluid-mantaflow
https://developer.blender.org/rBc5051412a153d7ab8d1429aec9cbd0e02759bcfe

first implementation of liquid API (similar to smoke)

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

A       intern/mantaflow/extern/manta_liquid_API.h
A       intern/mantaflow/intern/LIQUID.cpp
A       intern/mantaflow/intern/LIQUID.h
A       intern/mantaflow/intern/manta_liquid_API.cpp

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

diff --git a/intern/mantaflow/extern/manta_liquid_API.h 
b/intern/mantaflow/extern/manta_liquid_API.h
new file mode 100644
index 0000000..5da61c4
--- /dev/null
+++ b/intern/mantaflow/extern/manta_liquid_API.h
@@ -0,0 +1,45 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file mantaflow/extern/manta_liquid_API.h
+ *  \ingroup mantaflow
+ */
+
+#ifndef MANTA_LIQUID_API_H_
+#define MANTA_LIQUID_API_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct LIQUID;
+struct LIQUID *liquid_init();
+void liquid_step(struct LIQUID *liquid, int currentFrame);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MANTA_LIQUID_API_H_ */
\ No newline at end of file
diff --git a/intern/mantaflow/intern/LIQUID.cpp 
b/intern/mantaflow/intern/LIQUID.cpp
new file mode 100644
index 0000000..8834544
--- /dev/null
+++ b/intern/mantaflow/intern/LIQUID.cpp
@@ -0,0 +1,108 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file mantaflow/intern/LIQUID.cpp
+ *  \ingroup mantaflow
+ */
+
+#include <sstream>
+#include <fstream>
+#include <iostream>
+
+#include "LIQUID.h"
+#include "registry.h"
+#include "liquid_script.h"
+
+bool LIQUID::mantaInitialized = false;
+
+LIQUID::LIQUID()
+{
+       std::cout << "LIQUID" << std::endl;
+       
+       // Only start Mantaflow once. No need to start whenever new MANTA 
objected is allocated
+       if (!mantaInitialized)
+               startMantaflow();
+
+       initSetup();
+}
+
+void LIQUID::initSetup()
+{
+       std::string tmpString =
+               manta_import +
+               liquid_flags +
+               liquid_solver_setup +
+               alloc_liquid +
+               prep_domain +
+               mesh_loading +
+               manta_step +
+               liquid_step;
+//     std::string finalString = parseScript(tmpString, smd);
+       mCommands.clear();
+       mCommands.push_back(tmpString);
+       
+       runPythonString(mCommands);
+}
+
+void LIQUID::step(int currentFrame)
+{
+       // Run manta step and handover current frame number
+       mCommands.clear();
+       std::ostringstream manta_step;
+       manta_step <<  "manta_step(" << currentFrame << ")";
+       mCommands.push_back(manta_step.str());
+       
+       runPythonString(mCommands);
+}
+
+LIQUID::~LIQUID()
+{
+       std::cout << "~LIQUID()" << std::endl;
+}
+
+void LIQUID::runPythonString(std::vector<std::string> commands)
+{
+       PyGILState_STATE gilstate = PyGILState_Ensure();
+       for (std::vector<std::string>::iterator it = commands.begin(); it != 
commands.end(); ++it) {
+               std::string command = *it;
+               PyRun_SimpleString(command.c_str());
+       }
+       PyGILState_Release(gilstate);
+}
+
+void LIQUID::startMantaflow()
+{
+       std::cout << "Starting mantaflow" << std::endl;
+       std::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();
+       Pb::setup(filename, fill);  // Namespace from Mantaflow (registry)
+       PyGILState_Release(gilstate);
+       mantaInitialized = true;
+}
+
diff --git a/intern/mantaflow/intern/LIQUID.h b/intern/mantaflow/intern/LIQUID.h
new file mode 100644
index 0000000..6c32d21
--- /dev/null
+++ b/intern/mantaflow/intern/LIQUID.h
@@ -0,0 +1,55 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file mantaflow/intern/LIQUID.h
+ *  \ingroup mantaflow
+ */
+
+#ifndef LIQUID_H
+#define LIQUID_H
+
+#include <string>
+#include <vector>
+
+#include "Python.h"
+
+struct LIQUID {
+public:
+       LIQUID();
+       virtual ~LIQUID();
+       
+       void step(int currentFrame);
+       
+       static bool mantaInitialized;
+
+private:
+       std::vector<std::string> mCommands;
+
+       void initSetup();
+       void startMantaflow();
+       void runPythonString(std::vector<std::string> commands);
+};
+
+#endif
\ No newline at end of file
diff --git a/intern/mantaflow/intern/manta_liquid_API.cpp 
b/intern/mantaflow/intern/manta_liquid_API.cpp
new file mode 100644
index 0000000..b697633
--- /dev/null
+++ b/intern/mantaflow/intern/manta_liquid_API.cpp
@@ -0,0 +1,42 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Sebastian Barschkis (sebbas)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file mantaflow/intern/manta_liquid_API.cpp
+ *  \ingroup mantaflow
+ */
+
+#include "LIQUID.h"
+#include "manta_liquid_API.h"
+
+extern "C" LIQUID *liquid_init()
+{
+       LIQUID *liquid = new LIQUID();
+       return liquid;
+}
+
+extern "C" void liquid_step(LIQUID *liquid, int currentFrame)
+{
+       liquid->step(currentFrame);
+}

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

Reply via email to