diff options
author | YimingWu <xp8110@outlook.com> | 2020-02-01 05:35:40 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2020-02-01 05:35:40 +0300 |
commit | f7770cb97bb9d19d0806f67da9377129fd4d09b0 (patch) | |
tree | 2cd22d612ffba3a509d5548332c9cc8a06a1a638 /source/blender/python | |
parent | b47883a990ee68e659a8a8b44729be9b8e0d002f (diff) | |
parent | dc3f073d1c5255e79763dfff3ef17f6216f1b391 (diff) |
Merge remote-tracking branch 'origin/master' into temp-lanpr-review
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/BPY_extern.h | 1 | ||||
-rw-r--r-- | source/blender/python/bmesh/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_api.c | 4 | ||||
-rw-r--r-- | source/blender/python/generic/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/python/gpu/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/python/intern/CMakeLists.txt | 16 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app.c | 3 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_usd.c | 107 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_app_usd.h | 29 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_interface.c | 13 | ||||
-rw-r--r-- | source/blender/python/mathutils/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 3 |
12 files changed, 183 insertions, 3 deletions
diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index be2fd6c4e53..810c86c115a 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -51,6 +51,7 @@ int BPY_is_pyconstraint(struct Text *text); void BPY_python_start(int argc, const char **argv); void BPY_python_end(void); void BPY_python_reset(struct bContext *C); +void BPY_python_use_system_env(void); /* global interpreter lock */ diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt index 3875057185a..818498fe7db 100644 --- a/source/blender/python/bmesh/CMakeLists.txt +++ b/source/blender/python/bmesh/CMakeLists.txt @@ -55,6 +55,9 @@ set(LIB bf_blenkernel bf_blenlib bf_python_mathutils + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) if(WITH_FREESTYLE) diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c index 8ab5e7adea7..7f5b10e6759 100644 --- a/source/blender/python/bmesh/bmesh_py_api.c +++ b/source/blender/python/bmesh/bmesh_py_api.c @@ -148,9 +148,9 @@ static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args, { extern void EDBM_update_generic( - BMEditMesh * em, const bool do_tessface, const bool is_destructive); + struct Mesh * me, const bool do_tessface, const bool is_destructive); - EDBM_update_generic(me->edit_mesh, do_loop_triangles, is_destructive); + EDBM_update_generic(me, do_loop_triangles, is_destructive); } Py_RETURN_NONE; diff --git a/source/blender/python/generic/CMakeLists.txt b/source/blender/python/generic/CMakeLists.txt index c878103e19d..822f05bad90 100644 --- a/source/blender/python/generic/CMakeLists.txt +++ b/source/blender/python/generic/CMakeLists.txt @@ -50,6 +50,8 @@ set(SRC set(LIB ${GLEW_LIBRARY} + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt index ca0e6ced42b..22a3d3a79de 100644 --- a/source/blender/python/gpu/CMakeLists.txt +++ b/source/blender/python/gpu/CMakeLists.txt @@ -55,6 +55,8 @@ set(SRC ) set(LIB + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) add_definitions(${GL_DEFINITIONS}) diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 9aa364c4436..cfb61edee62 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -56,6 +56,7 @@ set(SRC bpy_app_sdl.c bpy_app_timers.c bpy_app_translations.c + bpy_app_usd.c bpy_capi_utils.c bpy_driver.c bpy_gizmo_wrap.c @@ -95,6 +96,7 @@ set(SRC bpy_app_sdl.h bpy_app_timers.h bpy_app_translations.h + bpy_app_usd.h bpy_capi_utils.h bpy_driver.h bpy_gizmo_wrap.h @@ -123,6 +125,9 @@ set(LIB bf_editor_interface bf_editor_space_api bf_python_gpu + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) # only to check if buildinfo is available @@ -156,6 +161,9 @@ if(WITH_CODEC_FFMPEG) list(APPEND INC_SYS ${FFMPEG_INCLUDE_DIRS} ) + list(APPEND LIB + ${FFMPEG_LIBRARIES} + ) add_definitions(-DWITH_FFMPEG) endif() @@ -244,6 +252,11 @@ if(WITH_SDL) list(APPEND INC_SYS ${SDL_INCLUDE_DIR} ) + if(NOT WITH_SDL_DYNLOAD) + list(APPEND LIB + ${SDL_LIBRARY} + ) + endif() add_definitions(-DWITH_SDL) endif() @@ -302,6 +315,9 @@ endif() if(WITH_USD) add_definitions(-DWITH_USD) + list(APPEND INC + ../../usd + ) endif() if(WITH_OPENIMAGEIO) diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index 043b31007f1..678df0d8993 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -33,6 +33,7 @@ #include "bpy_app_opensubdiv.h" #include "bpy_app_openvdb.h" #include "bpy_app_sdl.h" +#include "bpy_app_usd.h" #include "bpy_app_build_options.h" #include "bpy_app_translations.h" @@ -108,6 +109,7 @@ static PyStructSequence_Field app_info_fields[] = { /* submodules */ {"alembic", "Alembic library information backend"}, + {"usd", "USD library information backend"}, {"ffmpeg", "FFmpeg library information backend"}, {"ocio", "OpenColorIO library information backend"}, {"oiio", "OpenImageIO library information backend"}, @@ -201,6 +203,7 @@ static PyObject *make_app_info(void) #endif SetObjItem(BPY_app_alembic_struct()); + SetObjItem(BPY_app_usd_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_usd.c b/source/blender/python/intern/bpy_app_usd.c new file mode 100644 index 00000000000..d87d218a5e5 --- /dev/null +++ b/source/blender/python/intern/bpy_app_usd.c @@ -0,0 +1,107 @@ +/* + * 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. + */ + +/** \file + * \ingroup pythonintern + */ + +#include <Python.h> +#include "BLI_utildefines.h" + +#include "bpy_app_usd.h" + +#include "../generic/py_capi_utils.h" + +#ifdef WITH_USD +# include "usd.h" +#endif + +static PyTypeObject BlenderAppUSDType; + +static PyStructSequence_Field app_usd_info_fields[] = { + {"supported", "Boolean, True when Blender is built with USD support"}, + {"version", "The USD version as a tuple of 3 numbers"}, + {"version_string", "The USD version formatted as a string"}, + {NULL}, +}; + +static PyStructSequence_Desc app_usd_info_desc = { + "bpy.app.usd", /* name */ + "This module contains information about the Universal Scene Description library Bender is " + "linked against", /* doc */ + app_usd_info_fields, /* fields */ + ARRAY_SIZE(app_usd_info_fields) - 1, +}; + +static PyObject *make_usd_info(void) +{ + PyObject *usd_info = PyStructSequence_New(&BlenderAppUSDType); + + if (usd_info == NULL) { + return NULL; + } + + int pos = 0; + +#ifndef WITH_USD +# define SetStrItem(str) PyStructSequence_SET_ITEM(usd_info, pos++, PyUnicode_FromString(str)) +#endif + +#define SetObjItem(obj) PyStructSequence_SET_ITEM(usd_info, pos++, obj) + +#ifdef WITH_USD + const int curversion = USD_get_version(); + const int major = curversion / 10000; + const int minor = (curversion / 100) % 100; + const int patch = curversion % 100; + + SetObjItem(PyBool_FromLong(1)); + SetObjItem(PyC_Tuple_Pack_I32(major, minor, patch)); + SetObjItem(PyUnicode_FromFormat("%2d, %2d, %2d", major, minor, patch)); +#else + SetObjItem(PyBool_FromLong(0)); + SetObjItem(PyC_Tuple_Pack_I32(0, 0, 0)); + SetStrItem("Unknown"); +#endif + + if (PyErr_Occurred()) { + Py_CLEAR(usd_info); + return NULL; + } + +#undef SetStrItem +#undef SetObjItem + + return usd_info; +} + +PyObject *BPY_app_usd_struct(void) +{ + PyStructSequence_InitType(&BlenderAppUSDType, &app_usd_info_desc); + + PyObject *ret = make_usd_info(); + + /* prevent user from creating new instances */ + BlenderAppUSDType.tp_init = NULL; + BlenderAppUSDType.tp_new = NULL; + BlenderAppUSDType.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_usd.h b/source/blender/python/intern/bpy_app_usd.h new file mode 100644 index 00000000000..e3e1d72b366 --- /dev/null +++ b/source/blender/python/intern/bpy_app_usd.h @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/** \file + * \ingroup pythonintern + */ + +#ifndef __BPY_APP_USD_H__ +#define __BPY_APP_USD_H__ + +PyObject *BPY_app_usd_struct(void); + +#endif /* __BPY_APP_USD_H__ */ diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c index 9acf05abfe2..28afab1a6eb 100644 --- a/source/blender/python/intern/bpy_interface.c +++ b/source/blender/python/intern/bpy_interface.c @@ -84,6 +84,9 @@ CLG_LOGREF_DECLARE_GLOBAL(BPY_LOG_RNA, "bpy.rna"); * stop bpy_context_clear from invalidating. */ static int py_call_level = 0; +/* Set by command line arguments before Python starts. */ +static bool py_use_system_env = false; + // #define TIME_PY_RUN // simple python tests. prints on exit. #ifdef TIME_PY_RUN @@ -276,6 +279,10 @@ void BPY_python_start(int argc, const char **argv) * While harmless, it's noisy. */ Py_FrozenFlag = 1; + /* Only use the systems environment variables when explicitly requested. + * Since an incorrect 'PYTHONPATH' causes difficult to debug errors, see: T72807. */ + Py_IgnoreEnvironmentFlag = !py_use_system_env; + Py_Initialize(); // PySys_SetArgv(argc, argv); /* broken in py3, not a huge deal */ @@ -408,6 +415,12 @@ void BPY_python_reset(bContext *C) BPY_modules_load_user(C); } +void BPY_python_use_system_env(void) +{ + BLI_assert(!Py_IsInitialized()); + py_use_system_env = true; +} + static void python_script_error_jump_text(struct Text *text) { int lineno; diff --git a/source/blender/python/mathutils/CMakeLists.txt b/source/blender/python/mathutils/CMakeLists.txt index cdb562a3233..e34432f0c54 100644 --- a/source/blender/python/mathutils/CMakeLists.txt +++ b/source/blender/python/mathutils/CMakeLists.txt @@ -58,6 +58,9 @@ set(SRC set(LIB bf_blenlib bf_python_ext + + ${PYTHON_LINKFLAGS} + ${PYTHON_LIBRARIES} ) diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index fcb6a77bf36..859ece61ace 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -1246,7 +1246,8 @@ PyDoc_STRVAR(M_Geometry_tessellate_polygon_doc, ".. function:: tessellate_polygon(veclist_list)\n" "\n" " Takes a list of polylines (each point a pair or triplet of numbers) and returns " - "the point indices for a polyline filled with triangles.\n" + "the point indices for a polyline filled with triangles. Does not handle degenerate " + "geometry (such as zero-length lines due to consecutive identical points).\n" "\n" " :arg veclist_list: list of polylines\n" " :rtype: list\n"); |