From faaa12a10131b93757a8395f3448040436981e5f Mon Sep 17 00:00:00 2001 From: Julien Duroure Date: Mon, 2 Dec 2024 12:50:15 +0100 Subject: [PATCH] glTF: Install Draco lib in the same directory as the glTF2 addon This changes the location of the Draco library installation path. The new location is at the root of addons_core/io_scene_gltf2 addon, as the library is created for this addon only. This will solve issues where the gltf addon couldn't find the library in case of global python installation or custom script/lib paths Pull Request: https://projects.blender.org/blender/blender/pulls/131080 --- CMakeLists.txt | 7 --- .../addons_core/io_scene_gltf2/__init__.py | 4 +- .../io_scene_gltf2/io/com/draco.py | 44 ++--------------- source/creator/CMakeLists.txt | 48 ++++--------------- 4 files changed, 15 insertions(+), 88 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 97596dbee8d..d1ad6ac5de0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1237,13 +1237,6 @@ set_and_warn_dependency(WITH_PYTHON WITH_CYCLES OFF) set_and_warn_dependency(WITH_PYTHON WITH_DRACO OFF) set_and_warn_dependency(WITH_PYTHON WITH_MOD_FLUID OFF) -if(NOT WITH_PYTHON_MODULE) - if(WITH_DRACO AND NOT WITH_PYTHON_INSTALL) - message(STATUS "WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now") - set(WITH_DRACO OFF) - endif() -endif() - # enable boost for cycles, audaspace or i18n # otherwise if the user disabled diff --git a/scripts/addons_core/io_scene_gltf2/__init__.py b/scripts/addons_core/io_scene_gltf2/__init__.py index 4537b6e3a2a..0940a1791f8 100755 --- a/scripts/addons_core/io_scene_gltf2/__init__.py +++ b/scripts/addons_core/io_scene_gltf2/__init__.py @@ -5,8 +5,8 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Scurest, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (4, 4, 23), - 'blender': (4, 3, 0), + "version": (4, 4, 24), + 'blender': (4, 4, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', 'warning': '', diff --git a/scripts/addons_core/io_scene_gltf2/io/com/draco.py b/scripts/addons_core/io_scene_gltf2/io/com/draco.py index 75e23162c67..53f58860c43 100644 --- a/scripts/addons_core/io_scene_gltf2/io/com/draco.py +++ b/scripts/addons_core/io_scene_gltf2/io/com/draco.py @@ -8,59 +8,25 @@ from pathlib import Path import bpy -def find_draco_dll_in_module(library_name: str) -> Path: - """ - Get the extern Draco library if it exist in the default location used when - build PYthon as a module - :return: DLL/shared library path. - """ - bpy_path = Path(bpy.__file__).resolve() - bpy_dir = bpy_path.parents[4] - lib_dir = bpy_dir / 'lib' - - draco_path = lib_dir / library_name - if draco_path.exists(): - return draco_path - - return None - - def dll_path() -> Path: """ - Get the DLL path depending on the underlying platform. - :return: DLL path. + Get the library path, that should be at addon root + :return: library path. """ lib_name = 'extern_draco' - blender_root = Path(bpy.app.binary_path).parent - python_lib = Path('{v[0]}.{v[1]}/python/lib'.format(v=bpy.app.version)) - python_version = 'python{v[0]}.{v[1]}'.format(v=sys.version_info) - - path = os.environ.get('BLENDER_EXTERN_DRACO_LIBRARY_PATH') - if path is not None: - return Path(path) - library_name = { 'win32': '{}.dll'.format(lib_name), 'linux': 'lib{}.so'.format(lib_name), 'darwin': 'lib{}.dylib'.format(lib_name) }.get(sys.platform) - path = find_draco_dll_in_module(library_name) + path = os.path.dirname(sys.modules['io_scene_gltf2'].__file__) if path is not None: - return path + return Path(os.path.join(path, library_name)) - path = { - 'win32': blender_root / python_lib / 'site-packages', - 'linux': blender_root / python_lib / python_version / 'site-packages', - 'darwin': blender_root.parent / 'Resources' / python_lib / python_version / 'site-packages' - }.get(sys.platform) - - if path is None or library_name is None: + if library_name is None: print('WARNING', 'Unsupported platform {}, Draco mesh compression is unavailable'.format(sys.platform)) - return path / library_name - - def dll_exists(quiet=False) -> bool: """ Checks whether the DLL path exists. diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index c3fcdc755db..65b2f35c7d7 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -479,6 +479,14 @@ if(WITH_PYTHON) endif() endif() unset(FREESTYLE_EXCLUDE_CONDITIONAL) + + if(WITH_DRACO) + install( + PROGRAMS $ + DESTINATION ${TARGETDIR_VER}/scripts/addons_core/io_scene_gltf2 + ) + endif() + endif() # fonts @@ -983,19 +991,6 @@ file(REMOVE ${CMAKE_BINARY_DIR}/bin/lib/libglapi.so.0.0.0)\n endif() endif() - if(WITH_DRACO) - if(WITH_PYTHON_MODULE) - install( - PROGRAMS $ - DESTINATION ${CMAKE_BINARY_DIR}/bin/bpy/lib - ) - else() - install( - PROGRAMS $ - DESTINATION ${TARGETDIR_VER}/python/lib/python${PYTHON_VERSION}/site-packages - ) - endif() - endif() elseif(WIN32) if(WITH_WINDOWS_EXTERNAL_MANIFEST) install( @@ -1536,20 +1531,6 @@ elseif(WIN32) ) endif() - if(WITH_DRACO) - if(WITH_PYTHON_MODULE) - install( - PROGRAMS $ - DESTINATION ${CMAKE_BINARY_DIR}/bin/bpy/lib - ) - else() - install( - PROGRAMS $ - DESTINATION ${TARGETDIR_VER}/python/lib/site-packages - ) - endif() - endif() - if(WITH_PYTHON_MODULE AND TARGETDIR_BPY) install( TARGETS blender @@ -1680,19 +1661,6 @@ elseif(APPLE) ) endif() - if(WITH_DRACO) - if(WITH_PYTHON_MODULE) - install( - PROGRAMS $ - DESTINATION ${CMAKE_BINARY_DIR}/bin/bpy/lib - ) - else() - install( - PROGRAMS $ - DESTINATION ${TARGETDIR_VER}/python/lib/python${PYTHON_VERSION}/site-packages - ) - endif() - endif() endif() # -----------------------------------------------------------------------------