diff --git a/tools/blenvy/TODO.md b/tools/blenvy/TODO.md index c21db4c..2607d80 100644 --- a/tools/blenvy/TODO.md +++ b/tools/blenvy/TODO.md @@ -11,7 +11,6 @@ Auto export - blueprints/levels/blueprints path => relative to assets path - [ ] add error handling for de/serialization of project, so that in case of error, the previous saved serialized project is thrown away - - move out some parameters from auto export to a higher level (as they are now used in multiple places) - [x] main/ library scene names - [x] paths @@ -96,4 +95,9 @@ General issues: - [x] load settings on file load - [x] auto_export - [x] components - - [ ] add handling of errors when trying to load settings \ No newline at end of file + - [ ] add handling of errors when trying to load settings + + +- [ ] force overwrite of settings files instead of partial updates ? +- [ ] add tests for disabled components +- [ ] fix auto export workflow diff --git a/tools/blenvy/add_ons/auto_export/__init__.py b/tools/blenvy/add_ons/auto_export/__init__.py index a8672a2..2b6dd92 100644 --- a/tools/blenvy/add_ons/auto_export/__init__.py +++ b/tools/blenvy/add_ons/auto_export/__init__.py @@ -1,7 +1,9 @@ import os import json import bpy -from .helpers.generate_complete_preferences_dict import generate_complete_preferences_dict_gltf +from blenvy.settings import generate_complete_settings_dict +from io_scene_gltf2 import ExportGLTF2_Base + def cleanup_file(): gltf_filepath = bpy.context.window_manager.auto_export_tracker.dummy_file_path @@ -36,7 +38,8 @@ def gltf_post_export_callback(data): # now write new settings gltf_export_settings.clear() - current_gltf_settings = generate_complete_preferences_dict_gltf(dict(settings)) + settings = dict(settings) + current_gltf_settings = generate_complete_settings_dict(settings, presets=ExportGLTF2_Base, ignore_list=["use_active_collection", "use_active_collection_with_nested", "use_active_scene", "use_selection", "will_save_settings", "gltf_export_id"], preset_defaults=True) gltf_export_settings.write(json.dumps(current_gltf_settings)) # now reset the original gltf_settings if gltf_settings_backup != "": diff --git a/tools/blenvy/add_ons/auto_export/helpers/generate_complete_preferences_dict.py b/tools/blenvy/add_ons/auto_export/helpers/generate_complete_preferences_dict.py deleted file mode 100644 index 219fa1f..0000000 --- a/tools/blenvy/add_ons/auto_export/helpers/generate_complete_preferences_dict.py +++ /dev/null @@ -1,28 +0,0 @@ - -from io_scene_gltf2 import (ExportGLTF2_Base) - -# given the input (actual) gltf settings, filters out any invalid/useless params & params that are equal to defaults -def generate_complete_preferences_dict_gltf(settings): - complete_preferences = {} - defaults = {} - gltf_parameters_to_ignore = ["use_active_collection", "use_active_collection_with_nested", "use_active_scene", "use_selection", "will_save_settings", "gltf_export_id"] - def filter_out(pair): - key, value = pair - if key in gltf_parameters_to_ignore: - return False - return True - - for k in ExportGLTF2_Base.__annotations__: # we use parameters from the base class of the standard gltf exporter, that contains all relevant parameters - item = ExportGLTF2_Base.__annotations__[k] - #print("item", item) - default = item.keywords.get('default', None) - #complete_preferences[k] = default - defaults[k] = default - - for key in list(settings.keys()): - if key in defaults and settings[key] != defaults[key]: # only write out values different from defaults - complete_preferences[key] = settings[key] - - complete_preferences = dict(filter(filter_out, dict(complete_preferences).items())) - return complete_preferences - diff --git a/tools/blenvy/add_ons/auto_export/settings.py b/tools/blenvy/add_ons/auto_export/settings.py index 1927506..64248b3 100644 --- a/tools/blenvy/add_ons/auto_export/settings.py +++ b/tools/blenvy/add_ons/auto_export/settings.py @@ -1,14 +1,14 @@ import bpy from bpy_types import (PropertyGroup) from bpy.props import (EnumProperty, PointerProperty, StringProperty, BoolProperty, CollectionProperty, IntProperty) -from blenvy.settings import load_settings, upsert_settings, generate_complete_preferences_dict +from blenvy.settings import load_settings, upsert_settings, generate_complete_settings_dict # list of settings we do NOT want to save settings_black_list = ['settings_save_enabled', 'dry_run'] def save_settings(settings, context): if settings.settings_save_enabled: - settings_dict = generate_complete_preferences_dict(settings, AutoExportSettings, []) + settings_dict = generate_complete_settings_dict(settings, AutoExportSettings, []) print("save settings", settings, context, settings_dict) upsert_settings(settings.settings_save_path, {key: settings_dict[key] for key in settings_dict.keys() if key not in settings_black_list}) diff --git a/tools/blenvy/add_ons/bevy_components/registry/operators.py b/tools/blenvy/add_ons/bevy_components/registry/operators.py index eaf3f32..ab6d48a 100644 --- a/tools/blenvy/add_ons/bevy_components/registry/operators.py +++ b/tools/blenvy/add_ons/bevy_components/registry/operators.py @@ -193,7 +193,7 @@ class OT_OpenSchemaFileBrowser(Operator, ImportHelper): blenvy = context.window_manager.blenvy blenvy.components.schema_path = relative_path - upsert_settings(blenvy.settings_save_path, {"components_schemaPath": relative_path}) + upsert_settings(blenvy.components.settings_save_path, {"schema_path": relative_path}) return {'FINISHED'} diff --git a/tools/blenvy/add_ons/bevy_components/settings.py b/tools/blenvy/add_ons/bevy_components/settings.py index 4fed13b..b2a917e 100644 --- a/tools/blenvy/add_ons/bevy_components/settings.py +++ b/tools/blenvy/add_ons/bevy_components/settings.py @@ -2,7 +2,7 @@ import os import bpy from bpy_types import (PropertyGroup) from bpy.props import (EnumProperty, PointerProperty, StringProperty, BoolProperty, CollectionProperty, IntProperty) -from blenvy.settings import load_settings, upsert_settings, generate_complete_preferences_dict +from blenvy.settings import load_settings, upsert_settings, generate_complete_settings_dict from .propGroups.prop_groups import generate_propertyGroups_for_components from .components.metadata import ensure_metadata_for_all_items @@ -11,7 +11,7 @@ settings_black_list = ['settings_save_enabled', 'watcher_active'] def save_settings(settings, context): if settings.settings_save_enabled: - settings_dict = generate_complete_preferences_dict(settings, ComponentsSettings, []) + settings_dict = generate_complete_settings_dict(settings, ComponentsSettings, []) print("save settings", settings, context,settings_dict) upsert_settings(settings.settings_save_path, {key: settings_dict[key] for key in settings_dict.keys() if key not in settings_black_list}) diff --git a/tools/blenvy/core/blenvy_manager.py b/tools/blenvy/core/blenvy_manager.py index 9fab61a..cdaf295 100644 --- a/tools/blenvy/core/blenvy_manager.py +++ b/tools/blenvy/core/blenvy_manager.py @@ -3,7 +3,7 @@ import bpy from bpy_types import (PropertyGroup) from bpy.props import (BoolProperty, EnumProperty, PointerProperty, StringProperty, CollectionProperty, IntProperty) from .scene_helpers import SceneSelector -from ..settings import upsert_settings, load_settings, generate_complete_preferences_dict +from ..settings import upsert_settings, load_settings, generate_complete_settings_dict import blenvy.add_ons.auto_export.settings as auto_export_settings import blenvy.add_ons.bevy_components.settings as component_settings @@ -15,7 +15,7 @@ settings_black_list = ['settings_save_enabled', 'main_scene_selector', 'main_sce def save_settings(settings, context): if settings.settings_save_enabled: - settings_dict = generate_complete_preferences_dict(settings, BlenvyManager, []) + settings_dict = generate_complete_settings_dict(settings, BlenvyManager, []) print("save settings", settings, context, settings_dict) # upsert_settings(settings.settings_save_path, {key: settings_dict[key] for key in settings_dict.keys() if key not in settings_black_list}) diff --git a/tools/blenvy/settings.py b/tools/blenvy/settings.py index 00f5c23..2d4689f 100644 --- a/tools/blenvy/settings.py +++ b/tools/blenvy/settings.py @@ -23,7 +23,7 @@ def load_settings(name): # given the input (actual) settings, filters out any invalid/useless params & params that are equal to defaults -def generate_complete_preferences_dict(settings, presets, ignore_list=[], preset_defaults=True): +def generate_complete_settings_dict(settings, presets, ignore_list=[], preset_defaults=True): complete_preferences = {} defaults = {} @@ -40,12 +40,18 @@ def generate_complete_preferences_dict(settings, presets, ignore_list=[], preset defaults[k] = default if preset_defaults: complete_preferences[k] = default - # print("defaults", defaults) + #print("defaults", defaults) for key in list(settings.keys()): if key in defaults and settings[key] != defaults[key]: # only write out values different from defaults - complete_preferences[key] = getattr(settings, key, None) + value = getattr(settings, key, None) # this is needed for most of our settings (PropertyGroups) + if value is None: + value = settings[key] # and this for ...gltf settings + complete_preferences[key] = value + #print("setting", key, value, settings[key], settings) + + complete_preferences = dict(filter(filter_out, dict(complete_preferences).items())) return complete_preferences