diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-03-12 23:59:04 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-03-12 23:59:04 +0300 |
commit | 1ae12e6f5d3c131b0b3e390a7c5e8cdb992d21e5 (patch) | |
tree | 86b0115eda96dd3411a343c9205505bbf5f03547 | |
parent | bd54740ed08be078a870fcb3d83c7bd4ad304d43 (diff) |
glTF exporter: manage user extension at gltf level
-rwxr-xr-x | io_scene_gltf2/__init__.py | 2 | ||||
-rwxr-xr-x | io_scene_gltf2/blender/exp/gltf2_blender_export.py | 5 | ||||
-rw-r--r-- | io_scene_gltf2/io/exp/gltf2_io_user_extensions.py | 13 |
3 files changed, 15 insertions, 5 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 40e40158..e60bf8b8 100755 --- a/io_scene_gltf2/__init__.py +++ b/io_scene_gltf2/__init__.py @@ -15,7 +15,7 @@ bl_info = { 'name': 'glTF 2.0 format', 'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors', - "version": (1, 2, 41), + "version": (1, 2, 42), 'blender': (2, 82, 7), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_export.py b/io_scene_gltf2/blender/exp/gltf2_blender_export.py index 0e415e7a..6d9ab8bb 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_export.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_export.py @@ -24,6 +24,7 @@ from io_scene_gltf2.blender.exp.gltf2_blender_gltf2_exporter import GlTF2Exporte from io_scene_gltf2.io.com.gltf2_io_debug import print_console, print_newline from io_scene_gltf2.io.exp import gltf2_io_export from io_scene_gltf2.io.exp import gltf2_io_draco_compression_extension +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions def save(context, export_settings): @@ -61,6 +62,10 @@ def __export(export_settings): def __gather_gltf(exporter, export_settings): active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings) + plan = {'active_scene_idx': active_scene_idx, 'scenes': scenes, 'animations': animations} + export_user_extensions('gather_gltf_hook', export_settings, plan) + active_scene_idx, scenes, animations = plan['active_scene_idx'], plan['scenes'], plan['animations'] + if export_settings['gltf_draco_mesh_compression']: gltf2_io_draco_compression_extension.compress_scene_primitives(scenes, export_settings) exporter.add_draco_extension() diff --git a/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py b/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py index 424713c3..a149673f 100644 --- a/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py +++ b/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py @@ -12,11 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -def export_user_extensions(hook_name, export_settings, gltf2_object, *args): - if gltf2_object.extensions is None: - gltf2_object.extensions = {} +def export_user_extensions(hook_name, export_settings, *args): + if args and hasattr(args[0], "extensions"): + if args[0].extensions is None: + args[0].extensions = {} for extension in export_settings['gltf_user_extensions']: hook = getattr(extension, hook_name, None) if hook is not None: - hook(gltf2_object, *args, export_settings) + try: + hook(*args, export_settings) + except Exception as e: + print(hook_name, "fails on", extension) + print(str(e)) |