-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Expand file tree
/
Copy pathinfinite_grid.rs
More file actions
68 lines (61 loc) · 1.98 KB
/
infinite_grid.rs
File metadata and controls
68 lines (61 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! A simple example to show how to spawn an infinite grid.
//!
//! Infinite grids are useful as the ground plane in editor-like applications,
//! as they provide a consistent reference for the orientation of objects
//! and an evenly spaced grid to judge relative scale.
use bevy::{
camera_controller::free_camera::{FreeCamera, FreeCameraPlugin},
dev_tools::infinite_grid::{InfiniteGrid, InfiniteGridPlugin, InfiniteGridSettings},
prelude::*,
};
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
FreeCameraPlugin,
// Make sure to add the plugin
InfiniteGridPlugin,
))
.add_systems(Startup, setup_system)
.run();
}
fn setup_system(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut standard_materials: ResMut<Assets<StandardMaterial>>,
) {
commands.spawn((
// You need to spawn an entity with this component
InfiniteGrid,
// Optional component you can use to configure the grid
InfiniteGridSettings::default(),
));
commands.spawn((
Camera3d::default(),
Transform::from_xyz(-12.5, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
FreeCamera::default(),
));
commands.spawn((
DirectionalLight { ..default() },
Transform::from_translation(Vec3::X * 15. + Vec3::Y * 20.).looking_at(Vec3::ZERO, Vec3::Y),
));
// cube
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(
standard_materials.add(StandardMaterial::from_color(Color::srgba(
1.0, 1.0, 1.0, 0.5,
))),
),
Transform::from_xyz(0.0, 2.0, 0.0),
));
commands.spawn((
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
MeshMaterial3d(
standard_materials.add(StandardMaterial::from_color(Color::srgba(
1.0, 1.0, 1.0, 0.5,
))),
),
Transform::from_xyz(0.0, -2.0, 0.0),
));
}