|
@@ -1,71 +1,42 @@
|
|
|
-use bevy::prelude::*;
|
|
|
|
|
-
|
|
|
|
|
-mod config;
|
|
|
|
|
-mod player;
|
|
|
|
|
-
|
|
|
|
|
-#[derive(Component)]
|
|
|
|
|
-struct Plane;
|
|
|
|
|
|
|
+use bevy::{
|
|
|
|
|
+ prelude::*,
|
|
|
|
|
+ reflect::TypePath,
|
|
|
|
|
+ render::render_resource::{AsBindGroup, ShaderRef},
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
fn main() {
|
|
fn main() {
|
|
|
App::new()
|
|
App::new()
|
|
|
- .add_plugins(DefaultPlugins)
|
|
|
|
|
- .add_systems(Startup, setup1)
|
|
|
|
|
- .add_systems(Update, player::movement::player_movement)
|
|
|
|
|
- .add_systems(Update, planequery)
|
|
|
|
|
|
|
+ .add_plugins((DefaultPlugins, MaterialPlugin::<CustomMaterial>::default()))
|
|
|
|
|
+ .add_systems(Startup, setup)
|
|
|
.run();
|
|
.run();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-fn setup1(
|
|
|
|
|
|
|
+fn setup(
|
|
|
mut commands: Commands,
|
|
mut commands: Commands,
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
- mut materials: ResMut<Assets<StandardMaterial>>,
|
|
|
|
|
|
|
+ mut materials: ResMut<Assets<CustomMaterial>>,
|
|
|
) {
|
|
) {
|
|
|
- commands.spawn((
|
|
|
|
|
- PbrBundle {
|
|
|
|
|
- mesh: meshes.add(Mesh::from(shape::Cube { size: 2.0 })),
|
|
|
|
|
- material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()),
|
|
|
|
|
- ..Default::default()
|
|
|
|
|
- },
|
|
|
|
|
- Plane,
|
|
|
|
|
- ));
|
|
|
|
|
-
|
|
|
|
|
- commands.spawn((
|
|
|
|
|
- Camera3dBundle {
|
|
|
|
|
- transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
|
|
- ..default()
|
|
|
|
|
- },
|
|
|
|
|
- player::movement::Player,
|
|
|
|
|
- ));
|
|
|
|
|
|
|
+ // cube
|
|
|
|
|
+ commands.spawn(MaterialMeshBundle {
|
|
|
|
|
+ mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
|
|
|
|
|
+ transform: Transform::from_xyz(0.0, 0.5, 0.0),
|
|
|
|
|
+ material: materials.add(CustomMaterial {}),
|
|
|
|
|
+ ..default()
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- commands.spawn(PointLightBundle {
|
|
|
|
|
- point_light: PointLight {
|
|
|
|
|
- intensity: 1500.0,
|
|
|
|
|
- shadows_enabled: true,
|
|
|
|
|
- ..default()
|
|
|
|
|
- },
|
|
|
|
|
- transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
|
|
|
|
|
|
+ // camera
|
|
|
|
|
+ commands.spawn(Camera3dBundle {
|
|
|
|
|
+ transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
|
|
..default()
|
|
..default()
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[system(dependencies = [Res<AssetServer>])]
|
|
|
|
|
-fn planequery(mut commands: Commands, mut query: Query<(&Plane, &Handle<Mesh>)>, asset_server: Res<AssetServer>) {
|
|
|
|
|
- for (plane, mesh_handle) in query.iter_mut() {
|
|
|
|
|
- // Load the mesh data from the asset server.
|
|
|
|
|
- let mesh = asset_server.load(mesh_handle).await.unwrap();
|
|
|
|
|
|
|
+#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
|
|
|
|
|
+struct CustomMaterial {}
|
|
|
|
|
|
|
|
- // Get the vertex attribute values for the mesh.
|
|
|
|
|
- let vertex_attribute_values = mesh.vertex_attribute_values().unwrap();
|
|
|
|
|
-
|
|
|
|
|
- // Get the vertices from the vertex attribute values.
|
|
|
|
|
- let vertices = vertex_attribute_values.get("Position").unwrap().as_slice::<Vec3>();
|
|
|
|
|
-
|
|
|
|
|
- // Move the vertices up and down.
|
|
|
|
|
- for vertex in vertices.iter_mut() {
|
|
|
|
|
- vertex.y += 0.1; // Move the vertex up by 0.1 units.
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // Update the mesh with the new vertex positions.
|
|
|
|
|
- mesh.set_vertex_attribute_values(vertex_attribute_values).unwrap();
|
|
|
|
|
|
|
+impl Material for CustomMaterial {
|
|
|
|
|
+ fn fragment_shader() -> ShaderRef {
|
|
|
|
|
+ "shaders/animate_shader.wgsl".into()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|