|
|
@@ -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(())
|
|
|
}
|