mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-12-23 08:04:10 +00:00
fix(auto_export): first draft, working ! but horribly convoluted solution to the correct reseting of change detection state
This commit is contained in:
parent
86a1a4d717
commit
11e8786b59
@ -15,7 +15,7 @@ from pathlib import Path
|
||||
import json
|
||||
import bpy
|
||||
from bpy.types import Context
|
||||
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
|
||||
from bpy.props import (StringProperty, BoolProperty, IntProperty, PointerProperty)
|
||||
|
||||
# from .extension import ExampleExtensionProperties, GLTF_PT_UserExtensionPanel, unregister_panel
|
||||
|
||||
@ -133,6 +133,8 @@ def cleanup_file():
|
||||
|
||||
def glTF2_post_export_callback(data):
|
||||
#print("post_export", data)
|
||||
bpy.context.window_manager.auto_export_tracker.export_finished()
|
||||
|
||||
gltf_settings_backup = bpy.context.window_manager.gltf_settings_backup
|
||||
gltf_filepath = data["gltf_filepath"]
|
||||
gltf_export_id = data['gltf_export_id']
|
||||
@ -189,6 +191,10 @@ def register():
|
||||
bpy.types.TOPBAR_MT_file_export.append(menu_func_import)
|
||||
bpy.types.WindowManager.gltf_settings_backup = StringProperty(default="")
|
||||
|
||||
# FIXME: perhaps move this to tracker
|
||||
bpy.types.WindowManager.exports_count = IntProperty(default=0)
|
||||
|
||||
|
||||
"""bpy.utils.register_class(AutoExportExtensionProperties)
|
||||
bpy.types.Scene.AutoExportExtensionProperties = bpy.props.PointerProperty(type=AutoExportExtensionProperties)"""
|
||||
|
||||
@ -201,6 +207,7 @@ def unregister():
|
||||
bpy.app.handlers.save_post.remove(post_save)
|
||||
|
||||
"""bpy.utils.unregister_class(AutoExportExtensionProperties)"""
|
||||
del bpy.types.WindowManager.exports_count
|
||||
|
||||
if "gltf_auto_export" == "__main__":
|
||||
register()
|
||||
|
@ -107,6 +107,13 @@ def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
||||
export_materials(collections, library_scenes, folder_path, addon_prefs)
|
||||
|
||||
|
||||
main_scenes_to_export = [scene_name for scene_name in main_scene_names if not export_change_detection or changed_export_parameters or scene_name in changes_per_scene.keys() or not check_if_blueprint_on_disk(scene_name, export_levels_path, gltf_extension)]
|
||||
|
||||
bpy.context.window_manager.exports_count = len(collections_to_export)
|
||||
bpy.context.window_manager.exports_count += len(main_scenes_to_export)
|
||||
if export_materials_library:
|
||||
bpy.context.window_manager.exports_count += 1
|
||||
|
||||
print("--------------")
|
||||
print("collections: all:", collections)
|
||||
print("collections: changed:", changed_collections)
|
||||
@ -114,6 +121,9 @@ def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
||||
print("collections: in library:", library_collections)
|
||||
print("collections: to export:", collections_to_export)
|
||||
print("collections: per_scene:", collections_per_scene)
|
||||
print("--------------")
|
||||
print("MAIN SCENES TO EXPORT", main_scenes_to_export)
|
||||
|
||||
|
||||
# backup current active scene
|
||||
old_current_scene = bpy.context.scene
|
||||
|
@ -206,6 +206,9 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
|
||||
params_changed = self.did_export_settings_change()
|
||||
auto_export(changes_per_scene, params_changed, self)
|
||||
# cleanup
|
||||
if bpy.context.window_manager.exports_count == 0: # we need this in case there was nothing to export, to make sure change detection is enabled again
|
||||
print("YOLOOO")
|
||||
bpy.context.window_manager.auto_export_tracker.enable_change_detection()
|
||||
#bpy.context.window_manager.auto_export_tracker.enable_change_detection()
|
||||
# FIXME: wrong logic, this should be called only in an glTF2_post_export_callback
|
||||
bpy.app.timers.register(bpy.context.window_manager.auto_export_tracker.enable_change_detection, first_interval=1)
|
||||
|
@ -53,7 +53,7 @@ class AutoExportTracker(PropertyGroup):
|
||||
|
||||
@classmethod
|
||||
def deps_update_handler(cls, scene, depsgraph):
|
||||
# print("change detection enabled", cls.change_detection_enabled)
|
||||
print("change detection enabled", cls.change_detection_enabled)
|
||||
active_operator = bpy.context.active_operator
|
||||
if active_operator:
|
||||
# print("Operator", active_operator.bl_label, active_operator.bl_idname)
|
||||
@ -124,3 +124,9 @@ class AutoExportTracker(PropertyGroup):
|
||||
self.__class__.change_detection_enabled = True
|
||||
return None
|
||||
|
||||
def export_finished(self):
|
||||
print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHHHHHH export_finished")
|
||||
bpy.context.window_manager.exports_count -= 1
|
||||
if bpy.context.window_manager.exports_count == 0:
|
||||
print("YOLOOO")
|
||||
self.enable_change_detection()
|
||||
|
@ -133,8 +133,8 @@ def test_export_changed_parameters(setup_data):
|
||||
models_library_path = os.path.join(models_path, "library")
|
||||
model_library_file_paths = list(map(lambda file_name: os.path.join(models_library_path, file_name), sorted(os.listdir(models_library_path))))
|
||||
modification_times_first = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||
print("files", model_library_file_paths)
|
||||
print("mod times", modification_times_first)
|
||||
#print("files", model_library_file_paths)
|
||||
#print("mod times", modification_times_first)
|
||||
|
||||
auto_export_operator(
|
||||
auto_export=True,
|
||||
@ -150,7 +150,11 @@ def test_export_changed_parameters(setup_data):
|
||||
assert modification_times_no_change == modification_times_first
|
||||
|
||||
# now move the main cube & export again
|
||||
bpy.context.window_manager.auto_export_tracker.enable_change_detection() # FIXME: should not be needed, but ..
|
||||
print("----------------")
|
||||
print("main scene change")
|
||||
print("----------------")
|
||||
|
||||
#py.context.window_manager.auto_export_tracker.enable_change_detection() # FIXME: should not be needed, but ..
|
||||
bpy.data.objects["Cube"].location = [1, 0, 0]
|
||||
|
||||
auto_export_operator(
|
||||
@ -169,7 +173,10 @@ def test_export_changed_parameters(setup_data):
|
||||
|
||||
|
||||
# now same, but move the cube in the library
|
||||
print("----------------")
|
||||
print("library change")
|
||||
print("----------------")
|
||||
|
||||
bpy.data.objects["Blueprint1_mesh"].location = [1, 2, 1]
|
||||
auto_export_operator(
|
||||
auto_export=True,
|
||||
@ -186,7 +193,11 @@ def test_export_changed_parameters(setup_data):
|
||||
modification_times_first = modification_times
|
||||
|
||||
# now same, but using an operator
|
||||
""" bpy.ops.transform.translate(value=(20.0, 0.0, 0.0))
|
||||
print("----------------")
|
||||
print("change using operator")
|
||||
print("----------------")
|
||||
|
||||
bpy.ops.transform.translate(value=(20.0, 0.0, 0.0))
|
||||
|
||||
auto_export_operator(
|
||||
auto_export=True,
|
||||
@ -200,7 +211,7 @@ def test_export_changed_parameters(setup_data):
|
||||
|
||||
modification_times = list(map(lambda file_path: os.path.getmtime(file_path), model_library_file_paths + [world_file_path]))
|
||||
assert modification_times != modification_times_first
|
||||
modification_times_first = modification_times"""
|
||||
modification_times_first = modification_times
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user