feat(auto_export): more preferences handling tweaks, tracker changes etc

This commit is contained in:
kaosat.dev 2024-04-12 14:02:41 +02:00
parent 98930af5f5
commit 9ec60a783b
6 changed files with 49 additions and 22 deletions

View File

@ -27,12 +27,12 @@ def did_export_settings_change():
gltf_settings_changed = sorted(json.loads(previous_gltf_settings.as_string()).items()) != sorted(json.loads(current_gltf_settings.as_string()).items()) if current_gltf_settings != None else False gltf_settings_changed = sorted(json.loads(previous_gltf_settings.as_string()).items()) != sorted(json.loads(current_gltf_settings.as_string()).items()) if current_gltf_settings != None else False
"""print("auto settings previous", sorted(json.loads(previous_auto_settings.as_string()).items())) """print("auto settings previous", sorted(json.loads(previous_auto_settings.as_string()).items()))
print("auto settings current", sorted(json.loads(current_auto_settings.as_string()).items()))""" print("auto settings current", sorted(json.loads(current_auto_settings.as_string()).items()))
print("auto_settings_changed", auto_settings_changed) print("auto_settings_changed", auto_settings_changed)"""
"""print("gltf settings previous", sorted(json.loads(previous_gltf_settings.as_string()).items())) """print("gltf settings previous", sorted(json.loads(previous_gltf_settings.as_string()).items()))
print("gltf settings current", sorted(json.loads(current_gltf_settings.as_string()).items()))""" print("gltf settings current", sorted(json.loads(current_gltf_settings.as_string()).items()))
print("gltf_settings_changed", gltf_settings_changed) print("gltf_settings_changed", gltf_settings_changed)"""
changed = auto_settings_changed or gltf_settings_changed changed = auto_settings_changed or gltf_settings_changed

View File

@ -16,7 +16,7 @@ def get_collections_to_export(changes_per_scene, changed_export_parameters, addo
(collections, blueprint_hierarchy) = get_exportable_collections(level_scenes, library_scenes, addon_prefs) (collections, blueprint_hierarchy) = get_exportable_collections(level_scenes, library_scenes, addon_prefs)
collections_to_export = collections # just for clarity collections_to_export = collections # just for clarity
print("export_change_detection", export_change_detection, export_gltf_extension, export_blueprints_path, changed_export_parameters, changes_per_scene) print("export_change_detection", export_change_detection, "changed_export_parameters", changed_export_parameters, "changes_per_scene", changes_per_scene)
# if the export parameters have changed, bail out early # if the export parameters have changed, bail out early
# we need to re_export everything if the export parameters have been changed # we need to re_export everything if the export parameters have been changed
@ -38,7 +38,7 @@ def get_collections_to_export(changes_per_scene, changed_export_parameters, addo
# determine which collections have changed # determine which collections have changed
for scene, objects in changes_per_scene.items(): for scene, objects in changes_per_scene.items():
print(" changed scene", scene) print(" changed scene", scene)
for obj_name, obj in objects.items(): for obj_name, obj in list(objects.items()):
object_collections = list(obj.users_collection) if hasattr(obj, 'users_collection') else [] object_collections = list(obj.users_collection) if hasattr(obj, 'users_collection') else []
object_collection_names = list(map(lambda collection: collection.name, object_collections)) object_collection_names = list(map(lambda collection: collection.name, object_collections))

View File

@ -3,8 +3,10 @@ import bpy
from bpy.types import Operator from bpy.types import Operator
from bpy_extras.io_utils import ExportHelper from bpy_extras.io_utils import ExportHelper
from bpy.props import (IntProperty) from bpy.props import (IntProperty)
from .preferences import (AutoExportGltfAddonPreferences, AutoExportGltfPreferenceNames) from .preferences import (AutoExportGltfAddonPreferences, AutoExportGltfPreferenceNames)
from .auto_export import auto_export from .auto_export import auto_export
from ..helpers.generate_complete_preferences_dict import generate_complete_preferences_dict_auto
class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper): class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
"""auto export gltf""" """auto export gltf"""
@ -89,13 +91,16 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
return export_props return export_props
def save_settings(self, context): def save_settings(self, context):
export_props = self.format_settings() auto_export_settings = self.format_settings()
self.properties['main_scene_names'] = export_props['main_scene_names'] self.properties['main_scene_names'] = auto_export_settings['main_scene_names']
self.properties['library_scene_names'] = export_props['library_scene_names'] self.properties['library_scene_names'] = auto_export_settings['library_scene_names']
stored_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings") stored_settings = bpy.data.texts[".gltf_auto_export_settings"] if ".gltf_auto_export_settings" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings")
stored_settings.clear() stored_settings.clear()
stored_settings.write(json.dumps(export_props))
auto_export_settings = generate_complete_preferences_dict_auto(auto_export_settings)
stored_settings.write(json.dumps(auto_export_settings))
print("saved settings", auto_export_settings)
#print("saving settings", bpy.data.texts[".gltf_auto_export_settings"].as_string(), "raw", json.dumps(export_props)) #print("saving settings", bpy.data.texts[".gltf_auto_export_settings"].as_string(), "raw", json.dumps(export_props))
def load_settings(self, context): def load_settings(self, context):
@ -182,6 +187,7 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
changed = auto_settings_changed or gltf_settings_changed changed = auto_settings_changed or gltf_settings_changed
# now write the current settings to the "previous settings" # now write the current settings to the "previous settings"
if current_auto_settings != None: if current_auto_settings != None:
print("writing settings")
previous_auto_settings = bpy.data.texts[".gltf_auto_export_settings_previous"] if ".gltf_auto_export_settings_previous" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings_previous") previous_auto_settings = bpy.data.texts[".gltf_auto_export_settings_previous"] if ".gltf_auto_export_settings_previous" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_settings_previous")
previous_auto_settings.clear() previous_auto_settings.clear()
previous_auto_settings.write(current_auto_settings.as_string()) # TODO : check if this is always valid previous_auto_settings.write(current_auto_settings.as_string()) # TODO : check if this is always valid
@ -198,6 +204,7 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
bpy.context.window_manager.auto_export_tracker.disable_change_detection() bpy.context.window_manager.auto_export_tracker.disable_change_detection()
if self.direct_mode: if self.direct_mode:
self.load_settings(context) self.load_settings(context)
print("toto", self.will_save_settings)
if self.will_save_settings: if self.will_save_settings:
self.save_settings(context) self.save_settings(context)

View File

@ -106,7 +106,7 @@ class AutoExportTracker(PropertyGroup):
if cls.change_detection_enabled: if cls.change_detection_enabled:
# ignore anything going on with temporary scenes # ignore anything going on with temporary scenes
if not scene.name.startswith(TEMPSCENE_PREFIX): if not scene.name.startswith(TEMPSCENE_PREFIX):
# print("depsgraph_update_post", scene.name) print("depsgraph_update_post", scene.name)
changed_scene = scene.name or "" changed_scene = scene.name or ""
#print("-------------") #print("-------------")
if not changed_scene in cls.changed_objects_per_scene: if not changed_scene in cls.changed_objects_per_scene:
@ -118,7 +118,8 @@ class AutoExportTracker(PropertyGroup):
if isinstance(obj.id, bpy.types.Object): if isinstance(obj.id, bpy.types.Object):
# get the actual object # get the actual object
object = bpy.data.objects[obj.id.name] object = bpy.data.objects[obj.id.name]
print(" changed object", obj.id.name, "changes", obj, "transforms", obj.is_updated_transform, "geometry", obj.is_updated_geometry) print(" changed object", obj.id.name, "changes", obj, "evalutated", obj.id.is_evaluated, "transforms", obj.is_updated_transform, "geometry", obj.is_updated_geometry)
if obj.is_updated_transform or obj.is_updated_geometry:
cls.changed_objects_per_scene[scene.name][obj.id.name] = object cls.changed_objects_per_scene[scene.name][obj.id.name] = object
elif isinstance(obj.id, bpy.types.Material): # or isinstance(obj.id, bpy.types.ShaderNodeTree): elif isinstance(obj.id, bpy.types.Material): # or isinstance(obj.id, bpy.types.ShaderNodeTree):
# print(" changed material", obj.id, "scene", scene.name,) # print(" changed material", obj.id, "scene", scene.name,)
@ -135,9 +136,17 @@ class AutoExportTracker(PropertyGroup):
if items == 0: if items == 0:
cls.changed_objects_per_scene.clear() cls.changed_objects_per_scene.clear()
# print("changed_objects_per_scene", cls.changed_objects_per_scene) # print("changed_objects_per_scene", cls.changed_objects_per_scene)
else:
cls.changed_objects_per_scene.clear()
# filter out invalid objects
for scene_name in cls.changed_objects_per_scene.keys():
bla = {}
for object_name in cls.changed_objects_per_scene[scene.name]:
object = cls.changed_objects_per_scene[scene.name][object_name]
#print("sdfsd", object, object.valid)
#if not cls.changed_objects_per_scene[scene.name][object_name].invalid:
# bla[object_name] = cls.changed_objects_per_scene[scene.name][object_name]
#cls.changed_objects_per_scene[scene.name]= bla
#cls.changed_objects_per_scene[scene_name] = [o for o in cls.changed_objects_per_scene[scene_name] if not o.invalid]
# get a list of exportable collections for display # get a list of exportable collections for display
# keep it simple, just use Simplenamespace for compatibility with the rest of our code # keep it simple, just use Simplenamespace for compatibility with the rest of our code
@ -163,8 +172,10 @@ class AutoExportTracker(PropertyGroup):
export_blueprints_path = os.path.join(folder_path, export_output_folder, tmp["export_blueprints_path"]) if tmp["export_blueprints_path"] != '' else folder_path export_blueprints_path = os.path.join(folder_path, export_output_folder, tmp["export_blueprints_path"]) if tmp["export_blueprints_path"] != '' else folder_path
tmp["export_blueprints_path"] = export_blueprints_path tmp["export_blueprints_path"] = export_blueprints_path
tmp["export_models_path"] = export_models_path tmp["export_models_path"] = export_models_path
addon_prefs = SimpleNamespace(**tmp) addon_prefs = SimpleNamespace(**tmp)
print("cls.changed_objects_per_scene", cls.changed_objects_per_scene)
(collections, collections_to_export, library_collections, collections_per_scene) = get_collections_to_export(cls.changed_objects_per_scene, export_settings_changed, addon_prefs) (collections, collections_to_export, library_collections, collections_per_scene) = get_collections_to_export(cls.changed_objects_per_scene, export_settings_changed, addon_prefs)
print("collections to export", collections_to_export) print("collections to export", collections_to_export)
try: try:

View File

@ -1,7 +1,8 @@
from ..auto_export.preferences import AutoExportGltfAddonPreferences from ..auto_export.preferences import AutoExportGltfAddonPreferences
from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main,ExportGLTF2_Base, GLTF_PT_export_include) 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): def generate_complete_preferences_dict_gltf(settings):
complete_preferences = {} complete_preferences = {}
defaults = {} defaults = {}
@ -26,13 +27,21 @@ def generate_complete_preferences_dict_gltf(settings):
complete_preferences = dict(filter(filter_out, dict(complete_preferences).items())) complete_preferences = dict(filter(filter_out, dict(complete_preferences).items()))
return complete_preferences return complete_preferences
# given the input (actual) auto settings, filters out any invalid/useless params & params that are equal to defaults
def generate_complete_preferences_dict_auto(settings): def generate_complete_preferences_dict_auto(settings):
complete_preferences = {} complete_preferences = {}
defaults = {}
for k in AutoExportGltfAddonPreferences.__annotations__: for k in AutoExportGltfAddonPreferences.__annotations__:
item = AutoExportGltfAddonPreferences.__annotations__[k] item = AutoExportGltfAddonPreferences.__annotations__[k]
default = item.keywords.get('default', None) default = item.keywords.get('default', None)
complete_preferences[k] = default #complete_preferences[k] = default
defaults[k] = default
for key in list(settings.keys()): for key in list(settings.keys()):
if key in defaults:
if settings[key] != defaults[key]: # only write out values different from defaults
complete_preferences[key] = settings[key]
else:
complete_preferences[key] = settings[key] complete_preferences[key] = settings[key]
return complete_preferences return complete_preferences

View File

@ -228,8 +228,8 @@ def clear_hollow_scene(temp_scene, original_root_collection):
# convenience utility to get lists of scenes # convenience utility to get lists of scenes
def get_scenes(addon_prefs): def get_scenes(addon_prefs):
level_scene_names= getattr(addon_prefs,"main_scene_names") #list(map(lambda scene: scene.name, getattr(addon_prefs,"main_scenes"))) level_scene_names= getattr(addon_prefs,"main_scene_names", []) #list(map(lambda scene: scene.name, getattr(addon_prefs,"main_scenes")))
library_scene_names = getattr(addon_prefs,"library_scene_names") #list(map(lambda scene: scene.name, getattr(addon_prefs,"library_scenes"))) library_scene_names = getattr(addon_prefs,"library_scene_names", []) #list(map(lambda scene: scene.name, getattr(addon_prefs,"library_scenes")))
level_scene_names = list(filter(lambda name: name in bpy.data.scenes, level_scene_names)) level_scene_names = list(filter(lambda name: name in bpy.data.scenes, level_scene_names))
library_scene_names = list(filter(lambda name: name in bpy.data.scenes, library_scene_names)) library_scene_names = list(filter(lambda name: name in bpy.data.scenes, library_scene_names))