diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-08-09 17:37:15 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-08-09 17:37:15 +0300 |
commit | 4a801f6c6f0421ffd515c12422dd197441440520 (patch) | |
tree | 5415e844b460bb2aa07b9467c72e13abc2e61228 /source/blender/python/intern | |
parent | 49c63d46db8c055152d9e431e89405f9b51a4bbe (diff) | |
parent | 02719521d2e25abcc8ffcccc086d3a651986f52f (diff) |
Merge branch 'master' into object_nodesobject_nodes
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r-- | source/blender/python/intern/CMakeLists.txt | 13 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_alembic.c | 113 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_alembic.h | 38 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_build_options.c | 7 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_translations.c | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.c | 73 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_driver.h | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_intern_string.c | 6 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_intern_string.h | 2 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_library_load.c | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_driver.c | 21 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_driver.h | 4 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_id_collection.c | 2 |
14 files changed, 263 insertions, 28 deletions
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 2715d2c5992..038c1e7eb10 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -49,6 +49,7 @@ set(SRC gpu_offscreen.c bpy.c bpy_app.c + bpy_app_alembic.c bpy_app_build_options.c bpy_app_ffmpeg.c bpy_app_handlers.c @@ -82,6 +83,7 @@ set(SRC gpu.h bpy.h bpy_app.h + bpy_app_alembic.h bpy_app_build_options.h bpy_app_ffmpeg.h bpy_app_handlers.h @@ -264,6 +266,10 @@ if(WITH_OPENCOLLADA) add_definitions(-DWITH_COLLADA) endif() +if(WITH_ALEMBIC) + add_definitions(-DWITH_ALEMBIC) +endif() + if(WITH_OPENCOLORIO) add_definitions(-DWITH_OCIO) endif() @@ -275,6 +281,13 @@ if(WITH_OPENVDB) ) endif() +if(WITH_ALEMBIC) + add_definitions(-DWITH_ALEMBIC) + list(APPEND INC + ../../alembic + ) +endif() + if(WITH_OPENIMAGEIO) add_definitions(-DWITH_OPENIMAGEIO) list(APPEND INC diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 727d980b182..78cb537cccd 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -33,6 +33,7 @@ #include "bpy_app.h" +#include "bpy_app_alembic.h" #include "bpy_app_ffmpeg.h" #include "bpy_app_ocio.h" #include "bpy_app_oiio.h" @@ -104,6 +105,7 @@ static PyStructSequence_Field app_info_fields[] = { {(char *)"build_system", (char *)"Build system used"}, /* submodules */ + {(char *)"alembic", (char *)"Alembic library information backend"}, {(char *)"ffmpeg", (char *)"FFmpeg library information backend"}, {(char *)"ocio", (char *)"OpenColorIO library information backend"}, {(char *)"oiio", (char *)"OpenImageIO library information backend"}, @@ -182,6 +184,7 @@ static PyObject *make_app_info(void) SetBytesItem("Unknown"); #endif + SetObjItem(BPY_app_alembic_struct()); SetObjItem(BPY_app_ffmpeg_struct()); SetObjItem(BPY_app_ocio_struct()); SetObjItem(BPY_app_oiio_struct()); diff --git a/source/blender/python/intern/bpy_app_alembic.c b/source/blender/python/intern/bpy_app_alembic.c new file mode 100644 index 00000000000..90e6a02b418 --- /dev/null +++ b/source/blender/python/intern/bpy_app_alembic.c @@ -0,0 +1,113 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Kevin Dietrich + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_alembic.c + * \ingroup pythonintern + */ + +#include <Python.h> +#include "BLI_utildefines.h" + +#include "bpy_app_alembic.h" + +#ifdef WITH_ALEMBIC +# include "ABC_alembic.h" +#endif + +static PyTypeObject BlenderAppABCType; + +static PyStructSequence_Field app_alembic_info_fields[] = { + {(char *)"supported", (char *)"Boolean, True when Blender is built with Alembic support"}, + {(char *)"version", (char *)"The Alembic version as a tuple of 3 numbers"}, + {(char *)"version_string", (char *)"The Alembic version formatted as a string"}, + {NULL} +}; + +static PyStructSequence_Desc app_alembic_info_desc = { + (char *)"bpy.app.alembic", /* name */ + (char *)"This module contains information about Alembic blender is linked against", /* doc */ + app_alembic_info_fields, /* fields */ + ARRAY_SIZE(app_alembic_info_fields) - 1 +}; + +static PyObject *make_alembic_info(void) +{ + PyObject *alembic_info = PyStructSequence_New(&BlenderAppABCType); + + if (alembic_info == NULL) { + return NULL; + } + + int pos = 0; + +#ifndef WITH_ALEMBIC +# define SetStrItem(str) \ + PyStructSequence_SET_ITEM(alembic_info, pos++, PyUnicode_FromString(str)) +#endif + +#define SetObjItem(obj) \ + PyStructSequence_SET_ITEM(alembic_info, pos++, obj) + +#ifdef WITH_ALEMBIC + const int curversion = ABC_get_version(); + const int major = curversion / 10000; + const int minor = (curversion / 100) - (major * 100); + const int patch = curversion - ((curversion / 100 ) * 100); + + SetObjItem(PyBool_FromLong(1)); + SetObjItem(Py_BuildValue("(iii)", major, minor, patch)); + SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major, minor, patch)); +#else + SetObjItem(PyBool_FromLong(0)); + SetObjItem(Py_BuildValue("(iii)", 0, 0, 0)); + SetStrItem("Unknown"); +#endif + + if (PyErr_Occurred()) { + Py_CLEAR(alembic_info); + return NULL; + } + +#undef SetStrItem +#undef SetObjItem + + return alembic_info; +} + +PyObject *BPY_app_alembic_struct(void) +{ + PyStructSequence_InitType(&BlenderAppABCType, &app_alembic_info_desc); + + PyObject *ret = make_alembic_info(); + + /* prevent user from creating new instances */ + BlenderAppABCType.tp_init = NULL; + BlenderAppABCType.tp_new = NULL; + BlenderAppABCType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */ + + return ret; +} diff --git a/source/blender/python/intern/bpy_app_alembic.h b/source/blender/python/intern/bpy_app_alembic.h new file mode 100644 index 00000000000..8cc647a77df --- /dev/null +++ b/source/blender/python/intern/bpy_app_alembic.h @@ -0,0 +1,38 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2016 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): Kevin Dietrich + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/python/intern/bpy_app_alembic.h + * \ingroup pythonintern + */ + +#ifndef __BPY_APP_ALEMBIC_H__ +#define __BPY_APP_ALEMBIC_H__ + +PyObject *BPY_app_alembic_struct(void); + +#endif /* __BPY_APP_ALEMBIC_H__ */ + diff --git a/source/blender/python/intern/bpy_app_build_options.c b/source/blender/python/intern/bpy_app_build_options.c index 4c186aab100..a6b98567a9a 100644 --- a/source/blender/python/intern/bpy_app_build_options.c +++ b/source/blender/python/intern/bpy_app_build_options.c @@ -69,6 +69,7 @@ static PyStructSequence_Field app_builtopts_info_fields[] = { {(char *)"player", NULL}, {(char *)"openmp", NULL}, {(char *)"openvdb", NULL}, + {(char *)"alembic", NULL}, {NULL} }; @@ -303,6 +304,12 @@ static PyObject *make_builtopts_info(void) SetObjIncref(Py_False); #endif +#ifdef WITH_ALEMBIC + SetObjIncref(Py_True); +#else + SetObjIncref(Py_False); +#endif + #undef SetObjIncref return builtopts_info; diff --git a/source/blender/python/intern/bpy_app_translations.c b/source/blender/python/intern/bpy_app_translations.c index b90deafb377..6ba858f0228 100644 --- a/source/blender/python/intern/bpy_app_translations.c +++ b/source/blender/python/intern/bpy_app_translations.c @@ -675,7 +675,7 @@ static PyObject *app_translations_new(PyTypeObject *type, PyObject *UNUSED(args) _translations->contexts = app_translations_contexts_make(); - py_ctxts = PyDict_New(); + py_ctxts = _PyDict_NewPresized(ARRAY_SIZE(_contexts)); for (ctxt = _contexts; ctxt->c_id; ctxt++) { PyObject *val = PyUnicode_FromString(ctxt->py_id); PyDict_SetItemString(py_ctxts, ctxt->c_id, val); diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index 65b6bd501ce..c8ce7b2f770 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -44,6 +44,8 @@ #include "bpy_rna_driver.h" /* for pyrna_driver_get_variable_value */ +#include "bpy_intern_string.h" + #include "bpy_driver.h" extern void BPY_update_rna_module(void); @@ -97,26 +99,48 @@ int bpy_pydriver_create_dict(void) } /* note, this function should do nothing most runs, only when changing frame */ -static PyObject *bpy_pydriver_InternStr__frame = NULL; /* not thread safe but neither is python */ -static float bpy_pydriver_evaltime_prev = FLT_MAX; - -static void bpy_pydriver_update_dict(const float evaltime) +static struct { + float evaltime; + + /* borrowed reference to the 'self' in 'bpy_pydriver_Dict' + * keep for as long as the same self is used. */ + PyObject *self; +} g_pydriver_state_prev = { + .evaltime = FLT_MAX, + .self = NULL, +}; + +static void bpy_pydriver_namespace_update_frame(const float evaltime) { - if (bpy_pydriver_evaltime_prev != evaltime) { + if (g_pydriver_state_prev.evaltime != evaltime) { + PyObject *item = PyFloat_FromDouble(evaltime); + PyDict_SetItem(bpy_pydriver_Dict, bpy_intern_str_frame, item); + Py_DECREF(item); - /* currently only update the frame */ - if (bpy_pydriver_InternStr__frame == NULL) { - bpy_pydriver_InternStr__frame = PyUnicode_FromString("frame"); - } + g_pydriver_state_prev.evaltime = evaltime; + } +} - PyObject *item = PyFloat_FromDouble(evaltime); - PyDict_SetItem(bpy_pydriver_Dict, - bpy_pydriver_InternStr__frame, - item); +static void bpy_pydriver_namespace_update_self(struct PathResolvedRNA *anim_rna) +{ + if ((g_pydriver_state_prev.self == NULL) || + (pyrna_driver_is_equal_anim_rna(anim_rna, g_pydriver_state_prev.self) == false)) + { + PyObject *item = pyrna_driver_self_from_anim_rna(anim_rna); + PyDict_SetItem(bpy_pydriver_Dict, bpy_intern_str_self, item); Py_DECREF(item); - bpy_pydriver_evaltime_prev = evaltime; + g_pydriver_state_prev.self = item; + } +} + +static void bpy_pydriver_namespace_clear_self(void) +{ + if (g_pydriver_state_prev.self) { + PyDict_DelItem(bpy_pydriver_Dict, bpy_intern_str_self); + + g_pydriver_state_prev.self = NULL; } } @@ -139,11 +163,10 @@ void BPY_driver_reset(void) bpy_pydriver_Dict = NULL; } - if (bpy_pydriver_InternStr__frame) { - Py_DECREF(bpy_pydriver_InternStr__frame); - bpy_pydriver_InternStr__frame = NULL; - bpy_pydriver_evaltime_prev = FLT_MAX; - } + g_pydriver_state_prev.evaltime = FLT_MAX; + + /* freed when clearing driver dict */ + g_pydriver_state_prev.self = NULL; if (use_gil) PyGILState_Release(gilstate); @@ -174,7 +197,7 @@ static void pydriver_error(ChannelDriver *driver) * now release the GIL on python operator execution instead, using * PyEval_SaveThread() / PyEval_RestoreThread() so we don't lock up blender. */ -float BPY_driver_exec(ChannelDriver *driver, const float evaltime) +float BPY_driver_exec(struct PathResolvedRNA *anim_rna, ChannelDriver *driver, const float evaltime) { PyObject *driver_vars = NULL; PyObject *retval = NULL; @@ -224,8 +247,14 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) } /* update global namespace */ - bpy_pydriver_update_dict(evaltime); + bpy_pydriver_namespace_update_frame(evaltime); + if (driver->flag & DRIVER_FLAG_USE_SELF) { + bpy_pydriver_namespace_update_self(anim_rna); + } + else { + bpy_pydriver_namespace_clear_self(); + } if (driver->expr_comp == NULL) driver->flag |= DRIVER_FLAG_RECOMPILE; @@ -264,7 +293,7 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime) } /* add target values to a dict that will be used as '__locals__' dict */ - driver_vars = PyDict_New(); + driver_vars = _PyDict_NewPresized(PyTuple_GET_SIZE(expr_vars)); for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) { PyObject *driver_arg = NULL; diff --git a/source/blender/python/intern/bpy_driver.h b/source/blender/python/intern/bpy_driver.h index 1fccec7e1b2..017a6fe89c5 100644 --- a/source/blender/python/intern/bpy_driver.h +++ b/source/blender/python/intern/bpy_driver.h @@ -28,12 +28,13 @@ #define __BPY_DRIVER_H__ struct ChannelDriver; +struct PathResolvedRNA; int bpy_pydriver_create_dict(void); extern PyObject *bpy_pydriver_Dict; /* externals */ -float BPY_driver_exec(struct ChannelDriver *driver, const float evaltime); +float BPY_driver_exec(struct PathResolvedRNA *anim_rna, struct ChannelDriver *driver, const float evaltime); void BPY_driver_reset(void); #endif /* __BPY_DRIVER_H__ */ diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c index fd32c91a480..ac0100fa75d 100644 --- a/source/blender/python/intern/bpy_intern_string.c +++ b/source/blender/python/intern/bpy_intern_string.c @@ -34,7 +34,7 @@ #include "BLI_utildefines.h" -static PyObject *bpy_intern_str_arr[11]; +static PyObject *bpy_intern_str_arr[13]; PyObject *bpy_intern_str_register; PyObject *bpy_intern_str_unregister; @@ -43,6 +43,8 @@ PyObject *bpy_intern_str_bl_property; PyObject *bpy_intern_str_bpy_types; PyObject *bpy_intern_str_order; PyObject *bpy_intern_str_attr; +PyObject *bpy_intern_str_self; +PyObject *bpy_intern_str_frame; PyObject *bpy_intern_str___slots__; PyObject *bpy_intern_str___name__; PyObject *bpy_intern_str___doc__; @@ -62,6 +64,8 @@ void bpy_intern_string_init(void) BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types"); BPY_INTERN_STR(bpy_intern_str_order, "order"); BPY_INTERN_STR(bpy_intern_str_attr, "attr"); + BPY_INTERN_STR(bpy_intern_str_self, "self"); + BPY_INTERN_STR(bpy_intern_str_frame, "frame"); BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__"); BPY_INTERN_STR(bpy_intern_str___name__, "__name__"); BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__"); diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h index f4f4560dbfd..394e84d89bd 100644 --- a/source/blender/python/intern/bpy_intern_string.h +++ b/source/blender/python/intern/bpy_intern_string.h @@ -37,6 +37,8 @@ extern PyObject *bpy_intern_str_bl_property; extern PyObject *bpy_intern_str_bpy_types; extern PyObject *bpy_intern_str_order; extern PyObject *bpy_intern_str_attr; +extern PyObject *bpy_intern_str_self; +extern PyObject *bpy_intern_str_frame; extern PyObject *bpy_intern_str___slots__; extern PyObject *bpy_intern_str___name__; extern PyObject *bpy_intern_str___doc__; diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 37a7e0e23dd..ec69abbb1df 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -210,7 +210,7 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject * ret->flag = ((is_link ? FILE_LINK : 0) | (is_rel ? FILE_RELPATH : 0)); - ret->dict = PyDict_New(); + ret->dict = _PyDict_NewPresized(MAX_LIBARRAY); return (PyObject *)ret; } @@ -240,7 +240,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args)) { PyObject *ret; BPy_Library *self_from; - PyObject *from_dict = PyDict_New(); + PyObject *from_dict = _PyDict_NewPresized(MAX_LIBARRAY); ReportList reports; BKE_reports_init(&reports, RPT_STORE); diff --git a/source/blender/python/intern/bpy_rna_driver.c b/source/blender/python/intern/bpy_rna_driver.c index 482508a8d85..b4c0de51c04 100644 --- a/source/blender/python/intern/bpy_rna_driver.c +++ b/source/blender/python/intern/bpy_rna_driver.c @@ -77,3 +77,24 @@ PyObject *pyrna_driver_get_variable_value( return driver_arg; } + +PyObject *pyrna_driver_self_from_anim_rna(PathResolvedRNA *anim_rna) +{ + return pyrna_struct_CreatePyObject(&anim_rna->ptr); +} + +bool pyrna_driver_is_equal_anim_rna(const PathResolvedRNA *anim_rna, const PyObject *py_anim_rna) +{ + if (BPy_StructRNA_Check(py_anim_rna)) { + const PointerRNA *ptr_a = &anim_rna->ptr; + const PointerRNA *ptr_b = &(((const BPy_StructRNA *)py_anim_rna)->ptr); + + if ((ptr_a->id.data == ptr_b->id.data) && + (ptr_a->type == ptr_b->type) && + (ptr_a->data == ptr_b->data)) + { + return true; + } + } + return false; +} diff --git a/source/blender/python/intern/bpy_rna_driver.h b/source/blender/python/intern/bpy_rna_driver.h index 8deac2e4384..3f4bf2b9df5 100644 --- a/source/blender/python/intern/bpy_rna_driver.h +++ b/source/blender/python/intern/bpy_rna_driver.h @@ -27,7 +27,11 @@ struct ChannelDriver; struct DriverTarget; +struct PathResolvedRNA; PyObject *pyrna_driver_get_variable_value(struct ChannelDriver *driver, struct DriverTarget *dtar); +PyObject *pyrna_driver_self_from_anim_rna(struct PathResolvedRNA *anim_rna); +bool pyrna_driver_is_equal_anim_rna(const struct PathResolvedRNA *anim_rna, const PyObject *py_anim_rna); + #endif /* __BPY_RNA_DRIVER_H__ */ diff --git a/source/blender/python/intern/bpy_rna_id_collection.c b/source/blender/python/intern/bpy_rna_id_collection.c index 104e3e47646..31189ba4dee 100644 --- a/source/blender/python/intern/bpy_rna_id_collection.c +++ b/source/blender/python/intern/bpy_rna_id_collection.c @@ -198,7 +198,7 @@ static PyObject *bpy_user_map(PyObject *UNUSED(self), PyObject *args, PyObject * PyObject **subset_array = PySequence_Fast_ITEMS(subset_fast); Py_ssize_t subset_len = PySequence_Fast_GET_SIZE(subset_fast); - data_cb.user_map = PyDict_New(); + data_cb.user_map = _PyDict_NewPresized(subset_len); data_cb.is_subset = true; for (; subset_len; subset_array++, subset_len--) { PyObject *set = PySet_New(NULL); |