test(bevy_gltf_components): experimenting with tests
This commit is contained in:
parent
76f6a45fc4
commit
d1a369655a
|
@ -17,3 +17,7 @@ bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "
|
|||
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "bevy_scene", "bevy_gltf"] }
|
||||
serde = "1.0.188"
|
||||
ron = "0.8.1"
|
||||
|
||||
[[test]]
|
||||
name = "components_injections_test2"
|
||||
path = "tests/test2.rs"
|
Binary file not shown.
|
@ -21,8 +21,8 @@ use bevy::prelude::{App, IntoSystemConfigs, Plugin, SystemSet, Update};
|
|||
/// fn main() {
|
||||
/// App::new()
|
||||
/// .add_plugins(DefaultPlugins)
|
||||
/// .add_plugin(ComponentsFromGltfPlugin)
|
||||
/// .add_system(spawn_level)
|
||||
/// .add_plugins(ComponentsFromGltfPlugin)
|
||||
/// .add_systems(Update, spawn_level)
|
||||
/// .run();
|
||||
/// }
|
||||
///
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
use bevy::{prelude::*, gltf::{GltfPlugin, Gltf}, scene::ScenePlugin};
|
||||
use bevy_gltf_components::*;
|
||||
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug, )]
|
||||
#[reflect(Component)]
|
||||
struct BasicTest{
|
||||
a: f32,
|
||||
b: u64,
|
||||
c: String
|
||||
}
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug, )]
|
||||
#[reflect(Component)]
|
||||
struct UnitTest;
|
||||
|
||||
|
||||
#[derive(Resource)]
|
||||
struct AssetLoadHelper(Handle<Scene>);
|
||||
|
||||
#[derive(Resource)]
|
||||
struct Loaded(u32);
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
|
||||
let tmp: Handle<Scene> = asset_server.load("level1.glb#Scene0");
|
||||
println!("setting up loading");
|
||||
// commands.insert_resource(AssetLoadHelper(tmp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn spawn_level(
|
||||
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
|
||||
mut loaded: ResMut<Loaded>,
|
||||
){
|
||||
|
||||
//println!("loading");
|
||||
if let Some(asset_event) = asset_event_reader.iter().next() {
|
||||
println!("asset event");
|
||||
match asset_event {
|
||||
AssetEvent::Added { id: _ } => {
|
||||
info!("GLTF loaded");
|
||||
loaded.0 += 1;
|
||||
/*if scene_markers.is_empty() {
|
||||
info!("spawning scene");
|
||||
commands.spawn(
|
||||
(
|
||||
SceneBundle {
|
||||
scene: preloaded_scene.0.clone(),
|
||||
..default()
|
||||
},
|
||||
LoadedMarker,
|
||||
Name::new("Level1")
|
||||
)
|
||||
);
|
||||
next_state.set(AppState::Running);
|
||||
}*/
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// #[test]
|
||||
fn components_injected() {
|
||||
// Setup app
|
||||
let mut app = App::new();
|
||||
app
|
||||
.register_type::<BasicTest>()
|
||||
.register_type::<UnitTest>()
|
||||
.add_plugins((
|
||||
MinimalPlugins,
|
||||
AssetPlugin::default(),
|
||||
GltfPlugin::default(),
|
||||
ScenePlugin::default()
|
||||
))
|
||||
|
||||
//.add_plugins(ComponentsFromGltfPlugin)
|
||||
.add_systems(Startup, setup);
|
||||
// .add_systems(Update, spawn_level);
|
||||
|
||||
app.insert_resource(Loaded(0));
|
||||
|
||||
// Run systems
|
||||
app.run();
|
||||
/*app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
|
||||
loop {
|
||||
app.update();
|
||||
println!("foo {}", app.world.resource::<Loaded>().0);
|
||||
if app.world.resource::<Loaded>().0 > 0 {
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
|
||||
// Check resulting changes
|
||||
let mut query = app.world.query::<(Entity, &Name, &UnitTest)>();
|
||||
println!("AAAAHHH {:?}", query);
|
||||
let mut results = 0;
|
||||
for res in query.iter(&app.world) {
|
||||
results +=1;
|
||||
}
|
||||
assert_eq!(results, 1);
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
use bevy::{prelude::*, gltf::{GltfPlugin, Gltf}, scene::ScenePlugin, pbr::PbrPlugin, render::RenderPlugin, core_pipeline::CorePipelinePlugin};
|
||||
use bevy_gltf_components::ComponentsFromGltfPlugin;
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct MyGltf(pub Handle<Gltf>);
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
println!("setting up loading");
|
||||
commands.insert_resource(MyGltf(asset_server.load("models/level1.glb")));
|
||||
}
|
||||
|
||||
fn foo(
|
||||
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
|
||||
){
|
||||
if let Some(asset_event) = asset_event_reader.read().next() {
|
||||
println!("asset event {:?}",asset_event);
|
||||
match asset_event {
|
||||
AssetEvent::Added { id: _ } => {
|
||||
info!("GLTF Added");
|
||||
},
|
||||
AssetEvent::LoadedWithDependencies { id: _ } => {
|
||||
info!("GLTF loaded");
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
}
|
||||
fn bruteforce(
|
||||
foo: Res<MyGltf>,
|
||||
asset_server: Res<AssetServer>,
|
||||
){
|
||||
let load_state = asset_server.get_load_state(foo.0.id());
|
||||
println!("checking load state {:?}", load_state);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
// Setup app
|
||||
let mut app = App::new();
|
||||
app
|
||||
// .register_type::<BasicTest>()
|
||||
// .register_type::<UnitTest>()
|
||||
/* .add_plugins((
|
||||
MinimalPlugins,
|
||||
AssetPlugin::default(),
|
||||
CorePipelinePlugin::default(),
|
||||
|
||||
RenderPlugin::default(),
|
||||
|
||||
PbrPlugin::default(),
|
||||
GltfPlugin::default(),
|
||||
ScenePlugin::default(),
|
||||
|
||||
HierarchyPlugin::default(),
|
||||
TransformPlugin::default(),
|
||||
|
||||
))*/
|
||||
.add_plugins(DefaultPlugins)
|
||||
|
||||
.add_plugins(ComponentsFromGltfPlugin)
|
||||
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, foo)
|
||||
.add_systems(Update, bruteforce)
|
||||
|
||||
.run()
|
||||
;
|
||||
|
||||
/*app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
loop {
|
||||
// println!("foo {:?}", app.world.resource::<Added<MyGltf>>().clone());
|
||||
app.update();
|
||||
}*/
|
||||
|
||||
}
|
Loading…
Reference in New Issue