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
path: root/intern
diff options
context:
space:
mode:
Diffstat (limited to 'intern')
-rw-r--r--intern/CMakeLists.txt4
-rw-r--r--intern/cycles/blender/blender_mesh.cpp77
-rw-r--r--intern/cycles/kernel/kernel_light_background.h2
-rw-r--r--intern/cycles/render/graph.cpp4
-rw-r--r--intern/cycles/util/util_transform.cpp2
-rw-r--r--intern/ffmpeg/CMakeLists.txt42
-rw-r--r--intern/ffmpeg/tests/ffmpeg_codecs.cc147
-rw-r--r--intern/ghost/intern/GHOST_ContextEGL.cpp2
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp6
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp22
-rw-r--r--intern/ghost/test/multitest/MultiTest.c9
-rw-r--r--intern/guardedalloc/CMakeLists.txt16
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h2
-rw-r--r--intern/guardedalloc/intern/leak_detector.cc2
-rw-r--r--intern/guardedalloc/intern/mallocn_guarded_impl.c21
-rw-r--r--intern/guardedalloc/intern/mallocn_lockfree_impl.c10
-rw-r--r--intern/guardedalloc/intern/mmap_win.c43
-rw-r--r--intern/guardedalloc/tests/guardedalloc_alignment_test.cc121
-rw-r--r--intern/guardedalloc/tests/guardedalloc_overflow_test.cc60
-rw-r--r--intern/mantaflow/extern/manta_fluid_API.h17
-rw-r--r--intern/mantaflow/intern/MANTA_main.cpp528
-rw-r--r--intern/mantaflow/intern/MANTA_main.h170
-rw-r--r--intern/mantaflow/intern/manta_fluid_API.cpp93
-rw-r--r--intern/mantaflow/intern/strings/fluid_script.h13
-rw-r--r--intern/opencolorio/ocio_impl_glsl.cc141
-rw-r--r--intern/rigidbody/RBI_api.h8
-rw-r--r--intern/rigidbody/rb_bullet_api.cpp69
-rw-r--r--intern/sky/include/sky_model.h8
28 files changed, 1052 insertions, 587 deletions
diff --git a/intern/CMakeLists.txt b/intern/CMakeLists.txt
index 0758567bb78..c1792a312b2 100644
--- a/intern/CMakeLists.txt
+++ b/intern/CMakeLists.txt
@@ -77,6 +77,10 @@ if(WITH_QUADRIFLOW)
add_subdirectory(quadriflow)
endif()
+if(WITH_CODEC_FFMPEG)
+ add_subdirectory(ffmpeg)
+endif()
+
if(UNIX AND NOT APPLE)
add_subdirectory(libc_compat)
endif()
diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 49407799fcd..f4354d5166e 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -923,6 +923,74 @@ static void create_subd_mesh(Scene *scene,
/* Sync */
+static BL::MeshSequenceCacheModifier object_mesh_cache_find(BL::Object &b_ob,
+ BL::Scene /*b_scene*/)
+{
+ BL::Object::modifiers_iterator b_mod;
+
+ for (b_ob.modifiers.begin(b_mod); b_mod != b_ob.modifiers.end(); ++b_mod) {
+ if (!b_mod->is_a(&RNA_MeshSequenceCacheModifier)) {
+ continue;
+ }
+
+ BL::MeshSequenceCacheModifier mesh_cache = BL::MeshSequenceCacheModifier(*b_mod);
+
+ if (MeshSequenceCacheModifier_has_velocity_get(&mesh_cache.ptr)) {
+ return mesh_cache;
+ }
+ }
+
+ return BL::MeshSequenceCacheModifier(PointerRNA_NULL);
+}
+
+static void sync_mesh_cached_velocities(BL::Object &b_ob,
+ BL::Scene b_scene,
+ Scene *scene,
+ Mesh *mesh)
+{
+ if (scene->need_motion() == Scene::MOTION_NONE)
+ return;
+
+ BL::MeshSequenceCacheModifier b_mesh_cache = object_mesh_cache_find(b_ob, b_scene);
+
+ if (!b_mesh_cache) {
+ return;
+ }
+
+ /* Find or add attribute */
+ float3 *P = &mesh->verts[0];
+ Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
+
+ if (!attr_mP) {
+ attr_mP = mesh->attributes.add(ATTR_STD_MOTION_VERTEX_POSITION);
+ }
+
+ if (!MeshSequenceCacheModifier_read_velocity_get(&b_mesh_cache.ptr)) {
+ return;
+ }
+
+ const size_t numverts = mesh->verts.size();
+
+ if (b_mesh_cache.vertex_velocities.length() != numverts) {
+ return;
+ }
+
+ /* Only export previous and next frame, we don't have any in between data. */
+ float motion_times[2] = {-1.0f, 1.0f};
+ for (int step = 0; step < 2; step++) {
+ const float relative_time = motion_times[step] * scene->motion_shutter_time() * 0.5f;
+ float3 *mP = attr_mP->data_float3() + step * numverts;
+
+ BL::MeshSequenceCacheModifier::vertex_velocities_iterator vvi;
+ int i = 0;
+
+ for (b_mesh_cache.vertex_velocities.begin(vvi); vvi != b_mesh_cache.vertex_velocities.end();
+ ++vvi, ++i) {
+ mP[i] = P[i] + get_float3(vvi->velocity()) * relative_time;
+ }
+ }
+}
+
static void sync_mesh_fluid_motion(BL::Object &b_ob, Scene *scene, Mesh *mesh)
{
if (scene->need_motion() == Scene::MOTION_NONE)
@@ -1002,6 +1070,9 @@ void BlenderSync::sync_mesh(BL::Depsgraph b_depsgraph,
}
}
+ /* cached velocities (e.g. from alembic archive) */
+ sync_mesh_cached_velocities(b_ob, b_depsgraph.scene(), scene, mesh);
+
/* mesh fluid motion mantaflow */
sync_mesh_fluid_motion(b_ob, scene, mesh);
@@ -1023,6 +1094,12 @@ void BlenderSync::sync_mesh_motion(BL::Depsgraph b_depsgraph,
return;
}
+ /* Cached motion blur already exported. */
+ BL::MeshSequenceCacheModifier mesh_cache = object_mesh_cache_find(b_ob, b_scene);
+ if (mesh_cache) {
+ return;
+ }
+
/* Skip if no vertices were exported. */
size_t numverts = mesh->verts.size();
if (numverts == 0) {
diff --git a/intern/cycles/kernel/kernel_light_background.h b/intern/cycles/kernel/kernel_light_background.h
index 30e336f0f80..5fa25069fcd 100644
--- a/intern/cycles/kernel/kernel_light_background.h
+++ b/intern/cycles/kernel/kernel_light_background.h
@@ -445,4 +445,4 @@ ccl_device float background_light_pdf(KernelGlobals *kg, float3 P, float3 direct
#endif
-CCL_NAMESPACE_END \ No newline at end of file
+CCL_NAMESPACE_END
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 436324b00ba..1b138455515 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -484,8 +484,8 @@ void ShaderGraph::remove_proxy_nodes()
vector<ShaderInput *> links(output->links);
foreach (ShaderInput *to, links) {
- /* remove any autoconvert nodes too if they lead to
- * sockets with an automatically set default value */
+ /* Remove any auto-convert nodes too if they lead to
+ * sockets with an automatically set default value. */
ShaderNode *tonode = to->parent;
if (tonode->special_type == SHADER_SPECIAL_TYPE_AUTOCONVERT) {
diff --git a/intern/cycles/util/util_transform.cpp b/intern/cycles/util/util_transform.cpp
index 6417752f704..e8233b7fe6d 100644
--- a/intern/cycles/util/util_transform.cpp
+++ b/intern/cycles/util/util_transform.cpp
@@ -317,7 +317,7 @@ void transform_motion_decompose(DecomposedTransform *decomp, const Transform *mo
*
* Note that this is very simple and naive implementation, which only deals with degenerated
* scale happening only on one frame. It is possible to improve it further by interpolating
- * rotation into s degenerated range using rotation from timesteps from adjacent non-degenerated
+ * rotation into s degenerated range using rotation from time-steps from adjacent non-degenerated
* time steps. */
for (size_t i = 0; i < size; i++) {
const float3 scale = make_float3(decomp[i].y.w, decomp[i].z.w, decomp[i].w.w);
diff --git a/intern/ffmpeg/CMakeLists.txt b/intern/ffmpeg/CMakeLists.txt
new file mode 100644
index 00000000000..e141da9cbca
--- /dev/null
+++ b/intern/ffmpeg/CMakeLists.txt
@@ -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) 2020, Blender Foundation
+# All rights reserved.
+# ***** END GPL LICENSE BLOCK *****
+
+if(WITH_GTESTS)
+ set(TEST_SRC
+ tests/ffmpeg_codecs.cc
+ )
+ set(TEST_INC
+ )
+ set(TEST_INC_SYS
+ ${FFMPEG_INCLUDE_DIRS}
+ ${PNG_INCLUDE_DIRS}
+ ${ZLIB_INCLUDE_DIRS}
+ )
+ set(TEST_LIB
+ ${PNG_LIBRARIES}
+ ${FFMPEG_LIBRARIES}
+ ${ZLIB_LIBRARIES}
+ )
+ if(WITH_IMAGE_OPENJPEG)
+ set(TEST_LIB ${TEST_LIB} ${OPENJPEG_LIBRARIES})
+ endif()
+ include(GTestTesting)
+ blender_add_test_lib(bf_intern_ffmpeg_tests "${TEST_SRC}" "${TEST_INC}" "${TEST_INC_SYS}" "${TEST_LIB}")
+endif()
diff --git a/intern/ffmpeg/tests/ffmpeg_codecs.cc b/intern/ffmpeg/tests/ffmpeg_codecs.cc
new file mode 100644
index 00000000000..d3cba6d228a
--- /dev/null
+++ b/intern/ffmpeg/tests/ffmpeg_codecs.cc
@@ -0,0 +1,147 @@
+#include "testing/testing.h"
+
+extern "C" {
+#include <libavcodec/avcodec.h>
+#include <libavutil/log.h>
+}
+
+bool test_vcodec(AVCodec *codec, AVPixelFormat pixelformat)
+{
+ av_log_set_level(AV_LOG_QUIET);
+ bool result = false;
+ if (codec) {
+ AVCodecContext *ctx = avcodec_alloc_context3(codec);
+ if (ctx) {
+ ctx->time_base.num = 1;
+ ctx->time_base.den = 25;
+ ctx->pix_fmt = pixelformat;
+ ctx->width = 720;
+ ctx->height = 576;
+ int open = avcodec_open2(ctx, codec, NULL);
+ if (open >= 0) {
+ avcodec_free_context(&ctx);
+ result = true;
+ }
+ }
+ }
+ return result;
+}
+bool test_acodec(AVCodec *codec, AVSampleFormat fmt)
+{
+ av_log_set_level(AV_LOG_QUIET);
+ bool result = false;
+ if (codec) {
+ AVCodecContext *ctx = avcodec_alloc_context3(codec);
+ if (ctx) {
+ ctx->sample_fmt = fmt;
+ ctx->sample_rate = 48000;
+ ctx->channel_layout = AV_CH_LAYOUT_MONO;
+ ctx->bit_rate = 128000;
+ int open = avcodec_open2(ctx, codec, NULL);
+ if (open >= 0) {
+ avcodec_free_context(&ctx);
+ result = true;
+ }
+ }
+ }
+ return result;
+}
+
+bool test_codec_video_by_codecid(AVCodecID codec_id, AVPixelFormat pixelformat)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder(codec_id);
+ if (codec)
+ result = test_vcodec(codec, pixelformat);
+ return result;
+}
+
+bool test_codec_video_by_name(const char *codecname, AVPixelFormat pixelformat)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder_by_name(codecname);
+ if (codec)
+ result = test_vcodec(codec, pixelformat);
+ return result;
+}
+
+bool test_codec_audio_by_codecid(AVCodecID codec_id, AVSampleFormat fmt)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder(codec_id);
+ if (codec)
+ result = test_acodec(codec, fmt);
+ return result;
+}
+
+bool test_codec_audio_by_name(const char *codecname, AVSampleFormat fmt)
+{
+ bool result = false;
+ AVCodec *codec = avcodec_find_encoder_by_name(codecname);
+ if (codec)
+ result = test_acodec(codec, fmt);
+ return result;
+}
+
+#define str(s) #s
+#define FFMPEG_TEST_VCODEC_ID(codec, fmt) \
+ TEST(ffmpeg, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_video_by_codecid(codec, fmt)); \
+ }
+
+#define FFMPEG_TEST_VCODEC_NAME(codec, fmt) \
+ TEST(ffmpeg, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_video_by_name(str(codec), fmt)); \
+ }
+
+#define FFMPEG_TEST_ACODEC_ID(codec, fmt) \
+ TEST(ffmpeg, codec##_##fmt) \
+ { \
+ EXPECT_TRUE(test_codec_audio_by_codecid(codec, fmt)); \
+ }
+
+#define FFMPEG_TEST_ACODEC_NAME(codec, fmt) \
+ TEST(ffmpeg, codec) \
+ { \
+ EXPECT_TRUE(test_codec_audio_by_name(str(codec), fmt)); \
+ }
+
+/* generic codec ID's used in blender */
+
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_BGRA)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_HUFFYUV, AV_PIX_FMT_RGB32)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FFV1, AV_PIX_FMT_RGB32)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_QTRLE, AV_PIX_FMT_ARGB)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_VP9, AV_PIX_FMT_YUVA420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_PNG, AV_PIX_FMT_RGBA)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG4, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_THEORA, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_DVVIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG1VIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_MPEG2VIDEO, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_ID(AV_CODEC_ID_FLV1, AV_PIX_FMT_YUV420P)
+
+/* Audio codecs */
+
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AAC, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_AC3, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_FLAC, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP2, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_MP3, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_OPUS, AV_SAMPLE_FMT_FLT)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_PCM_S16LE, AV_SAMPLE_FMT_S16)
+FFMPEG_TEST_ACODEC_ID(AV_CODEC_ID_VORBIS, AV_SAMPLE_FMT_FLTP)
+
+/* Libraries we count on ffmpeg being linked against */
+
+FFMPEG_TEST_VCODEC_NAME(libtheora, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libx264, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libvpx, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libopenjpeg, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_VCODEC_NAME(libxvid, AV_PIX_FMT_YUV420P)
+FFMPEG_TEST_ACODEC_NAME(libvorbis, AV_SAMPLE_FMT_FLTP)
+FFMPEG_TEST_ACODEC_NAME(libopus, AV_SAMPLE_FMT_FLT)
+FFMPEG_TEST_ACODEC_NAME(libmp3lame, AV_SAMPLE_FMT_FLTP)
diff --git a/intern/ghost/intern/GHOST_ContextEGL.cpp b/intern/ghost/intern/GHOST_ContextEGL.cpp
index 02daad2111a..bac7057d953 100644
--- a/intern/ghost/intern/GHOST_ContextEGL.cpp
+++ b/intern/ghost/intern/GHOST_ContextEGL.cpp
@@ -118,7 +118,7 @@ static const char *get_egl_error_message_string(EGLint error)
case EGL_CONTEXT_LOST:
return (
"A power management event has occurred. "
- "The application must destroy all contexts and reinitialise OpenGL ES state "
+ "The application must destroy all contexts and reinitialize OpenGL ES state "
"and objects to continue rendering.");
default:
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 96073c21e79..c0676618101 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -1951,7 +1951,7 @@ void GHOST_SystemX11::getClipboard_xcout(const XEvent *evt,
switch (*context) {
/* There is no context, do an XConvertSelection() */
case XCLIB_XCOUT_NONE:
- /* Initialise return length to 0 */
+ /* Initialize return length to 0. */
if (*len > 0) {
free(*txt);
*len = 0;
@@ -2169,7 +2169,7 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const
}
}
else if (owner == None)
- return (NULL);
+ return NULL;
/* Restore events so copy doesn't swallow other event types (keyboard/mouse). */
vector<XEvent> restore_events;
@@ -2237,7 +2237,7 @@ GHOST_TUns8 *GHOST_SystemX11::getClipboard(bool selection) const
return tmp_data;
}
- return (NULL);
+ return NULL;
}
void GHOST_SystemX11::putClipboard(GHOST_TInt8 *buffer, bool selection) const
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index 691f1790a2d..9a38631adb9 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -901,7 +901,7 @@ bool GHOST_WindowX11::netwmIsMaximized(void) const
if (prop_ret)
XFree(prop_ret);
- return (st);
+ return st;
}
void GHOST_WindowX11::netwmFullScreen(bool set)
@@ -964,7 +964,7 @@ bool GHOST_WindowX11::netwmIsFullScreen(void) const
if (prop_ret)
XFree(prop_ret);
- return (st);
+ return st;
}
void GHOST_WindowX11::motifFullScreen(bool set)
@@ -1018,7 +1018,7 @@ bool GHOST_WindowX11::motifIsFullScreen(void) const
if (prop_ret)
XFree(prop_ret);
- return (state);
+ return state;
}
GHOST_TWindowState GHOST_WindowX11::getState() const
@@ -1040,7 +1040,7 @@ GHOST_TWindowState GHOST_WindowX11::getState() const
state_ret = GHOST_kWindowStateFullScreen;
else if (netwmIsMaximized() == True)
state_ret = GHOST_kWindowStateMaximized;
- return (state_ret);
+ return state_ret;
}
GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
@@ -1078,7 +1078,7 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
if (is_motif_full == True)
motifFullScreen(False);
icccmSetState(NormalState);
- return (GHOST_kSuccess);
+ return GHOST_kSuccess;
}
if (state == GHOST_kWindowStateFullScreen) {
@@ -1087,7 +1087,7 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
* isn't mapped.
*/
if (cur_state == GHOST_kWindowStateMinimized)
- return (GHOST_kFailure);
+ return GHOST_kFailure;
m_normal_state = cur_state;
@@ -1097,7 +1097,7 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
netwmFullScreen(True);
if (is_motif_full == False)
motifFullScreen(True);
- return (GHOST_kSuccess);
+ return GHOST_kSuccess;
}
if (state == GHOST_kWindowStateMaximized) {
@@ -1106,7 +1106,7 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
* isn't mapped.
*/
if (cur_state == GHOST_kWindowStateMinimized)
- return (GHOST_kFailure);
+ return GHOST_kFailure;
if (is_full == True)
netwmFullScreen(False);
@@ -1114,7 +1114,7 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
motifFullScreen(False);
if (is_max == False)
netwmMaximized(True);
- return (GHOST_kSuccess);
+ return GHOST_kSuccess;
}
if (state == GHOST_kWindowStateMinimized) {
@@ -1123,10 +1123,10 @@ GHOST_TSuccess GHOST_WindowX11::setState(GHOST_TWindowState state)
* the window (maximized, full screen, etc).
*/
icccmSetState(IconicState);
- return (GHOST_kSuccess);
+ return GHOST_kSuccess;
}
- return (GHOST_kFailure);
+ return GHOST_kFailure;
}
GHOST_TSuccess GHOST_WindowX11::setOrder(GHOST_TWindowOrder order)
diff --git a/intern/ghost/test/multitest/MultiTest.c b/intern/ghost/test/multitest/MultiTest.c
index 5ddcb2470a8..cf7a06bf3e5 100644
--- a/intern/ghost/test/multitest/MultiTest.c
+++ b/intern/ghost/test/multitest/MultiTest.c
@@ -330,8 +330,7 @@ MainWindow *mainwindow_new(MultiTestApp *app)
if (win) {
MainWindow *mw = MEM_callocN(sizeof(*mw), "mainwindow_new");
- GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(win);
- mw->gpu_context = GPU_context_create(default_fb);
+ mw->gpu_context = GPU_context_create(win);
GPU_init();
mw->app = app;
@@ -587,8 +586,7 @@ LoggerWindow *loggerwindow_new(MultiTestApp *app)
if (win) {
LoggerWindow *lw = MEM_callocN(sizeof(*lw), "loggerwindow_new");
- GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(win);
- lw->gpu_context = GPU_context_create(default_fb);
+ lw->gpu_context = GPU_context_create(win);
GPU_init();
int bbox[2][2];
@@ -788,8 +786,7 @@ ExtraWindow *extrawindow_new(MultiTestApp *app)
if (win) {
ExtraWindow *ew = MEM_callocN(sizeof(*ew), "mainwindow_new");
- GLuint default_fb = GHOST_GetDefaultOpenGLFramebuffer(win);
- ew->gpu_context = GPU_context_create(default_fb);
+ ew->gpu_context = GPU_context_create(win);
GPU_init();
ew->app = app;
diff --git a/intern/guardedalloc/CMakeLists.txt b/intern/guardedalloc/CMakeLists.txt
index 1ab365a376a..ccc1500c014 100644
--- a/intern/guardedalloc/CMakeLists.txt
+++ b/intern/guardedalloc/CMakeLists.txt
@@ -78,3 +78,19 @@ if(WITH_CXX_GUARDEDALLOC)
)
blender_add_lib(bf_intern_guardedalloc_cpp "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
endif()
+
+if(WITH_GTESTS)
+ set(TEST_SRC
+ tests/guardedalloc_alignment_test.cc
+ tests/guardedalloc_overflow_test.cc
+ )
+ set(TEST_INC
+ ../../source/blender/blenlib
+ )
+ set(TEST_LIB
+ bf_intern_guardedalloc
+ bf_blenlib
+ )
+ include(GTestTesting)
+ blender_add_test_lib(bf_intern_guardedalloc_tests "${TEST_SRC}" "${INC};${TEST_INC}" "${INC_SYS}" "${LIB};${TEST_LIB}")
+endif()
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 604330bd1d3..9c62b2396f6 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -213,7 +213,7 @@ extern const char *(*MEM_name_ptr)(void *vmemh);
/** This should be called as early as possible in the program. When it has been called, information
* about memory leaks will be printed on exit. */
-void MEM_initialize_memleak_detection(void);
+void MEM_init_memleak_detection(void);
/* Switch allocator to slower but fully guarded mode. */
void MEM_use_guarded_allocator(void);
diff --git a/intern/guardedalloc/intern/leak_detector.cc b/intern/guardedalloc/intern/leak_detector.cc
index 4b2689ee28c..d7b6f749742 100644
--- a/intern/guardedalloc/intern/leak_detector.cc
+++ b/intern/guardedalloc/intern/leak_detector.cc
@@ -46,7 +46,7 @@ class MemLeakPrinter {
};
} // namespace
-void MEM_initialize_memleak_detection(void)
+void MEM_init_memleak_detection(void)
{
/**
* This variable is constructed when this function is first called. This should happen as soon as
diff --git a/intern/guardedalloc/intern/mallocn_guarded_impl.c b/intern/guardedalloc/intern/mallocn_guarded_impl.c
index 2c207935e43..6c08cb3bb62 100644
--- a/intern/guardedalloc/intern/mallocn_guarded_impl.c
+++ b/intern/guardedalloc/intern/mallocn_guarded_impl.c
@@ -249,9 +249,8 @@ size_t MEM_guarded_allocN_len(const void *vmemh)
memh--;
return memh->len;
}
- else {
- return 0;
- }
+
+ return 0;
}
void *MEM_guarded_dupallocN(const void *vmemh)
@@ -611,12 +610,11 @@ static int compare_len(const void *p1, const void *p2)
if (pb1->len < pb2->len) {
return 1;
}
- else if (pb1->len == pb2->len) {
+ if (pb1->len == pb2->len) {
return 0;
}
- else {
- return -1;
- }
+
+ return -1;
}
void MEM_guarded_printmemlist_stats(void)
@@ -682,7 +680,7 @@ void MEM_guarded_printmemlist_stats(void)
if (a == b) {
continue;
}
- else if (strcmp(printblock[a].name, printblock[b].name) == 0) {
+ if (strcmp(printblock[a].name, printblock[b].name) == 0) {
printblock[b].len += printblock[a].len;
printblock[b].items++;
}
@@ -1162,7 +1160,7 @@ static const char *check_memlist(MemHead *memh)
return ("Additional error in header");
}
- return (name);
+ return name;
}
size_t MEM_guarded_get_peak_memory(void)
@@ -1213,8 +1211,7 @@ const char *MEM_guarded_name_ptr(void *vmemh)
memh--;
return memh->name;
}
- else {
- return "MEM_guarded_name_ptr(NULL)";
- }
+
+ return "MEM_guarded_name_ptr(NULL)";
}
#endif /* NDEBUG */
diff --git a/intern/guardedalloc/intern/mallocn_lockfree_impl.c b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
index b71e2c963eb..8f5c9cf85a9 100644
--- a/intern/guardedalloc/intern/mallocn_lockfree_impl.c
+++ b/intern/guardedalloc/intern/mallocn_lockfree_impl.c
@@ -94,9 +94,8 @@ size_t MEM_lockfree_allocN_len(const void *vmemh)
if (vmemh) {
return MEMHEAD_FROM_PTR(vmemh)->len & ~((size_t)(MEMHEAD_ALIGN_FLAG));
}
- else {
- return 0;
- }
+
+ return 0;
}
void MEM_lockfree_freeN(void *vmemh)
@@ -436,8 +435,7 @@ const char *MEM_lockfree_name_ptr(void *vmemh)
if (vmemh) {
return "unknown block name ptr";
}
- else {
- return "MEM_lockfree_name_ptr(NULL)";
- }
+
+ return "MEM_lockfree_name_ptr(NULL)";
}
#endif /* NDEBUG */
diff --git a/intern/guardedalloc/intern/mmap_win.c b/intern/guardedalloc/intern/mmap_win.c
index 245fe05b6af..a02a0f88fa9 100644
--- a/intern/guardedalloc/intern/mmap_win.c
+++ b/intern/guardedalloc/intern/mmap_win.c
@@ -138,10 +138,12 @@ void *mmap(void *UNUSED(start), size_t len, int prot, int flags, int fd, off_t o
ptr = MapViewOfFile(maphandle, access_flags, 0, offset, 0);
if (ptr == NULL) {
DWORD dwLastErr = GetLastError();
- if (dwLastErr == ERROR_MAPPED_ALIGNMENT)
+ if (dwLastErr == ERROR_MAPPED_ALIGNMENT) {
errno = EINVAL;
- else
+ }
+ else {
errno = EACCES;
+ }
CloseHandle(maphandle);
return MAP_FAILED;
}
@@ -182,18 +184,22 @@ static void mmap_addtail(volatile mmapListBase *listbase, void *vlink)
{
struct mmapLink *link = vlink;
- if (link == NULL)
+ if (link == NULL) {
return;
- if (listbase == NULL)
+ }
+ if (listbase == NULL) {
return;
+ }
link->next = 0;
link->prev = listbase->last;
- if (listbase->last)
+ if (listbase->last) {
((struct mmapLink *)listbase->last)->next = link;
- if (listbase->first == NULL)
+ }
+ if (listbase->first == NULL) {
listbase->first = link;
+ }
listbase->last = link;
}
@@ -201,30 +207,37 @@ static void mmap_remlink(volatile mmapListBase *listbase, void *vlink)
{
struct mmapLink *link = vlink;
- if (link == NULL)
+ if (link == NULL) {
return;
- if (listbase == NULL)
+ }
+ if (listbase == NULL) {
return;
-
- if (link->next)
+ }
+ if (link->next) {
link->next->prev = link->prev;
- if (link->prev)
+ }
+ if (link->prev) {
link->prev->next = link->next;
+ }
- if (listbase->last == link)
+ if (listbase->last == link) {
listbase->last = link->prev;
- if (listbase->first == link)
+ }
+ if (listbase->first == link) {
listbase->first = link->next;
+ }
}
static void *mmap_findlink(volatile mmapListBase *listbase, void *ptr)
{
MemMap *mm;
- if (ptr == NULL)
+ if (ptr == NULL) {
return NULL;
- if (listbase == NULL)
+ }
+ if (listbase == NULL) {
return NULL;
+ }
mm = (MemMap *)listbase->first;
while (mm) {
diff --git a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
new file mode 100644
index 00000000000..4c676c6cc76
--- /dev/null
+++ b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
@@ -0,0 +1,121 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+
+#include "BLI_utildefines.h"
+
+#include "MEM_guardedalloc.h"
+
+#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0)
+
+namespace {
+
+void DoBasicAlignmentChecks(const int alignment)
+{
+ int *foo, *bar;
+
+ foo = (int *)MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test");
+ CHECK_ALIGNMENT(foo, alignment);
+
+ bar = (int *)MEM_dupallocN(foo);
+ CHECK_ALIGNMENT(bar, alignment);
+ MEM_freeN(bar);
+
+ foo = (int *)MEM_reallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
+
+ foo = (int *)MEM_recallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
+
+ MEM_freeN(foo);
+}
+
+} // namespace
+
+TEST(guardedalloc, LockfreeAlignedAlloc1)
+{
+ DoBasicAlignmentChecks(1);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc1)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(1);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc2)
+{
+ DoBasicAlignmentChecks(2);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc2)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(2);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc4)
+{
+ DoBasicAlignmentChecks(4);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc4)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(4);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc8)
+{
+ DoBasicAlignmentChecks(8);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc8)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(8);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc16)
+{
+ DoBasicAlignmentChecks(16);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc16)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(16);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc32)
+{
+ DoBasicAlignmentChecks(32);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc32)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(32);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc256)
+{
+ DoBasicAlignmentChecks(256);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc256)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(256);
+}
+
+TEST(guardedalloc, LockfreeAlignedAlloc512)
+{
+ DoBasicAlignmentChecks(512);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc512)
+{
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(512);
+}
diff --git a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
new file mode 100644
index 00000000000..bd47482d033
--- /dev/null
+++ b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
@@ -0,0 +1,60 @@
+/* Apache License, Version 2.0 */
+
+#include "testing/testing.h"
+
+#include "MEM_guardedalloc.h"
+
+/* We expect to abort on integer overflow, to prevent possible exploits. */
+#ifdef _WIN32
+# define ABORT_PREDICATE ::testing::ExitedWithCode(3)
+#else
+# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT)
+#endif
+
+namespace {
+
+void MallocArray(size_t len, size_t size)
+{
+ void *mem = MEM_malloc_arrayN(len, size, "MallocArray");
+ if (mem) {
+ MEM_freeN(mem);
+ }
+}
+
+void CallocArray(size_t len, size_t size)
+{
+ void *mem = MEM_calloc_arrayN(len, size, "CallocArray");
+ if (mem) {
+ MEM_freeN(mem);
+ }
+}
+
+} // namespace
+
+TEST(guardedalloc, LockfreeIntegerOverflow)
+{
+ MallocArray(1, SIZE_MAX);
+ CallocArray(SIZE_MAX, 1);
+ MallocArray(SIZE_MAX / 2, 2);
+ CallocArray(SIZE_MAX / 1234567, 1234567);
+
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
+}
+
+TEST(guardedalloc, GuardedIntegerOverflow)
+{
+ MEM_use_guarded_allocator();
+
+ MallocArray(1, SIZE_MAX);
+ CallocArray(SIZE_MAX, 1);
+ MallocArray(SIZE_MAX / 2, 2);
+ CallocArray(SIZE_MAX / 1234567, 1234567);
+
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, "");
+ EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, "");
+ EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
+}
diff --git a/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 3da1d8f53f0..124671467f7 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -33,10 +33,10 @@ struct MANTA;
/* Fluid functions */
struct MANTA *manta_init(int *res, struct FluidModifierData *fmd);
void manta_free(struct MANTA *fluid);
-void manta_ensure_obstacle(struct MANTA *fluid, struct FluidModifierData *fmd);
-void manta_ensure_guiding(struct MANTA *fluid, struct FluidModifierData *fmd);
-void manta_ensure_invelocity(struct MANTA *fluid, struct FluidModifierData *fmd);
-void manta_ensure_outflow(struct MANTA *fluid, struct FluidModifierData *fmd);
+int manta_ensure_obstacle(struct MANTA *fluid, struct FluidModifierData *fmd);
+int manta_ensure_guiding(struct MANTA *fluid, struct FluidModifierData *fmd);
+int manta_ensure_invelocity(struct MANTA *fluid, struct FluidModifierData *fmd);
+int manta_ensure_outflow(struct MANTA *fluid, struct FluidModifierData *fmd);
int manta_write_config(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr);
int manta_write_data(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr);
int manta_write_noise(struct MANTA *fluid, struct FluidModifierData *fmd, int framenr);
@@ -77,6 +77,7 @@ int manta_get_frame(struct MANTA *fluid);
float manta_get_timestep(struct MANTA *fluid);
void manta_adapt_timestep(struct MANTA *fluid);
bool manta_needs_realloc(struct MANTA *fluid, struct FluidModifierData *fmd);
+void manta_update_pointers(struct MANTA *fluid, struct FluidModifierData *fmd, bool flush);
/* Fluid accessors */
size_t manta_get_index(int x, int max_x, int y, int max_y, int z /*, int max_z */);
@@ -121,9 +122,9 @@ void manta_noise_get_rgba_fixed_color(struct MANTA *smoke,
float color[3],
float *data,
int sequential);
-void manta_smoke_ensure_heat(struct MANTA *smoke, struct FluidModifierData *fmd);
-void manta_smoke_ensure_fire(struct MANTA *smoke, struct FluidModifierData *fmd);
-void manta_smoke_ensure_colors(struct MANTA *smoke, struct FluidModifierData *fmd);
+int manta_smoke_ensure_heat(struct MANTA *smoke, struct FluidModifierData *fmd);
+int manta_smoke_ensure_fire(struct MANTA *smoke, struct FluidModifierData *fmd);
+int manta_smoke_ensure_colors(struct MANTA *smoke, struct FluidModifierData *fmd);
/* Smoke accessors */
float *manta_smoke_get_density(struct MANTA *smoke);
@@ -167,7 +168,7 @@ int manta_noise_get_cells(struct MANTA *smoke);
/* Liquid functions */
void manta_liquid_export_script(struct MANTA *smoke, struct FluidModifierData *fmd);
-void manta_liquid_ensure_sndparts(struct MANTA *fluid, struct FluidModifierData *fmd);
+int manta_liquid_ensure_sndparts(struct MANTA *fluid, struct FluidModifierData *fmd);
/* Liquid accessors */
int manta_liquid_get_particle_res_x(struct MANTA *liquid);
diff --git a/intern/mantaflow/intern/MANTA_main.cpp b/intern/mantaflow/intern/MANTA_main.cpp
index 6e6451be725..5997e819ccf 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);
}
@@ -1073,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);
}
@@ -1111,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;
@@ -1616,10 +1619,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;
@@ -1627,14 +1630,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;
@@ -1658,36 +1661,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;
@@ -1726,10 +1729,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;
@@ -1738,7 +1741,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;
@@ -1747,7 +1750,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;
@@ -1764,13 +1767,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;
@@ -1779,23 +1782,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;
@@ -1824,12 +1827,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);
@@ -1912,6 +1921,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)
@@ -1956,137 +1970,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 60546bc1183..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 */)
{
@@ -441,34 +444,35 @@ void manta_noise_get_rgba_fixed_color(MANTA *smoke, float color[3], float *data,
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 */
@@ -645,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 83ad201fcbd..d669e8cf3b4 100644
--- a/intern/mantaflow/intern/strings/fluid_script.h
+++ b/intern/mantaflow/intern/strings/fluid_script.h
@@ -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";
diff --git a/intern/opencolorio/ocio_impl_glsl.cc b/intern/opencolorio/ocio_impl_glsl.cc
index 43416f734c5..f766f57732a 100644
--- a/intern/opencolorio/ocio_impl_glsl.cc
+++ b/intern/opencolorio/ocio_impl_glsl.cc
@@ -45,9 +45,8 @@
# pragma warning(pop)
#endif
-extern "C" {
#include "GPU_immediate.h"
-}
+#include "GPU_shader.h"
using namespace OCIO_NAMESPACE;
@@ -94,18 +93,15 @@ struct OCIO_GLSLCurveMappingParameters {
struct OCIO_GLSLShader {
/** Cache IDs */
std::string cacheId;
- /** TODO(fclem): Remove. IMM shader interface. */
- struct GPUShaderInterface *interface;
- /** OpenGL Shader objects handles. */
- GLuint frag;
- GLuint vert;
- GLuint program;
+
+ struct GPUShader *shader;
/** Uniform locations. */
GLint dither_loc;
GLint overlay_loc;
GLint overlay_tex_loc;
GLint predivide_loc;
GLint curve_mapping_loc;
+ GLint ubo_bind;
/** Error checking. */
bool valid;
};
@@ -152,56 +148,6 @@ static OCIO_GLSLDrawState *allocateOpenGLState(void)
/** \name Shader
* \{ */
-static GLuint compileShaderText(GLenum shader_type, const char *text)
-{
- GLuint shader;
- GLint stat;
-
- shader = glCreateShader(shader_type);
- glShaderSource(shader, 1, (const GLchar **)&text, NULL);
- glCompileShader(shader);
- glGetShaderiv(shader, GL_COMPILE_STATUS, &stat);
-
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetShaderInfoLog(shader, 1000, &len, log);
- fprintf(stderr, "Shader compile error:\n%s\n", log);
- return 0;
- }
-
- return shader;
-}
-
-static GLuint linkShaders(GLuint frag, GLuint vert)
-{
- if (!frag || !vert) {
- return 0;
- }
-
- GLuint program = glCreateProgram();
-
- glAttachShader(program, frag);
- glAttachShader(program, vert);
-
- glLinkProgram(program);
-
- /* check link */
- {
- GLint stat;
- glGetProgramiv(program, GL_LINK_STATUS, &stat);
- if (!stat) {
- GLchar log[1000];
- GLsizei len;
- glGetProgramInfoLog(program, 1000, &len, log);
- fprintf(stderr, "Shader link error:\n%s\n", log);
- return 0;
- }
- }
-
- return program;
-}
-
static void updateGLSLShader(OCIO_GLSLShader *shader,
ConstProcessorRcPtr *processor_scene_to_ui,
ConstProcessorRcPtr *processpr_ui_to_display,
@@ -213,28 +159,14 @@ static void updateGLSLShader(OCIO_GLSLShader *shader,
}
/* Delete any previous shader. */
- glDeleteProgram(shader->program);
- glDeleteShader(shader->frag);
- glDeleteShader(shader->vert);
-
- if (shader->interface) {
- GPU_shaderinterface_discard(shader->interface);
+ if (shader->shader) {
+ GPU_shader_free(shader->shader);
}
- {
- /* Vertex shader */
- std::ostringstream osv;
-
- osv << "#version 330\n";
- osv << datatoc_gpu_shader_display_transform_vertex_glsl;
-
- shader->vert = compileShaderText(GL_VERTEX_SHADER, osv.str().c_str());
- }
+ std::ostringstream os;
{
/* Fragment shader */
- std::ostringstream os;
- os << "#version 330\n";
/* Work around OpenColorIO not supporting latest GLSL yet. */
os << "#define texture2D texture\n";
os << "#define texture3D texture\n";
@@ -246,41 +178,36 @@ static void updateGLSLShader(OCIO_GLSLShader *shader,
os << (*processpr_ui_to_display)->getGpuShaderText(*shader_desc) << "\n";
os << datatoc_gpu_shader_display_transform_glsl;
-
- shader->frag = compileShaderText(GL_FRAGMENT_SHADER, os.str().c_str());
}
- /* shader_Program */
- if (shader->frag && shader->vert) {
- shader->program = linkShaders(shader->frag, shader->vert);
- }
+ shader->shader = GPU_shader_create(datatoc_gpu_shader_display_transform_vertex_glsl,
+ os.str().c_str(),
+ NULL,
+ NULL,
+ NULL,
+ __func__);
- if (shader->program) {
- shader->dither_loc = glGetUniformLocation(shader->program, "dither");
- shader->overlay_tex_loc = glGetUniformLocation(shader->program, "overlay_texture");
- shader->overlay_loc = glGetUniformLocation(shader->program, "overlay");
- shader->predivide_loc = glGetUniformLocation(shader->program, "predivide");
- shader->curve_mapping_loc = glGetUniformLocation(shader->program, "curve_mapping");
+ if (shader->shader) {
+ shader->dither_loc = GPU_shader_get_uniform(shader->shader, "dither");
+ shader->overlay_tex_loc = GPU_shader_get_uniform(shader->shader, "overlay_texture");
+ shader->overlay_loc = GPU_shader_get_uniform(shader->shader, "overlay");
+ shader->predivide_loc = GPU_shader_get_uniform(shader->shader, "predivide");
+ shader->curve_mapping_loc = GPU_shader_get_uniform(shader->shader, "curve_mapping");
+ shader->ubo_bind = GPU_shader_get_uniform_block_binding(shader->shader,
+ "OCIO_GLSLCurveMappingParameters");
- glUseProgram(shader->program);
-
- /* TODO(fclem) Remove this. Make caller always assume viewport space and
- * specify texco via vertex attribs. */
- shader->interface = GPU_shaderinterface_create(shader->program);
-
- /* Set UBO binding location. */
- GLuint index = glGetUniformBlockIndex(shader->program, "OCIO_GLSLCurveMappingParameters");
- glUniformBlockBinding(shader->program, index, UBO_BIND_LOC);
+ GPU_shader_bind(shader->shader);
/* Set texture bind point uniform once. This is saved by the shader. */
- glUniform1i(glGetUniformLocation(shader->program, "image_texture"), 0);
- glUniform1i(glGetUniformLocation(shader->program, "lut3d_texture"), 2);
- glUniform1i(glGetUniformLocation(shader->program, "lut3d_display_texture"), 3);
- glUniform1i(glGetUniformLocation(shader->program, "curve_mapping_texture"), 4);
+ GPUShader *sh = shader->shader;
+ GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "image_texture"), 0);
+ GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "lut3d_texture"), 2);
+ GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "lut3d_display_texture"), 3);
+ GPU_shader_uniform_int(sh, GPU_shader_get_uniform(sh, "curve_mapping_texture"), 4);
}
shader->cacheId = cache_id;
- shader->valid = (shader->program != 0);
+ shader->valid = (shader->shader != NULL);
}
static void ensureGLSLShader(OCIO_GLSLShader **shader_ptr,
@@ -302,12 +229,8 @@ static void ensureGLSLShader(OCIO_GLSLShader **shader_ptr,
static void freeGLSLShader(OCIO_GLSLShader *shader)
{
- glDeleteProgram(shader->program);
- glDeleteShader(shader->frag);
- glDeleteShader(shader->vert);
-
- if (shader->interface) {
- GPU_shaderinterface_discard(shader->interface);
+ if (shader->shader) {
+ GPU_shader_free(shader->shader);
}
OBJECT_GUARDED_DELETE(shader, OCIO_GLSLShader);
@@ -674,10 +597,10 @@ bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r,
glActiveTexture(GL_TEXTURE0);
/* Bind UBO. */
- glBindBufferBase(GL_UNIFORM_BUFFER, 0, shader_curvemap->buffer);
+ glBindBufferBase(GL_UNIFORM_BUFFER, shader->ubo_bind, shader_curvemap->buffer);
/* TODO(fclem) remove remains of IMM. */
- immBindProgram(shader->program, shader->interface);
+ immBindShader(shader->shader);
/* Bind Shader and set uniforms. */
// glUseProgram(shader->program);
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index d46cb5a7eed..07cda49e04b 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -238,6 +238,14 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh);
/* 2b - GImpact Meshes */
rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh);
+/* Compound Shape ---------------- */
+
+rbCollisionShape *RB_shape_new_compound(void);
+void RB_compound_add_child_shape(rbCollisionShape *collisionShape,
+ rbCollisionShape *shape,
+ const float loc[3],
+ const float rot[4]);
+
/* Cleanup --------------------------- */
void RB_shape_delete(rbCollisionShape *shape);
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index a8bf1420523..db8c062990c 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -98,6 +98,8 @@ struct rbMeshData {
struct rbCollisionShape {
btCollisionShape *cshape;
rbMeshData *mesh;
+ rbCollisionShape **compoundChildShapes;
+ int compoundChilds;
};
struct rbFilterCallback : public btOverlapFilterCallback {
@@ -331,6 +333,7 @@ rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const floa
rbRigidBody *object = new rbRigidBody;
/* current transform */
btTransform trans;
+ trans.setIdentity();
trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
@@ -413,6 +416,10 @@ void RB_body_set_mass(rbRigidBody *object, float value)
shape->calculateLocalInertia(value, localInertia);
}
+ btVector3 minAabb, maxAabb;
+ btTransform ident;
+ ident.setIdentity();
+ body->getCollisionShape()->getAabb(ident, minAabb, maxAabb);
body->setMassProps(value, localInertia);
body->updateInertiaTensor();
}
@@ -597,6 +604,7 @@ void RB_body_set_loc_rot(rbRigidBody *object, const float loc[3], const float ro
/* set transform matrix */
btTransform trans;
+ trans.setIdentity();
trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
@@ -655,6 +663,8 @@ rbCollisionShape *RB_shape_new_box(float x, float y, float z)
rbCollisionShape *shape = new rbCollisionShape;
shape->cshape = new btBoxShape(btVector3(x, y, z));
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -663,6 +673,8 @@ rbCollisionShape *RB_shape_new_sphere(float radius)
rbCollisionShape *shape = new rbCollisionShape;
shape->cshape = new btSphereShape(radius);
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -671,6 +683,8 @@ rbCollisionShape *RB_shape_new_capsule(float radius, float height)
rbCollisionShape *shape = new rbCollisionShape;
shape->cshape = new btCapsuleShapeZ(radius, height);
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -679,6 +693,8 @@ rbCollisionShape *RB_shape_new_cone(float radius, float height)
rbCollisionShape *shape = new rbCollisionShape;
shape->cshape = new btConeShapeZ(radius, height);
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -687,6 +703,8 @@ rbCollisionShape *RB_shape_new_cylinder(float radius, float height)
rbCollisionShape *shape = new rbCollisionShape;
shape->cshape = new btCylinderShapeZ(btVector3(radius, radius, height));
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -709,6 +727,8 @@ rbCollisionShape *RB_shape_new_convex_hull(
shape->cshape = hull_shape;
shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -773,6 +793,8 @@ rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh)
shape->cshape = new btScaledBvhTriangleMeshShape(unscaledShape, btVector3(1.0f, 1.0f, 1.0f));
shape->mesh = mesh;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
@@ -813,9 +835,46 @@ rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh)
shape->cshape = gimpactShape;
shape->mesh = mesh;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
return shape;
}
+/* Compound Shape ---------------- */
+
+rbCollisionShape *RB_shape_new_compound()
+{
+ rbCollisionShape *shape = new rbCollisionShape;
+ btCompoundShape *compoundShape = new btCompoundShape();
+
+ shape->cshape = compoundShape;
+ shape->mesh = NULL;
+ shape->compoundChilds = 0;
+ shape->compoundChildShapes = NULL;
+ return shape;
+}
+
+void RB_compound_add_child_shape(rbCollisionShape *parentShape,
+ rbCollisionShape *shape,
+ const float loc[3],
+ const float rot[4])
+{
+ /* set transform matrix */
+ btTransform trans;
+ trans.setIdentity();
+ trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
+ trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
+
+ btCompoundShape *compoundShape = (btCompoundShape *)(parentShape->cshape);
+ compoundShape->addChildShape(trans, shape->cshape);
+
+ /* Store shapes for deletion later */
+ parentShape->compoundChildShapes = (rbCollisionShape **)(realloc(
+ parentShape->compoundChildShapes,
+ sizeof(rbCollisionShape *) * (++parentShape->compoundChilds)));
+ parentShape->compoundChildShapes[parentShape->compoundChilds - 1] = shape;
+}
+
/* Cleanup --------------------------- */
void RB_shape_delete(rbCollisionShape *shape)
@@ -829,6 +888,15 @@ void RB_shape_delete(rbCollisionShape *shape)
if (shape->mesh)
RB_trimesh_data_delete(shape->mesh);
delete shape->cshape;
+
+ /* Delete compound child shapes if there are any */
+ for (int i = 0; i < shape->compoundChilds; i++) {
+ RB_shape_delete(shape->compoundChildShapes[i]);
+ }
+ if (shape->compoundChildShapes != NULL) {
+ free(shape->compoundChildShapes);
+ }
+
delete shape;
}
@@ -873,6 +941,7 @@ static void make_constraint_transforms(btTransform &transform1,
float orn[4])
{
btTransform pivot_transform = btTransform();
+ pivot_transform.setIdentity();
pivot_transform.setOrigin(btVector3(pivot[0], pivot[1], pivot[2]));
pivot_transform.setRotation(btQuaternion(orn[1], orn[2], orn[3], orn[0]));
diff --git a/intern/sky/include/sky_model.h b/intern/sky/include/sky_model.h
index 021086e1e02..983b90fed35 100644
--- a/intern/sky/include/sky_model.h
+++ b/intern/sky/include/sky_model.h
@@ -112,7 +112,7 @@ bands, you would need something like
ArHosekSkyModelState * skymodel_state[num_channels];
-You then have to allocate and initialise these states. In the following code
+You then have to allocate and initialize these states. In the following code
snippet, we assume that 'albedo' is defined as
double albedo[num_channels];
@@ -228,7 +228,7 @@ actually not altered at all in this release. All we did was to add some support
functionality for doing this more easily with the existing data and functions,
and to add some explanations.
-Just use 'arhosekskymodelstate_alienworld_alloc_init()' to initialise the sky
+Just use 'arhosekskymodelstate_alienworld_alloc_init()' to initialize the sky
model states (you will have to provide values for star temperature and solar
intensity compared to the terrestrial sun), and do everything else as you
did before.
@@ -351,7 +351,7 @@ typedef struct SKY_ArHosekSkyModelState {
arhosekskymodelstate_alloc_init() function
------------------------------------------
- Initialises an ArHosekSkyModelState struct for a terrestrial setting.
+ Initializes an #ArHosekSkyModelState struct for a terrestrial setting.
---------------------------------------------------------------------------- */
@@ -364,7 +364,7 @@ SKY_ArHosekSkyModelState *SKY_arhosekskymodelstate_alloc_init(const double solar
arhosekskymodelstate_alienworld_alloc_init() function
-----------------------------------------------------
- Initialises an ArHosekSkyModelState struct for an "alien world" setting
+ Initializes an ArHosekSkyModelState struct for an "alien world" setting
with a sun of a surface temperature given in 'kelvin'. The parameter
'solar_intensity' controls the overall brightness of the sky, relative
to the solar irradiance on Earth. A value of 1.0 yields a sky dome that