mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-12-23 08:04:10 +00:00
feat(blenvy): overhauled directory handling, seems ok now
This commit is contained in:
parent
00bf63cbd3
commit
c476c05c55
@ -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)
|
||||
- [ ] main/ library scene names
|
||||
- [ ] paths
|
||||
- [x] main/ library scene names
|
||||
- [x] paths
|
||||
|
||||
Data storage:
|
||||
- for scenes (main scenes)
|
||||
@ -37,7 +37,7 @@ Assets:
|
||||
- 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
|
||||
- so add an option ?
|
||||
- [ ] the assets of local blueprints
|
||||
- [] the assets of local blueprints
|
||||
|
||||
|
||||
Blueprints:
|
||||
|
@ -8,4 +8,4 @@ def absolute_path_from_blend_file(path):
|
||||
blend_file_folder_path = os.path.dirname(blend_file_path)
|
||||
|
||||
# absolute path
|
||||
return os.path.join(blend_file_folder_path, path)
|
||||
return os.path.abspath(os.path.join(blend_file_folder_path, path))
|
||||
|
@ -2,7 +2,9 @@
|
||||
import bpy
|
||||
import os
|
||||
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):
|
||||
"""Browse for registry json file"""
|
||||
@ -38,35 +40,60 @@ class OT_OpenFolderbrowser(Operator, ImportHelper):
|
||||
blend_file_path = bpy.data.filepath
|
||||
# Get the folder
|
||||
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)
|
||||
|
||||
asset_path_names = ['export_assets_path', 'export_blueprints_path', 'export_levels_path', 'export_materials_path']
|
||||
export_root_path = operator.export_root_path
|
||||
asset_path_names = ['export_blueprints_path', 'export_levels_path', 'export_materials_path']
|
||||
export_root_path = absolute_path_from_blend_file(operator.export_root_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 = os.path.join(blend_file_folder_path, export_root_path, export_assets_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)
|
||||
print("export_assets_path_full", export_assets_path_full)
|
||||
|
||||
#new_root_path = os.path.join(blend_file_folder_path, new_path)
|
||||
if target_path_name == 'export_root_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)
|
||||
# we need to change all other relative paths before setting the new absolute path
|
||||
for path_name in asset_path_names:
|
||||
# get current relative path
|
||||
relative_path = getattr(operator, path_name, None)
|
||||
if relative_path is not None:
|
||||
# and now get absolute path of asset_path
|
||||
absolute_path = os.path.join(export_assets_path_full, relative_path)
|
||||
print("absolute path for", path_name, absolute_path)
|
||||
relative_path = os.path.relpath(absolute_path, new_path)
|
||||
setattr(operator, path_name, relative_path)
|
||||
new_root_path_absolute = new_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:
|
||||
# get current relative path
|
||||
relative_path = getattr(operator, path_name, None)
|
||||
if relative_path is not None:
|
||||
# and now get absolute path of asset_path
|
||||
# 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)
|
||||
|
||||
# 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':
|
||||
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:
|
||||
relative_path = os.path.relpath(new_path, export_assets_path_full)
|
||||
setattr(operator, target_path_name, relative_path)
|
||||
|
@ -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
|
||||
# need them.
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
print("DRAW STUFF", self)
|
||||
ob = data
|
||||
# draw_item must handle the three layout types... Usually 'DEFAULT' and 'COMPACT' can share the same code.
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
|
Loading…
Reference in New Issue
Block a user