Clemsim 2 rokov pred
rodič
commit
a00ac108b4
1 zmenil súbory, kde vykonal 46 pridanie a 15 odobranie
  1. 46 15
      src/main.rs

+ 46 - 15
src/main.rs

@@ -3,28 +3,38 @@ use bevy::prelude::*;
 mod config;
 mod player;
 
-fn main(){
+#[derive(Component)]
+struct Plane;
+
+fn main() {
     App::new()
         .add_plugins(DefaultPlugins)
         .add_systems(Startup, setup1)
-        .add_systems(Update, player::movement::player_movement);
+        .add_systems(Update, player::movement::player_movement)
+        .add_systems(Update, planequery)
+        .run();
 }
 
 fn setup1(
     mut commands: Commands,
-    mut meshes : ResMut<Assets<Mesh>>,
-    mut materials : ResMut<Assets<StandardMaterial>>
-){
-    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()
-    });
+    mut meshes: ResMut<Assets<Mesh>>,
+    mut materials: ResMut<Assets<StandardMaterial>>,
+) {
+    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
+    commands.spawn((
+        Camera3dBundle {
+            transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
+            ..default()
+        },
+        player::movement::Player,
     ));
 
     commands.spawn(PointLightBundle {
@@ -36,5 +46,26 @@ fn setup1(
         transform: Transform::from_xyz(4.0, 8.0, 4.0),
         ..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();
+
+        // 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();
+    }
+}