Skip to content

Commit

Permalink
vertex color example
Browse files Browse the repository at this point in the history
  • Loading branch information
ManevilleF committed Aug 25, 2023
1 parent ddecd78 commit 6cb335e
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions examples/flag_example.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::{prelude::*, render::mesh::VertexAttributeValues};
use bevy::prelude::*;
use bevy_inspector_egui::quick::{ResourceInspectorPlugin, WorldInspectorPlugin};
use bevy_silk::prelude::*;

Expand Down Expand Up @@ -112,17 +112,16 @@ fn spawn_cloth(

// Color flag
let mut mesh = mesh;
if let Some(VertexAttributeValues::Float32x3(positions)) =
mesh.attribute(Mesh::ATTRIBUTE_POSITION)
{
let colors: Vec<[f32; 4]> = positions
.iter()
.map(|[r, g, b]| [(1. - *r) / 2., (1. - *g) / 2., (1. - *b) / 2., 1.])
.collect();
println!("{}", colors.len());
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
}
let cloth = ClothBuilder::new().with_pinned_vertex_ids((0..size_y).map(|i| i * size_x));
let colors: Vec<[f32; 4]> = (0..size_y)
.flat_map(|_| {
(0..size_x).map(|v| {
let v = v as f32 / size_x as f32;
[1.0, v, v, 1.0]
})
})
.collect();
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors);
let cloth = ClothBuilder::new().with_pinned_vertex_color(Color::RED);
commands.spawn((
PbrBundle {
mesh: meshes.add(mesh),
Expand Down

0 comments on commit 6cb335e

Please sign in to comment.