diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-12-14 10:42:04 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-12-14 10:42:04 +0300 |
commit | 18246268e802958bf02ffa14c764d2cc32ddb4d4 (patch) | |
tree | 9359d37137116430f478945f938e71a1d3be8929 /io_scene_gltf2/blender | |
parent | 13b7618409aac26eb512133373828ab9e92a6ac7 (diff) |
glTF exporter: define a user extension API
Diffstat (limited to 'io_scene_gltf2/blender')
16 files changed, 108 insertions, 7 deletions
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 fa0f9976..5fcd4ede 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 d217b217..50918b68 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 5d5d310c..cd237f35 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 a2e903e5..bf78dabd 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 3cde0fcb..6075440c 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 9309eb64..183da33e 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 ee948ff2..4a46814c 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 4c4297ce..da603bdf 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 9b9a9abe..fceb46f1 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 04a0fcd1..77c7fe55 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 3af26ced..50df1395 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 f1901180..b30f6a0e 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 78fbc282..80b74e9c 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 18503fdd..1ee54b89 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 fbf8483a..b906413f 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 124c8ba0..66b9b4eb 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 |