use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::*,
window::PresentMode,
};
use bevy_mod_picking::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
window: WindowDescriptor {
title: "bevy_mod_picking stress test".to_string(),
width: 800.,
height: 600.,
present_mode: PresentMode::AutoNoVsync, ..default()
},
..default()
}))
.add_plugins(DefaultPickingPlugins) .add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_startup_system(setup)
.run();
}
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
) {
let half_width: isize = 5;
let subdivisions: usize = 50;
let tris_sphere = 20 * subdivisions.pow(2);
let tris_total = tris_sphere * (half_width as usize * 2).pow(3);
info!("Total tris: {}, Tris per mesh: {}", tris_total, tris_sphere);
let mesh_handle = meshes.add(Mesh::from(shape::Icosphere {
radius: 0.2,
subdivisions,
}));
let matl_handle = materials.add(StandardMaterial {
perceptual_roughness: 0.5,
metallic: 0.6,
base_color: Color::hsla(0.0, 0.0, 0.3, 1.0),
..Default::default()
});
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(half_width as f32, half_width as f32, half_width as f32)
.looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
},
PickingCameraBundle::default(),
));
for x in -half_width..half_width {
for y in -half_width..half_width {
for z in -half_width..half_width {
commands.spawn((
PbrBundle {
mesh: mesh_handle.clone(),
material: matl_handle.clone(),
transform: Transform::from_translation(Vec3::new(
x as f32 + 0.35,
y as f32 - 1.0,
z as f32,
)),
..Default::default()
},
PickableBundle::default(),
));
}
}
}
commands.spawn(PointLightBundle {
transform: Transform::from_xyz(half_width as f32, half_width as f32, half_width as f32),
point_light: PointLight {
intensity: 2500.0,
..Default::default()
},
..Default::default()
});
}