Kaynağa Gözat

Update dependencies and simplify plan creation

sdf
Ghastrod 1 yıl önce
ebeveyn
işleme
3d0eedee77
4 değiştirilmiş dosya ile 68 ekleme ve 100 silme
  1. 15 15
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 46 71
      src/lib.rs
  4. 6 13
      src/shader.wgsl

+ 15 - 15
Cargo.lock

@@ -748,9 +748,9 @@ dependencies = [
 
 [[package]]
 name = "glam"
-version = "0.25.0"
+version = "0.26.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3"
+checksum = "bebe52f2c58f1eea4d6fd3307058cf818c74181435a3620502d1651db07ff018"
 
 [[package]]
 name = "glow"
@@ -862,9 +862,9 @@ dependencies = [
 
 [[package]]
 name = "heck"
-version = "0.4.1"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
 
 [[package]]
 name = "hexf-parse"
@@ -914,9 +914,9 @@ dependencies = [
 
 [[package]]
 name = "image-webp"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ba6107a25f04af48ceeb4093eebc9b405ee5a1813a0bab5ecf1805d3eabb3337"
+checksum = "7a84a25dcae3ac487bc24ef280f9e20c79c9b1a3e5e32cbed3041d1c514aa87c"
 dependencies = [
  "byteorder",
  "thiserror",
@@ -1918,9 +1918,9 @@ dependencies = [
 
 [[package]]
 name = "system-deps"
-version = "6.2.1"
+version = "6.2.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8e9199467bcbc77c6a13cc6e32a6af21721ab8c96aa0261856c4fda5a4433f0"
+checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349"
 dependencies = [
  "cfg-expr",
  "heck",
@@ -2002,14 +2002,14 @@ dependencies = [
 
 [[package]]
 name = "toml"
-version = "0.8.11"
+version = "0.8.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e"
+checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
 dependencies = [
  "serde",
  "serde_spanned",
  "toml_datetime",
- "toml_edit 0.22.7",
+ "toml_edit 0.22.9",
 ]
 
 [[package]]
@@ -2034,9 +2034,9 @@ dependencies = [
 
 [[package]]
 name = "toml_edit"
-version = "0.22.7"
+version = "0.22.9"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992"
+checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4"
 dependencies = [
  "indexmap",
  "serde",
@@ -2110,9 +2110,9 @@ dependencies = [
 
 [[package]]
 name = "version-compare"
-version = "0.1.1"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
+checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"
 
 [[package]]
 name = "version_check"

+ 1 - 1
Cargo.toml

@@ -15,4 +15,4 @@ pollster = "0.3.0"
 bytemuck = { version = "1.15.0", features = ["derive"] }
 image = { version = "0.25.0", features = ["rayon"] }
 anyhow = "1.0.81"
-glam = "0.25.0"
+glam = "0.26.0"

+ 46 - 71
src/lib.rs

@@ -56,55 +56,29 @@ impl Vertex {
 //     2, 3, 4,
 // ];
 
-// fn creer_plan_subdivise(largeur: f32, hauteur: f32, niveau_subdivision: usize) -> (Vec<Vertex>, Vec<u32>) {
-
-//     // Vecteurs pour stocker les vertices et les indices
-//     let mut vertices: Vec<Vertex> = Vec::new();
-//     let mut indices: Vec<u32> = Vec::new();
-  
-//     // Calcul du pas de subdivision
-//     let pas_x = largeur / (2.0f32.powf(niveau_subdivision as f32));
-//     let pas_y = hauteur / (2.0f32.powf(niveau_subdivision as f32));
-  
-//     // Parcours des points du plan
-//     for i in 0..(2usize.pow(niveau_subdivision as u32) + 1) {
-//       for j in 0..(2usize.pow(niveau_subdivision as u32) + 1) {
-//         // Coordonnées du point
-//         let x = i as f32 * pas_x;
-//         let y = j as f32 * pas_y;
-  
-//         // Couleur par défaut (ajustez selon vos besoins)
-//         let couleur = [1.0, 1.0, 1.0];
+fn creer_plan_simple(largeur: f32, hauteur: f32) -> Vec<Vertex> {
+    // Vecteur pour stocker les vertices
+    let mut vertices: Vec<Vertex> = Vec::new();
+
+    // Coordonnées des quatre coins du plan
+    let coin_sup_gauche = [0.0, hauteur, 0.0];
+    let coin_sup_droit = [largeur, hauteur, 0.0];
+    let coin_inf_droit = [largeur, 0.0, 0.0];
+    let coin_inf_gauche = [0.0, 0.0, 0.0];
   
-//         // Création du vertex et ajout au tableau
-//         vertices.push(Vertex { position: [x, y, 0.0], color: couleur });
-//       }
-//     }
+    // Couleur par défaut (ajustez selon vos besoins)
+    let couleur = [1.0, 1.0, 1.0];
   
-//     // Parcours des triangles du plan
-//     for i in 0..(2usize.pow(niveau_subdivision as u32)) {
-//       for j in 0..(2usize.pow(niveau_subdivision as u32)) {
-//         // Calcul des indices des vertices
-//         let indice1 = i * (2usize.pow(niveau_subdivision as u32) + 1) + j;
-//         let indice2 = indice1 + 1;
-//         let indice3 = indice1 + (2usize.pow(niveau_subdivision as u32) + 1);
-//         let indice4 = indice3 + 1;
+    // Ajout des vertices
+    vertices.push(Vertex { position: coin_sup_gauche, color: couleur });
+    vertices.push(Vertex { position: coin_sup_droit, color: couleur });
+    vertices.push(Vertex { position: coin_inf_droit, color: couleur });
+    vertices.push(Vertex { position: coin_inf_gauche, color: couleur });
   
-//         // Ajout des indices du premier triangle
-//         indices.push(indice1 as u32);
-//         indices.push(indice2 as u32);
-//         indices.push(indice3 as u32);
+    // Retourne le vecteur de vertices
+    vertices
+  }
   
-//         // Ajout des indices du second triangle
-//         indices.push(indice2 as u32);
-//         indices.push(indice3 as u32);
-//         indices.push(indice4 as u32);
-//       }
-//     }
-  
-//     // Retourne les vertices et les indices
-//     (vertices, indices)
-//   }
 struct State<'a> {
     surface: wgpu::Surface<'a>,
     device: wgpu::Device,
@@ -118,12 +92,12 @@ struct State<'a> {
     render_pipeline: wgpu::RenderPipeline,
 
     vertex_buffer: wgpu::Buffer,
-    index_buffer: wgpu::Buffer,
-    //num_vertices: u32,
-    num_indices: u32,
+    //index_buffer: wgpu::Buffer,
+    num_vertices: u32,
+    //num_indices: u32,
 
-    diffuse_bind_group: wgpu::BindGroup,
-    diffuse_texture: texture::Texture,
+    //diffuse_bind_group: wgpu::BindGroup,
+    //diffuse_texture: texture::Texture,
 }
 
 impl<'a> State<'a> {
@@ -295,26 +269,26 @@ impl<'a> State<'a> {
         });
 
         //let (vertices, indices) = creer_plan_subdivise(1.0, 1.0, 10);
-        let (vertices,indices) = wave::generate_mesh(20,20);
+        let vert = creer_plan_simple(1.0, 1.0);
         // Create a buffer with the vertex data
         let vertex_buffer = device.create_buffer_init(
             &wgpu::util::BufferInitDescriptor{
                 label: Some("Vertex Buffer"),
-                contents: bytemuck::cast_slice(&vertices),
+                contents: bytemuck::cast_slice(&vert),
                 usage: wgpu::BufferUsages::VERTEX,
             }
         );
 
-        let index_buffer = device.create_buffer_init(
-            &wgpu::util::BufferInitDescriptor{
-                label: Some("Indice Buffer"),
-                usage: wgpu::BufferUsages::INDEX,
-                contents: bytemuck::cast_slice(&indices),
-            }
-        );
+        // let index_buffer = device.create_buffer_init(
+        //     &wgpu::util::BufferInitDescriptor{
+        //         label: Some("Indice Buffer"),
+        //         usage: wgpu::BufferUsages::INDEX,
+        //         contents: bytemuck::cast_slice(&indices),
+        //     }
+        // );
 
-        //let num_vertices = VERTICES.len() as u32;
-        let num_indices = indices.len() as u32;
+        let num_vertices = vert.len() as u32;
+        //let num_indices = indices.len() as u32;
         Self {
             surface,
             device,
@@ -324,11 +298,11 @@ impl<'a> State<'a> {
             window,
             render_pipeline,
             vertex_buffer,
-            index_buffer,
-            //num_vertices,
-            num_indices,
-            diffuse_bind_group,
-            diffuse_texture,
+            //index_buffer,
+            num_vertices,
+            //num_indices,
+            //diffuse_bind_group,
+            //diffuse_texture,
         }
     }
 
@@ -386,15 +360,16 @@ impl<'a> State<'a> {
             });
 
             render_pass.set_pipeline(&self.render_pipeline);
-            render_pass.set_bind_group(0, &self.diffuse_bind_group, &[]);
+            //render_pass.set_bind_group(0, &self.diffuse_bind_group, &[]);
 
             render_pass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
-            render_pass.set_index_buffer(self.index_buffer.slice(..), wgpu::IndexFormat::Uint16);
-            render_pass.draw_indexed(0..self.num_indices,0, 0..1);
+            //render_pass.set_index_buffer(self.index_buffer.slice(..), wgpu::IndexFormat::Uint16);
+            //render_pass.draw_indexed(0..self.num_indices,0, 0..1);
+            render_pass.draw(0..self.num_vertices, 0..1);
         }
 
-        self.queue.submit(iter::once(encoder.finish()));
-        output.present();
+        //self.queue.submit(iter::once(encoder.finish()));
+        //output.present();
 
         Ok(())
     }

+ 6 - 13
src/shader.wgsl

@@ -2,34 +2,27 @@
 
 struct VertexInput {
     @location(0) position: vec3<f32>,
-    @location(1) tex_coords: vec2<f32>,
-}
+    @location(1) color: vec3<f32>,
+};
 
 struct VertexOutput {
     @builtin(position) clip_position: vec4<f32>,
-    @location(0) tex_coords: vec2<f32>,
-}
+    @location(0) color: vec3<f32>,
+};
 
 @vertex
 fn vs_main(
     model: VertexInput,
 ) -> VertexOutput {
     var out: VertexOutput;
-    out.tex_coords = model.tex_coords;
+    out.color = model.color;
     out.clip_position = vec4<f32>(model.position, 1.0);
     return out;
 }
 
-
 // Fragment shader
 
-@group(0) @binding(0)
-var t_diffuse: texture_2d<f32>;
-@group(0) @binding(1)
-var s_diffuse: sampler;
-
 @fragment
 fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
-    //return textureSample(t_diffuse, s_diffuse, in.tex_coords);
-    return vec4<f32>(1.0, 1.0, 0.0, 1.0);
+    return vec4<f32>(in.color, 1.0);
 }