Skip to main content

pan_orbit_camera_minimal/
pan_orbit_camera_minimal.rs

1//! A minimal example showing the steps needed to get started with the plugin.
2//!
3//! Controls:
4//! - Pan: Left mouse button + drag
5//! - Orbit: Right mouse button + drag
6//! - Zoom: Mouse wheel
7//!
8//! This controller relies on picking to determine what point to orbit around and zoom towards:
9//! your motion will be relative to the point under the mouse cursor.
10
11mod pan_orbit_camera_custom_input_plugin;
12
13use bevy::camera_controller::pan_orbit_camera::prelude::*;
14use bevy::prelude::*;
15
16use crate::pan_orbit_camera_custom_input_plugin::CustomInputPlugin;
17
18fn main() {
19    App::new()
20        .add_plugins((
21            DefaultPlugins,
22            MeshPickingPlugin, // Step 0: enable some picking backends for hit detection
23            DefaultPanOrbitCameraPlugins, // Step 1: Add camera controller plugin
24            CustomInputPlugin, // Step 1.5: Connect the camera controller to your inputs.
25        ))
26        .add_systems(Startup, setup)
27        .run();
28}
29
30fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
31    commands.spawn((
32        Camera3d::default(),
33        PanOrbitCamera::default(), // Step 2: add camera controller component to any cameras
34        EnvironmentMapLight {
35            // EnvironmentMapLight is optional and can be replaced with usual light.
36            diffuse_map: asset_server.load("environment_maps/pisa_diffuse_rgb9e5_zstd.ktx2"),
37            specular_map: asset_server.load("environment_maps/pisa_specular_rgb9e5_zstd.ktx2"),
38            intensity: 2500.0,
39            ..default()
40        },
41        Transform::from_xyz(0.0, 0.0, 1.0),
42    ));
43    commands.spawn(WorldAssetRoot(
44        asset_server.load("https://raw.githubusercontent.com/bevyengine/bevy_asset_files/refs/heads/main/PlaneEngine/scene.gltf#Scene0"),
45    ));
46}