mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 20:00:53 +00:00
refactor(Blenvy): deprecated BlueprintName (& BluprintPath), and replaced them with BlueprintInfo
* contains both name & path * also experimented with merging the asset load tracking into BlenvyAssets by adding the fields from the asset loading tracker & ignoring them/ defaulting them for deserialization
This commit is contained in:
parent
253d33f1bb
commit
ee5c74aa9e
@ -13,7 +13,7 @@ this crate adds the ability to define Blueprints/Prefabs for [Bevy](https://bevy
|
|||||||
A blueprint is a set of **overrideable** components + a hierarchy: ie
|
A blueprint is a set of **overrideable** components + a hierarchy: ie
|
||||||
|
|
||||||
* just a Gltf file with Gltf_extras specifying components
|
* just a Gltf file with Gltf_extras specifying components
|
||||||
* a component called BlueprintName
|
* a component called BlueprintInfo
|
||||||
|
|
||||||
Particularly useful when using [Blender](https://www.blender.org/) as an editor for the [Bevy](https://bevyengine.org/) game engine, combined with the Blender add-on that do a lot of the work for you
|
Particularly useful when using [Blender](https://www.blender.org/) as an editor for the [Bevy](https://bevyengine.org/) game engine, combined with the Blender add-on that do a lot of the work for you
|
||||||
- [blenvy](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/blenvy)
|
- [blenvy](https://github.com/kaosat-dev/Blender_bevy_components_workflow/tree/main/tools/blenvy)
|
||||||
@ -51,7 +51,7 @@ fn spawn_blueprint(
|
|||||||
){
|
){
|
||||||
if keycode.just_pressed(KeyCode::S) {
|
if keycode.just_pressed(KeyCode::S) {
|
||||||
let new_entity = commands.spawn((
|
let new_entity = commands.spawn((
|
||||||
BlueprintName("Health_Pickup".to_string()), // mandatory !!
|
BlueprintInfo(name: "Health_Pickup".to_string(), path:""), // mandatory !!
|
||||||
SpawnHere, // mandatory !!
|
SpawnHere, // mandatory !!
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // VERY important !!
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // VERY important !!
|
||||||
// any other component you want to insert
|
// any other component you want to insert
|
||||||
@ -114,7 +114,7 @@ fn main() {
|
|||||||
You can spawn entities from blueprints like this:
|
You can spawn entities from blueprints like this:
|
||||||
```rust no_run
|
```rust no_run
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
BlueprintName("Health_Pickup".to_string()), // mandatory !!
|
BlueprintInfo("Health_Pickup".to_string()), // mandatory !!
|
||||||
SpawnHere, // mandatory !!
|
SpawnHere, // mandatory !!
|
||||||
|
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // optional
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)), // optional
|
||||||
@ -134,7 +134,7 @@ you can just add any additional components you need when spawning :
|
|||||||
|
|
||||||
```rust no_run
|
```rust no_run
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
BlueprintName("Health_Pickup".to_string()),
|
BlueprintInfo("Health_Pickup".to_string()),
|
||||||
SpawnHere,
|
SpawnHere,
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||||
// from Rapier/bevy_xpbd: this means the entity will also have a velocity component when inserted into the world
|
// from Rapier/bevy_xpbd: this means the entity will also have a velocity component when inserted into the world
|
||||||
@ -152,7 +152,7 @@ any component you specify when spawning the Blueprint that is also specified **w
|
|||||||
for example
|
for example
|
||||||
```rust no_run
|
```rust no_run
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
BlueprintName("Health_Pickup".to_string()),
|
BlueprintInfo("Health_Pickup".to_string()),
|
||||||
SpawnHere,
|
SpawnHere,
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||||
HealthPowerUp(20)// if this is component is also present inside the "Health_Pickup" blueprint, that one will be replaced with this component during spawning
|
HealthPowerUp(20)// if this is component is also present inside the "Health_Pickup" blueprint, that one will be replaced with this component during spawning
|
||||||
@ -163,7 +163,7 @@ commands.spawn((
|
|||||||
### BluePrintBundle
|
### BluePrintBundle
|
||||||
|
|
||||||
There is also a ```BluePrintBundle``` for convenience , which just has
|
There is also a ```BluePrintBundle``` for convenience , which just has
|
||||||
* a ```BlueprintName``` component
|
* a ```BlueprintInfo``` component
|
||||||
* a ```SpawnHere``` component
|
* a ```SpawnHere``` component
|
||||||
|
|
||||||
## Additional information
|
## Additional information
|
||||||
@ -178,7 +178,7 @@ commands
|
|||||||
.spawn((
|
.spawn((
|
||||||
Name::from("test"),
|
Name::from("test"),
|
||||||
BluePrintBundle {
|
BluePrintBundle {
|
||||||
blueprint: BlueprintName("TestBlueprint".to_string()),
|
blueprint: BlueprintInfo("TestBlueprint".to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
Library("models".into()) // now the path to the blueprint above will be /assets/models/TestBlueprint.glb
|
Library("models".into()) // now the path to the blueprint above will be /assets/models/TestBlueprint.glb
|
||||||
|
@ -16,7 +16,22 @@ pub struct MyAsset{
|
|||||||
/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints
|
/// helper component, is used to store the list of sub blueprints to enable automatic loading of dependend blueprints
|
||||||
#[derive(Component, Reflect, Default, Debug, Deserialize)]
|
#[derive(Component, Reflect, Default, Debug, Deserialize)]
|
||||||
#[reflect(Component)]
|
#[reflect(Component)]
|
||||||
pub struct BlenvyAssets(pub Vec<MyAsset>);
|
pub struct BlenvyAssets {
|
||||||
|
/// only this field should get filled in from the Blender side
|
||||||
|
pub assets: Vec<MyAsset>,
|
||||||
|
/// set to default when deserializing
|
||||||
|
#[serde(default)]
|
||||||
|
#[reflect(default)]
|
||||||
|
pub loaded: bool,
|
||||||
|
/// set to default when deserializing
|
||||||
|
#[serde(default)]
|
||||||
|
#[reflect(default)]
|
||||||
|
pub progress: f32,
|
||||||
|
#[reflect(ignore)]
|
||||||
|
#[serde(skip)]
|
||||||
|
pub asset_infos: Vec<AssetLoadTracker>,
|
||||||
|
}
|
||||||
|
//(pub Vec<MyAsset>);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -30,7 +45,7 @@ pub(crate) struct BlueprintAssetsLoaded;
|
|||||||
pub(crate) struct BlueprintAssetsNotLoaded;
|
pub(crate) struct BlueprintAssetsNotLoaded;
|
||||||
|
|
||||||
/// helper component, for tracking loaded assets's loading state, id , handle etc
|
/// helper component, for tracking loaded assets's loading state, id , handle etc
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Reflect)]
|
||||||
pub(crate) struct AssetLoadTracker {
|
pub(crate) struct AssetLoadTracker {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
@ -35,15 +35,13 @@ pub enum GltfBlueprintsSet {
|
|||||||
|
|
||||||
#[derive(Bundle)]
|
#[derive(Bundle)]
|
||||||
pub struct BluePrintBundle {
|
pub struct BluePrintBundle {
|
||||||
pub blueprint: BlueprintName,
|
pub blueprint: BlueprintInfo,
|
||||||
pub blueprint_path: BlueprintPath,
|
|
||||||
pub spawn_here: SpawnHere,
|
pub spawn_here: SpawnHere,
|
||||||
}
|
}
|
||||||
impl Default for BluePrintBundle {
|
impl Default for BluePrintBundle {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
BluePrintBundle {
|
BluePrintBundle {
|
||||||
blueprint: BlueprintName("default".into()),
|
blueprint: BlueprintInfo{ name: "default".into(), path:"".into()},
|
||||||
blueprint_path: BlueprintPath("".into()),
|
|
||||||
spawn_here: SpawnHere,
|
spawn_here: SpawnHere,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,8 +74,7 @@ fn aabbs_enabled(blenvy_config: Res<BlenvyConfig>) -> bool {
|
|||||||
impl Plugin for BlueprintsPlugin {
|
impl Plugin for BlueprintsPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app
|
app
|
||||||
.register_type::<BlueprintName>()
|
.register_type::<BlueprintInfo>()
|
||||||
.register_type::<BlueprintPath>()
|
|
||||||
.register_type::<MaterialInfo>()
|
.register_type::<MaterialInfo>()
|
||||||
.register_type::<SpawnHere>()
|
.register_type::<SpawnHere>()
|
||||||
.register_type::<BlueprintAnimations>()
|
.register_type::<BlueprintAnimations>()
|
||||||
|
@ -9,17 +9,6 @@ use crate::{BlenvyAssets, BlenvyAssetsLoadState, AssetLoadTracker, BlenvyConfig,
|
|||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct GameWorldTag;
|
pub struct GameWorldTag;
|
||||||
|
|
||||||
/// Main component for the blueprints
|
|
||||||
#[derive(Component, Reflect, Default, Debug)]
|
|
||||||
#[reflect(Component)]
|
|
||||||
pub struct BlueprintName(pub String);
|
|
||||||
|
|
||||||
/// path component for the blueprints
|
|
||||||
#[derive(Component, Reflect, Default, Debug)]
|
|
||||||
#[reflect(Component)]
|
|
||||||
pub struct BlueprintPath(pub String);
|
|
||||||
|
|
||||||
|
|
||||||
/// Main component for the blueprints
|
/// Main component for the blueprints
|
||||||
/// has both name & path of the blueprint to enable injecting the data from the correct blueprint
|
/// has both name & path of the blueprint to enable injecting the data from the correct blueprint
|
||||||
/// into the entity that contains this component
|
/// into the entity that contains this component
|
||||||
@ -100,67 +89,35 @@ pub enum BlueprintEvent {
|
|||||||
use gltf::Gltf as RawGltf;
|
use gltf::Gltf as RawGltf;
|
||||||
|
|
||||||
pub(crate) fn blueprints_prepare_spawn(
|
pub(crate) fn blueprints_prepare_spawn(
|
||||||
spawn_placeholders: Query<
|
|
||||||
(
|
|
||||||
Entity,
|
|
||||||
&BlueprintPath,
|
|
||||||
),
|
|
||||||
(Added<BlueprintPath>, Without<Spawned>, Without<SpawnHere>)>,
|
|
||||||
|
|
||||||
// before 0.14 we have to use a seperate query, after migrating we can query at the root level
|
|
||||||
entities_with_assets: Query<
|
|
||||||
(
|
|
||||||
Entity,
|
|
||||||
/*&BlueprintName,
|
|
||||||
&BlueprintPath,
|
|
||||||
Option<&Parent>,*/
|
|
||||||
Option<&Name>,
|
|
||||||
Option<&BlenvyAssets>,
|
|
||||||
),
|
|
||||||
(Added<BlenvyAssets>), // Added<BlenvyAssets>
|
|
||||||
>,
|
|
||||||
|
|
||||||
|
|
||||||
blueprint_instances_to_spawn : Query<
|
blueprint_instances_to_spawn : Query<
|
||||||
(
|
(
|
||||||
Entity,
|
Entity,
|
||||||
&BlueprintName,
|
&BlueprintInfo,
|
||||||
&BlueprintPath,
|
|
||||||
Option<&Parent>,
|
Option<&Parent>,
|
||||||
Option<&BlenvyAssets>,
|
Option<&BlenvyAssets>,
|
||||||
),(Added<BlueprintPath>)
|
),(Added<BlueprintInfo>)
|
||||||
>,
|
>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
|
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for (entity, blueprint_path) in spawn_placeholders.iter() {
|
|
||||||
println!("added blueprint_path {:?}", blueprint_path);
|
|
||||||
/*commands.entity(entity).insert(
|
|
||||||
SceneBundle {
|
|
||||||
scene: asset_server.load(format!("{}#Scene0", &blueprint_path.0)), // "levels/World.glb#Scene0"),
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
);*/
|
|
||||||
// let model_handle: Handle<Gltf> = asset_server.load(model_path.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (entity, blueprint_name, blueprint_path, parent, all_assets) in blueprint_instances_to_spawn.iter() {
|
for (entity, blueprint_info, parent, all_assets) in blueprint_instances_to_spawn.iter() {
|
||||||
println!("Detected blueprint to spawn {:?} {:?}", blueprint_name, blueprint_path);
|
println!("Detected blueprint to spawn {:?} {:?}", blueprint_info.name, blueprint_info.path);
|
||||||
println!("all assets {:?}", all_assets);
|
println!("all assets {:?}", all_assets);
|
||||||
//////////////
|
//////////////
|
||||||
|
|
||||||
// we add the asset of the blueprint itself
|
// we add the asset of the blueprint itself
|
||||||
// TODO: add detection of already loaded data
|
// TODO: add detection of already loaded data
|
||||||
let untyped_handle = asset_server.load_untyped(&blueprint_path.0);
|
let untyped_handle = asset_server.load_untyped(&blueprint_info.path);
|
||||||
let asset_id = untyped_handle.id();
|
let asset_id = untyped_handle.id();
|
||||||
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
let loaded = asset_server.is_loaded_with_dependencies(asset_id);
|
||||||
|
|
||||||
let mut asset_infos: Vec<AssetLoadTracker> = vec![];
|
let mut asset_infos: Vec<AssetLoadTracker> = vec![];
|
||||||
if !loaded {
|
if !loaded {
|
||||||
asset_infos.push(AssetLoadTracker {
|
asset_infos.push(AssetLoadTracker {
|
||||||
name: blueprint_name.0.clone(),
|
name: blueprint_info.name.clone(),
|
||||||
id: asset_id,
|
id: asset_id,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
handle: untyped_handle.clone(),
|
handle: untyped_handle.clone(),
|
||||||
@ -169,7 +126,7 @@ asset_server: Res<AssetServer>,
|
|||||||
|
|
||||||
// and we also add all its assets
|
// and we also add all its assets
|
||||||
/* prefetch attempt */
|
/* prefetch attempt */
|
||||||
let gltf = RawGltf::open(format!("assets/{}", blueprint_path.0)).unwrap();// RawGltf::open("examples/Box.gltf")?;
|
let gltf = RawGltf::open(format!("assets/{}", blueprint_info.path)).unwrap();// RawGltf::open("examples/Box.gltf")?;
|
||||||
for scene in gltf.scenes() {
|
for scene in gltf.scenes() {
|
||||||
let foo_extras = scene.extras().clone().unwrap();
|
let foo_extras = scene.extras().clone().unwrap();
|
||||||
|
|
||||||
@ -184,7 +141,7 @@ asset_server: Res<AssetServer>,
|
|||||||
let all_assets: BlenvyAssets = ron::from_str(&assets_raw.as_str().unwrap()).unwrap();
|
let all_assets: BlenvyAssets = ron::from_str(&assets_raw.as_str().unwrap()).unwrap();
|
||||||
println!("all_assets {:?}", all_assets);
|
println!("all_assets {:?}", all_assets);
|
||||||
|
|
||||||
for asset in all_assets.0.iter() {
|
for asset in all_assets.assets.iter() {
|
||||||
let untyped_handle = asset_server.load_untyped(&asset.path);
|
let untyped_handle = asset_server.load_untyped(&asset.path);
|
||||||
//println!("untyped handle {:?}", untyped_handle);
|
//println!("untyped handle {:?}", untyped_handle);
|
||||||
//asset_server.load(asset.path);
|
//asset_server.load(asset.path);
|
||||||
@ -222,7 +179,7 @@ asset_server: Res<AssetServer>,
|
|||||||
|
|
||||||
pub(crate) fn blueprints_check_assets_loading(
|
pub(crate) fn blueprints_check_assets_loading(
|
||||||
mut blueprint_assets_to_load: Query<
|
mut blueprint_assets_to_load: Query<
|
||||||
(Entity, Option<&Name>, &BlueprintPath, &mut BlenvyAssetsLoadState),
|
(Entity, Option<&Name>, &BlueprintInfo, &mut BlenvyAssetsLoadState),
|
||||||
With<BlueprintAssetsNotLoaded>,
|
With<BlueprintAssetsNotLoaded>,
|
||||||
>,
|
>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
@ -230,7 +187,7 @@ pub(crate) fn blueprints_check_assets_loading(
|
|||||||
mut blueprint_events: EventWriter<BlueprintEvent>,
|
mut blueprint_events: EventWriter<BlueprintEvent>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for (entity, entity_name, blueprint_path, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
for (entity, entity_name, blueprint_info, mut assets_to_load) in blueprint_assets_to_load.iter_mut() {
|
||||||
let mut all_loaded = true;
|
let mut all_loaded = true;
|
||||||
let mut loaded_amount = 0;
|
let mut loaded_amount = 0;
|
||||||
let total = assets_to_load.asset_infos.len();
|
let total = assets_to_load.asset_infos.len();
|
||||||
@ -259,8 +216,8 @@ pub(crate) fn blueprints_check_assets_loading(
|
|||||||
|
|
||||||
if all_loaded {
|
if all_loaded {
|
||||||
assets_to_load.all_loaded = true;
|
assets_to_load.all_loaded = true;
|
||||||
println!("LOADING: in progress for ALL assets of {:?} (instance of {}), preparing for spawn", entity_name, blueprint_path.0);
|
println!("LOADING: in progress for ALL assets of {:?} (instance of {}), preparing for spawn", entity_name, blueprint_info.path);
|
||||||
blueprint_events.send(BlueprintEvent::AssetsLoaded {blueprint_name:"".into(), blueprint_path: blueprint_path.0.clone() });
|
blueprint_events.send(BlueprintEvent::AssetsLoaded {blueprint_name:"".into(), blueprint_path: blueprint_info.path.clone() });
|
||||||
|
|
||||||
commands
|
commands
|
||||||
.entity(entity)
|
.entity(entity)
|
||||||
@ -269,7 +226,7 @@ pub(crate) fn blueprints_check_assets_loading(
|
|||||||
.remove::<BlenvyAssetsLoadState>()
|
.remove::<BlenvyAssetsLoadState>()
|
||||||
;
|
;
|
||||||
}else {
|
}else {
|
||||||
println!("LOADING: done for ALL assets of {:?} (instance of {}): {} ",entity_name, blueprint_path.0, progress * 100.0);
|
println!("LOADING: done for ALL assets of {:?} (instance of {}): {} ",entity_name, blueprint_info.path, progress * 100.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,8 +237,7 @@ pub(crate) fn blueprints_spawn(
|
|||||||
spawn_placeholders: Query<
|
spawn_placeholders: Query<
|
||||||
(
|
(
|
||||||
Entity,
|
Entity,
|
||||||
&BlueprintName,
|
&BlueprintInfo,
|
||||||
&BlueprintPath,
|
|
||||||
Option<&Transform>,
|
Option<&Transform>,
|
||||||
Option<&Parent>,
|
Option<&Parent>,
|
||||||
Option<&AddToGameWorld>,
|
Option<&AddToGameWorld>,
|
||||||
@ -303,8 +259,7 @@ pub(crate) fn blueprints_spawn(
|
|||||||
) {
|
) {
|
||||||
for (
|
for (
|
||||||
entity,
|
entity,
|
||||||
blupeprint_name,
|
blueprint_info,
|
||||||
blueprint_path,
|
|
||||||
transform,
|
transform,
|
||||||
original_parent,
|
original_parent,
|
||||||
add_to_world,
|
add_to_world,
|
||||||
@ -313,16 +268,16 @@ pub(crate) fn blueprints_spawn(
|
|||||||
{
|
{
|
||||||
info!(
|
info!(
|
||||||
"all assets loaded, attempting to spawn blueprint {:?} for entity {:?}, id: {:?}, parent:{:?}",
|
"all assets loaded, attempting to spawn blueprint {:?} for entity {:?}, id: {:?}, parent:{:?}",
|
||||||
blupeprint_name.0, name, entity, original_parent
|
blueprint_info.name, name, entity, original_parent
|
||||||
);
|
);
|
||||||
|
|
||||||
// info!("attempting to spawn {:?}", model_path);
|
// info!("attempting to spawn {:?}", model_path);
|
||||||
let model_handle: Handle<Gltf> = asset_server.load(blueprint_path.0.clone()); // FIXME: kinda weird now
|
let model_handle: Handle<Gltf> = asset_server.load(blueprint_info.path.clone()); // FIXME: kinda weird now
|
||||||
|
|
||||||
let gltf = assets_gltf.get(&model_handle).unwrap_or_else(|| {
|
let gltf = assets_gltf.get(&model_handle).unwrap_or_else(|| {
|
||||||
panic!(
|
panic!(
|
||||||
"gltf file {:?} should have been loaded",
|
"gltf file {:?} should have been loaded",
|
||||||
&blueprint_path.0
|
&blueprint_info.path
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use bevy::prelude::*;
|
|||||||
use bevy::scene::SceneInstance;
|
use bevy::scene::SceneInstance;
|
||||||
// use bevy::utils::hashbrown::HashSet;
|
// use bevy::utils::hashbrown::HashSet;
|
||||||
|
|
||||||
use crate::{BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintPath};
|
use crate::{BlueprintAnimationPlayerLink, BlueprintAnimations, BlueprintInfo};
|
||||||
use crate::{SpawnHere, Spawned};
|
use crate::{SpawnHere, Spawned};
|
||||||
use crate::{
|
use crate::{
|
||||||
BlenvyAssetsLoadState, BlueprintAssetsLoaded, BlueprintEvent, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren
|
BlenvyAssetsLoadState, BlueprintAssetsLoaded, BlueprintEvent, CopyComponents, InBlueprint, NoInBlueprint, OriginalChildren
|
||||||
@ -28,7 +28,7 @@ pub(crate) fn spawned_blueprint_post_process(
|
|||||||
&BlueprintAnimations,
|
&BlueprintAnimations,
|
||||||
Option<&NoInBlueprint>,
|
Option<&NoInBlueprint>,
|
||||||
Option<&Name>,
|
Option<&Name>,
|
||||||
&BlueprintPath
|
&BlueprintInfo
|
||||||
),
|
),
|
||||||
(With<SpawnHere>, With<SceneInstance>, With<Spawned>),
|
(With<SpawnHere>, With<SceneInstance>, With<Spawned>),
|
||||||
>,
|
>,
|
||||||
@ -39,7 +39,7 @@ pub(crate) fn spawned_blueprint_post_process(
|
|||||||
mut blueprint_events: EventWriter<BlueprintEvent>,
|
mut blueprint_events: EventWriter<BlueprintEvent>,
|
||||||
|
|
||||||
) {
|
) {
|
||||||
for (original, children, original_children, animations, no_inblueprint, name, blueprint_path) in
|
for (original, children, original_children, animations, no_inblueprint, name, blueprint_info) in
|
||||||
unprocessed_entities.iter()
|
unprocessed_entities.iter()
|
||||||
{
|
{
|
||||||
info!("post processing blueprint for entity {:?}", name);
|
info!("post processing blueprint for entity {:?}", name);
|
||||||
@ -103,7 +103,7 @@ pub(crate) fn spawned_blueprint_post_process(
|
|||||||
//commands.entity(original).remove::<BlueprintAssetsLoaded>();
|
//commands.entity(original).remove::<BlueprintAssetsLoaded>();
|
||||||
commands.entity(root_entity).despawn_recursive();
|
commands.entity(root_entity).despawn_recursive();
|
||||||
|
|
||||||
blueprint_events.send(BlueprintEvent::Spawned {blueprint_name:"".into(), blueprint_path: blueprint_path.0.clone() });
|
blueprint_events.send(BlueprintEvent::Spawned {blueprint_name: blueprint_info.name.clone(), blueprint_path: blueprint_info.path.clone() });
|
||||||
|
|
||||||
debug!("DONE WITH POST PROCESS");
|
debug!("DONE WITH POST PROCESS");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
// use bevy_gltf_blueprints::{BluePrintBundle, BlueprintName, BlueprintPath, GameWorldTag};
|
use blenvy::{BluePrintBundle, BlueprintInfo, GameWorldTag, SpawnHere};
|
||||||
use blenvy::{BluePrintBundle, BlueprintName, BlueprintPath, GameWorldTag, SpawnHere};
|
|
||||||
use crate::{GameState, InAppRunning};
|
use crate::{GameState, InAppRunning};
|
||||||
|
|
||||||
//use bevy_rapier3d::prelude::Velocity;
|
//use bevy_rapier3d::prelude::Velocity;
|
||||||
@ -23,8 +22,7 @@ pub fn setup_game(
|
|||||||
));*/
|
));*/
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
BlueprintName("World".into()),
|
BlueprintInfo{name: "World".into(), path: "levels/World.glb".into()},
|
||||||
BlueprintPath("levels/World.glb".into()),
|
|
||||||
bevy::prelude::Name::from("world"), //FIXME: not really needed ? could be infered from blueprint's name/ path
|
bevy::prelude::Name::from("world"), //FIXME: not really needed ? could be infered from blueprint's name/ path
|
||||||
SpawnHere,
|
SpawnHere,
|
||||||
GameWorldTag,
|
GameWorldTag,
|
||||||
@ -64,11 +62,10 @@ pub fn spawn_test(
|
|||||||
let new_entity = commands
|
let new_entity = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
BluePrintBundle {
|
BluePrintBundle {
|
||||||
blueprint: BlueprintName("Health_Pickup".to_string()),
|
blueprint: BlueprintInfo{name: "Health_Pickup".into() , path:"foo/bar.glb".into()}, // FIXME
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
bevy::prelude::Name::from(format!("test{}", name_index)),
|
bevy::prelude::Name::from(format!("test{}", name_index)),
|
||||||
// BlueprintName("Health_Pickup".to_string()),
|
|
||||||
// SpawnHere,
|
// SpawnHere,
|
||||||
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
TransformBundle::from_transform(Transform::from_xyz(x, 2.0, y)),
|
||||||
/*Velocity {
|
/*Velocity {
|
||||||
|
@ -7,7 +7,7 @@ pub use animation::*;
|
|||||||
use std::{collections::HashMap, fs, time::Duration};
|
use std::{collections::HashMap, fs, time::Duration};
|
||||||
|
|
||||||
use blenvy::{
|
use blenvy::{
|
||||||
BlenvyAssets, BlueprintAnimationPlayerLink, BlueprintEvent, BlueprintName, GltfBlueprintsSet, SceneAnimations
|
BlenvyAssets, BlueprintAnimationPlayerLink, BlueprintEvent, BlueprintInfo, GltfBlueprintsSet, SceneAnimations
|
||||||
};
|
};
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
@ -25,7 +25,7 @@ fn start_game(mut next_app_state: ResMut<NextState<AppState>>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if the export from Blender worked correctly, we should have animations (simplified here by using AnimationPlayerLink)
|
// if the export from Blender worked correctly, we should have animations (simplified here by using AnimationPlayerLink)
|
||||||
// if the export from Blender worked correctly, we should have an Entity called "Blueprint4_nested" that has a child called "Blueprint3" that has a "BlueprintName" component with value Blueprint3
|
// if the export from Blender worked correctly, we should have an Entity called "Blueprint4_nested" that has a child called "Blueprint3" that has a "BlueprintInfo" component with value Blueprint3
|
||||||
// if the export from Blender worked correctly, we should have an assets_list
|
// if the export from Blender worked correctly, we should have an assets_list
|
||||||
// if the export from Blender worked correctly, we should have the correct tree of entities
|
// if the export from Blender worked correctly, we should have the correct tree of entities
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
@ -34,7 +34,7 @@ fn validate_export(
|
|||||||
parents: Query<&Parent>,
|
parents: Query<&Parent>,
|
||||||
children: Query<&Children>,
|
children: Query<&Children>,
|
||||||
names: Query<&Name>,
|
names: Query<&Name>,
|
||||||
blueprints: Query<(Entity, &Name, &BlueprintName)>,
|
blueprints: Query<(Entity, &Name, &BlueprintInfo)>,
|
||||||
animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>,
|
animation_player_links: Query<(Entity, &BlueprintAnimationPlayerLink)>,
|
||||||
scene_animations: Query<(Entity, &SceneAnimations)>,
|
scene_animations: Query<(Entity, &SceneAnimations)>,
|
||||||
empties_candidates: Query<(Entity, &Name, &GlobalTransform)>,
|
empties_candidates: Query<(Entity, &Name, &GlobalTransform)>,
|
||||||
@ -46,13 +46,13 @@ fn validate_export(
|
|||||||
!animation_player_links.is_empty() && scene_animations.into_iter().len() == 4;
|
!animation_player_links.is_empty() && scene_animations.into_iter().len() == 4;
|
||||||
|
|
||||||
let mut nested_blueprint_found = false;
|
let mut nested_blueprint_found = false;
|
||||||
for (entity, name, blueprint_name) in blueprints.iter() {
|
for (entity, name, blueprint_info) in blueprints.iter() {
|
||||||
if name.to_string() == *"Blueprint4_nested" && blueprint_name.0 == *"Blueprint4_nested" {
|
if name.to_string() == *"Blueprint4_nested" && blueprint_info.name == *"Blueprint4_nested" {
|
||||||
if let Ok(cur_children) = children.get(entity) {
|
if let Ok(cur_children) = children.get(entity) {
|
||||||
for child in cur_children.iter() {
|
for child in cur_children.iter() {
|
||||||
if let Ok((_, child_name, child_blueprint_name)) = blueprints.get(*child) {
|
if let Ok((_, child_name, child_blueprint_info)) = blueprints.get(*child) {
|
||||||
if child_name.to_string() == *"Blueprint3"
|
if child_name.to_string() == *"Blueprint3"
|
||||||
&& child_blueprint_name.0 == *"Blueprint3"
|
&& child_blueprint_info.name == *"Blueprint3"
|
||||||
{
|
{
|
||||||
nested_blueprint_found = true;
|
nested_blueprint_found = true;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ This issue has been resolved in v0.9.
|
|||||||
You can enable this option to automatically replace all the **collection instances** inside your main scene with blueprints
|
You can enable this option to automatically replace all the **collection instances** inside your main scene with blueprints
|
||||||
- whenever you change your main scene (or your library scene , if that option is enabled), all your collection instances
|
- whenever you change your main scene (or your library scene , if that option is enabled), all your collection instances
|
||||||
* will be replaced with empties (this will not be visible to you)
|
* will be replaced with empties (this will not be visible to you)
|
||||||
* those empties will have additional custom properties / components : ```BlueprintName``` & ```SpawnHere```
|
* those empties will have additional custom properties / components : ```BlueprintInfo``` & ```SpawnHere```
|
||||||
* your main scene/ level will be exported to a much more trimmed down gltf file (see next point)
|
* your main scene/ level will be exported to a much more trimmed down gltf file (see next point)
|
||||||
* all the original collections (that you used to create the instances) will be exported as **seperate gltf files** into the "library" folder
|
* all the original collections (that you used to create the instances) will be exported as **seperate gltf files** into the "library" folder
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ General issues:
|
|||||||
- [ ] scan for used materials per blueprint !
|
- [ ] scan for used materials per blueprint !
|
||||||
- [ ] for scenes, scan for used materials of all non instance objects (TODO: what about overrides ?)
|
- [ ] for scenes, scan for used materials of all non instance objects (TODO: what about overrides ?)
|
||||||
- [ ] find a solution for the new color handling
|
- [ ] find a solution for the new color handling
|
||||||
- [ ] add back lighting_components
|
- [x] add back lighting_components
|
||||||
- [ ] check if scene components are being deleted through our scene re-orgs in the spawn post process
|
- [x] check if scene components are being deleted through our scene re-orgs in the spawn post process
|
||||||
- [ ] should "blueprint spawned" only be triggered after all its sub blueprints have spawned ?
|
- [ ] should "blueprint spawned" only be triggered after all its sub blueprints have spawned ?
|
||||||
|
|
||||||
- [ ] simplify testing example:
|
- [ ] simplify testing example:
|
||||||
@ -171,6 +171,11 @@ General issues:
|
|||||||
- [ ] rename repo to "Blenvy"
|
- [ ] rename repo to "Blenvy"
|
||||||
- [ ] do a deprecation release of all bevy_gltf_xxx crates to point at the new Blenvy crate
|
- [ ] do a deprecation release of all bevy_gltf_xxx crates to point at the new Blenvy crate
|
||||||
- [ ] hidden objects/collections not respected at export !!!
|
- [ ] hidden objects/collections not respected at export !!!
|
||||||
|
- [ ] add a way of overriding assets for collection instances
|
||||||
|
- [ ] add a way of visualizing per blueprint instances
|
||||||
|
- [ ] cleanup all the spurious debug messages
|
||||||
|
- [ ] deprecate BlueprintName & BlueprintPath & use BlueprintInfo instead
|
||||||
|
- [ ] fix animation handling
|
||||||
|
|
||||||
|
|
||||||
clear && pytest -svv --blender-template ../../testing/bevy_example/art/testing_library.blend --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration_prepare.py && pytest -svv --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration.py
|
clear && pytest -svv --blender-template ../../testing/bevy_example/art/testing_library.blend --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration_prepare.py && pytest -svv --blender-executable /home/ckaos/tools/blender/blender-4.1.0-linux-x64/blender tests/test_bevy_integration.py
|
@ -10,7 +10,11 @@ def assets_to_fake_ron(list_like):
|
|||||||
result = []
|
result = []
|
||||||
for item in list_like:
|
for item in list_like:
|
||||||
result.append(f"(name: \"{item['name']}\", path: \"{item['path']}\")")
|
result.append(f"(name: \"{item['name']}\", path: \"{item['path']}\")")
|
||||||
return f"({result})".replace("'", '')#.join(", ")
|
|
||||||
|
return f"(assets: {result})".replace("'", '')
|
||||||
|
|
||||||
|
return f"({result})".replace("'", '')
|
||||||
|
|
||||||
|
|
||||||
def export_blueprints(blueprints, settings, blueprints_data):
|
def export_blueprints(blueprints, settings, blueprints_data):
|
||||||
blueprints_path_full = getattr(settings, "blueprints_path_full")
|
blueprints_path_full = getattr(settings, "blueprints_path_full")
|
||||||
|
@ -97,10 +97,9 @@ def duplicate_object(object, parent, combine_mode, destination_collection, bluep
|
|||||||
object.name = original_name + "____bak"
|
object.name = original_name + "____bak"
|
||||||
empty_obj = make_empty(original_name, object.location, object.rotation_euler, object.scale, destination_collection)
|
empty_obj = make_empty(original_name, object.location, object.rotation_euler, object.scale, destination_collection)
|
||||||
|
|
||||||
"""we inject the collection/blueprint name, as a component called 'BlueprintName', but we only do this in the empty, not the original object"""
|
"""we inject the collection/blueprint name & path, as a component called 'BlueprintInfo', but we only do this in the empty, not the original object"""
|
||||||
empty_obj['BlueprintName'] = f'("{blueprint_name}")'
|
|
||||||
empty_obj["BlueprintPath"] = f'("{blueprint_path}")'
|
|
||||||
empty_obj['SpawnHere'] = '()'
|
empty_obj['SpawnHere'] = '()'
|
||||||
|
empty_obj['BlueprintInfo'] = f'(name: "{blueprint_name}", path: "{blueprint_path}")'
|
||||||
|
|
||||||
# we copy custom properties over from our original object to our empty
|
# we copy custom properties over from our original object to our empty
|
||||||
for component_name, component_value in object.items():
|
for component_name, component_value in object.items():
|
||||||
|
@ -64,7 +64,7 @@ class ExampleExtensionProperties(bpy.types.PropertyGroup):
|
|||||||
# blueprint settings
|
# blueprint settings
|
||||||
auto_export_blueprints: BoolProperty(
|
auto_export_blueprints: BoolProperty(
|
||||||
name='Export Blueprints',
|
name='Export Blueprints',
|
||||||
description='Replaces collection instances with an Empty with a BlueprintName custom property',
|
description='Replaces collection instances with an Empty with a BlueprintInfo custom property',
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
auto_export_blueprints_path: StringProperty(
|
auto_export_blueprints_path: StringProperty(
|
||||||
|
@ -14,7 +14,10 @@ def assets_to_fake_ron(list_like):
|
|||||||
result = []
|
result = []
|
||||||
for item in list_like:
|
for item in list_like:
|
||||||
result.append(f"(name: \"{item['name']}\", path: \"{item['path']}\")")
|
result.append(f"(name: \"{item['name']}\", path: \"{item['path']}\")")
|
||||||
return f"({result})".replace("'", '')#.join(", ")
|
|
||||||
|
return f"(assets: {result})".replace("'", '')
|
||||||
|
|
||||||
|
return f"({result})".replace("'", '')
|
||||||
|
|
||||||
|
|
||||||
def export_main_scene(scene, settings, blueprints_data):
|
def export_main_scene(scene, settings, blueprints_data):
|
||||||
|
@ -59,7 +59,7 @@ class AutoExportSettings(PropertyGroup):
|
|||||||
# blueprint settings
|
# blueprint settings
|
||||||
export_blueprints: BoolProperty(
|
export_blueprints: BoolProperty(
|
||||||
name='Export Blueprints',
|
name='Export Blueprints',
|
||||||
description='Replaces collection instances with an Empty with a BlueprintName custom property, and enabled a lot more features !',
|
description='Replaces collection instances with an Empty with a BlueprintInfo custom property, and enabled a lot more features !',
|
||||||
default=True,
|
default=True,
|
||||||
update=save_settings
|
update=save_settings
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
@ -88,7 +88,6 @@ expected_custom_property_values = {'bevy_animation::AnimationPlayer': '(animatio
|
|||||||
'bevy_gltf_blueprints::animation::BlueprintAnimations': '(named_animations: "")',
|
'bevy_gltf_blueprints::animation::BlueprintAnimations': '(named_animations: "")',
|
||||||
'bevy_gltf_blueprints::animation::SceneAnimations': '(named_animations: "")',
|
'bevy_gltf_blueprints::animation::SceneAnimations': '(named_animations: "")',
|
||||||
'bevy_gltf_blueprints::materials::MaterialInfo': '(name: " ", source: " ")',
|
'bevy_gltf_blueprints::materials::MaterialInfo': '(name: " ", source: " ")',
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintName': '(" ")',
|
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintsList': '({})',
|
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintsList': '({})',
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::SpawnHere': '()',
|
'bevy_gltf_blueprints::spawn_from_blueprints::SpawnHere': '()',
|
||||||
'bevy_gltf_components::GltfProcessed': '()',
|
'bevy_gltf_components::GltfProcessed': '()',
|
||||||
@ -347,7 +346,6 @@ expected_custom_property_values_randomized = {'bevy_animation::AnimationPlayer':
|
|||||||
'bevy_gltf_blueprints::animation::BlueprintAnimations': '(named_animations: "")',
|
'bevy_gltf_blueprints::animation::BlueprintAnimations': '(named_animations: "")',
|
||||||
'bevy_gltf_blueprints::animation::SceneAnimations': '(named_animations: "")',
|
'bevy_gltf_blueprints::animation::SceneAnimations': '(named_animations: "")',
|
||||||
'bevy_gltf_blueprints::materials::MaterialInfo': '(name: "sbnpsago", source: "piuzfbqp")',
|
'bevy_gltf_blueprints::materials::MaterialInfo': '(name: "sbnpsago", source: "piuzfbqp")',
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintName': '("sbnpsago")',
|
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintsList': '({})',
|
'bevy_gltf_blueprints::spawn_from_blueprints::BlueprintsList': '({})',
|
||||||
'bevy_gltf_blueprints::spawn_from_blueprints::SpawnHere': '()',
|
'bevy_gltf_blueprints::spawn_from_blueprints::SpawnHere': '()',
|
||||||
'bevy_gltf_components::GltfProcessed': '()',
|
'bevy_gltf_components::GltfProcessed': '()',
|
||||||
|
Loading…
Reference in New Issue
Block a user