diff --git a/tools/gltf_auto_export/__init__.py b/tools/gltf_auto_export/__init__.py index 2be2b6c..dd05679 100644 --- a/tools/gltf_auto_export/__init__.py +++ b/tools/gltf_auto_export/__init__.py @@ -35,61 +35,16 @@ from .ui.main import (GLTF_PT_auto_export_main, GLTF_PT_auto_export_scenes, GLTF_PT_auto_export_blueprints, GLTF_PT_auto_export_collections_list, - GLTF_PT_auto_export_gltf, SCENE_UL_GLTF_auto_export, - HelloWorldOperator, - - - #GLTF_PT_export_data, - #GLTF_PT_export_data_scene + GLTF_PT_auto_export_SidePanel ) from .ui.operators import (SCENES_LIST_OT_actions) ###################################################### -""" there are two places where we load settings for auto_export from: -- in ui/main AutoExportGLTF -> invoke -- in auto_export.py -> auto_export -This is a workaround needed because of the way the settings are stored , perhaps there is a better way to deal with it ? ie by calling the AutoExportGLTF operator from the auto_export function ? + """ -from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main, GLTF_PT_export_include) - - -class Auto_Export_SidePanel(bpy.types.Panel): - bl_idname = "Auto_Export_SidePanel" - bl_label = "" - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_category = "Auto Export" - bl_context = "objectmode" - - - def draw_header(self, context): - layout = self.layout - layout.label(text="Gltf auto export ") - - def draw(self, context): - layout = self.layout - layout.label(text="MAKE SURE TO KEEP 'REMEMBER EXPORT SETTINGS' !!") - op = layout.operator("EXPORT_SCENE_OT_gltf", text='Gltf Settings')#'glTF 2.0 (.glb/.gltf)') - #op.export_format = 'GLTF_SEPARATE' - op.use_selection=True - op.will_save_settings=True - op.use_visible=True # Export visible and hidden objects. See Object/Batch Export to skip. - op.use_renderable=True - op.use_active_collection = True - op.use_active_collection_with_nested=True - op.use_active_scene = True - op.filepath="____dummy____" - op.gltf_export_id = "gltf_auto_export" # we specify that we are in a special case - - op = layout.operator("EXPORT_SCENES_OT_auto_gltf", text="Auto Export Settings") - #op.will_save_settings=True - - #print("GLTF_PT_export_main", GLTF_PT_export_main.bl_parent_id) - - # glTF extensions are named following a convention with known prefixes. # See: https://github.com/KhronosGroup/glTF/tree/main/extensions#about-gltf-extensions # also: https://github.com/KhronosGroup/glTF/blob/main/extensions/Prefixes.md @@ -135,8 +90,7 @@ class glTF2ExportUserExtension: def gather_gltf_hook(self, active_scene_idx, scenes, animations, export_settings): if self.properties.enabled: print("extension enabled") - - #print("gather_gltf_hook", self, active_scene_idx, scenes, animations, export_settings) + #print("gather_gltf_hook", self, active_scene_idx, scenes, animations, export_settings)""" #see here for original gltf exporter infos https://github.com/KhronosGroup/glTF-Blender-IO/blob/main/addons/io_scene_gltf2/__init__.py @@ -150,8 +104,6 @@ classes = [ AutoExportGLTF, #AutoExportGltfAddonPreferences, - HelloWorldOperator, - CollectionToExport, CollectionsToExport, @@ -161,10 +113,10 @@ classes = [ GLTF_PT_auto_export_scenes, GLTF_PT_auto_export_blueprints, GLTF_PT_auto_export_collections_list, + GLTF_PT_auto_export_SidePanel, AutoExportTracker, - Auto_Export_SidePanel, ] def glTF2_pre_export_callback(data): @@ -174,7 +126,6 @@ def glTF2_pre_export_callback(data): def cleanup_file(): gltf_filepath = "/home/ckaos/projects/bevy/Blender_bevy_components_worklflow/testing/bevy_example/assets/____dummy____.glb" if os.path.exists(gltf_filepath): - print("removing dummy file", gltf_filepath) os.remove(gltf_filepath) return None else: @@ -183,7 +134,6 @@ def cleanup_file(): def glTF2_post_export_callback(data): #print("post_export", data) gltf_settings_backup = bpy.context.window_manager.gltf_settings_backup - print("gltf_settings_backup", gltf_settings_backup) gltf_filepath = data["gltf_filepath"] gltf_export_id = data['gltf_export_id'] if gltf_export_id == "gltf_auto_export": @@ -204,10 +154,8 @@ def glTF2_post_export_callback(data): export_settings.write(json.dumps(dict(settings))) # now reset the original gltf_settings if gltf_settings_backup != "": - print("resetting original gltf settings") scene["glTF2ExportSettings"] = json.loads(gltf_settings_backup) else: - print("no pre_existing settings") if "glTF2ExportSettings" in scene: del scene["glTF2ExportSettings"] bpy.context.window_manager.gltf_settings_backup = "" @@ -241,8 +189,8 @@ def register(): bpy.types.TOPBAR_MT_file_export.append(menu_func_import) bpy.types.WindowManager.gltf_settings_backup = StringProperty(default="") - bpy.utils.register_class(AutoExportExtensionProperties) - bpy.types.Scene.AutoExportExtensionProperties = bpy.props.PointerProperty(type=AutoExportExtensionProperties) + """bpy.utils.register_class(AutoExportExtensionProperties) + bpy.types.Scene.AutoExportExtensionProperties = bpy.props.PointerProperty(type=AutoExportExtensionProperties)""" def unregister(): for cls in classes: @@ -252,7 +200,7 @@ def unregister(): bpy.app.handlers.depsgraph_update_post.remove(post_update) bpy.app.handlers.save_post.remove(post_save) - bpy.utils.unregister_class(AutoExportExtensionProperties) + """bpy.utils.unregister_class(AutoExportExtensionProperties)""" if "gltf_auto_export" == "__main__": register() diff --git a/tools/gltf_auto_export/__init___extension.py b/tools/gltf_auto_export/__init___extension.py deleted file mode 100644 index ac5fa9e..0000000 --- a/tools/gltf_auto_export/__init___extension.py +++ /dev/null @@ -1,172 +0,0 @@ -import bpy -from bpy.props import (BoolProperty, - IntProperty, - StringProperty, - EnumProperty, - CollectionProperty - ) -bl_info = { - "name": "auto_export", - "category": "Generic", - "version": (1, 0, 0), - "blender": (2, 80, 0), - 'location': 'File > Export > glTF 2.0', - 'description': 'Example addon to add a custom extension to an exported glTF file.', - 'tracker_url': "https://github.com/KhronosGroup/glTF-Blender-IO/issues/", # Replace with your issue tracker - 'isDraft': False, - 'developer': "(Your name here)", # Replace this - 'url': 'https://your_url_here', # Replace this -} - -# glTF extensions are named following a convention with known prefixes. -# See: https://github.com/KhronosGroup/glTF/tree/main/extensions#about-gltf-extensions -# also: https://github.com/KhronosGroup/glTF/blob/main/extensions/Prefixes.md -glTF_extension_name = "EXT_auto_export" - -# Support for an extension is "required" if a typical glTF viewer cannot be expected -# to load a given model without understanding the contents of the extension. -# For example, a compression scheme or new image format (with no fallback included) -# would be "required", but physics metadata or app-specific settings could be optional. -extension_is_required = False -from io_scene_gltf2 import (GLTF_PT_export_main, GLTF_PT_export_include) - -class ExampleExtensionProperties(bpy.types.PropertyGroup): - enabled: bpy.props.BoolProperty( - name=bl_info["name"], - description='Include this extension in the exported glTF file.', - default=True - ) - - auto_export_main_scene_name: StringProperty( - name='Main scene', - description='The name of the main scene/level/world to auto export', - default='Scene' - ) - auto_export_output_folder: StringProperty( - name='Export folder (relative)', - description='The root folder for all exports(relative to current file) Defaults to current folder', - default='' - ) - auto_export_library_scene_name: StringProperty( - name='Library scene', - description='The name of the library scene to auto export', - default='Library' - ) - # scene components - auto_export_scene_settings: BoolProperty( - name='Export scene settings', - description='Export scene settings ie AmbientLighting, Bloom, AO etc', - default=False - ) - - # blueprint settings - auto_export_blueprints: BoolProperty( - name='Export Blueprints', - description='Replaces collection instances with an Empty with a BlueprintName custom property', - default=True - ) - auto_export_blueprints_path: StringProperty( - name='Blueprints path', - description='path to export the blueprints to (relative to the Export folder)', - default='library' - ) - - auto_export_materials_library: BoolProperty( - name='Export materials library', - description='remove materials from blueprints and use the material library instead', - default=False - ) - auto_export_materials_path: StringProperty( - name='Materials path', - description='path to export the materials libraries to (relative to the root folder)', - default='materials' - ) - -def register(): - bpy.utils.register_class(ExampleExtensionProperties) - bpy.types.Scene.ExampleExtensionProperties = bpy.props.PointerProperty(type=ExampleExtensionProperties) - -def register_panel(): - # Register the panel on demand, we need to be sure to only register it once - # This is necessary because the panel is a child of the extensions panel, - # which may not be registered when we try to register this extension - try: - bpy.utils.register_class(GLTF_PT_UserExtensionPanel) - except Exception: - pass - - # If the glTF exporter is disabled, we need to unregister the extension panel - # Just return a function to the exporter so it can unregister the panel - return unregister_panel - - -def unregister_panel(): - # Since panel is registered on demand, it is possible it is not registered - try: - bpy.utils.unregister_class(GLTF_PT_UserExtensionPanel) - except Exception: - pass - - -def unregister(): - unregister_panel() - bpy.utils.unregister_class(ExampleExtensionProperties) - del bpy.types.Scene.ExampleExtensionProperties - -class GLTF_PT_UserExtensionPanel(bpy.types.Panel): - - bl_space_type = 'FILE_BROWSER' - bl_region_type = 'TOOL_PROPS' - bl_label = "Enabled" - bl_parent_id = "GLTF_PT_export_user_extensions" - 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" - - def draw_header(self, context): - props = bpy.context.scene.ExampleExtensionProperties - self.layout.prop(props, 'enabled') - - def draw(self, context): - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False # No animation. - - props = bpy.context.scene.ExampleExtensionProperties - layout.active = props.enabled - - props = bpy.context.scene.ExampleExtensionProperties - for bla in props.__annotations__: - layout.prop(props, bla) - - -class glTF2ExportUserExtension: - - def __init__(self): - # We need to wait until we create the gltf2UserExtension to import the gltf2 modules - # Otherwise, it may fail because the gltf2 may not be loaded yet - from io_scene_gltf2.io.com.gltf2_io_extensions import Extension - self.Extension = Extension - self.properties = bpy.context.scene.ExampleExtensionProperties - - def gather_node_hook(self, gltf2_object, blender_object, export_settings): - if self.properties.enabled: - if gltf2_object.extensions is None: - gltf2_object.extensions = {} - print("bla bla") - gltf2_object.extensions[glTF_extension_name] = self.Extension( - name=glTF_extension_name, - extension={"auto_export_blueprints": self.properties.auto_export_blueprints}, - required=extension_is_required - ) - - -def glTF2_pre_export_callback(data): - print("pre_export", data) - -def glTF2_post_export_callback(data): - print("post_export", data) \ No newline at end of file diff --git a/tools/gltf_auto_export/auto_export/tracker.py b/tools/gltf_auto_export/auto_export/tracker.py index 1c8150d..1eb6da6 100644 --- a/tools/gltf_auto_export/auto_export/tracker.py +++ b/tools/gltf_auto_export/auto_export/tracker.py @@ -69,7 +69,7 @@ class AutoExportTracker(PropertyGroup): active_operator.will_save_settings = True # we set the last operator here so we can clear the specific settings (yeah for overly complex logic) cls.last_operator = active_operator - print("active_operator", active_operator.has_active_exporter_extensions, active_operator.__annotations__.keys(), active_operator.filepath, active_operator.gltf_export_id) + #print("active_operator", active_operator.has_active_exporter_extensions, active_operator.__annotations__.keys(), active_operator.filepath, active_operator.gltf_export_id) if active_operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf": # we force saving params active_operator.will_save_settings = True diff --git a/tools/gltf_auto_export/helpers/to_remove_later.py b/tools/gltf_auto_export/helpers/to_remove_later.py index ecbe545..989fe86 100644 --- a/tools/gltf_auto_export/helpers/to_remove_later.py +++ b/tools/gltf_auto_export/helpers/to_remove_later.py @@ -361,3 +361,7 @@ def invoke_override(self, context, event): wm = context.window_manager wm.fileselect_add(self) return {'RUNNING_MODAL'} + + + +from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main, GLTF_PT_export_include) diff --git a/tools/gltf_auto_export/tests/test_bevy_integration.py b/tools/gltf_auto_export/tests/test_bevy_integration.py index 4d2b863..76da5ea 100644 --- a/tools/gltf_auto_export/tests/test_bevy_integration.py +++ b/tools/gltf_auto_export/tests/test_bevy_integration.py @@ -65,7 +65,8 @@ def test_export_complex(setup_data): # "export_format":'GLTF_SEPARATE' } gltf_settings = { - "export_animations": True + "export_animations": True, + "export_optimize_animation_size": False } # store settings for the auto_export part @@ -76,7 +77,7 @@ def test_export_complex(setup_data): # and store settings for the gltf part stored_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings"] if ".gltf_auto_export_gltf_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings") stored_gltf_settings.clear() - stored_gltf_settings.write(str(gltf_settings)) + stored_gltf_settings.write(json.dumps(gltf_settings)) # move the main cube bpy.data.objects["Cube"].location = [1, 0, 0] diff --git a/tools/gltf_auto_export/ui/main.py b/tools/gltf_auto_export/ui/main.py index f3db50a..dcb8a80 100644 --- a/tools/gltf_auto_export/ui/main.py +++ b/tools/gltf_auto_export/ui/main.py @@ -17,6 +17,39 @@ from ..helpers.helpers_collections import (get_exportable_collections) ###################################################### ## ui logic & co +# side panel that opens auto_export specific gltf settings & the auto export settings themselves +class GLTF_PT_auto_export_SidePanel(bpy.types.Panel): + bl_idname = "GLTF_PT_auto_export_SidePanel" + bl_label = "" + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = "Auto Export" + bl_context = "objectmode" + + + def draw_header(self, context): + layout = self.layout + layout.label(text="Gltf auto export ") + + def draw(self, context): + layout = self.layout + layout.label(text="MAKE SURE TO KEEP 'REMEMBER EXPORT SETTINGS' TOGGLED !!") + op = layout.operator("EXPORT_SCENE_OT_gltf", text='Gltf Settings')#'glTF 2.0 (.glb/.gltf)') + #op.export_format = 'GLTF_SEPARATE' + op.use_selection=True + op.will_save_settings=True + op.use_visible=True # Export visible and hidden objects. See Object/Batch Export to skip. + op.use_renderable=True + op.use_active_collection = True + op.use_active_collection_with_nested=True + op.use_active_scene = True + op.filepath="____dummy____" + op.gltf_export_id = "gltf_auto_export" # we specify that we are in a special case + + op = layout.operator("EXPORT_SCENES_OT_auto_gltf", text="Auto Export Settings") + #print("GLTF_PT_export_main", GLTF_PT_export_main.bl_parent_id) + +# main ui in the file => export class GLTF_PT_auto_export_main(bpy.types.Panel): bl_space_type = 'FILE_BROWSER' bl_region_type = 'TOOL_PROPS' @@ -247,37 +280,6 @@ class GLTF_PT_auto_export_collections_list(bpy.types.Panel): row = layout.row() row.label(text=collection.name) - - -class HelloWorldOperator(bpy.types.Operator): - bl_idname = "export_scenes.wrapper" - bl_label = "Minimal Operator" - - def execute(self, context): - print("Hello World") - return {'FINISHED'} - - def invoke(self, context: Context, event: Event): - wm = context.window_manager - wm.fileselect_add(self) - - return {'RUNNING_MODAL'} - - - def draw(self, context: Context): - layout = self.layout - op = layout.operator("EXPORT_SCENE_OT_gltf", text='Gltf settings')#'glTF 2.0 (.glb/.gltf)') - op.use_selection=True - op.will_save_settings=True - op.use_visible=True # Export visible and hidden objects. See Object/Batch Export to skip. - op.use_renderable=True - op.use_active_collection = True - op.use_active_collection_with_nested=True - op.use_active_scene = True - op.filepath="dummy" - #export_scenes.auto_gltf - - class GLTF_PT_auto_export_gltf(bpy.types.Panel): bl_space_type = 'FILE_BROWSER' bl_region_type = 'TOOL_PROPS' diff --git a/tools/gltf_auto_export/ui2/main.py b/tools/gltf_auto_export/ui2/main.py deleted file mode 100644 index 2eedced..0000000 --- a/tools/gltf_auto_export/ui2/main.py +++ /dev/null @@ -1,267 +0,0 @@ -import bpy -from bpy.types import Operator -from bpy_extras.io_utils import ExportHelper -from bpy.props import (BoolProperty, - IntProperty, - StringProperty, - EnumProperty, - CollectionProperty - ) - -from ..auto_export import auto_export - -from ..auto_export.preferences import (AutoExportGltfAddonPreferences, AutoExportGltfPreferenceNames) -from ..helpers.helpers_scenes import (get_scenes) -from ..helpers.helpers_collections import (get_exportable_collections) -###################################################### -## ui logic & co - -class GLTF_PT_auto_export_main(bpy.types.Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_label = "" - #bl_options = {'HIDE_HEADER'} - bl_category = "Gltf auto_export" - bl_context = "objectmode" - - """ @classmethod - def poll(cls, context): - sfile = context.space_data - operator = sfile.active_operator - - return operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf" - """ - - def draw(self, context): - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False # No animation. - -class GLTF_PT_auto_export_root(bpy.types.Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_label = "Auto export" - bl_parent_id = "GLTF_PT_auto_export_main" - #bl_options = {'DEFAULT_CLOSED'} - - """@classmethod - def poll(cls, context): - sfile = context.space_data - operator = sfile.active_operator - return operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf" - """ - - """def draw_header(self, context): - sfile = context.space_data - operator = sfile.active_operator - self.layout.prop(operator, "auto_export", text="")""" - - def draw(self, context): - - pass - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False # No animation. - - sfile = context.space_data - operator = layout.operator("export_scenes.auto_gltf")#bpy.ops.export_scenes.auto_gltf #sfile.active_operator - layout.prop(context.window_manager.operator_properties_last("export_scenes.auto_gltf"), "export_change_detection") - layout.prop(context.window_manager.operator_properties_last("export_scenes.auto_gltf"), "export_output_folder") - - #layout.active = operator.auto_export - layout.prop(operator, 'will_save_settings') - layout.prop(operator, "export_change_detection") - layout.prop(operator, "export_output_folder") - layout.prop(operator, "export_scene_settings") - layout.prop(operator, "export_legacy_mode") - - # scene selectors - row = layout.row() - col = row.column(align=True) - col.separator() - - source = operator - - rows = 2 - - # main/level scenes - layout.label(text="main scenes") - layout.prop(context.window_manager, "main_scene", text='') - - row = layout.row() - row.template_list("SCENE_UL_GLTF_auto_export", "level scenes", source, "main_scenes", source, "main_scenes_index", rows=rows) - - col = row.column(align=True) - sub_row = col.row() - add_operator = sub_row.operator("scene_list.list_action", icon='ADD', text="") - add_operator.action = 'ADD' - add_operator.scene_type = 'level' - #add_operator.source = operator - sub_row.enabled = context.window_manager.main_scene is not None - - sub_row = col.row() - remove_operator = sub_row.operator("scene_list.list_action", icon='REMOVE', text="") - remove_operator.action = 'REMOVE' - remove_operator.scene_type = 'level' - col.separator() - - #up_operator = col.operator("scene_list.list_action", icon='TRIA_UP', text="") - #up_operator.action = 'UP' - #col.operator("scene_list.list_action", icon='TRIA_DOWN', text="").action = 'DOWN' - - # library scenes - layout.label(text="library scenes") - layout.prop(context.window_manager, "library_scene", text='') - - row = layout.row() - row.template_list("SCENE_UL_GLTF_auto_export", "library scenes", source, "library_scenes", source, "library_scenes_index", rows=rows) - - col = row.column(align=True) - sub_row = col.row() - add_operator = sub_row.operator("scene_list.list_action", icon='ADD', text="") - add_operator.action = 'ADD' - add_operator.scene_type = 'library' - sub_row.enabled = context.window_manager.library_scene is not None - - - sub_row = col.row() - remove_operator = sub_row.operator("scene_list.list_action", icon='REMOVE', text="") - remove_operator.action = 'REMOVE' - remove_operator.scene_type = 'library' - col.separator() - -class GLTF_PT_auto_export_blueprints(bpy.types.Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_label = "Blueprints" - bl_parent_id = "GLTF_PT_auto_export_main" - - """@classmethod - def poll(cls, context): - sfile = context.space_data - operator = sfile.active_operator - - return operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf" #"EXPORT_SCENE_OT_gltf" - """ - - - """def draw_header(self, context): - layout = self.layout - sfile = context.space_data - operator = sfile.active_operator - layout.prop(operator, "export_blueprints", text="")""" - - #self.layout.prop(operator, "auto_export", text="") - - def draw(self, context): - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False # No animation. - - sfile = context.space_data - operator = layout.operator("export_scenes.auto_gltf")#bpy.ops.export_scenes.auto_gltf #sfile.active_operator -#sfile.active_operator - - layout.active = operator.export_blueprints - - # collections/blueprints - layout.prop(operator, "export_blueprints_path") - layout.prop(operator, "collection_instances_combine_mode") - layout.prop(operator, "export_marked_assets") - layout.prop(operator, "export_separate_dynamic_and_static_objects") - layout.separator() - # materials - layout.prop(operator, "export_materials_library") - layout.prop(operator, "export_materials_path") - - -class GLTF_PT_auto_export_collections_list(bpy.types.Panel): - bl_space_type = 'FILE_BROWSER' - bl_region_type = 'TOOL_PROPS' - bl_label = "Blueprints: Exported Collections" - bl_parent_id = "GLTF_PT_auto_export_blueprints" - bl_options = {'DEFAULT_CLOSED'} - - @classmethod - def poll(cls, context): - sfile = context.space_data - operator = sfile.active_operator - - return operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf" #"EXPORT_SCENE_OT_gltf" - - def draw(self, context): - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False # No animation. - - sfile = context.space_data - operator = sfile.active_operator - - for collection in bpy.context.window_manager.exportedCollections: - row = layout.row() - row.label(text=collection.name) - -class GLTF_PT_auto_export_gltf(bpy.types.Panel): - bl_space_type = 'VIEW_3D' - bl_region_type = 'UI' - bl_label = "Gltf" - bl_parent_id = "GLTF_PT_auto_export_main" - bl_options = {'DEFAULT_CLOSED'} - - """@classmethod - def poll(cls, context): - sfile = context.space_data - operator = sfile.active_operator - - return operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf" #"EXPORT_SCENE_OT_gltf" - """ - - def draw(self, context): - preferences = context.preferences - layout = self.layout - - layout.label(text="MAKE SURE TO KEEP 'REMEMBER EXPORT SETTINGS' !!") - op = layout.operator("EXPORT_SCENE_OT_gltf", text='Gltf settings')#'glTF 2.0 (.glb/.gltf)') - #op.export_format = 'GLTF_SEPARATE' - op.use_selection=True - op.will_save_settings=True - op.use_visible=True # Export visible and hidden objects. See Object/Batch Export to skip. - op.use_renderable=True - op.use_active_collection = True - op.use_active_collection_with_nested=True - op.use_active_scene = True - op.filepath="dummy" - -class SCENE_UL_GLTF_auto_export(bpy.types.UIList): - # The draw_item function is called for each item of the collection that is visible in the list. - # data is the RNA object containing the collection, - # item is the current drawn item of the collection, - # icon is the "computed" icon for the item (as an integer, because some objects like materials or textures - # have custom icons ID, which are not available as enum items). - # active_data is the RNA object containing the active property for the collection (i.e. integer pointing to the - # active item of the collection). - # active_propname is the name of the active property (use 'getattr(active_data, active_propname)'). - # index is index of the current item in the collection. - # flt_flag is the result of the filtering process for this item. - # Note: as index and flt_flag are optional arguments, you do not have to use/declare them here if you don't - # need them. - def draw_item(self, context, layout, data, item, icon, active_data, active_propname): - ob = data - # draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code. - if self.layout_type in {'DEFAULT', 'COMPACT'}: - # You should always start your row layout by a label (icon + text), or a non-embossed text field, - # this will also make the row easily selectable in the list! The later also enables ctrl-click rename. - # We use icon_value of label, as our given icon is an integer value, not an enum ID. - # Note "data" names should never be translated! - #if ma: - # layout.prop(ma, "name", text="", emboss=False, icon_value=icon) - #else: - # layout.label(text="", translate=False, icon_value=icon) - layout.label(text=item.name, icon_value=icon) - #layout.prop(item, "name", text="", emboss=False, icon_value=icon) - # 'GRID' layout type should be as compact as possible (typically a single icon!). - elif self.layout_type == 'GRID': - layout.alignment = 'CENTER' - layout.label(text="", icon_value=icon) - - diff --git a/tools/gltf_auto_export/ui2/operators.py b/tools/gltf_auto_export/ui2/operators.py deleted file mode 100644 index 31ea51d..0000000 --- a/tools/gltf_auto_export/ui2/operators.py +++ /dev/null @@ -1,83 +0,0 @@ - -import bpy -from bpy.types import Operator - -class SCENES_LIST_OT_actions(Operator): - """Move items up and down, add and remove""" - bl_idname = "scene_list.list_action" - bl_label = "List Actions" - bl_description = "Move items up and down, add and remove" - bl_options = {'REGISTER'} - - action: bpy.props.EnumProperty( - items=( - ('UP', "Up", ""), - ('DOWN', "Down", ""), - ('REMOVE', "Remove", ""), - ('ADD', "Add", ""))) - - - scene_type: bpy.props.StringProperty()#TODO: replace with enum - - def invoke(self, context, event): - source = context.space_data.active_operator - target_name = "library_scenes" - target_index = "library_scenes_index" - if self.scene_type == "level": - target_name = "main_scenes" - target_index = "main_scenes_index" - - target = getattr(source, target_name) - idx = getattr(source, target_index) - current_index = getattr(source, target_index) - - try: - item = target[idx] - except IndexError: - pass - else: - if self.action == 'DOWN' and idx < len(target) - 1: - target.move(idx, idx + 1) - setattr(source, target_index, current_index +1 ) - info = 'Item "%s" moved to position %d' % (item.name, current_index + 1) - self.report({'INFO'}, info) - - elif self.action == 'UP' and idx >= 1: - target.move(idx, idx - 1) - setattr(source, target_index, current_index -1 ) - info = 'Item "%s" moved to position %d' % (item.name, current_index + 1) - self.report({'INFO'}, info) - - elif self.action == 'REMOVE': - info = 'Item "%s" removed from list' % (target[idx].name) - setattr(source, target_index, current_index -1 ) - target.remove(idx) - self.report({'INFO'}, info) - - if self.action == 'ADD': - new_scene_name = None - if self.scene_type == "level": - if context.window_manager.main_scene: - new_scene_name = context.window_manager.main_scene.name - else: - if context.window_manager.library_scene: - new_scene_name = context.window_manager.library_scene.name - if new_scene_name: - item = target.add() - item.name = new_scene_name#f"Rule {idx +1}" - - if self.scene_type == "level": - context.window_manager.main_scene = None - else: - context.window_manager.library_scene = None - - #name = f"Rule {idx +1}" - #target.append({"name": name}) - setattr(source, target_index, len(target) - 1) - #source[target_index] = len(target) - 1 - info = '"%s" added to list' % (item.name) - self.report({'INFO'}, info) - - return {"FINISHED"} - -