forked from LeenkxTeam/LNXSDK
Repe [T3DU] and Moises Jpelaez updates
This commit is contained in:
@ -118,10 +118,12 @@ def remove_readonly(func, path, excinfo):
|
||||
func(path)
|
||||
|
||||
|
||||
appended_scenes = []
|
||||
linked_blend_paths = []
|
||||
linked_scenes = []
|
||||
|
||||
def load_external_blends():
|
||||
global appended_scenes
|
||||
global linked_scenes
|
||||
global linked_blend_paths
|
||||
|
||||
wrd = bpy.data.worlds['Lnx']
|
||||
if not hasattr(wrd, 'lnx_external_blends_path'):
|
||||
@ -146,22 +148,24 @@ def load_external_blends():
|
||||
with bpy.data.libraries.load(blend_path, link=True) as (data_from, data_to):
|
||||
data_to.scenes = list(data_from.scenes)
|
||||
|
||||
linked_blend_paths.append(blend_path)
|
||||
|
||||
for scn in data_to.scenes:
|
||||
if scn is not None and scn not in appended_scenes:
|
||||
# make name unique with file name
|
||||
scn.name += "_" + filename.replace(".blend", "")
|
||||
appended_scenes.append(scn)
|
||||
if scn is not None and scn not in linked_scenes:
|
||||
linked_scenes.append(scn)
|
||||
|
||||
log.info(f"Loaded external blend: {blend_path}")
|
||||
except Exception as e:
|
||||
log.error(f"Failed to load external blend {blend_path}: {e}")
|
||||
|
||||
def clear_external_scenes():
|
||||
global appended_scenes
|
||||
if not appended_scenes:
|
||||
global linked_blend_paths
|
||||
global linked_scenes
|
||||
|
||||
if not linked_scenes and not linked_blend_paths:
|
||||
return
|
||||
|
||||
for scn in appended_scenes:
|
||||
for scn in linked_scenes:
|
||||
try:
|
||||
bpy.data.scenes.remove(scn, do_unlink=True)
|
||||
except Exception as e:
|
||||
@ -169,7 +173,7 @@ def clear_external_scenes():
|
||||
|
||||
for lib in list(bpy.data.libraries):
|
||||
try:
|
||||
if lib.users == 0:
|
||||
if lib.users == 0 or lib.filepath in linked_blend_paths:
|
||||
bpy.data.libraries.remove(lib)
|
||||
except Exception as e:
|
||||
log.error(f"Failed to remove library {lib.name}: {e}")
|
||||
@ -179,7 +183,8 @@ def clear_external_scenes():
|
||||
except Exception as e:
|
||||
log.error(f"Failed to purge orphan data: {e}")
|
||||
|
||||
appended_scenes = []
|
||||
linked_scenes = []
|
||||
linked_blend_paths = []
|
||||
|
||||
def export_data(fp, sdk_path):
|
||||
state.is_exporting = True
|
||||
@ -190,6 +195,11 @@ def export_data(fp, sdk_path):
|
||||
|
||||
|
||||
def export_data_impl(fp, sdk_path):
|
||||
# Reload all libraries to retrieve updated data without needing to restart Blender
|
||||
for lib in bpy.data.libraries:
|
||||
lib.reload()
|
||||
log.info(f"Reloaded: {lib.filepath}")
|
||||
|
||||
load_external_blends()
|
||||
|
||||
wrd = bpy.data.worlds['Lnx']
|
||||
@ -263,8 +273,10 @@ def export_data_impl(fp, sdk_path):
|
||||
|
||||
for scene in bpy.data.scenes:
|
||||
if scene.lnx_export:
|
||||
# Reset shader comparison arrays to prevent cross-scene shader merging
|
||||
assets.reset_shader_cons()
|
||||
ext = '.lz4' if LeenkxExporter.compress_enabled else '.lnx'
|
||||
asset_path = build_dir + '/compiled/Assets/' + lnx.utils.safestr(scene.name) + ext
|
||||
asset_path = build_dir + '/compiled/Assets/' + lnx.utils.safestr(scene.name + "_" + os.path.basename(scene.library.filepath).replace(".blend", "") if scene.library else scene.name) + ext
|
||||
LeenkxExporter.export_scene(bpy.context, asset_path, scene=scene, depsgraph=depsgraph)
|
||||
if LeenkxExporter.export_physics:
|
||||
physics_found = True
|
||||
|
||||
Reference in New Issue
Block a user