Skip to content

Commit fef7322

Browse files
committed
Add tutorial for torus
1 parent 4536815 commit fef7322

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ We try to keep each part of the tutorial as simple as possible.
110110
* [Icosphere](./tutorial/icosphere.md)
111111
* [Cylinder](./tutorial/cylinder.md)
112112
* [Capsule](./tutorial/capsule.md)
113-
* Torus
113+
* [Torus](./tutorial/torus.md)
114114
* Plane
115115
* Transformation
116116
* 3D Transformation

tutorial/capsule.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ Result:
8181

8282
![Capsule](./pic/capsule.png)
8383

84-
<!-- :arrow_right: Next: -->
84+
:arrow_right: Next: [Torus](./torus.md)
8585

8686
:blue_book: Back: [Table of contents](./../README.md)

tutorial/pic/torus.png

199 KB
Loading

tutorial/torus.md

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Torus
2+
3+
A [Torus](https://docs.rs/bevy/latest/bevy/prelude/shape/struct.Torus.html) is a donut-like shape.
4+
5+
```rust
6+
commands.spawn(PbrBundle {
7+
mesh: meshes
8+
.add(
9+
Torus {
10+
radius: 0.5,
11+
ring_radius: 0.1,
12+
..default()
13+
}
14+
.into(),
15+
)
16+
.into(),
17+
..default()
18+
});
19+
```
20+
21+
We can set the [radius](https://docs.rs/bevy/latest/bevy/prelude/shape/struct.Torus.html#structfield.radius) of the [Torus](https://docs.rs/bevy/latest/bevy/prelude/shape/struct.Torus.html) and the radius ([ring_radius](https://docs.rs/bevy/latest/bevy/prelude/shape/struct.Torus.html#structfield.ring_radius)) of the [Torus](https://docs.rs/bevy/latest/bevy/prelude/shape/struct.Torus.html)'s ring.
22+
23+
We set our camera position to `(2, 1, 3)` and make it looking at the origin.
24+
25+
The full code is as follows:
26+
27+
```rust
28+
use bevy::{
29+
app::{App, Startup},
30+
asset::Assets,
31+
core_pipeline::core_3d::Camera3dBundle,
32+
ecs::system::{Commands, ResMut},
33+
math::Vec3,
34+
pbr::{PbrBundle, PointLightBundle, StandardMaterial},
35+
render::mesh::{shape::Torus, Mesh},
36+
transform::components::Transform,
37+
utils::default,
38+
DefaultPlugins,
39+
};
40+
41+
fn main() {
42+
App::new()
43+
.add_plugins(DefaultPlugins)
44+
.add_systems(Startup, setup)
45+
.run();
46+
}
47+
48+
fn setup(
49+
mut commands: Commands,
50+
mut meshes: ResMut<Assets<Mesh>>,
51+
mut materials: ResMut<Assets<StandardMaterial>>,
52+
) {
53+
commands.spawn(Camera3dBundle {
54+
transform: Transform::from_xyz(2., 1., 3.).looking_at(Vec3::ZERO, Vec3::Y),
55+
..default()
56+
});
57+
58+
commands.spawn(PbrBundle {
59+
mesh: meshes
60+
.add(
61+
Torus {
62+
radius: 0.5,
63+
ring_radius: 0.1,
64+
..default()
65+
}
66+
.into(),
67+
)
68+
.into(),
69+
material: materials.add(StandardMaterial::default()).into(),
70+
..default()
71+
});
72+
73+
commands.spawn(PointLightBundle {
74+
transform: Transform::from_xyz(2., 2., 1.),
75+
..default()
76+
});
77+
}
78+
```
79+
80+
Result:
81+
82+
![Torus](./pic/torus.png)
83+
84+
<!-- :arrow_right: Next: -->
85+
86+
:blue_book: Back: [Table of contents](./../README.md)

0 commit comments

Comments
 (0)