chore(): more experimenting
This commit is contained in:
parent
d1a369655a
commit
8a62240b7d
|
@ -28,8 +28,9 @@ pub fn track_new_gltf(
|
|||
mut events: EventReader<AssetEvent<Gltf>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
println!("tracking");
|
||||
for event in events.read() {
|
||||
if let AssetEvent::Added { id } = event {
|
||||
if let AssetEvent::LoadedWithDependencies { id } = event {
|
||||
let handle = asset_server
|
||||
.get_id_handle(*id)
|
||||
.expect("this gltf should have been loaded");
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
use bevy::{prelude::*, gltf::{GltfPlugin, Gltf}, scene::ScenePlugin, pbr::PbrPlugin, render::RenderPlugin, core_pipeline::CorePipelinePlugin};
|
||||
use bevy_gltf_components::ComponentsFromGltfPlugin;
|
||||
use bevy::{prelude::*, gltf::{GltfPlugin, Gltf}, scene::ScenePlugin, pbr::PbrPlugin, render::{RenderPlugin, pipelined_rendering::PipelinedRenderingPlugin}, core_pipeline::CorePipelinePlugin};
|
||||
use bevy_gltf_components::{ComponentsFromGltfPlugin, GltfComponentsSet};
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct MyGltf(pub Handle<Gltf>);
|
||||
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
/// helper marker component
|
||||
pub struct LoadedMarker;
|
||||
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
pub struct Pickable;
|
||||
|
||||
#[derive(Component, Reflect, Default, Debug)]
|
||||
#[reflect(Component)]
|
||||
pub struct Player;
|
||||
|
||||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
asset_server: Res<AssetServer>,
|
||||
|
@ -28,55 +44,100 @@ fn foo(
|
|||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
|
||||
fn spawn_level(
|
||||
mut commands: Commands,
|
||||
scene_markers: Query<&LoadedMarker>,
|
||||
mut asset_event_reader: EventReader<AssetEvent<Gltf>>,
|
||||
models: Res<Assets<bevy::gltf::Gltf>>,
|
||||
) {
|
||||
if let Some(asset_event) = asset_event_reader.read().next() {
|
||||
match asset_event {
|
||||
AssetEvent::LoadedWithDependencies { id } => {
|
||||
info!("GLTF loaded/ added {:?}", asset_event);
|
||||
let my_gltf = models.get(*id).unwrap();
|
||||
if scene_markers.is_empty() {
|
||||
info!("spawning scene");
|
||||
commands.spawn((
|
||||
SceneBundle {
|
||||
scene: my_gltf.scenes[0].clone(),
|
||||
..default()
|
||||
},
|
||||
LoadedMarker,
|
||||
Name::new("Level1"),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test(
|
||||
players: Query<&Player>,
|
||||
pickables: Query<&Pickable>
|
||||
){
|
||||
println!("foo");
|
||||
for player in players.iter() {
|
||||
println!("found player")
|
||||
}
|
||||
|
||||
for pickable in pickables.iter() {
|
||||
println!("found pickable")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
// Setup app
|
||||
let mut app = App::new();
|
||||
app
|
||||
// .register_type::<BasicTest>()
|
||||
// .register_type::<UnitTest>()
|
||||
/* .add_plugins((
|
||||
.register_type::<Pickable>()
|
||||
.register_type::<Player>()
|
||||
.add_plugins((
|
||||
MinimalPlugins,
|
||||
|
||||
TransformPlugin::default(),
|
||||
HierarchyPlugin::default(),
|
||||
AssetPlugin::default(),
|
||||
CorePipelinePlugin::default(),
|
||||
|
||||
RenderPlugin::default(),
|
||||
|
||||
PbrPlugin::default(),
|
||||
GltfPlugin::default(),
|
||||
ScenePlugin::default(),
|
||||
|
||||
HierarchyPlugin::default(),
|
||||
TransformPlugin::default(),
|
||||
|
||||
))*/
|
||||
.add_plugins(DefaultPlugins)
|
||||
/*RenderPlugin::default(),
|
||||
ImagePlugin::default(),
|
||||
WindowPlugin::default(),
|
||||
|
||||
.add_plugins(ComponentsFromGltfPlugin)
|
||||
CorePipelinePlugin::default(),
|
||||
PipelinedRenderingPlugin::default(),
|
||||
|
||||
|
||||
*/
|
||||
PbrPlugin::default(),
|
||||
GltfPlugin::default(),
|
||||
|
||||
|
||||
|
||||
))
|
||||
//.add_plugins(DefaultPlugins)
|
||||
//.add_plugins(ComponentsFromGltfPlugin)
|
||||
|
||||
.add_systems(Startup, setup)
|
||||
.add_systems(Update, foo)
|
||||
.add_systems(Update, bruteforce)
|
||||
.add_systems(Update, (
|
||||
(
|
||||
spawn_level,
|
||||
test)
|
||||
.chain()
|
||||
.after(GltfComponentsSet::Injection))
|
||||
)
|
||||
|
||||
.run()
|
||||
//.run_app_until()
|
||||
;
|
||||
|
||||
/*app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
app.update();
|
||||
loop {
|
||||
|
||||
/*loop {
|
||||
// println!("foo {:?}", app.world.resource::<Added<MyGltf>>().clone());
|
||||
app.update();
|
||||
}*/
|
||||
|
|
Loading…
Reference in New Issue