File headers: use SPDX license identifiers
[blender-addons.git] / io_scene_gltf2 / io / com / gltf2_io_draco_compression_extension.py
blob28f06e5106e791329528dd006b330c63674e5a35
1 # SPDX-License-Identifier: Apache-2.0
2 # Copyright 2018-2021 The glTF-Blender-IO authors.
4 import os
5 import sys
6 from pathlib import Path
7 import bpy
9 from ...io.com.gltf2_io_debug import print_console
12 def dll_path() -> Path:
13 """
14 Get the DLL path depending on the underlying platform.
15 :return: DLL path.
16 """
17 lib_name = 'extern_draco'
18 blender_root = Path(bpy.app.binary_path).parent
19 python_lib = Path('{v[0]}.{v[1]}/python/lib'.format(v=bpy.app.version))
20 python_version = 'python{v[0]}.{v[1]}'.format(v=sys.version_info)
22 path = os.environ.get('BLENDER_EXTERN_DRACO_LIBRARY_PATH')
23 if path is None:
24 path = {
25 'win32': blender_root / python_lib / 'site-packages',
26 'linux': blender_root / python_lib / python_version / 'site-packages',
27 'darwin': blender_root.parent / 'Resources' / python_lib / python_version / 'site-packages'
28 }.get(sys.platform)
29 else:
30 path = Path(path)
32 library_name = {
33 'win32': '{}.dll'.format(lib_name),
34 'linux': 'lib{}.so'.format(lib_name),
35 'darwin': 'lib{}.dylib'.format(lib_name)
36 }.get(sys.platform)
38 if path is None or library_name is None:
39 print_console('WARNING', 'Unsupported platform {}, Draco mesh compression is unavailable'.format(sys.platform))
41 return path / library_name
44 def dll_exists(quiet=False) -> bool:
45 """
46 Checks whether the DLL path exists.
47 :return: True if the DLL exists.
48 """
49 exists = dll_path().exists()
50 if quiet is False:
51 print("'{}' ".format(dll_path().absolute()) + ("exists, draco mesh compression is available" if exists else
52 "{} {} {}".format(
53 "does not exist, draco mesh compression not available,",
54 "please add it or create environment variable BLENDER_EXTERN_DRACO_LIBRARY_PATH",
55 "pointing to the folder"
56 )))
57 return exists