pub fn spawn_cube(
world: &mut World,
position: Matrix<f32, Const<3>, Const<1>, ArrayStorage<f32, 3, 1>>,
) -> EntityExpand description
Spawn a unit cube mesh at position with the default material.
Examples found in repository?
More examples
examples/gallery.rs (line 27)
3fn main() {
4 let mut app = open();
5 set_background(&mut app.world, Background::Color([0.02, 0.02, 0.04, 1.0]));
6 show_grid(&mut app.world, false);
7 set_bloom(&mut app.world, true);
8 spawn_floor(&mut app.world, 12.0);
9
10 for row in 0..5 {
11 for column in 0..5 {
12 let sphere = spawn_sphere(
13 &mut app.world,
14 vec3(column as f32 * 1.5 - 3.0, 0.5, row as f32 * 1.5 - 3.0),
15 );
16 set_color(&mut app.world, sphere, RED);
17 set_metallic_roughness(
18 &mut app.world,
19 sphere,
20 row as f32 / 4.0,
21 column as f32 / 4.0,
22 );
23 }
24 }
25
26 let lineup = [
27 spawn_cube(&mut app.world, vec3(-5.5, 0.5, 4.5)),
28 spawn_cylinder(&mut app.world, vec3(-4.0, 0.5, 4.5)),
29 spawn_cone(&mut app.world, vec3(-2.5, 0.5, 4.5)),
30 ];
31 for (index, entity) in lineup.into_iter().enumerate() {
32 set_color(&mut app.world, entity, [GOLD, TEAL, PURPLE][index]);
33 }
34 let checkered = spawn_cube(&mut app.world, vec3(-5.5, 0.5, 2.5));
35 set_texture(&mut app.world, checkered, "checkerboard");
36
37 let torus = spawn_torus(&mut app.world, vec3(0.0, 2.5, 0.0));
38 set_emissive(&mut app.world, torus, [1.0, 0.6, 0.1], 6.0);
39
40 orbit_camera(&mut app.world, vec3(0.0, 1.0, 0.0), 12.0);
41 while frame(&mut app) {}
42}examples/hud.rs (line 5)
3fn main() {
4 let mut app = open();
5 let cube = spawn_cube(&mut app.world, vec3(0.0, 0.5, 0.0));
6 set_color(&mut app.world, cube, TEAL);
7
8 let fps_text = spawn_text(&mut app.world, "fps: 0", ScreenAnchor::TopLeft);
9 spawn_text(
10 &mut app.world,
11 "G grid, B bloom, 1 sky, 2 night, 3 black",
12 ScreenAnchor::BottomLeft,
13 );
14
15 let mut grid = true;
16 let mut bloom = false;
17 while frame(&mut app) {
18 let step = delta_time(&app.world);
19 rotate(&mut app.world, cube, Vec3::y(), step);
20 let frames_per_second = app.world.resources.window.timing.frames_per_second;
21 set_text(
22 &mut app.world,
23 fps_text,
24 &format!("fps: {frames_per_second:.0}"),
25 );
26 if key_pressed(&app.world, KeyCode::KeyG) {
27 grid = !grid;
28 show_grid(&mut app.world, grid);
29 }
30 if key_pressed(&app.world, KeyCode::KeyB) {
31 bloom = !bloom;
32 set_bloom(&mut app.world, bloom);
33 }
34 if key_pressed(&app.world, KeyCode::Digit1) {
35 set_background(&mut app.world, Background::Sky);
36 }
37 if key_pressed(&app.world, KeyCode::Digit2) {
38 set_background(&mut app.world, Background::Color([0.02, 0.01, 0.08, 1.0]));
39 }
40 if key_pressed(&app.world, KeyCode::Digit3) {
41 set_background(&mut app.world, Background::Color(BLACK));
42 }
43 }
44}