mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-26 21:37:01 +00:00
Compare commits
2 Commits
f561112704
...
c476c05c55
Author | SHA1 | Date | |
---|---|---|---|
|
c476c05c55 | ||
|
00bf63cbd3 |
@ -62,14 +62,9 @@ pub enum GltfComponentsSet {
|
|||||||
#[derive(Clone, Resource)]
|
#[derive(Clone, Resource)]
|
||||||
pub struct GltfComponentsConfig {}
|
pub struct GltfComponentsConfig {}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct ComponentsFromGltfPlugin {}
|
pub struct ComponentsFromGltfPlugin {}
|
||||||
|
|
||||||
impl Default for ComponentsFromGltfPlugin {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Plugin for ComponentsFromGltfPlugin {
|
impl Plugin for ComponentsFromGltfPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_plugins(blender_settings::plugin)
|
app.add_plugins(blender_settings::plugin)
|
||||||
|
@ -15,16 +15,15 @@ pub fn ronstring_to_reflect_component(
|
|||||||
let mut components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
|
let mut components: Vec<(Box<dyn Reflect>, TypeRegistration)> = Vec::new();
|
||||||
// println!("ron_string {:?}", ron_string);
|
// println!("ron_string {:?}", ron_string);
|
||||||
for (name, value) in lookup.into_iter() {
|
for (name, value) in lookup.into_iter() {
|
||||||
let parsed_value: String;
|
let parsed_value: String = match value.clone() {
|
||||||
match value.clone() {
|
|
||||||
Value::String(str) => {
|
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" {
|
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 {
|
} else {
|
||||||
components_string_to_components(
|
components_string_to_components(
|
||||||
name,
|
name,
|
||||||
@ -32,7 +31,7 @@ pub fn ronstring_to_reflect_component(
|
|||||||
parsed_value,
|
parsed_value,
|
||||||
type_registry,
|
type_registry,
|
||||||
&mut components,
|
&mut components,
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
components
|
components
|
||||||
@ -95,13 +94,12 @@ fn bevy_components_string_to_components(
|
|||||||
) {
|
) {
|
||||||
let lookup: HashMap<String, Value> = ron::from_str(&parsed_value).unwrap();
|
let lookup: HashMap<String, Value> = ron::from_str(&parsed_value).unwrap();
|
||||||
for (key, value) in lookup.into_iter() {
|
for (key, value) in lookup.into_iter() {
|
||||||
let parsed_value: String;
|
let parsed_value: String = match value.clone() {
|
||||||
match value.clone() {
|
|
||||||
Value::String(str) => {
|
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()) {
|
if let Some(type_registration) = type_registry.get_with_type_path(key.as_str()) {
|
||||||
debug!("TYPE INFO {:?}", type_registration.type_info());
|
debug!("TYPE INFO {:?}", type_registration.type_info());
|
||||||
|
@ -17,7 +17,6 @@ pub fn export_types(world: &mut World) {
|
|||||||
|
|
||||||
let asset_root = world.resource::<AssetRoot>();
|
let asset_root = world.resource::<AssetRoot>();
|
||||||
let registry_save_path = Path::join(&asset_root.0, &config.save_path);
|
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 writer = File::create(registry_save_path).expect("should have created schema file");
|
||||||
|
|
||||||
let components_to_filter_out = &config.component_filter.clone();
|
let components_to_filter_out = &config.component_filter.clone();
|
||||||
@ -29,8 +28,8 @@ pub fn export_types(world: &mut World) {
|
|||||||
.iter()
|
.iter()
|
||||||
.filter(|type_info| {
|
.filter(|type_info| {
|
||||||
let type_id = type_info.type_id();
|
let type_id = type_info.type_id();
|
||||||
return components_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);
|
&& resources_to_filter_out.is_allowed_by_id(type_id)
|
||||||
})
|
})
|
||||||
.map(export_type)
|
.map(export_type)
|
||||||
.collect::<Map<_, _>>();
|
.collect::<Map<_, _>>();
|
||||||
|
@ -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:
|
||||||
|
@ -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))
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import os
|
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"""
|
||||||
@ -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
|
|
||||||
for path_name in asset_path_names:
|
print("new_root_path_relative", new_root_path_relative, new_root_path_absolute)
|
||||||
# get current relative path
|
# first change the asset's path
|
||||||
relative_path = getattr(operator, path_name, None)
|
old_assets_paths_relative = getattr(operator, "export_assets_path", None)
|
||||||
if relative_path is not None:
|
if old_assets_paths_relative is not None:
|
||||||
# and now get absolute path of asset_path
|
old_assets_paths_absolute = os.path.abspath(os.path.join(export_root_path, old_assets_paths_relative))
|
||||||
absolute_path = os.path.join(export_assets_path_full, relative_path)
|
new_assets_path_relative = os.path.relpath(old_assets_paths_absolute, new_root_path_absolute)
|
||||||
print("absolute path for", path_name, absolute_path)
|
new_assets_path_absolute = os.path.abspath(os.path.join(new_root_path_absolute, new_assets_path_relative))
|
||||||
relative_path = os.path.relpath(absolute_path, new_path)
|
|
||||||
setattr(operator, path_name, relative_path)
|
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
|
# 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)
|
||||||
|
@ -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'}:
|
||||||
|
Loading…
Reference in New Issue
Block a user