Skip to content

Commit

Permalink
Add basic example
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim committed Feb 19, 2024
1 parent 2cbdf22 commit cd3be30
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ features = ["png", "bevy_asset", "bevy_pbr", "bevy_gltf"]
[dev-dependencies.bevy]
version = "0.13"
default-features = true
features = ["multi-threaded", "file_watcher"]
Binary file added assets/Fox.glb
Binary file not shown.
18 changes: 9 additions & 9 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ fn main() {
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// sphere
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// objects
commands.spawn((
SceneBundle {
scene: asset_server.load("FlightHelmet/FlightHelmet.gltf#Scene0"),
transform: Transform {
translation: Vec3::new(0.0, -1.0, 0.0),
scale: Vec3::splat(3.0),
..default()
},
PbrBundle {
mesh: meshes.add(Sphere::default()),
material: materials.add(Color::WHITE),
..default()
},
WindWakerShaderBuilder::default()
Expand Down
22 changes: 19 additions & 3 deletions examples/change_color_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ fn main() {
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// sphere
// objects
commands.spawn((
SceneBundle {
scene: asset_server.load("FlightHelmet/FlightHelmet.gltf#Scene0"),
transform: Transform {
translation: Vec3::new(0.0, -1.0, 0.0),
scale: Vec3::splat(3.0),
translation: Vec3::new(-1.5, -1.0, 0.0),
scale: Vec3::splat(4.0),
..default()
},
..default()
Expand All @@ -26,6 +26,22 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
.weather(Weather::Sunny)
.build(),
));
commands.spawn((
SceneBundle {
scene: asset_server.load("Fox.glb#Scene0"),
transform: Transform {
translation: Vec3::new(1.5, -1.0, 0.0),
scale: Vec3::splat(0.03),
..default()
}
.looking_at(Vec3::new(2.0, -2.5, -5.0), Vec3::Y),
..default()
},
WindWakerShaderBuilder::default()
.time_of_day(TimeOfDay::Day)
.weather(Weather::Sunny)
.build(),
));

// light
commands.spawn(PointLightBundle {
Expand Down
64 changes: 64 additions & 0 deletions examples/scene.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
use bevy::prelude::*;
use bevy_wind_waker_shader::prelude::*;

fn main() {
App::new()
.add_plugins((DefaultPlugins, WindWakerShaderPlugin::default()))
.add_systems(Startup, setup)
.add_systems(Update, rotate_light)
.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// objects
commands.spawn((
SceneBundle {
scene: asset_server.load("FlightHelmet/FlightHelmet.gltf#Scene0"),
transform: Transform {
translation: Vec3::new(-1.5, -1.0, 0.0),
scale: Vec3::splat(4.0),
..default()
},
..default()
},
WindWakerShaderBuilder::default()
.time_of_day(TimeOfDay::Day)
.weather(Weather::Sunny)
.build(),
));
commands.spawn((
SceneBundle {
scene: asset_server.load("Fox.glb#Scene0"),
transform: Transform {
translation: Vec3::new(1.5, -1.0, 0.0),
scale: Vec3::splat(0.03),
..default()
}
.looking_at(Vec3::new(2.0, -2.5, -5.0), Vec3::Y),
..default()
},
WindWakerShaderBuilder::default()
.time_of_day(TimeOfDay::Day)
.weather(Weather::Sunny)
.build(),
));

// light
commands.spawn(PointLightBundle::default());

// camera
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
}

fn rotate_light(mut q: Query<&mut Transform, With<PointLight>>, time: Res<Time>) {
for mut t in q.iter_mut() {
t.translation = Vec3::new(
time.elapsed_seconds().sin(),
0.5,
time.elapsed_seconds().cos(),
) * 4.0;
}
}

0 comments on commit cd3be30

Please sign in to comment.