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.48k stars 316 forks source link

Calling export in RenderEngine does not work #1943

Open betstick opened 1 year ago

betstick commented 1 year ago

Describe the bug When trying to use the export within a bpy RenderEngine render function results in a context error in the console and the export does not occur.

To Reproduce Steps to reproduce the behavior: gltf_error_addon.zip Copy the attached code directory into the addons folder for Blender to install it Open Blender via a terminal, enable the Error Engine addon in preferences and select Error from the render engine menu Hit F12 to render Check the console logs to see the error messages

Expected behavior The scene should be exported to the specified files/directories.

Screenshots

23:09:26 | INFO: Draco mesh compression is available, use library at /usr/lib/python3.11/site-packages/libextern_draco.so
Traceback (most recent call last):
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/__init__.py", line 718, in execute
    return gltf2_blender_export.save(context, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 21, in save
    if bpy.context.active_object is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Context' object has no attribute 'active_object'
Error: Python: Traceback (most recent call last):
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/__init__.py", line 718, in execute
    return gltf2_blender_export.save(context, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 21, in save
    if bpy.context.active_object is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Context' object has no attribute 'active_object'
Location: /usr/share/blender/3.5/scripts/modules/bpy/ops.py:113
Traceback (most recent call last):
  File "/home/username/.config/blender/3.5/scripts/addons/engine_exporter/engine/engine.py", line 27, in render
    bpy.ops.export_scene.gltf(
  File "/usr/share/blender/3.5/scripts/modules/bpy/ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), None, kw)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Error: Python: Traceback (most recent call last):
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/__init__.py", line 718, in execute
    return gltf2_blender_export.save(context, export_settings)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/share/blender/3.5/scripts/addons/io_scene_gltf2/blender/exp/gltf2_blender_export.py", line 21, in save
    if bpy.context.active_object is not None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Context' object has no attribute 'active_object'
Location: /usr/share/blender/3.5/scripts/modules/bpy/ops.py:113

Version

julienduroure commented 1 year ago

Hello, I can confirm, but not sure to understand why you are trying to use a render engine to export files. What is your use case? Why not creating a custom operator to export your file?

Currently, export uses various attributes that are not available in rendering context.

betstick commented 1 year ago

I've opted to use the GLTF export as it is robust, compatible with multiple systems, and fast. I measured the GLTF exporter to be one of the fastest in Blender (with compression turned off). When I hit F12 to render my scene with my custom engine, I need a way to get the finalized mesh data into my engine. My engine can import from just about any pre-existing format, and I'd rather keep it that way as opposed to writing a custom mesh interface just for Blender.

betstick commented 1 year ago

I've opted to write a Python exporter for the time being. I don't strictly have need of being able to call the exporter from the RenderEngine context anymore. If it doesn't seem like anyone else would need this, I think the issue can be closed.

victorb commented 1 month ago

What is your use case? Why not creating a custom operator to export your file?

Would the custom operator be able to get the output from a custom renderer into the viewport, the render window and the various preview panes?

If that's not possible, then being able to call the export inside a render context (with RenderEngine) is to allow custom renderers to really be integrated into Blender and work just like Cycles/EEVEE instead of requiring their own panels.