glTF: Fix #113469: enable Draco compression for bpy as a py module

By looking in correct directory for bpy module
This was of course already available for Blender itself since few years
This commit is contained in:
Julien Duroure
2024-10-31 13:11:59 +01:00
parent ab89e367da
commit b25da97fef
2 changed files with 29 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
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, 3, 36),
"version": (4, 3, 37),
'blender': (4, 2, 0),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@@ -8,6 +8,23 @@ 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.
@@ -19,13 +36,7 @@ def dll_path() -> Path:
python_version = 'python{v[0]}.{v[1]}'.format(v=sys.version_info)
path = os.environ.get('BLENDER_EXTERN_DRACO_LIBRARY_PATH')
if path is None:
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)
else:
if path is not None:
return Path(path)
library_name = {
@@ -34,6 +45,16 @@ def dll_path() -> Path:
'darwin': 'lib{}.dylib'.format(lib_name)
}.get(sys.platform)
path = find_draco_dll_in_module(library_name)
if path is not None:
return path
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:
print('WARNING', 'Unsupported platform {}, Draco mesh compression is unavailable'.format(sys.platform))