|
@@ -1,86 +1,42 @@
|
|
|
-use bevy::{
|
|
|
|
|
- prelude::*,
|
|
|
|
|
- render::{
|
|
|
|
|
- shader::{Shader, ShaderStage},
|
|
|
|
|
- pipeline::PipelineDescriptor,
|
|
|
|
|
- },
|
|
|
|
|
-};
|
|
|
|
|
|
|
+use bevy::prelude::*;
|
|
|
|
|
|
|
|
-struct Plane {
|
|
|
|
|
- mesh: Handle<Mesh>,
|
|
|
|
|
- material: Handle<Material>,
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-fn animate_plane(plane: &mut Plane, time: f32) {
|
|
|
|
|
- // Get the vertices of the plane mesh.
|
|
|
|
|
- let vertices = plane.mesh.get_attribute::<VertexPosition>().unwrap();
|
|
|
|
|
-
|
|
|
|
|
- // For each vertex, offset it up and down based on the time.
|
|
|
|
|
- for vertex in vertices {
|
|
|
|
|
- vertex.position.y += (time * 0.1).sin();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Update the mesh with the new vertices.
|
|
|
|
|
- plane.mesh.update_attribute(VertexPosition, vertices);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// Fragment shader.
|
|
|
|
|
-struct FragmentInput {
|
|
|
|
|
- [[location(0)]] position: Vec2,
|
|
|
|
|
- [[location(1)]] color: Vec3,
|
|
|
|
|
-}
|
|
|
|
|
|
|
+mod config;
|
|
|
|
|
+mod player;
|
|
|
|
|
|
|
|
-#[stage(fragment)]
|
|
|
|
|
-fn main([[location(0)]] input: FragmentInput) -> [[location(0)]] Vec4 {
|
|
|
|
|
- return Vec4::new(input.color.x, input.color.y, input.color.z, 1.0);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// Vertex shader.
|
|
|
|
|
-struct VertexOutput {
|
|
|
|
|
- [[builtin(position)]] position: Vec4,
|
|
|
|
|
- [[location(0)]] color: Vec3,
|
|
|
|
|
-}
|
|
|
|
|
|
|
+#[derive(Component)]
|
|
|
|
|
+struct Plane;
|
|
|
|
|
|
|
|
-#[stage(vertex)]
|
|
|
|
|
-fn main([[location(0)]] position: Vec2, [[location(1)]] color: Vec3) -> VertexOutput {
|
|
|
|
|
- return VertexOutput {
|
|
|
|
|
- position: Vec4::new(position.x, position.y, 1.0, 1.0),
|
|
|
|
|
- color,
|
|
|
|
|
- };
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-fn main() {
|
|
|
|
|
- App::build()
|
|
|
|
|
|
|
+fn main(){
|
|
|
|
|
+ App::new()
|
|
|
.add_plugins(DefaultPlugins)
|
|
.add_plugins(DefaultPlugins)
|
|
|
- .add_startup_system(setup)
|
|
|
|
|
- .add_system(animate_planes)
|
|
|
|
|
|
|
+ .add_systems(Update, player::movement::player_movement)
|
|
|
|
|
+ .add_systems(Startup, setup)
|
|
|
.run();
|
|
.run();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fn setup(
|
|
fn setup(
|
|
|
mut commands: Commands,
|
|
mut commands: Commands,
|
|
|
- mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
- mut shaders: ResMut<Assets<Shader>>,
|
|
|
|
|
-) {
|
|
|
|
|
- // Create the plane mesh.
|
|
|
|
|
- let plane_mesh = meshes.add(Mesh::from(shape::Plane::default()));
|
|
|
|
|
-
|
|
|
|
|
- // Create the material.
|
|
|
|
|
- let material = commands
|
|
|
|
|
- .spawn()
|
|
|
|
|
- .insert(material::Material::pipeline(PipelineDescriptor::default()
|
|
|
|
|
- .set_vertex_layout(Vertex::layout())
|
|
|
|
|
- .set_fragment_shader(shaders.add(Shader::from_glsl(ShaderStage::Fragment, include_str!("fragment.wgsl"))))
|
|
|
|
|
- .set_vertex_shader(shaders.add(Shader::from_glsl(ShaderStage::Vertex, include_str!("vertex.wgsl"))))
|
|
|
|
|
- .build()
|
|
|
|
|
- .unwrap()))
|
|
|
|
|
- .id();
|
|
|
|
|
-
|
|
|
|
|
- // Create the plane entity.
|
|
|
|
|
- commands
|
|
|
|
|
- .spawn_bundle(MeshBundle {
|
|
|
|
|
- mesh: plane_mesh,
|
|
|
|
|
- material,
|
|
|
|
|
- transform: Transform::default(),
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ mut meshes : ResMut<Assets<Mesh>>,
|
|
|
|
|
+ mut materials : ResMut<Assets<StandardMaterial>>
|
|
|
|
|
+){
|
|
|
|
|
+ commands.spawn((Plane,PbrBundle{
|
|
|
|
|
+ mesh: meshes.add(Mesh::from(shape::Plane {size: 5.0,subdivisions: 5})),
|
|
|
|
|
+ material: materials.add(Color::rgb(0.3,0.5,0.3).into()),
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ }));
|
|
|
|
|
+
|
|
|
|
|
+ commands.spawn(PointLightBundle{
|
|
|
|
|
+ point_light: PointLight {
|
|
|
|
|
+ intensity: 10000.0,
|
|
|
|
|
+ range: 100.0,
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ },
|
|
|
|
|
+ transform: Transform::from_translation(Vec3::new(0.0, 5.0, 0.0)),
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ commands.spawn((player::movement::Player, Camera3dBundle{
|
|
|
|
|
+ transform: Transform::from_xyz(4., 4., 4.).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
|
+ ..Default::default()
|
|
|
|
|
+ }));
|
|
|
}
|
|
}
|