mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-27 05:46:59 +00:00
Compare commits
1 Commits
2917577de8
...
d83b281c0b
Author | SHA1 | Date | |
---|---|---|---|
|
d83b281c0b |
@ -123,6 +123,7 @@ impl Plugin for BlueprintsPlugin {
|
||||
.register_type::<BlueprintsList>()
|
||||
.register_type::<Vec<String>>()
|
||||
.register_type::<HashMap<String,Vec<String>>>()
|
||||
|
||||
.insert_resource(BluePrintsConfig {
|
||||
format: self.format,
|
||||
library_folder: self.library_folder.clone(),
|
||||
@ -147,17 +148,22 @@ impl Plugin for BlueprintsPlugin {
|
||||
prepare_blueprints,
|
||||
check_for_loaded,
|
||||
spawn_from_blueprints,
|
||||
apply_deferred,
|
||||
apply_deferred
|
||||
)
|
||||
.chain(),
|
||||
(compute_scene_aabbs, apply_deferred)
|
||||
(
|
||||
compute_scene_aabbs,
|
||||
apply_deferred
|
||||
)
|
||||
.chain()
|
||||
.run_if(aabbs_enabled),
|
||||
|
||||
apply_deferred,
|
||||
|
||||
(
|
||||
materials_inject,
|
||||
check_for_material_loaded,
|
||||
materials_inject2,
|
||||
materials_inject2
|
||||
)
|
||||
.chain()
|
||||
.run_if(materials_library_enabled),
|
||||
|
@ -1,17 +1,13 @@
|
||||
use std::path::Path;
|
||||
|
||||
use bevy::{
|
||||
asset::{AssetServer, Assets, Handle},
|
||||
asset::{AssetId, AssetServer, Assets, Handle},
|
||||
ecs::{
|
||||
component::Component,
|
||||
entity::Entity,
|
||||
query::{Added, With},
|
||||
reflect::ReflectComponent,
|
||||
system::{Commands, Query, Res, ResMut},
|
||||
component::Component, entity::Entity, query::{Added, With}, reflect::ReflectComponent, system::{Commands, Query, Res, ResMut}
|
||||
},
|
||||
gltf::Gltf,
|
||||
hierarchy::{Children, Parent},
|
||||
log::debug,
|
||||
log::{debug, info},
|
||||
pbr::StandardMaterial,
|
||||
reflect::Reflect,
|
||||
render::mesh::Mesh,
|
||||
@ -63,24 +59,25 @@ pub(crate) fn materials_inject(
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintMaterialAssetsLoaded);
|
||||
|
||||
} else {
|
||||
let material_file_handle: Handle<Gltf> = asset_server.load(materials_path.clone());
|
||||
let material_file_id = material_file_handle.id();
|
||||
let asset_infos: Vec<AssetLoadTracker<Gltf>> = vec![
|
||||
AssetLoadTracker {
|
||||
let mut asset_infos:Vec<AssetLoadTracker<Gltf>> = vec![];
|
||||
|
||||
asset_infos.push(AssetLoadTracker {
|
||||
name: material_full_path,
|
||||
id: material_file_id,
|
||||
loaded: false,
|
||||
handle: material_file_handle.clone(),
|
||||
}
|
||||
];
|
||||
|
||||
handle: material_file_handle.clone()
|
||||
});
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(AssetsToLoad{
|
||||
all_loaded: false,
|
||||
asset_infos,
|
||||
..Default::default()
|
||||
asset_infos: asset_infos,
|
||||
progress: 0.0
|
||||
//..Default::default()
|
||||
})
|
||||
.insert(BlueprintMaterialAssetsNotLoaded);
|
||||
/**/
|
||||
@ -90,10 +87,7 @@ pub(crate) fn materials_inject(
|
||||
|
||||
// TODO, merge with check_for_loaded, make generic ?
|
||||
pub(crate) fn check_for_material_loaded(
|
||||
mut blueprint_assets_to_load: Query<
|
||||
(Entity, &mut AssetsToLoad<Gltf>),
|
||||
With<BlueprintMaterialAssetsNotLoaded>,
|
||||
>,
|
||||
mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>),With<BlueprintMaterialAssetsNotLoaded>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
){
|
||||
@ -116,24 +110,18 @@ pub(crate) fn check_for_material_loaded(
|
||||
|
||||
if all_loaded {
|
||||
assets_to_load.all_loaded = true;
|
||||
commands
|
||||
.entity(entity)
|
||||
commands.entity(entity)
|
||||
.insert(BlueprintMaterialAssetsLoaded)
|
||||
.remove::<BlueprintMaterialAssetsNotLoaded>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// system that injects / replaces materials from material library
|
||||
pub(crate) fn materials_inject2(
|
||||
mut blueprints_config: ResMut<BluePrintsConfig>,
|
||||
material_infos: Query<
|
||||
(&MaterialInfo, &Children),
|
||||
(
|
||||
Added<BlueprintMaterialAssetsLoaded>,
|
||||
With<BlueprintMaterialAssetsLoaded>,
|
||||
),
|
||||
>,
|
||||
material_infos: Query<(&MaterialInfo, &Children, ), (Added<BlueprintMaterialAssetsLoaded>, With<BlueprintMaterialAssetsLoaded>)>,
|
||||
with_materials_and_meshes: Query<
|
||||
(),
|
||||
(
|
||||
|
@ -52,25 +52,19 @@ pub struct BlueprintsList(pub HashMap<String, Vec<String>>);
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct AssetLoadTracker<T:bevy::prelude::Asset>{
|
||||
#[allow(dead_code)]
|
||||
pub name: String,
|
||||
pub id: AssetId<T>,
|
||||
pub loaded: bool,
|
||||
#[allow(dead_code)]
|
||||
pub handle: Handle<T>,
|
||||
pub handle: Handle<T>
|
||||
}
|
||||
#[derive(Component, Debug)]
|
||||
#[derive(Component, Default, Debug)]
|
||||
pub(crate) struct AssetsToLoad<T:bevy::prelude::Asset>{
|
||||
pub all_loaded: bool,
|
||||
pub asset_infos: Vec<AssetLoadTracker<T>>,
|
||||
pub progress: f32,
|
||||
}
|
||||
impl <T: bevy::prelude::Asset>Default for AssetsToLoad<T> {
|
||||
fn default() -> Self {
|
||||
Self { all_loaded: Default::default(), asset_infos: Default::default(), progress: Default::default() }
|
||||
}
|
||||
pub progress: f32
|
||||
}
|
||||
|
||||
|
||||
/// flag component
|
||||
#[derive(Component)]
|
||||
pub(crate) struct BlueprintAssetsLoaded;
|
||||
@ -97,8 +91,15 @@ pub(crate) fn prepare_blueprints(
|
||||
asset_server: Res<AssetServer>,
|
||||
blueprints_config: Res<BluePrintsConfig>,
|
||||
) {
|
||||
for (entity, blupeprint_name, original_parent, library_override, name, blueprints_list) in
|
||||
spawn_placeholders.iter()
|
||||
for (
|
||||
entity,
|
||||
blupeprint_name,
|
||||
original_parent,
|
||||
library_override,
|
||||
name,
|
||||
|
||||
blueprints_list,
|
||||
) in spawn_placeholders.iter()
|
||||
{
|
||||
debug!(
|
||||
"requesting to spawn {:?} for entity {:?}, id: {:?}, parent:{:?}",
|
||||
@ -110,9 +111,18 @@ pub(crate) fn prepare_blueprints(
|
||||
let blueprints_list = blueprints_list.unwrap();
|
||||
// println!("blueprints list {:?}", blueprints_list.0.keys());
|
||||
let mut asset_infos:Vec<AssetLoadTracker<Gltf>> = vec![];
|
||||
let library_path =
|
||||
library_override.map_or_else(|| &blueprints_config.library_folder, |l| &l.0);
|
||||
|
||||
for (blueprint_name, _) in blueprints_list.0.iter() {
|
||||
/*if blueprint_name == what {
|
||||
println!("WHOLY MOLLY !")
|
||||
}*/
|
||||
// println!("library path {:?}", library_path);
|
||||
let mut library_path = &blueprints_config.library_folder; // TODO: we cannot use the overriden library path
|
||||
// FIXME: hack
|
||||
if blueprint_name == "World" {
|
||||
library_path= &library_override.unwrap().0;
|
||||
}
|
||||
|
||||
let model_file_name = format!("{}.{}", &blueprint_name, &blueprints_config.format);
|
||||
let model_path = Path::new(&library_path).join(Path::new(model_file_name.as_str()));
|
||||
|
||||
@ -124,35 +134,37 @@ pub(crate) fn prepare_blueprints(
|
||||
name: model_path.to_string_lossy().into(),
|
||||
id: model_id,
|
||||
loaded: false,
|
||||
handle: model_handle.clone(),
|
||||
});
|
||||
handle: model_handle.clone()
|
||||
})
|
||||
}
|
||||
}
|
||||
// if not all assets are already loaded, inject a component to signal that we need them to be loaded
|
||||
if !asset_infos.is_empty() {
|
||||
if asset_infos.len() > 0 {
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(AssetsToLoad{
|
||||
all_loaded: false,
|
||||
asset_infos,
|
||||
..Default::default()
|
||||
asset_infos: asset_infos,
|
||||
progress: 0.0
|
||||
//..Default::default()
|
||||
})
|
||||
.insert(BlueprintAssetsNotLoaded);
|
||||
}else {
|
||||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
} else {
|
||||
// in case there are no blueprintsList
|
||||
commands.entity(entity).insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
else { // in case there are no blueprintsList
|
||||
commands
|
||||
.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn check_for_loaded(
|
||||
mut blueprint_assets_to_load: Query<
|
||||
(Entity, &mut AssetsToLoad<Gltf>),
|
||||
With<BlueprintAssetsNotLoaded>,
|
||||
>,
|
||||
mut blueprint_assets_to_load: Query<(Entity, &mut AssetsToLoad<Gltf>), With<BlueprintAssetsNotLoaded>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
mut commands: Commands,
|
||||
){
|
||||
@ -176,8 +188,7 @@ pub(crate) fn check_for_loaded(
|
||||
|
||||
if all_loaded {
|
||||
assets_to_load.all_loaded = true;
|
||||
commands
|
||||
.entity(entity)
|
||||
commands.entity(entity)
|
||||
.insert(BlueprintAssetsLoaded)
|
||||
.remove::<BlueprintAssetsNotLoaded>();
|
||||
}
|
||||
@ -195,11 +206,7 @@ pub(crate) fn spawn_from_blueprints(
|
||||
Option<&AddToGameWorld>,
|
||||
Option<&Name>,
|
||||
),
|
||||
(
|
||||
With<BlueprintAssetsLoaded>,
|
||||
Added<BlueprintAssetsLoaded>,
|
||||
Without<BlueprintAssetsNotLoaded>,
|
||||
),
|
||||
(With<BlueprintAssetsLoaded>, Added<BlueprintAssetsLoaded>, Without<BlueprintAssetsNotLoaded>),
|
||||
>,
|
||||
|
||||
mut commands: Commands,
|
||||
@ -211,6 +218,7 @@ pub(crate) fn spawn_from_blueprints(
|
||||
|
||||
children: Query<&Children>,
|
||||
){
|
||||
|
||||
for (
|
||||
entity,
|
||||
blupeprint_name,
|
||||
@ -219,6 +227,7 @@ pub(crate) fn spawn_from_blueprints(
|
||||
library_override,
|
||||
add_to_world,
|
||||
name,
|
||||
|
||||
) in spawn_placeholders.iter()
|
||||
{
|
||||
info!(
|
||||
|
@ -7,10 +7,7 @@ use bevy::scene::SceneInstance;
|
||||
|
||||
use super::{AnimationPlayerLink, Animations};
|
||||
use super::{SpawnHere, Spawned};
|
||||
use crate::{
|
||||
AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint,
|
||||
OriginalChildren,
|
||||
};
|
||||
use crate::{AssetsToLoad, BlueprintAssetsLoaded, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren};
|
||||
|
||||
/// this system is in charge of doing any necessary post processing after a blueprint scene has been spawned
|
||||
/// - it removes one level of useless nesting
|
||||
|
@ -1,8 +1,6 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_gltf_blueprints::{
|
||||
BluePrintBundle, BlueprintName, GameWorldTag,
|
||||
};
|
||||
use bevy_gltf_worlflow_examples_common_rapier::{GameState, InAppRunning};
|
||||
use bevy::{prelude::*, utils::hashbrown::HashMap};
|
||||
use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, BlueprintsList, GameWorldTag, Library, SpawnHere};
|
||||
use bevy_gltf_worlflow_examples_common_rapier::{assets::GameAssets, GameState, InAppRunning};
|
||||
|
||||
use bevy_rapier3d::prelude::Velocity;
|
||||
use rand::Rng;
|
||||
|
@ -73,13 +73,6 @@ def copy_hollowed_collection_into(source_collection, destination_collection, par
|
||||
"""we inject the collection/blueprint name, as a component called 'BlueprintName', but we only do this in the empty, not the original object"""
|
||||
empty_obj['BlueprintName'] = '"'+collection_name+'"' if legacy_mode else '("'+collection_name+'")'
|
||||
empty_obj['SpawnHere'] = '()'
|
||||
# we also inject a list of all sub blueprints, so that the bevy side can preload them
|
||||
root_node = CollectionNode()
|
||||
root_node.name = "root"
|
||||
children_per_collection = {}
|
||||
get_sub_collections([object.instance_collection], root_node, children_per_collection)
|
||||
empty_obj["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})"
|
||||
#empty_obj["Assets"] = {"Animations": [], "Materials": [], "Models":[], "Textures":[], "Audio":[], "Other":[]}
|
||||
|
||||
# we copy custom properties over from our original object to our empty
|
||||
for component_name, component_value in object.items():
|
||||
@ -169,7 +162,8 @@ def inject_blueprints_list_into_main_scene(scene):
|
||||
break
|
||||
|
||||
if assets_list is None:
|
||||
assets_list = make_empty('assets_list_'+scene.name+"_components", [0,0,0], [0,0,0], [0,0,0], root_collection)
|
||||
assets_list = make_empty('assets_list_'+scene.name, [0,0,0], [0,0,0], [0,0,0], root_collection)
|
||||
|
||||
|
||||
# find all blueprints used in a scene
|
||||
# TODO: export a tree rather than a flat list ? because you could have potential clashing items in flat lists (amongst other issues)
|
||||
@ -180,12 +174,16 @@ def inject_blueprints_list_into_main_scene(scene):
|
||||
|
||||
#print("collection_names", collection_names, "collections", collections)
|
||||
(bla, bli ) = get_sub_collections(collections, root_node, children_per_collection)
|
||||
#print("sfdsfsdf", bla, bli, "root", root_node, "children_per_collection", children_per_collection)
|
||||
# with sub collections
|
||||
# (collection_names, collections) = get_sub_collections(all_collections, root_node, children_per_collection)
|
||||
#
|
||||
# what about marked assets ?
|
||||
# what about audio assets ?
|
||||
# what about materials ?
|
||||
# object['MaterialInfo'] = '(name: "'+material.name+'", source: "'+current_project_name + '")'
|
||||
|
||||
#assets_list["blueprints_direct"] = list(collection_names)
|
||||
assets_list["BlueprintsList"] = f"({json.dumps(dict(children_per_collection))})"
|
||||
assets_list["Materials"]= '()'
|
||||
#'({"a":[]})'
|
||||
#'([])'
|
||||
#
|
||||
#
|
||||
|
||||
print("assets list", assets_list["BlueprintsList"], children_per_collection)
|
||||
|
@ -16,7 +16,7 @@ def setup_data(request):
|
||||
root_path = "../../testing/bevy_example"
|
||||
assets_root_path = os.path.join(root_path, "assets")
|
||||
models_path = os.path.join(assets_root_path, "models")
|
||||
materials_path = os.path.join(assets_root_path, "materials")
|
||||
#materials_path = os.path.join("../../testing", "materials")
|
||||
#other_materials_path = os.path.join("../../testing", "other_materials")
|
||||
|
||||
print("\nPerforming teardown...")
|
||||
@ -75,8 +75,7 @@ def test_export_complex(setup_data):
|
||||
export_scene_settings=True,
|
||||
export_blueprints=True,
|
||||
export_legacy_mode=False,
|
||||
export_animations=True,
|
||||
export_materials_library=True
|
||||
export_animations=True
|
||||
)
|
||||
# blueprint1 => has an instance, got changed, should export
|
||||
# blueprint2 => has NO instance, but marked as asset, should export
|
||||
|
Loading…
Reference in New Issue
Block a user