From 18246268e802958bf02ffa14c764d2cc32ddb4d4 Mon Sep 17 00:00:00 2001 From: Julien Duroure <julien.duroure@gmail.com> Date: Sat, 14 Dec 2019 08:42:04 +0100 Subject: [PATCH] glTF exporter: define a user extension API --- io_scene_gltf2/__init__.py | 46 ++++++++++++++++++- ...blender_gather_animation_channel_target.py | 13 +++++- ...gltf2_blender_gather_animation_channels.py | 16 ++++++- ...gltf2_blender_gather_animation_samplers.py | 16 ++++++- .../exp/gltf2_blender_gather_animations.py | 3 ++ .../exp/gltf2_blender_gather_cameras.py | 7 ++- .../blender/exp/gltf2_blender_gather_image.py | 7 ++- ...ther_material_normal_texture_info_class.py | 6 +++ ...r_material_occlusion_texture_info_class.py | 6 +++ .../exp/gltf2_blender_gather_materials.py | 3 ++ ...gather_materials_pbr_metallic_roughness.py | 3 ++ .../blender/exp/gltf2_blender_gather_mesh.py | 12 +++++ .../blender/exp/gltf2_blender_gather_nodes.py | 3 ++ .../exp/gltf2_blender_gather_sampler.py | 7 ++- .../blender/exp/gltf2_blender_gather_skins.py | 7 ++- .../exp/gltf2_blender_gather_texture.py | 3 ++ .../exp/gltf2_blender_gather_texture_info.py | 3 ++ .../io/exp/gltf2_io_user_extensions.py | 23 ++++++++++ 18 files changed, 176 insertions(+), 8 deletions(-) create mode 100644 io_scene_gltf2/io/exp/gltf2_io_user_extensions.py diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index a875b9a66..7a3cd13a1 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, 1, 23), + "version": (1, 1, 24), 'blender': (2, 81, 6), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', @@ -67,6 +67,7 @@ from bpy_extras.io_utils import ImportHelper, ExportHelper # Functions / Classes. # +extension_panel_unregister_functors = [] class ExportGLTF2_Base: # TODO: refactor to avoid boilerplate @@ -334,6 +335,7 @@ class ExportGLTF2_Base: def invoke(self, context, event): settings = context.scene.get(self.scene_key) self.will_save_settings = False + self.has_active_extenions = False if settings: try: for (k, v) in settings.items(): @@ -344,6 +346,15 @@ class ExportGLTF2_Base: self.report({"ERROR"}, "Loading export settings failed. Removed corrupted settings") del context.scene[self.scene_key] + import sys + for addon_name in bpy.context.preferences.addons.keys(): + try: + if hasattr(sys.modules[addon_name], 'glTF2ExportUserExtension'): + extension_panel_unregister_functors.append(sys.modules[addon_name].register_panel()) + self.has_active_extenions = True + except Exception: + pass + return ExportHelper.invoke(self, context, event) def save_settings(self, context): @@ -438,6 +449,15 @@ class ExportGLTF2_Base: export_settings['gltf_binaryfilename'] = os.path.splitext(os.path.basename( bpy.path.ensure_ext(self.filepath,self.filename_ext)))[0] + '.bin' + user_extensions = [] + + import sys + for addon_name in bpy.context.preferences.addons.keys(): + if hasattr(sys.modules[addon_name], 'glTF2ExportUserExtension'): + extension_ctor = sys.modules[addon_name].glTF2ExportUserExtension + user_extensions.append(extension_ctor()) + export_settings['gltf_user_extensions'] = user_extensions + return gltf2_blender_export.save(context, export_settings) @@ -734,6 +754,25 @@ class GLTF_PT_export_animation_skinning(bpy.types.Panel): layout.active = operator.export_skins layout.prop(operator, 'export_all_influences') +class GLTF_PT_export_user_extensions(bpy.types.Panel): + bl_space_type = 'FILE_BROWSER' + bl_region_type = 'TOOL_PROPS' + bl_label = "Extensions" + bl_parent_id = "FILE_PT_operator" + bl_options = {'DEFAULT_CLOSED'} + + @classmethod + def poll(cls, context): + sfile = context.space_data + operator = sfile.active_operator + + return operator.bl_idname == "EXPORT_SCENE_OT_gltf" and operator.has_active_extenions + + def draw(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False # No animation. + class ExportGLTF2(bpy.types.Operator, ExportGLTF2_Base, ExportHelper): """Export scene as glTF 2.0 file""" @@ -859,6 +898,7 @@ classes = ( GLTF_PT_export_animation_export, GLTF_PT_export_animation_shapekeys, GLTF_PT_export_animation_skinning, + GLTF_PT_export_user_extensions, ImportGLTF2 ) @@ -876,6 +916,10 @@ def register(): def unregister(): for c in classes: bpy.utils.unregister_class(c) + for f in extension_panel_unregister_functors: + f() + extension_panel_unregister_functors.clear() + # bpy.utils.unregister_module(__name__) # remove from the export / import menu diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py index fa0f9976d..5fcd4eded 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channel_target.py @@ -20,6 +20,7 @@ from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached from io_scene_gltf2.blender.exp import gltf2_blender_gather_nodes from io_scene_gltf2.blender.exp import gltf2_blender_gather_joints from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached def gather_animation_channel_target(channels: typing.Tuple[bpy.types.FCurve], @@ -29,13 +30,23 @@ def gather_animation_channel_target(channels: typing.Tuple[bpy.types.FCurve], export_settings ) -> gltf2_io.AnimationChannelTarget: - return gltf2_io.AnimationChannelTarget( + animation_channel_target = gltf2_io.AnimationChannelTarget( extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone), extras=__gather_extras(channels, blender_object, export_settings, bake_bone), node=__gather_node(channels, blender_object, export_settings, bake_bone), path=__gather_path(channels, blender_object, export_settings, bake_bone, bake_channel) ) + export_user_extensions('gather_animation_channel_target_hook', + export_settings, + animation_channel_target, + channels, + blender_object, + bake_bone, + bake_channel) + + return animation_channel_target + def __gather_extensions(channels: typing.Tuple[bpy.types.FCurve], blender_object: bpy.types.Object, export_settings, diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py index d217b217d..50918b68f 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_channels.py @@ -23,6 +23,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_samplers from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_channel_target from io_scene_gltf2.blender.exp import gltf2_blender_get from io_scene_gltf2.blender.exp import gltf2_blender_gather_skins +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -149,13 +150,26 @@ def __gather_animation_channel(channels: typing.Tuple[bpy.types.FCurve], if not __filter_animation_channel(channels, blender_object, export_settings): return None - return gltf2_io.AnimationChannel( + animation_channel = gltf2_io.AnimationChannel( extensions=__gather_extensions(channels, blender_object, export_settings, bake_bone), extras=__gather_extras(channels, blender_object, export_settings, bake_bone), sampler=__gather_sampler(channels, blender_object, export_settings, bake_bone, bake_channel, bake_range_start, bake_range_end, action_name), target=__gather_target(channels, blender_object, export_settings, bake_bone, bake_channel) ) + export_user_extensions('gather_animation_channel_hook', + export_settings, + animation_channel, + channels, + blender_object, + bake_bone, + bake_channel, + bake_range_start, + bake_range_end, + action_name) + + return animation_channel + def __filter_animation_channel(channels: typing.Tuple[bpy.types.FCurve], blender_object: bpy.types.Object, diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py index 5d5d310cd..cd237f35b 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animation_samplers.py @@ -27,6 +27,7 @@ from io_scene_gltf2.io.com import gltf2_io from io_scene_gltf2.io.com import gltf2_io_constants from io_scene_gltf2.io.exp import gltf2_io_binary_data from . import gltf2_blender_export_keys +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -55,7 +56,7 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve], export_settings) - return gltf2_io.AnimationSampler( + sampler = gltf2_io.AnimationSampler( extensions=__gather_extensions(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel), extras=__gather_extras(channels, blender_object_if_armature, export_settings, bake_bone, bake_channel), input=__gather_input(channels, blender_object_if_armature, non_keyed_values, @@ -72,6 +73,19 @@ def gather_animation_sampler(channels: typing.Tuple[bpy.types.FCurve], export_settings) ) + export_user_extensions('gather_animation_sampler_hook', + export_settings, + sampler, + channels, + blender_object, + bake_bone, + bake_channel, + bake_range_start, + bake_range_end, + action_name) + + return sampler + def __gather_non_keyed_values(channels: typing.Tuple[bpy.types.FCurve], blender_object: bpy.types.Object, blender_object_if_armature: typing.Optional[bpy.types.Object], diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py index a2e903e58..bf78dabdd 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_animations.py @@ -19,6 +19,7 @@ from io_scene_gltf2.io.com import gltf2_io from io_scene_gltf2.blender.exp import gltf2_blender_gather_animation_channels from io_scene_gltf2.io.com.gltf2_io_debug import print_console from ..com.gltf2_blender_extras import generate_extras +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions def gather_animations(blender_object: bpy.types.Object, @@ -108,6 +109,8 @@ def __gather_animation(blender_action: bpy.types.Action, if not animation.channels: return None + export_user_extensions('gather_animation_hook', export_settings, animation, blender_action, blender_object) + return animation diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py index 3cde0fcba..6075440c3 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cameras.py @@ -16,6 +16,7 @@ from . import gltf2_blender_export_keys from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached from ..com.gltf2_blender_extras import generate_extras from io_scene_gltf2.io.com import gltf2_io +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions import bpy import math @@ -26,7 +27,7 @@ def gather_camera(blender_camera, export_settings): if not __filter_camera(blender_camera, export_settings): return None - return gltf2_io.Camera( + camera = gltf2_io.Camera( extensions=__gather_extensions(blender_camera, export_settings), extras=__gather_extras(blender_camera, export_settings), name=__gather_name(blender_camera, export_settings), @@ -35,6 +36,10 @@ def gather_camera(blender_camera, export_settings): type=__gather_type(blender_camera, export_settings) ) + export_user_extensions('gather_camera_hook', export_settings, camera, blender_camera) + + return camera + def __filter_camera(blender_camera, export_settings): return bool(__gather_type(blender_camera, export_settings)) diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py index 9309eb642..183da33e2 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_image.py @@ -26,6 +26,7 @@ from io_scene_gltf2.io.exp import gltf2_io_image_data from io_scene_gltf2.io.com import gltf2_io_debug from io_scene_gltf2.blender.exp import gltf2_blender_image from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -47,7 +48,7 @@ def gather_image( uri = __gather_uri(image_data, mime_type, name, export_settings) buffer_view = __gather_buffer_view(image_data, mime_type, name, export_settings) - return __make_image( + image = __make_image( buffer_view, __gather_extensions(blender_shader_sockets_or_texture_slots, export_settings), __gather_extras(blender_shader_sockets_or_texture_slots, export_settings), @@ -57,6 +58,10 @@ def gather_image( export_settings ) + export_user_extensions('gather_image_hook', export_settings, image, blender_shader_sockets_or_texture_slots) + + return image + @cached def __make_image(buffer_view, extensions, extras, mime_type, name, uri, export_settings): return gltf2_io.Image( diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_normal_texture_info_class.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_normal_texture_info_class.py index ee948ff2a..4a46814cb 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_normal_texture_info_class.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_normal_texture_info_class.py @@ -21,6 +21,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree from io_scene_gltf2.blender.exp import gltf2_blender_export_keys from io_scene_gltf2.blender.exp import gltf2_blender_get from io_scene_gltf2.io.com.gltf2_io_extensions import Extension +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -41,6 +42,11 @@ def gather_material_normal_texture_info_class(blender_shader_sockets_or_texture_ if texture_info.index is None: return None + export_user_extensions('gather_material_normal_texture_info_class_hook', + export_settings, + texture_info, + blender_shader_sockets_or_texture_slots) + return texture_info diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_occlusion_texture_info_class.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_occlusion_texture_info_class.py index 4c4297ce9..da603bdf4 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_occlusion_texture_info_class.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_material_occlusion_texture_info_class.py @@ -20,6 +20,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree from io_scene_gltf2.blender.exp import gltf2_blender_get from io_scene_gltf2.io.com.gltf2_io_extensions import Extension +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -40,6 +41,11 @@ def gather_material_occlusion_texture_info_class(blender_shader_sockets_or_textu if texture_info.index is None: return None + export_user_extensions('gather_material_occlusion_texture_info_class_hook', + export_settings, + texture_info, + blender_shader_sockets_or_texture_slots) + return texture_info diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py index 9b9a9abee..fceb46f17 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials.py @@ -25,6 +25,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree from io_scene_gltf2.blender.exp import gltf2_blender_gather_materials_pbr_metallic_roughness from ..com.gltf2_blender_extras import generate_extras from io_scene_gltf2.blender.exp import gltf2_blender_get +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -55,6 +56,8 @@ def gather_material(blender_material, mesh_double_sided, export_settings): pbr_metallic_roughness=__gather_pbr_metallic_roughness(blender_material, orm_texture, export_settings) ) + export_user_extensions('gather_material_hook', export_settings, material, blender_material) + return material # material = blender_primitive['material'] # diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py index 04a0fcd17..77c7fe55a 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_materials_pbr_metallic_roughness.py @@ -20,6 +20,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_texture_info, gltf2_ from io_scene_gltf2.blender.exp import gltf2_blender_get from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached from io_scene_gltf2.io.com.gltf2_io_debug import print_console +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -37,6 +38,8 @@ def gather_material_pbr_metallic_roughness(blender_material, orm_texture, export roughness_factor=__gather_roughness_factor(blender_material, export_settings) ) + export_user_extensions('gather_material_pbr_metallic_roughness_hook', export_settings, material, blender_material, orm_texture) + return material diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py index 3af26ced6..50df1395e 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py @@ -20,6 +20,7 @@ from io_scene_gltf2.io.com import gltf2_io from io_scene_gltf2.blender.exp import gltf2_blender_gather_primitives from ..com.gltf2_blender_extras import generate_extras from io_scene_gltf2.io.com.gltf2_io_debug import print_console +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -45,6 +46,17 @@ def gather_mesh(blender_mesh: bpy.types.Mesh, if len(mesh.primitives) == 0: print_console("WARNING", "Mesh '{}' has no primitives and will be omitted.".format(mesh.name)) return None + + export_user_extensions('gather_mesh_hook', + export_settings, + mesh, + blender_mesh, + blender_object, + vertex_groups, + modifiers, + skip_filter, + material_names) + return mesh diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py index f19011802..b30f6a0e3 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py @@ -28,6 +28,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_lights from ..com.gltf2_blender_extras import generate_extras from io_scene_gltf2.io.com import gltf2_io from io_scene_gltf2.io.com import gltf2_io_extensions +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions def gather_node(blender_object, blender_scene, export_settings): @@ -86,6 +87,8 @@ def __gather_node(blender_object, blender_scene, export_settings): node.children.append(correction_node) node.camera = None + export_user_extensions('gather_node_hook', export_settings, node, blender_object) + return node diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_sampler.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_sampler.py index 78fbc2823..80b74e9cb 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_sampler.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_sampler.py @@ -15,6 +15,7 @@ import bpy from io_scene_gltf2.io.com import gltf2_io from io_scene_gltf2.blender.exp.gltf2_blender_gather_cache import cached +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -22,7 +23,7 @@ def gather_sampler(blender_shader_node: bpy.types.Node, export_settings): if not __filter_sampler(blender_shader_node, export_settings): return None - return gltf2_io.Sampler( + sampler = gltf2_io.Sampler( extensions=__gather_extensions(blender_shader_node, export_settings), extras=__gather_extras(blender_shader_node, export_settings), mag_filter=__gather_mag_filter(blender_shader_node, export_settings), @@ -32,6 +33,10 @@ def gather_sampler(blender_shader_node: bpy.types.Node, export_settings): wrap_t=__gather_wrap_t(blender_shader_node, export_settings) ) + export_user_extensions('gather_sampler_hook', export_settings, sampler, blender_shader_node) + + return sampler + def __filter_sampler(blender_shader_node, export_settings): if not blender_shader_node.interpolation == 'Closest' and not blender_shader_node.extension == 'CLIP': diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py index 18503fdde..1ee54b89d 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_skins.py @@ -21,6 +21,7 @@ from io_scene_gltf2.io.com import gltf2_io_constants from io_scene_gltf2.blender.exp import gltf2_blender_gather_accessors from io_scene_gltf2.blender.exp import gltf2_blender_gather_joints from io_scene_gltf2.blender.com import gltf2_blender_math +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -35,7 +36,7 @@ def gather_skin(blender_object, export_settings): if not __filter_skin(blender_object, export_settings): return None - return gltf2_io.Skin( + skin = gltf2_io.Skin( extensions=__gather_extensions(blender_object, export_settings), extras=__gather_extras(blender_object, export_settings), inverse_bind_matrices=__gather_inverse_bind_matrices(blender_object, export_settings), @@ -44,6 +45,10 @@ def gather_skin(blender_object, export_settings): skeleton=__gather_skeleton(blender_object, export_settings) ) + export_user_extensions('gather_skin_hook', export_settings, skin, blender_object) + + return skin + def __filter_skin(blender_object, export_settings): if not export_settings[gltf2_blender_export_keys.SKINS]: diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture.py index fbf8483ab..b906413f8 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture.py @@ -21,6 +21,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_gather_sampler from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree from io_scene_gltf2.blender.exp import gltf2_blender_gather_image from io_scene_gltf2.io.com import gltf2_io_debug +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -51,6 +52,8 @@ def gather_texture( if texture.source is None: return None + export_user_extensions('gather_texture_hook', export_settings, texture, blender_shader_sockets_or_texture_slots) + return texture diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py index 124c8ba04..66b9b4ebd 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_texture_info.py @@ -21,6 +21,7 @@ from io_scene_gltf2.blender.exp import gltf2_blender_search_node_tree from io_scene_gltf2.blender.exp import gltf2_blender_get from io_scene_gltf2.io.com.gltf2_io_debug import print_console from io_scene_gltf2.io.com.gltf2_io_extensions import Extension +from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions @cached @@ -40,6 +41,8 @@ def gather_texture_info(blender_shader_sockets_or_texture_slots: typing.Union[ if texture_info.index is None: return None + export_user_extensions('gather_texture_info_hook', export_settings, texture_info, blender_shader_sockets_or_texture_slots) + return texture_info diff --git a/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py b/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py new file mode 100644 index 000000000..f8f5e8838 --- /dev/null +++ b/io_scene_gltf2/io/exp/gltf2_io_user_extensions.py @@ -0,0 +1,23 @@ +# Copyright 2019 The glTF-Blender-IO authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# 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 = {} + + 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) + -- GitLab