mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 11:50:53 +00:00
feat(tools):
* auto_export now defaults to being disabled (otherwise you will get export attempts etc even if you only had the add-on installed ! * modified logic accordingly * various related tweaks * adjusted tests
This commit is contained in:
parent
1cf47d36b1
commit
ed09ab7d48
@ -22,7 +22,6 @@ def auto_export(changes_per_scene, changed_export_parameters, addon_prefs):
|
|||||||
# Get the folder
|
# Get the folder
|
||||||
folder_path = os.path.dirname(file_path)
|
folder_path = os.path.dirname(file_path)
|
||||||
# get the preferences for our addon
|
# get the preferences for our addon
|
||||||
|
|
||||||
#should we use change detection or not
|
#should we use change detection or not
|
||||||
export_change_detection = getattr(addon_prefs, "export_change_detection")
|
export_change_detection = getattr(addon_prefs, "export_change_detection")
|
||||||
|
|
||||||
|
@ -179,13 +179,15 @@ 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"
|
||||||
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")
|
if current_auto_settings != None:
|
||||||
previous_auto_settings.clear()
|
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.write(current_auto_settings.as_string()) # TODO : check if this is always valid
|
previous_auto_settings.clear()
|
||||||
|
previous_auto_settings.write(current_auto_settings.as_string()) # TODO : check if this is always valid
|
||||||
|
|
||||||
previous_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings_previous"] if ".gltf_auto_export_gltf_settings_previous" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings_previous")
|
if previous_gltf_settings != None:
|
||||||
previous_gltf_settings.clear()
|
previous_gltf_settings = bpy.data.texts[".gltf_auto_export_gltf_settings_previous"] if ".gltf_auto_export_gltf_settings_previous" in bpy.data.texts else bpy.data.texts.new(".gltf_auto_export_gltf_settings_previous")
|
||||||
previous_gltf_settings.write(current_gltf_settings.as_string())
|
previous_gltf_settings.clear()
|
||||||
|
previous_gltf_settings.write(current_gltf_settings.as_string())
|
||||||
|
|
||||||
print("changed", changed)
|
print("changed", changed)
|
||||||
return changed
|
return changed
|
||||||
@ -206,24 +208,26 @@ class AutoExportGLTF(Operator, AutoExportGltfAddonPreferences, ExportHelper):
|
|||||||
print("changed FINAL: auto_settings", changed, "gltf_settings", changed_gltf_settings, "combo", changed or changed_gltf_settings)
|
print("changed FINAL: auto_settings", changed, "gltf_settings", changed_gltf_settings, "combo", changed or changed_gltf_settings)
|
||||||
return changed and changed_gltf_settings"""
|
return changed and changed_gltf_settings"""
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
|
|
||||||
# disable change detection while the operator runs
|
# disable change detection while the operator runs
|
||||||
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)
|
||||||
if self.will_save_settings:
|
if self.will_save_settings:
|
||||||
print("SAVING SETTINGS")
|
|
||||||
self.save_settings(context)
|
self.save_settings(context)
|
||||||
|
|
||||||
changes_per_scene = context.window_manager.auto_export_tracker.changed_objects_per_scene
|
changes_per_scene = context.window_manager.auto_export_tracker.changed_objects_per_scene
|
||||||
|
if self.auto_export: # only do the actual exporting if auto export is actually enabled
|
||||||
#& do the export
|
#& do the export
|
||||||
if self.direct_mode: #Do not auto export when applying settings in the menu, do it on save only
|
if self.direct_mode: #Do not auto export when applying settings in the menu, do it on save only
|
||||||
#determine changed parameters
|
#determine changed parameters
|
||||||
params_changed = self.did_export_settings_change()
|
params_changed = self.did_export_settings_change()
|
||||||
auto_export(changes_per_scene, params_changed, self)
|
auto_export(changes_per_scene, params_changed, self)
|
||||||
# cleanup
|
# cleanup
|
||||||
bpy.app.timers.register(bpy.context.window_manager.auto_export_tracker.enable_change_detection, first_interval=1)
|
bpy.app.timers.register(bpy.context.window_manager.auto_export_tracker.enable_change_detection, first_interval=1)
|
||||||
|
else:
|
||||||
|
print("auto export disabled, skipping")
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
|
@ -64,7 +64,7 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
|
|||||||
auto_export: BoolProperty(
|
auto_export: BoolProperty(
|
||||||
name='Auto export',
|
name='Auto export',
|
||||||
description='Automatically export to gltf on save',
|
description='Automatically export to gltf on save',
|
||||||
default=True
|
default=False
|
||||||
)
|
)
|
||||||
export_main_scene_name: StringProperty(
|
export_main_scene_name: StringProperty(
|
||||||
name='Main scene',
|
name='Main scene',
|
||||||
|
@ -73,6 +73,7 @@ class AutoExportTracker(PropertyGroup):
|
|||||||
if active_operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf":
|
if active_operator.bl_idname == "EXPORT_SCENES_OT_auto_gltf":
|
||||||
# we force saving params
|
# we force saving params
|
||||||
active_operator.will_save_settings = True
|
active_operator.will_save_settings = True
|
||||||
|
active_operator.auto_export = True
|
||||||
|
|
||||||
if scene.name != "temp_scene":
|
if scene.name != "temp_scene":
|
||||||
# print("depsgraph_update_post", scene.name)
|
# print("depsgraph_update_post", scene.name)
|
||||||
|
@ -365,3 +365,38 @@ def invoke_override(self, context, event):
|
|||||||
|
|
||||||
|
|
||||||
from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main, GLTF_PT_export_include)
|
from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main, GLTF_PT_export_include)
|
||||||
|
|
||||||
|
|
||||||
|
from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main,ExportGLTF2_Base, GLTF_PT_export_include)
|
||||||
|
import io_scene_gltf2 as gltf_exporter_original
|
||||||
|
#import io_scene_gltf2.GLTF_PT_export_data_scene as GLTF_PT_export_data_scene_original
|
||||||
|
"""
|
||||||
|
class GLTF_PT_export_data(gltf_exporter_original.GLTF_PT_export_data):
|
||||||
|
bl_space_type = 'FILE_BROWSER'
|
||||||
|
bl_region_type = 'TOOL_PROPS'
|
||||||
|
bl_label = "Data"
|
||||||
|
bl_parent_id = "GLTF_PT_auto_export_gltf"
|
||||||
|
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"
|
||||||
|
|
||||||
|
class GLTF_PT_export_data_scene(gltf_exporter_original.GLTF_PT_export_data_scene):
|
||||||
|
bl_space_type = 'FILE_BROWSER'
|
||||||
|
bl_region_type = 'TOOL_PROPS'
|
||||||
|
bl_label = "Scene Graph"
|
||||||
|
bl_parent_id = "GLTF_PT_export_data"
|
||||||
|
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(self, context):
|
||||||
|
return super().draw(context)"""
|
@ -85,6 +85,7 @@ def test_export_complex(setup_data):
|
|||||||
bpy.data.objects["Blueprint1_mesh"].location = [1, 2, 1]
|
bpy.data.objects["Blueprint1_mesh"].location = [1, 2, 1]
|
||||||
|
|
||||||
auto_export_operator(
|
auto_export_operator(
|
||||||
|
auto_export=True,
|
||||||
direct_mode=True,
|
direct_mode=True,
|
||||||
export_output_folder="./models",
|
export_output_folder="./models",
|
||||||
export_scene_settings=True,
|
export_scene_settings=True,
|
||||||
|
@ -47,6 +47,7 @@ class GLTF_PT_auto_export_SidePanel(bpy.types.Panel):
|
|||||||
op.gltf_export_id = "gltf_auto_export" # we specify that we are in a special case
|
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 = layout.operator("EXPORT_SCENES_OT_auto_gltf", text="Auto Export Settings")
|
||||||
|
op.auto_export = True
|
||||||
#print("GLTF_PT_export_main", GLTF_PT_export_main.bl_parent_id)
|
#print("GLTF_PT_export_main", GLTF_PT_export_main.bl_parent_id)
|
||||||
|
|
||||||
# main ui in the file => export
|
# main ui in the file => export
|
||||||
@ -69,8 +70,6 @@ class GLTF_PT_auto_export_main(bpy.types.Panel):
|
|||||||
layout.use_property_split = True
|
layout.use_property_split = True
|
||||||
layout.use_property_decorate = False # No animation.
|
layout.use_property_decorate = False # No animation.
|
||||||
|
|
||||||
sfile = context.space_data
|
|
||||||
|
|
||||||
class GLTF_PT_auto_export_root(bpy.types.Panel):
|
class GLTF_PT_auto_export_root(bpy.types.Panel):
|
||||||
bl_space_type = 'FILE_BROWSER'
|
bl_space_type = 'FILE_BROWSER'
|
||||||
bl_region_type = 'TOOL_PROPS'
|
bl_region_type = 'TOOL_PROPS'
|
||||||
@ -159,8 +158,8 @@ class GLTF_PT_auto_export_scenes(bpy.types.Panel):
|
|||||||
col = row.column(align=True)
|
col = row.column(align=True)
|
||||||
col.separator()
|
col.separator()
|
||||||
|
|
||||||
|
layout.active = operator.auto_export
|
||||||
source = operator
|
source = operator
|
||||||
|
|
||||||
rows = 2
|
rows = 2
|
||||||
|
|
||||||
# main/level scenes
|
# main/level scenes
|
||||||
@ -241,8 +240,8 @@ class GLTF_PT_auto_export_blueprints(bpy.types.Panel):
|
|||||||
sfile = context.space_data
|
sfile = context.space_data
|
||||||
operator = sfile.active_operator
|
operator = sfile.active_operator
|
||||||
|
|
||||||
layout.active = operator.export_blueprints
|
layout.active = operator.auto_export and operator.export_blueprints
|
||||||
|
|
||||||
# collections/blueprints
|
# collections/blueprints
|
||||||
layout.prop(operator, "export_blueprints_path")
|
layout.prop(operator, "export_blueprints_path")
|
||||||
layout.prop(operator, "collection_instances_combine_mode")
|
layout.prop(operator, "collection_instances_combine_mode")
|
||||||
@ -275,50 +274,11 @@ class GLTF_PT_auto_export_collections_list(bpy.types.Panel):
|
|||||||
|
|
||||||
sfile = context.space_data
|
sfile = context.space_data
|
||||||
operator = sfile.active_operator
|
operator = sfile.active_operator
|
||||||
|
layout.active = operator.auto_export and operator.export_blueprints
|
||||||
|
|
||||||
for collection in bpy.context.window_manager.exportedCollections:
|
for collection in bpy.context.window_manager.exportedCollections:
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.label(text=collection.name)
|
row.label(text=collection.name)
|
||||||
|
|
||||||
class GLTF_PT_auto_export_gltf(bpy.types.Panel):
|
|
||||||
bl_space_type = 'FILE_BROWSER'
|
|
||||||
bl_region_type = 'TOOL_PROPS'
|
|
||||||
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
|
|
||||||
|
|
||||||
sfile = context.space_data
|
|
||||||
operator = sfile.active_operator
|
|
||||||
addon_prefs = operator
|
|
||||||
|
|
||||||
op = layout.operator("EXPORT_SCENES_OT_wrapper", text='Gltf settings')#'glTF 2.0 (.glb/.gltf)')
|
|
||||||
|
|
||||||
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"
|
|
||||||
#bpy.ops.export_scene.gltf
|
|
||||||
|
|
||||||
"""for key in addon_prefs.__annotations__.keys():
|
|
||||||
if key not in AutoExportGltfPreferenceNames:
|
|
||||||
layout.prop(operator, key)"""
|
|
||||||
|
|
||||||
class SCENE_UL_GLTF_auto_export(bpy.types.UIList):
|
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.
|
# The draw_item function is called for each item of the collection that is visible in the list.
|
||||||
@ -351,41 +311,3 @@ class SCENE_UL_GLTF_auto_export(bpy.types.UIList):
|
|||||||
elif self.layout_type == 'GRID':
|
elif self.layout_type == 'GRID':
|
||||||
layout.alignment = 'CENTER'
|
layout.alignment = 'CENTER'
|
||||||
layout.label(text="", icon_value=icon)
|
layout.label(text="", icon_value=icon)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from io_scene_gltf2 import (ExportGLTF2, GLTF_PT_export_main,ExportGLTF2_Base, GLTF_PT_export_include)
|
|
||||||
import io_scene_gltf2 as gltf_exporter_original
|
|
||||||
#import io_scene_gltf2.GLTF_PT_export_data_scene as GLTF_PT_export_data_scene_original
|
|
||||||
"""
|
|
||||||
class GLTF_PT_export_data(gltf_exporter_original.GLTF_PT_export_data):
|
|
||||||
bl_space_type = 'FILE_BROWSER'
|
|
||||||
bl_region_type = 'TOOL_PROPS'
|
|
||||||
bl_label = "Data"
|
|
||||||
bl_parent_id = "GLTF_PT_auto_export_gltf"
|
|
||||||
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"
|
|
||||||
|
|
||||||
class GLTF_PT_export_data_scene(gltf_exporter_original.GLTF_PT_export_data_scene):
|
|
||||||
bl_space_type = 'FILE_BROWSER'
|
|
||||||
bl_region_type = 'TOOL_PROPS'
|
|
||||||
bl_label = "Scene Graph"
|
|
||||||
bl_parent_id = "GLTF_PT_export_data"
|
|
||||||
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(self, context):
|
|
||||||
return super().draw(context)"""
|
|
Loading…
Reference in New Issue
Block a user