Compare commits

...

2 Commits

Author SHA1 Message Date
kaosat.dev
c476c05c55 feat(blenvy): overhauled directory handling, seems ok now 2024-05-16 23:41:26 +02:00
kaosat.dev
00bf63cbd3 chore(clippy): minor tweaks 2024-05-16 22:38:45 +02:00
7 changed files with 63 additions and 45 deletions

View File

@ -62,14 +62,9 @@ pub enum GltfComponentsSet {
#[derive(Clone, Resource)]
pub struct GltfComponentsConfig {}
#[derive(Default)]
pub struct ComponentsFromGltfPlugin {}
impl Default for ComponentsFromGltfPlugin {
fn default() -> Self {
Self {}
}
}
impl Plugin for ComponentsFromGltfPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(blender_settings::plugin)

View File

@ -15,16 +15,15 @@ pub fn ronstring_to_reflect_component(
let mut components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
// println!("ron_string {:?}", ron_string);
for (name, value) in lookup.into_iter() {
let parsed_value: String;
match value.clone() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
parsed_value = str;
str
}
_ => parsed_value = ron::to_string(&value).unwrap().to_string(),
}
_ => ron::to_string(&value).unwrap().to_string(),
};
if name.as_str() == "bevy_components" {
bevy_components_string_to_components(parsed_value, type_registry, &mut components)
bevy_components_string_to_components(parsed_value, type_registry, &mut components);
} else {
components_string_to_components(
name,
@ -32,7 +31,7 @@ pub fn ronstring_to_reflect_component(
parsed_value,
type_registry,
&mut components,
)
);
}
}
components
@ -95,13 +94,12 @@ fn bevy_components_string_to_components(
) {
let lookup: HashMap<String, Value> = ron::from_str(&parsed_value).unwrap();
for (key, value) in lookup.into_iter() {
let parsed_value: String;
match value.clone() {
let parsed_value: String = match value.clone() {
Value::String(str) => {
parsed_value = str;
str
}
_ => parsed_value = ron::to_string(&value).unwrap().to_string(),
}
_ => ron::to_string(&value).unwrap().to_string(),
};
if let Some(type_registration) = type_registry.get_with_type_path(key.as_str()) {
debug!("TYPE INFO {:?}", type_registration.type_info());

View File

@ -17,7 +17,6 @@ pub fn export_types(world: &mut World) {
let asset_root = world.resource::<AssetRoot>();
let registry_save_path = Path::join(&asset_root.0, &config.save_path);
println!("registry_save_path {}", registry_save_path.display());
let writer = File::create(registry_save_path).expect("should have created schema file");
let components_to_filter_out = &config.component_filter.clone();
@ -29,8 +28,8 @@ pub fn export_types(world: &mut World) {
.iter()
.filter(|type_info| {
let type_id = type_info.type_id();
return components_to_filter_out.is_allowed_by_id(type_id)
&& resources_to_filter_out.is_allowed_by_id(type_id);
components_to_filter_out.is_allowed_by_id(type_id)
&& resources_to_filter_out.is_allowed_by_id(type_id)
})
.map(export_type)
.collect::<Map<_, _>>();

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)
- [ ] 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:

View File

@ -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))

View File

@ -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)

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
# 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'}: