mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 20:00:53 +00:00
feat(auto_export): major ui restructuring
* operator ui is not a file browser anymore * restructured/recreated ui to work inside a props_dialog * added ui_only toggles to control the "pseudo panels" (as panels are not supported in props dialogs) * regrouped a few toggle in a more logical manner * change sub type of a few properties to be directories * some related cleanups
This commit is contained in:
parent
8a3cecf0c9
commit
84e5de8c3e
@ -28,7 +28,7 @@ from .auto_export.preferences import (AutoExportGltfAddonPreferences)
|
||||
from .auto_export.internals import (SceneLink,
|
||||
SceneLinks,
|
||||
CollectionToExport,
|
||||
CollectionsToExport,
|
||||
BlueprintsToExport,
|
||||
CUSTOM_PG_sceneName
|
||||
)
|
||||
from .ui.main import (GLTF_PT_auto_export_change_detection, GLTF_PT_auto_export_changes_list, GLTF_PT_auto_export_main,
|
||||
@ -36,7 +36,7 @@ from .ui.main import (GLTF_PT_auto_export_change_detection, GLTF_PT_auto_export_
|
||||
GLTF_PT_auto_export_general,
|
||||
GLTF_PT_auto_export_scenes,
|
||||
GLTF_PT_auto_export_blueprints,
|
||||
GLTF_PT_auto_export_collections_list,
|
||||
GLTF_PT_auto_export_blueprints_list,
|
||||
SCENE_UL_GLTF_auto_export,
|
||||
|
||||
GLTF_PT_auto_export_SidePanel
|
||||
@ -108,7 +108,7 @@ classes = [
|
||||
#AutoExportGltfAddonPreferences,
|
||||
|
||||
CollectionToExport,
|
||||
CollectionsToExport,
|
||||
BlueprintsToExport,
|
||||
|
||||
GLTF_PT_auto_export_main,
|
||||
GLTF_PT_auto_export_root,
|
||||
@ -117,7 +117,7 @@ classes = [
|
||||
GLTF_PT_auto_export_scenes,
|
||||
GLTF_PT_auto_export_blueprints,
|
||||
GLTF_PT_auto_export_SidePanel,
|
||||
GLTF_PT_auto_export_collections_list,
|
||||
GLTF_PT_auto_export_blueprints_list,
|
||||
GLTF_PT_auto_export_changes_list,
|
||||
|
||||
AutoExportTracker,
|
||||
|
@ -106,6 +106,10 @@ def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
||||
bpy.context.window_manager.auto_export_tracker.exports_total = exports_total
|
||||
bpy.context.window_manager.auto_export_tracker.exports_count = exports_total
|
||||
|
||||
bpy.context.window_manager.exportedCollections.clear()
|
||||
for blueprint in blueprints_to_export:
|
||||
bla = bpy.context.window_manager.exportedCollections.add()
|
||||
bla.name = blueprint.name
|
||||
print("-------------------------------")
|
||||
#print("collections: all:", collections)
|
||||
#print("collections: not found on disk:", collections_not_on_disk)
|
||||
|
@ -15,7 +15,7 @@ class CUSTOM_PG_sceneName(bpy.types.PropertyGroup):
|
||||
class CollectionToExport(bpy.types.PropertyGroup):
|
||||
name: bpy.props.StringProperty(name="")
|
||||
|
||||
class CollectionsToExport(bpy.types.PropertyGroup):
|
||||
class BlueprintsToExport(bpy.types.PropertyGroup):
|
||||
name = bpy.props.StringProperty(name="List of collections to export", default="Unknown")
|
||||
items: bpy.props.CollectionProperty(type = CollectionToExport)
|
||||
|
||||
|
@ -2,8 +2,9 @@ import json
|
||||
import bpy
|
||||
from bpy.types import Operator
|
||||
from bpy_extras.io_utils import ExportHelper
|
||||
from bpy.props import (IntProperty)
|
||||
from bpy.props import (IntProperty, StringProperty, BoolProperty)
|
||||
|
||||
#from ..ui.main import GLTF_PT_auto_export_general, GLTF_PT_auto_export_main, GLTF_PT_auto_export_root
|
||||
|
||||
from .preferences import (AutoExportGltfAddonPreferences, AutoExportGltfPreferenceNames)
|
||||
from .auto_export import auto_export
|
||||
@ -16,16 +17,22 @@ def bubble_up_changes(object, changes_per_scene):
|
||||
bubble_up_changes(object.parent, changes_per_scene)
|
||||
|
||||
|
||||
class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
|
||||
class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences):#, ExportHelper):
|
||||
"""auto export gltf"""
|
||||
#bl_idname = "object.xxx"
|
||||
bl_idname = "export_scenes.auto_gltf"
|
||||
bl_label = "Apply settings"
|
||||
bl_options = {'PRESET'} # we do not add UNDO otherwise it leads to an invisible operation that resets the state of the saved serialized scene, breaking compares for normal undo/redo operations
|
||||
# ExportHelper mixin class uses this
|
||||
filename_ext = ''
|
||||
|
||||
#filename_ext = ''
|
||||
#filepath: bpy.props.StringProperty(subtype="FILE_PATH", default="") # type: ignore
|
||||
|
||||
# Filters folders
|
||||
filter_folder: BoolProperty(
|
||||
default=True,
|
||||
options={"HIDDEN"}
|
||||
) # type: ignore
|
||||
|
||||
#list of settings (other than purely gltf settings) whose change should trigger a re-generation of gltf files
|
||||
white_list = ['auto_export',
|
||||
'export_main_scene_name',
|
||||
@ -299,7 +306,7 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
|
||||
|
||||
|
||||
def execute(self, context):
|
||||
#print("execute")
|
||||
print("execute", self.directory)
|
||||
bpy.context.window_manager.auto_export_tracker.disable_change_detection()
|
||||
if self.direct_mode:
|
||||
self.load_settings(context)
|
||||
@ -327,14 +334,121 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
|
||||
|
||||
def invoke(self, context, event):
|
||||
#print("invoke")
|
||||
|
||||
bpy.context.window_manager.auto_export_tracker.disable_change_detection()
|
||||
self.load_settings(context)
|
||||
wm = context.window_manager
|
||||
wm.fileselect_add(self)
|
||||
#wm.fileselect_add(self)
|
||||
return context.window_manager.invoke_props_dialog(self, title="Auto export", width=600)
|
||||
#context.window_manager.modal_handler_add(self)
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
"""def modal(self, context, event):
|
||||
|
||||
if event.type == 'SPACE':
|
||||
wm = context.window_manager
|
||||
wm.invoke_popup(self)
|
||||
#wm.invoke_props_dialog(self)
|
||||
|
||||
if event.type in {'ESC'}:
|
||||
return {'CANCELLED'}
|
||||
|
||||
return {'RUNNING_MODAL'}"""
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
pass
|
||||
layout = self.layout
|
||||
operator = self
|
||||
|
||||
controls_enabled = self.auto_export
|
||||
|
||||
layout.prop(self, "auto_export")
|
||||
layout.separator()
|
||||
|
||||
toggle_icon = "TRIA_DOWN" if self.show_general_settings else "TRIA_RIGHT"
|
||||
layout.prop(self, "show_general_settings", text="General", icon=toggle_icon)
|
||||
if self.show_general_settings:
|
||||
section = layout.box()
|
||||
section.enabled = controls_enabled
|
||||
|
||||
section.prop(self, "root_folder")
|
||||
section.prop(operator, "export_output_folder")
|
||||
section.prop(operator, "export_scene_settings")
|
||||
section.prop(operator, "export_legacy_mode")
|
||||
"""header, panel = layout.panel("my_panel_id", default_closed=False)
|
||||
header.label(text="Hello World")
|
||||
if panel:
|
||||
panel.label(text="Success")"""
|
||||
|
||||
# main/level scenes
|
||||
toggle_icon = "TRIA_DOWN" if self.show_scene_settings else "TRIA_RIGHT"
|
||||
layout.prop(operator, "show_scene_settings", text="Scenes", icon=toggle_icon)
|
||||
if self.show_scene_settings:
|
||||
section = layout.box()
|
||||
section.enabled = controls_enabled
|
||||
rows = 2
|
||||
row = section.row()
|
||||
row.label(text="main scenes")
|
||||
row.prop(context.window_manager, "main_scene", text='')
|
||||
|
||||
row = section.row()
|
||||
row.template_list("SCENE_UL_GLTF_auto_export", "level scenes", operator, "main_scenes", operator, "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.operator = 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()
|
||||
|
||||
# library scenes
|
||||
row = section.row()
|
||||
row.label(text="library scenes")
|
||||
row.prop(context.window_manager, "library_scene", text='')
|
||||
|
||||
row = section.row()
|
||||
row.template_list("SCENE_UL_GLTF_auto_export", "library scenes", operator, "library_scenes", operator, "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()
|
||||
|
||||
toggle_icon = "TRIA_DOWN" if self.show_blueprint_settings else "TRIA_RIGHT"
|
||||
layout.prop(operator, "show_blueprint_settings", text="Blueprints", icon=toggle_icon)
|
||||
if self.show_blueprint_settings:
|
||||
section = layout.box()
|
||||
section.enabled = controls_enabled
|
||||
section.prop(operator, "export_blueprints")
|
||||
section = section.box()
|
||||
section.enabled = controls_enabled and self.export_blueprints
|
||||
# collections/blueprints
|
||||
section.prop(operator, "export_blueprints_path")
|
||||
section.prop(operator, "collection_instances_combine_mode")
|
||||
section.prop(operator, "export_marked_assets")
|
||||
section.prop(operator, "export_separate_dynamic_and_static_objects")
|
||||
section.separator()
|
||||
# materials
|
||||
section.prop(operator, "export_materials_library")
|
||||
section.prop(operator, "export_materials_path")
|
||||
|
||||
|
||||
def cancel(self, context):
|
||||
print("cancel")
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
import os
|
||||
from bpy.types import AddonPreferences
|
||||
|
||||
from bpy.props import (BoolProperty,
|
||||
IntProperty,
|
||||
StringProperty,
|
||||
@ -42,6 +42,11 @@ AutoExportGltfPreferenceNames = [
|
||||
'will_save_settings',
|
||||
]
|
||||
|
||||
def on_export_output_folder_updated(self, context):
|
||||
#self.root_folder = os.path.relpath(self.root_folder)
|
||||
#self.export_output_folder = os.path.join(self.root_folder, self.export_output_folder)
|
||||
print("on_foo_updated", self.root_folder, self.export_output_folder)
|
||||
|
||||
class AutoExportGltfAddonPreferences(AddonPreferences):
|
||||
# this must match the add-on name, use '__package__'
|
||||
# when defining this in a submodule of a python package.
|
||||
@ -53,68 +58,102 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
|
||||
name='Remember Export Settings',
|
||||
description='Store glTF export settings in the Blender project',
|
||||
default=True
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
# use when operator is called directly, works a bit differently than inside the ui
|
||||
direct_mode: BoolProperty(
|
||||
default=False
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
#### general
|
||||
# for UI only, workaround for lacking panels
|
||||
show_general_settings: BoolProperty(
|
||||
name="show_general settings",
|
||||
description="show/hide general settings (UI only: has no impact on exports)",
|
||||
default=True
|
||||
) # type: ignore
|
||||
|
||||
root_folder: StringProperty(
|
||||
name = "Project Root Path",
|
||||
description="The root folder of your (Bevy) project (not assets!)",
|
||||
subtype='DIR_PATH',
|
||||
update=on_export_output_folder_updated) # type: ignore
|
||||
|
||||
####
|
||||
auto_export: BoolProperty(
|
||||
name='Auto export',
|
||||
description='Automatically export to gltf on save',
|
||||
default=False
|
||||
)
|
||||
) # type: ignore
|
||||
export_main_scene_name: StringProperty(
|
||||
name='Main scene',
|
||||
description='The name of the main scene/level/world to auto export',
|
||||
default='Scene'
|
||||
)
|
||||
) # type: ignore
|
||||
export_output_folder: StringProperty(
|
||||
name='Export folder (relative)',
|
||||
description='The root folder for all exports(relative to current file) Defaults to current folder',
|
||||
default=''
|
||||
)
|
||||
default='',
|
||||
subtype='DIR_PATH',
|
||||
options={'HIDDEN'},
|
||||
update=on_export_output_folder_updated
|
||||
) # type: ignore
|
||||
|
||||
# scenes
|
||||
# for UI only, workaround for lacking panels
|
||||
show_scene_settings: BoolProperty(
|
||||
name="show scene settings",
|
||||
description="show/hide scene settings (UI only: has no impact on exports)",
|
||||
default=True
|
||||
) # type: ignore
|
||||
|
||||
export_library_scene_name: StringProperty(
|
||||
name='Library scene',
|
||||
description='The name of the library scene to auto export',
|
||||
default='Library'
|
||||
)
|
||||
) # type: ignore
|
||||
export_change_detection: BoolProperty(
|
||||
name='Change detection',
|
||||
description='Use change detection to determine what/if should be exported',
|
||||
default=True
|
||||
)
|
||||
) # type: ignore
|
||||
# scene components
|
||||
export_scene_settings: BoolProperty(
|
||||
name='Export scene settings',
|
||||
description='Export scene settings ie AmbientLighting, Bloom, AO etc',
|
||||
default=False
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
# blueprint settings
|
||||
# for UI only, workaround for lacking panels
|
||||
show_blueprint_settings: BoolProperty(
|
||||
name="show blueprint settings",
|
||||
description="show/hide blueprint settings (UI only: has no impact on exports)",
|
||||
default=True
|
||||
) # type: ignore
|
||||
|
||||
export_blueprints: BoolProperty(
|
||||
name='Export Blueprints',
|
||||
description='Replaces collection instances with an Empty with a BlueprintName custom property',
|
||||
default=True
|
||||
)
|
||||
) # type: ignore
|
||||
export_blueprints_path: StringProperty(
|
||||
name='Blueprints path',
|
||||
description='path to export the blueprints to (relative to the Export folder)',
|
||||
default='library'
|
||||
)
|
||||
default='library',
|
||||
subtype='DIR_PATH'
|
||||
) # type: ignore
|
||||
|
||||
export_materials_library: BoolProperty(
|
||||
name='Export materials library',
|
||||
description='remove materials from blueprints and use the material library instead',
|
||||
default=False
|
||||
)
|
||||
) # type: ignore
|
||||
export_materials_path: StringProperty(
|
||||
name='Materials path',
|
||||
description='path to export the materials libraries to (relative to the root folder)',
|
||||
default='materials'
|
||||
)
|
||||
default='materials',
|
||||
subtype='DIR_PATH'
|
||||
) # type: ignore
|
||||
|
||||
""" combine mode can be
|
||||
- 'Split' (default): replace with an empty, creating links to sub blueprints
|
||||
@ -133,13 +172,13 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
|
||||
#('Inject', 'Inject', 'inject components from sub collection instances into the curent object')
|
||||
),
|
||||
default='Split'
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
export_marked_assets: BoolProperty(
|
||||
name='Auto export marked assets',
|
||||
description='Collections that have been marked as assets will be systematically exported, even if not in use in another scene',
|
||||
default=True
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
export_separate_dynamic_and_static_objects: BoolProperty(
|
||||
name='Export dynamic and static objects seperatly',
|
||||
@ -147,16 +186,16 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
|
||||
- one with all dynamic data: collection or instances marked as dynamic/ saveable
|
||||
- one with all static data: anything else that is NOT marked as dynamic""",
|
||||
default=False
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
export_legacy_mode: BoolProperty(
|
||||
name='Legacy mode for Bevy',
|
||||
description='Toggle this if you want to be compatible with bevy_gltf_blueprints/components < 0.8',
|
||||
default=True
|
||||
)
|
||||
) # type: ignore
|
||||
|
||||
main_scenes: CollectionProperty(name="main scenes", type=CUSTOM_PG_sceneName)
|
||||
main_scenes_index: IntProperty(name = "Index for main scenes list", default = 0)
|
||||
main_scenes: CollectionProperty(name="main scenes", type=CUSTOM_PG_sceneName) # type: ignore
|
||||
main_scenes_index: IntProperty(name = "Index for main scenes list", default = 0) # type: ignore
|
||||
|
||||
library_scenes: CollectionProperty(name="library scenes", type=CUSTOM_PG_sceneName)
|
||||
library_scenes_index: IntProperty(name = "Index for library scenes list", default = 0)
|
||||
library_scenes: CollectionProperty(name="library scenes", type=CUSTOM_PG_sceneName) # type: ignore
|
||||
library_scenes_index: IntProperty(name = "Index for library scenes list", default = 0) # type: ignore
|
||||
|
@ -10,7 +10,7 @@ from .did_export_settings_change import did_export_settings_change
|
||||
from .get_collections_to_export import get_collections_to_export
|
||||
|
||||
from ..constants import TEMPSCENE_PREFIX
|
||||
from .internals import CollectionsToExport
|
||||
from .internals import BlueprintsToExport
|
||||
from ..helpers.helpers_scenes import (get_scenes)
|
||||
from .preferences import AutoExportGltfAddonPreferences
|
||||
|
||||
@ -40,7 +40,7 @@ class AutoExportTracker(PropertyGroup):
|
||||
def register(cls):
|
||||
bpy.types.WindowManager.auto_export_tracker = PointerProperty(type=AutoExportTracker)
|
||||
# register list of exportable collections
|
||||
bpy.types.WindowManager.exportedCollections = bpy.props.CollectionProperty(type=CollectionsToExport)
|
||||
bpy.types.WindowManager.exportedCollections = bpy.props.CollectionProperty(type=BlueprintsToExport)
|
||||
|
||||
# setup handlers for updates & saving
|
||||
#bpy.app.handlers.save_post.append(cls.save_handler)
|
||||
|
@ -32,7 +32,7 @@
|
||||
BLUEPRINTS LIST {'Blueprint1': [], 'Blueprint6_animated': [], 'Blueprint4_nested': ['Blueprint3'], 'Blueprint3': [], 'Blueprint7_hierarchy': [], 'External_blueprint': [], 'External_blueprint2': ['External_blueprint3'], 'External_blueprint3': [], 'Blueprint8_animated_no_bones': []}
|
||||
- [x] internal_collections => replace with "internal_collections" or "local_collections"
|
||||
|
||||
- [ ] fix COMBINE MODE passed as int instead of enum value
|
||||
- [x] fix COMBINE MODE passed as int instead of enum value
|
||||
=> comes from our custom logic for add_on prefs
|
||||
- [ ] double check compares to "None" values
|
||||
|
||||
|
@ -55,7 +55,7 @@ class GLTF_PT_auto_export_changes_list(bpy.types.Panel):
|
||||
row = layout.row()
|
||||
row.label(text=f' {object_name}')
|
||||
|
||||
class GLTF_PT_auto_export_collections_list(bpy.types.Panel):
|
||||
class GLTF_PT_auto_export_blueprints_list(bpy.types.Panel):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_label = "Blueprints to export"
|
||||
|
@ -14,13 +14,13 @@ class SCENES_LIST_OT_actions(Operator):
|
||||
('UP', "Up", ""),
|
||||
('DOWN', "Down", ""),
|
||||
('REMOVE', "Remove", ""),
|
||||
('ADD', "Add", "")))
|
||||
('ADD', "Add", ""))) # type: ignore
|
||||
|
||||
|
||||
scene_type: bpy.props.StringProperty()#TODO: replace with enum
|
||||
|
||||
def invoke(self, context, event):
|
||||
source = context.space_data.active_operator
|
||||
source = context.active_operator
|
||||
target_name = "library_scenes"
|
||||
target_index = "library_scenes_index"
|
||||
if self.scene_type == "level":
|
||||
|
Loading…
Reference in New Issue
Block a user