feat(blenvy): overhauled directory handling, seems ok now

This commit is contained in:
kaosat.dev 2024-05-16 23:41:26 +02:00
parent 00bf63cbd3
commit c476c05c55
4 changed files with 50 additions and 24 deletions

View File

@ -12,8 +12,8 @@ Auto export
- move out some parameters from auto export to a higher level (as they are now used in multiple places) - move out some parameters from auto export to a higher level (as they are now used in multiple places)
- [ ] main/ library scene names - [x] main/ library scene names
- [ ] paths - [x] paths
Data storage: Data storage:
- for scenes (main scenes) - for scenes (main scenes)
@ -37,7 +37,7 @@ Assets:
- QUESTION : do we want to include them in the list of assets per level ? - QUESTION : do we want to include them in the list of assets per level ?
- this would enable pre-loading ALL the assets, but is not ideal in most other cases - this would enable pre-loading ALL the assets, but is not ideal in most other cases
- so add an option ? - so add an option ?
- [ ] the assets of local blueprints - [] the assets of local blueprints
Blueprints: Blueprints:

View File

@ -8,4 +8,4 @@ def absolute_path_from_blend_file(path):
blend_file_folder_path = os.path.dirname(blend_file_path) blend_file_folder_path = os.path.dirname(blend_file_path)
# absolute path # absolute path
return os.path.join(blend_file_folder_path, path) return os.path.abspath(os.path.join(blend_file_folder_path, path))

View File

@ -4,6 +4,8 @@ import os
from bpy_extras.io_utils import ImportHelper from bpy_extras.io_utils import ImportHelper
from bpy.types import Operator from bpy.types import Operator
from ...core.path_helpers import absolute_path_from_blend_file
class OT_OpenFolderbrowser(Operator, ImportHelper): class OT_OpenFolderbrowser(Operator, ImportHelper):
"""Browse for registry json file""" """Browse for registry json file"""
bl_idname = "generic.open_folderbrowser" bl_idname = "generic.open_folderbrowser"
@ -38,35 +40,60 @@ class OT_OpenFolderbrowser(Operator, ImportHelper):
blend_file_path = bpy.data.filepath blend_file_path = bpy.data.filepath
# Get the folder # Get the folder
blend_file_folder_path = os.path.dirname(blend_file_path) blend_file_folder_path = os.path.dirname(blend_file_path)
print("blend_file_folder_path", blend_file_folder_path) #print("blend_file_folder_path", blend_file_folder_path)
print("new_path", self.directory, self.target_property, operator) print("new_path", self.directory, self.target_property, operator)
asset_path_names = ['export_assets_path', 'export_blueprints_path', 'export_levels_path', 'export_materials_path'] asset_path_names = ['export_blueprints_path', 'export_levels_path', 'export_materials_path']
export_root_path = operator.export_root_path export_root_path = absolute_path_from_blend_file(operator.export_root_path)
export_assets_path = operator.export_assets_path export_assets_path = operator.export_assets_path
#export_root_path_absolute = os.path.join(blend_file_folder_path, export_root_path) export_assets_path_full = absolute_path_from_blend_file(os.path.join(export_root_path, export_assets_path)) #os.path.join(blend_file_folder_path, export_root_path, export_assets_path)
export_assets_path_full = os.path.join(blend_file_folder_path, export_root_path, export_assets_path)
print("export_assets_path_full", export_assets_path_full) print("export_assets_path_full", export_assets_path_full)
#new_root_path = os.path.join(blend_file_folder_path, new_path) #new_root_path = os.path.join(blend_file_folder_path, new_path)
if target_path_name == 'export_root_path': if target_path_name == 'export_root_path':
new_root_path_relative = os.path.relpath(new_path, blend_file_folder_path) new_root_path_relative = os.path.relpath(new_path, blend_file_folder_path)
print("changing root new_path to", self.directory, blend_file_folder_path, new_root_path_relative) new_root_path_absolute = new_path
# we need to change all other relative paths before setting the new absolute path
print("new_root_path_relative", new_root_path_relative, new_root_path_absolute)
# first change the asset's path
old_assets_paths_relative = getattr(operator, "export_assets_path", None)
if old_assets_paths_relative is not None:
old_assets_paths_absolute = os.path.abspath(os.path.join(export_root_path, old_assets_paths_relative))
new_assets_path_relative = os.path.relpath(old_assets_paths_absolute, new_root_path_absolute)
new_assets_path_absolute = os.path.abspath(os.path.join(new_root_path_absolute, new_assets_path_relative))
print("old_assets_paths_absolute", old_assets_paths_absolute)
print("new_assets_path_relative", new_assets_path_relative)
print("new_assets_path_absolute", new_assets_path_absolute)
setattr(operator, "export_assets_path", new_assets_path_relative)
# we need to change all other relative paths (root => assets => blueprints/levels/materials etc)
for path_name in asset_path_names: for path_name in asset_path_names:
# get current relative path # get current relative path
relative_path = getattr(operator, path_name, None) relative_path = getattr(operator, path_name, None)
if relative_path is not None: if relative_path is not None:
# and now get absolute path of asset_path # and now get absolute path of asset_path
absolute_path = os.path.join(export_assets_path_full, relative_path) # compute 'old' absolute path
print("absolute path for", path_name, absolute_path) old_absolute_path = os.path.abspath(os.path.join(export_assets_path_full, relative_path))
relative_path = os.path.relpath(absolute_path, new_path) relative_path = os.path.relpath(old_absolute_path, new_assets_path_absolute)
setattr(operator, path_name, relative_path) setattr(operator, path_name, relative_path)
# store the root path as relative to the current blend file # store the root path as relative to the current blend file
setattr(operator, target_path_name, new_path) setattr(operator, target_path_name, new_root_path_relative)
elif target_path_name == 'export_assets_path': elif target_path_name == 'export_assets_path':
pass new_assets_path_relative = os.path.relpath(new_path, export_root_path)
new_assets_path_absolute = new_path
# we need to change all other relative paths (root => assets => blueprints/levels/materials etc)
for path_name in asset_path_names:
# get 'old' relative path
relative_path = getattr(operator, path_name, None)
if relative_path is not None:
# compute 'old' absolute path
old_absolute_path = os.path.abspath(os.path.join(export_assets_path_full, relative_path))
relative_path = os.path.relpath(old_absolute_path, new_assets_path_absolute)
setattr(operator, path_name, relative_path)
setattr(operator, target_path_name, new_assets_path_relative)
else: else:
relative_path = os.path.relpath(new_path, export_assets_path_full) relative_path = os.path.relpath(new_path, export_assets_path_full)
setattr(operator, target_path_name, relative_path) setattr(operator, target_path_name, relative_path)

View File

@ -15,7 +15,6 @@ class SCENE_UL_Blenvy(bpy.types.UIList):
# Note: as index and flt_flag are optional arguments, you do not have to use/declare them here if you don't # Note: as index and flt_flag are optional arguments, you do not have to use/declare them here if you don't
# need them. # need them.
def draw_item(self, context, layout, data, item, icon, active_data, active_propname): def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
print("DRAW STUFF", self)
ob = data ob = data
# draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code. # draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code.
if self.layout_type in {'DEFAULT', 'COMPACT'}: if self.layout_type in {'DEFAULT', 'COMPACT'}: