KhronosGroup / glTF-Blender-IO

Blender glTF 2.0 importer and exporter
https://docs.blender.org/manual/en/latest/addons/import_export/scene_gltf2.html
Apache License 2.0
1.5k stars 319 forks source link

Exporter Callback to return glb buffer and json as well as disable output file writing #1906

Open OptimisticMonkey opened 1 year ago

OptimisticMonkey commented 1 year ago

Thank you so much for making glTF-Blender-IO - it is awesome!!!

I am writing a "geometry clipboard" utility for Blender, Unreal, Houdini, etc that uses a glb memory buffer.

For exporting from Blender, I am using glTF-Blender-IO. But I need to disable writing the output to a file, and instead just return the buffer and json of the glb to a callback.

I am just uncertain how to pass a callback function to the exporter.

My operator is calling: bpy.ops.export_scene.gltf(filepath=export_path, export_format='GLB', use_selection=True, use_memory_buffer = True)

(use_memory_buffer is a bool setting I added for testing) I was hoping to pass the exporter an additional callback method instead of that bool.

In gltf2_blender_export.py source, save(context, export_settings):

I have located the data I want: json, buffer = __export(export_settings)

and also the file write I want to disable: __write_file(json, buffer, export_settings)

Can I add a PointerProperty setting and use it to pass a callback to the exporter?

Thanks for any help/advice - I am still learning python and blender

julienduroure commented 1 year ago

I think this can be handle by hooks. Let's add a new hook to handle the code & disable to file writing

OptimisticMonkey commented 1 year ago

That sounds awesome! Is there a common approach to adding a hook to a blender exporter?