use bevy::prelude::*;
use bevy_mod_picking::prelude::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins.set(low_latency_window_plugin()),
DefaultPickingPlugins
.build()
.disable::<DebugPickingPlugin>(),
))
.insert_resource(DebugPickingMode::Normal)
.add_systems(Startup, setup)
.add_systems(Update, make_pickable)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn((Camera3dBundle {
transform: Transform::from_xyz(0.7, 0.7, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
},));
commands.spawn(DirectionalLightBundle::default());
commands.spawn((
SceneBundle {
scene: asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"),
..default()
},
On::<Pointer<Click>>::run(|event: Listener<Pointer<Click>>| {
info!("Clicked on entity {:?}", event.target);
}),
));
}
fn make_pickable(
mut commands: Commands,
meshes: Query<Entity, (With<Handle<Mesh>>, Without<Pickable>)>,
) {
for entity in meshes.iter() {
commands
.entity(entity)
.insert((PickableBundle::default(), HIGHLIGHT_TINT.clone()));
}
}
const HIGHLIGHT_TINT: Highlight<StandardMaterial> = Highlight {
hovered: Some(HighlightKind::new_dynamic(|matl| StandardMaterial {
base_color: matl
.base_color
.mix(&Color::srgba(-0.5, -0.3, 0.9, 0.8), 0.5), ..matl.to_owned()
})),
pressed: Some(HighlightKind::new_dynamic(|matl| StandardMaterial {
base_color: matl
.base_color
.mix(&Color::srgba(-0.4, -0.4, 0.8, 0.8), 0.5), ..matl.to_owned()
})),
selected: Some(HighlightKind::new_dynamic(|matl| StandardMaterial {
base_color: matl
.base_color
.mix(&Color::srgba(-0.4, 0.8, -0.4, 0.0), 0.5), ..matl.to_owned()
})),
};