mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-21 19:44:18 +00:00
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>>,
|
mut events: EventReader<AssetEvent<Gltf>>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
|
println!("tracking");
|
||||||
for event in events.read() {
|
for event in events.read() {
|
||||||
if let AssetEvent::Added { id } = event {
|
if let AssetEvent::LoadedWithDependencies { id } = event {
|
||||||
let handle = asset_server
|
let handle = asset_server
|
||||||
.get_id_handle(*id)
|
.get_id_handle(*id)
|
||||||
.expect("this gltf should have been loaded");
|
.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::{prelude::*, gltf::{GltfPlugin, Gltf}, scene::ScenePlugin, pbr::PbrPlugin, render::{RenderPlugin, pipelined_rendering::PipelinedRenderingPlugin}, core_pipeline::CorePipelinePlugin};
|
||||||
use bevy_gltf_components::ComponentsFromGltfPlugin;
|
use bevy_gltf_components::{ComponentsFromGltfPlugin, GltfComponentsSet};
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct MyGltf(pub Handle<Gltf>);
|
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(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
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]
|
#[test]
|
||||||
fn main() {
|
fn main() {
|
||||||
// Setup app
|
// Setup app
|
||||||
let mut app = App::new();
|
let mut app = App::new();
|
||||||
app
|
app
|
||||||
// .register_type::<BasicTest>()
|
.register_type::<Pickable>()
|
||||||
// .register_type::<UnitTest>()
|
.register_type::<Player>()
|
||||||
/* .add_plugins((
|
.add_plugins((
|
||||||
MinimalPlugins,
|
MinimalPlugins,
|
||||||
|
|
||||||
|
TransformPlugin::default(),
|
||||||
|
HierarchyPlugin::default(),
|
||||||
AssetPlugin::default(),
|
AssetPlugin::default(),
|
||||||
CorePipelinePlugin::default(),
|
|
||||||
|
|
||||||
RenderPlugin::default(),
|
|
||||||
|
|
||||||
PbrPlugin::default(),
|
|
||||||
GltfPlugin::default(),
|
|
||||||
ScenePlugin::default(),
|
ScenePlugin::default(),
|
||||||
|
|
||||||
HierarchyPlugin::default(),
|
|
||||||
TransformPlugin::default(),
|
|
||||||
|
|
||||||
))*/
|
/*RenderPlugin::default(),
|
||||||
.add_plugins(DefaultPlugins)
|
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(Startup, setup)
|
||||||
.add_systems(Update, foo)
|
.add_systems(Update, (
|
||||||
.add_systems(Update, bruteforce)
|
(
|
||||||
|
spawn_level,
|
||||||
|
test)
|
||||||
|
.chain()
|
||||||
|
.after(GltfComponentsSet::Injection))
|
||||||
|
)
|
||||||
|
|
||||||
.run()
|
.run()
|
||||||
|
//.run_app_until()
|
||||||
;
|
;
|
||||||
|
|
||||||
/*app.update();
|
|
||||||
app.update();
|
/*loop {
|
||||||
app.update();
|
|
||||||
app.update();
|
|
||||||
app.update();
|
|
||||||
app.update();
|
|
||||||
loop {
|
|
||||||
// println!("foo {:?}", app.world.resource::<Added<MyGltf>>().clone());
|
// println!("foo {:?}", app.world.resource::<Added<MyGltf>>().clone());
|
||||||
app.update();
|
app.update();
|
||||||
}*/
|
}*/
|
||||||
|
Loading…
Reference in New Issue
Block a user