Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-export & post-export hooks #2469

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions addons/io_scene_gltf2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ def execute(self, context):
import os
import datetime
import logging
from .io.exp.user_extensions import export_user_extensions
from .io.com.debug import Log
from .blender.exp import export as gltf2_blender_export
from .io.com.path import path_to_uri
Expand Down Expand Up @@ -1347,6 +1348,9 @@ def execute(self, context):
# Initialize logging for export
export_settings['log'] = Log(export_settings['loglevel'])

# Pre-export hook
export_user_extensions('pre_export_hook', export_settings)

profile = bpy.app.debug_value == 102
if profile:
import cProfile
Expand All @@ -1371,6 +1375,9 @@ def execute(self, context):

export_settings['log'].flush()

# Post-export hook
export_user_extensions('post_export_hook', export_settings)

return res

def draw(self, context):
Expand Down
6 changes: 6 additions & 0 deletions example-addons/example_gltf_exporter_extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ def gather_node_hook(self, gltf2_object, blender_object, export_settings):
extension={"float": self.properties.float_property},
required=extension_is_required
)

def glTF2_pre_export_callback(export_settings):
print("This will be called before exporting the glTF file.")

def glTF2_post_export_callback(export_settings):
print("This will be called after exporting the glTF file.")
2 changes: 2 additions & 0 deletions example-addons/example_gltf_exporter_extension/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ If you want to use this file as a base of your addon, make sure to make it prope
Next, define functions that contain the data of the extension you would like to include. Write those functions for each type you want to include extensions for. Currently implemented are:

```
pre_export_hook(self, export_settings)
post_export_hook(self, export_settings)
gather_animation_channel_hook(self, gltf2_animation_channel, channel, blender_object, bone, action_name, node_channel_is_animated, export_settings)
gather_animation_channel_target_hook(self, gltf2_animation_channel_target, channels, blender_object, bake_bone, bake_channel, export_settings)
gather_animation_sampler_hook(self, gltf2_sampler, blender_object, bone, action_name, node_channel_is_animated, export_settings)
Expand Down
Loading