Last active
October 19, 2022 04:04
-
-
Save rparrett/d7864d70d7226d450000623206a5bfde to your computer and use it in GitHub Desktop.
Load a mesh with bevy_asset_loader 0.12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// License: Apache-2.0 / MIT | |
use bevy::prelude::*; | |
use bevy_asset_loader::prelude::*; | |
fn main() { | |
App::new() | |
.add_loading_state( | |
LoadingState::new(MyStates::AssetLoading) | |
.continue_to_state(MyStates::Next) | |
.with_collection::<MyAssets>(), | |
) | |
.add_state(MyStates::AssetLoading) | |
.add_plugins(DefaultPlugins) | |
.add_system_set(SystemSet::on_enter(MyStates::Next).with_system(spawn)) | |
.run(); | |
} | |
#[derive(AssetCollection)] | |
struct MyAssets { | |
#[asset(path = "combine.glb#Mesh0/Primitive0")] | |
test: Handle<Mesh>, | |
} | |
fn spawn( | |
mut commands: Commands, | |
my_assets: Res<MyAssets>, | |
mut meshes: ResMut<Assets<Mesh>>, | |
mut materials: ResMut<Assets<StandardMaterial>>, | |
) { | |
// our mesh | |
commands.spawn_bundle(PbrBundle { | |
mesh: my_assets.test.clone(), | |
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), | |
transform: Transform::from_xyz(0.0, 0.5, 0.0), | |
..default() | |
}); | |
// plane | |
commands.spawn_bundle(PbrBundle { | |
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), | |
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), | |
..default() | |
}); | |
// light | |
commands.spawn_bundle(PointLightBundle { | |
point_light: PointLight { | |
intensity: 1500.0, | |
shadows_enabled: true, | |
..default() | |
}, | |
transform: Transform::from_xyz(4.0, 8.0, 4.0), | |
..default() | |
}); | |
// camera | |
commands.spawn_bundle(Camera3dBundle { | |
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), | |
..default() | |
}); | |
} | |
#[derive(Clone, Eq, PartialEq, Debug, Hash)] | |
enum MyStates { | |
AssetLoading, | |
Next, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment