feat(tools): updated blender_auto_export_gltf

* library scene is not a must have anymore
 * added option to scene prefered library scene name
 * option to auto-export on library changes is more coherent
 * renamed variables for more clarity
 * y-up is default
This commit is contained in:
kaosat.dev 2023-07-29 16:41:57 +02:00
parent e4171e5969
commit b3b643c427
1 changed files with 36 additions and 28 deletions

View File

@ -259,9 +259,6 @@ def auto_export():
folder_path = os.path.dirname(file_path) folder_path = os.path.dirname(file_path)
addon_prefs = bpy.context.preferences.addons[__name__].preferences addon_prefs = bpy.context.preferences.addons[__name__].preferences
library_scene = bpy.data.scenes["library"]
""" """
print("folder", folder_path) print("folder", folder_path)
scn_col = bpy.context.scene.collection scn_col = bpy.context.scene.collection
@ -315,7 +312,7 @@ def auto_export():
export_cameras=True, export_cameras=True,
export_extras=True, # For custom exported properties. export_extras=True, # For custom exported properties.
export_lights=True, export_lights=True,
export_yup=False, export_yup=True,
export_skins=True, export_skins=True,
export_morph=False, export_morph=False,
export_apply=False, export_apply=False,
@ -323,7 +320,7 @@ def auto_export():
) )
for key in addon_prefs.__annotations__.keys(): for key in addon_prefs.__annotations__.keys():
if key is not "export_game" and key is not "export_game_scene_name" and key is not "export_game_output_name": #FIXME: ugh, cleanup if key is not "export_on_library_changes" and key is not "export_main_scene_name" and key is not "export_main_output_name" and key is not "export_library_scene_name": #FIXME: ugh, cleanup
gltf_export_preferences[key] = getattr(addon_prefs,key) gltf_export_preferences[key] = getattr(addon_prefs,key)
print("overriding setting", key, "value", getattr(addon_prefs,key)) print("overriding setting", key, "value", getattr(addon_prefs,key))
@ -338,29 +335,32 @@ def auto_export():
# export the main game world # export the main game world
# export_main(game_scene, folder_path, gltf_export_preferences) # export_main(game_scene, folder_path, gltf_export_preferences)
export_game = getattr(addon_prefs,"export_game") export_main_scene_name = getattr(addon_prefs,"export_main_scene_name")
export_game_scene_name = getattr(addon_prefs,"export_game_scene_name") export_main_output_name = getattr(addon_prefs,"export_main_output_name")
export_game_output_name = getattr(addon_prefs,"export_game_output_name") export_on_library_changes = getattr(addon_prefs,"export_on_library_changes")
print("exporting ??", export_game, export_game_scene_name, export_game_output_name) export_library_scene_name = getattr(addon_prefs,"export_library_scene_name")
print("exporting ??", export_on_library_changes, export_main_scene_name, export_main_output_name)
print("last changed", bpy.context.scene.changedScene) print("last changed", bpy.context.scene.changedScene)
# optimised variation # optimised variation
last_changed = bpy.context.scene.changedScene #get_changedScene() last_changed = bpy.context.scene.changedScene #get_changedScene()
if last_changed == export_game_scene_name: if last_changed == export_main_scene_name:
# export the main game world # export the main game world
if export_game: game_scene = bpy.data.scenes[export_main_scene_name]
game_scene = bpy.data.scenes[export_game_scene_name]
print("game world changed, exporting game gltf only") print("game world changed, exporting game gltf only")
export_main(game_scene, folder_path, gltf_export_preferences, export_game_output_name) export_main(game_scene, folder_path, gltf_export_preferences, export_main_output_name)
if last_changed == "library": # if the library has changed, so will likely the game world that uses the library assets if last_changed == export_library_scene_name and export_library_scene_name is not "" : # if the library has changed, so will likely the game world that uses the library assets
print("library changed, exporting both game & library gltf") print("library changed, exporting both game & library gltf")
library_scene = bpy.data.scenes[export_library_scene_name]
# export the library # export the library
# export_library_merged(library_scene, folder_path, gltf_export_preferences) # export_library_merged(library_scene, folder_path, gltf_export_preferences)
# export the main game world # export the main game world
if export_game: if export_on_library_changes:
game_scene = bpy.data.scenes[export_game_scene_name] game_scene = bpy.data.scenes[export_main_scene_name]
export_main(game_scene, folder_path, gltf_export_preferences, export_game_output_name) export_main(game_scene, folder_path, gltf_export_preferences, export_main_output_name)
return {'FINISHED'} return {'FINISHED'}
@ -403,22 +403,30 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
default='GLB' default='GLB'
) )
export_game: BoolProperty(
name='Export world/level', export_main_scene_name: StringProperty(
description='Export world/level into a seperate gltf file', name='Main scene',
default=False
)
export_game_scene_name: StringProperty(
name='Scene to auto export',
description='The name of the main scene/level/world to auto export', description='The name of the main scene/level/world to auto export',
default='world' default='Scene'
) )
export_game_output_name: StringProperty( export_main_output_name: StringProperty(
name='Glb output name', name='Glb output name',
description='The glb output name for the main scene to auto export', description='The glb output name for the main scene to auto export',
default='world' default='world'
) )
export_on_library_changes: BoolProperty(
name='Export on library changes',
description='Export main scene on library changes',
default=False
)
export_library_scene_name: StringProperty(
name='Library scene',
description='The name of the library scene to auto export',
default=''
)
#####
export_copyright: StringProperty( export_copyright: StringProperty(
name='Copyright', name='Copyright',
description='Legal rights and conditions for the model', description='Legal rights and conditions for the model',
@ -624,7 +632,7 @@ class AutoExportGltfAddonPreferences(AddonPreferences):
export_yup: BoolProperty( export_yup: BoolProperty(
name='+Y Up', name='+Y Up',
description='Export using glTF convention, +Y up', description='Export using glTF convention, +Y up',
default=False default=True
) )
use_visible: BoolProperty( use_visible: BoolProperty(