Skip to content

Commit

Permalink
Merge pull request #2429 from KhronosGroup/draco_lib_at_addon_root
Browse files Browse the repository at this point in the history
Search draco lib at addon root
  • Loading branch information
julienduroure authored Dec 2, 2024
2 parents 94281c0 + bfa37d9 commit a84276f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 41 deletions.
4 changes: 2 additions & 2 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,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': '',
Expand Down
44 changes: 5 additions & 39 deletions addons/io_scene_gltf2/io/com/draco.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,59 +18,25 @@
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

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)
return Path(os.path.join(path, library_name))

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.
Expand Down

0 comments on commit a84276f

Please sign in to comment.