boid mesh setup

main
Zynh Ludwig 2024-09-01 02:14:22 -07:00
parent 5f9998b98d
commit f42d8bffd5
1 changed files with 20 additions and 8 deletions

View File

@ -11,33 +11,45 @@ use std::f32::consts::FRAC_PI_2;
fn main() {
App::new()
.init_resource::<BoidMesh>()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Startup, (build_boid_mesh, setup).chain())
.run();
}
#[derive(Resource, Default)]
struct BoidMesh(Mesh2dHandle);
#[derive(Component)]
struct Boid;
#[derive(Component)]
struct Velocity(Vec2);
#[derive(Bundle)]
struct BoidBundle {
mesh: MaterialMesh2dBundle<ColorMaterial>,
position: TransformBundle,
velocity: Vec2,
velocity: Velocity,
boid: Boid,
}
fn build_boid_mesh(mut meshes: ResMut<Assets<Mesh>>, mut boid_mesh: ResMut<BoidMesh>) {
let mesh = Mesh2dHandle(meshes.add(make_boid_mesh()));
boid_mesh.0 = mesh;
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
boid_mesh: Res<BoidMesh>,
) {
commands.spawn(Camera2dBundle::default());
let boid_mesh = make_boid_mesh();
let boid_color = materials.add(Color::from(tailwind::NEUTRAL_50));
let boid_color = Color::from(tailwind::NEUTRAL_50);
commands.spawn(MaterialMesh2dBundle {
mesh: Mesh2dHandle(meshes.add(boid_mesh)),
material: materials.add(boid_color),
mesh: boid_mesh.0.clone(),
material: boid_color,
transform: Transform::from_scale(Vec3::splat(2.5)),
..default()
});