diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index a875b9a6666f619644326561f5aec4bc24a62e9f..7a3cd13a125b1e9d6ed2d33c8b0cbc9e7a9eae80 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 fa0f9976db418081bed81dedb51619cb2cea8625..5fcd4ededf5c9787f69e7c9345eb69411946b3ec 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 d217b217d058867253b955de780be26dfc7f047e..50918b68f0d58bee2c54e6f22e471ad4e83d9f51 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 5d5d310cdcb7e496842b20cf1e15f50ecb5c42fc..cd237f35b235bd3eb3a1668e59db20daf200f2b8 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 a2e903e58aa0871ea31af1b67b894745cad89d20..bf78dabdded7617c2d764122587d79b397f9508e 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 3cde0fcbaa15a16074bbc8b6707502299e0e8415..6075440c328b53d6b3d089366eca9f447a8a7aad 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 9309eb642c6af726b56ddf2ac67a048d48d963f6..183da33e2ce3e27b11d117f20e0df304e5150bfc 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 ee948ff2ae6a5c965a750f9901f0b5879174e950..4a46814cb4ac59cb53d920baba9f67de5aede96a 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 4c4297ce960105d22353e6d07985ac53a8a8ed5f..da603bdf498d55576b4ccb0997daa09e32619ae7 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 9b9a9abee2408873463392b5d98eb2eae6719ea3..fceb46f1749092d6d8b6cf855d6c7937cc9d8488 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 04a0fcd171696c2295b5255297f73808a6a76a12..77c7fe55ad3226a9014f28c54573f8c11c765f34 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 3af26ced607fef2fb2a31906162012bea8cf3352..50df1395e278499f2c26cb5a92e98f7a3156f047 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 f19011802377eb9295dae6cde48212e33265fe1b..b30f6a0e36440dc3f85ea4da060a043d51f6bf4a 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 78fbc2823e6b8202468c184f054ff10000c24970..80b74e9cb4bb6164234bd61dc86739cd54a80b02 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 18503fddefe7d25b8b27409fe5d07da9bf8a77b5..1ee54b89d1e79d151464e13c95115cbe14c619c2 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 fbf8483ab0a861ea6b1033220d2fc2a93def3a60..b906413f868c2ab2480016931343cfb7229458dd 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 124c8ba0404f7081fcc4938e8afa7074e8f102a0..66b9b4ebd7d0a081fa19163e6a7d8a1511ba893d 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 0000000000000000000000000000000000000000..f8f5e883802f1e36fa9cf10272080f45818dc7c8 --- /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) +