@@ -26,57 +26,90 @@ fn setup(
26
26
mut meshes : ResMut < Assets < Mesh > > ,
27
27
mut materials : ResMut < Assets < StandardMaterial > > ,
28
28
) {
29
- cmds. spawn ( (
29
+ /*
30
+ Lowercase denotes an entity, and uppercase denotes a component:
31
+
32
+ player
33
+ ├── Player
34
+ ├── TransformBundle
35
+ ├── VisibilityBundle
36
+ ├── body
37
+ │ └── BodyBundle
38
+ └── head
39
+ ├── Head (marker)
40
+ ├── TransformBundle (offsets the head from the player)
41
+ ├── VisibilityBundle (camera needs to be child of a visible entity)
42
+ └── camera
43
+ ├── AtmosphereCamera (cancels atmosphere translation)
44
+ ├── Camera3dBundle
45
+ ├── CameraMode (first or third person)
46
+ ├── Fxaa
47
+ └── TransformBundle (moves camera w.r.t. head orientation)
48
+ */
49
+
50
+ let visibility_bundle = || VisibilityBundle {
51
+ visibility : Visibility :: Visible ,
52
+ ..default ( )
53
+ } ;
54
+
55
+ let player_bundle = (
30
56
player:: Player ,
31
- VisibilityBundle {
32
- visibility : Visibility :: Visible ,
33
- ..default ( )
34
- } ,
57
+ visibility_bundle ( ) ,
35
58
TransformBundle {
36
59
local : Transform :: from_xyz ( 2.0 , 170.0 , 2.0 ) . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
37
60
..default ( )
38
61
} ,
39
- ) )
40
- . with_children ( |player| {
41
- player. spawn ( player:: Body ) . insert ( MaterialMeshBundle {
62
+ ) ;
63
+
64
+ let body_bundle = player:: BodyBundle {
65
+ material_mesh_bundle : MaterialMeshBundle {
42
66
mesh : meshes. add ( Mesh :: from ( shape:: Box :: new ( 0.5 , 1.8 , 0.5 ) ) ) ,
43
67
material : materials. add ( StandardMaterial {
44
68
base_color : Color :: WHITE ,
45
69
..default ( )
46
70
} ) ,
47
71
transform : Transform :: IDENTITY . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
48
72
..default ( )
49
- } ) ;
73
+ } ,
74
+ ..default ( )
75
+ } ;
50
76
51
- player
52
- . spawn ( (
53
- player:: Head ,
54
- TransformBundle {
55
- // head is 1.8m above feet
56
- local : Transform :: from_translation ( Vec3 :: new ( 0.0 , 0.9 , 0.0 ) )
57
- . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
58
- ..default ( )
59
- } ,
60
- ) )
61
- . with_children ( |head| {
62
- // spawn camera as a child of head
63
- head. spawn ( Camera3dBundle {
64
- projection : bevy:: render:: camera:: Projection :: Perspective (
65
- PerspectiveProjection {
66
- fov : PI / 2. ,
67
- far : 2048.0 ,
68
- ..Default :: default ( )
69
- } ,
70
- ) ,
71
- transform : Transform :: from_translation ( Vec3 :: new ( 0.0 , 0.0 , -5.0 ) )
72
- . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
73
- ..Default :: default ( )
74
- } )
75
- . insert ( CameraMode :: ThirdPersonForward ) ;
76
- } ) ;
77
- } )
78
- . insert ( Fxaa :: default ( ) )
79
- . insert ( bevy_atmosphere:: plugin:: AtmosphereCamera :: default ( ) ) ;
77
+ let head_bundle = (
78
+ player:: Head ,
79
+ visibility_bundle ( ) ,
80
+ TransformBundle {
81
+ // head is 1.8m above feet or 0.9m above the center
82
+ local : Transform :: from_translation ( Vec3 :: new ( 0.0 , 0.9 , 0.0 ) )
83
+ . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
84
+ ..default ( )
85
+ } ,
86
+ ) ;
87
+
88
+ let camera_bundle = (
89
+ CameraMode :: ThirdPersonForward ,
90
+ visibility_bundle ( ) ,
91
+ Camera3dBundle {
92
+ projection : bevy:: render:: camera:: Projection :: Perspective ( PerspectiveProjection {
93
+ fov : PI / 2. ,
94
+ far : 2048.0 ,
95
+ ..Default :: default ( )
96
+ } ) ,
97
+ transform : Transform :: from_translation ( Vec3 :: new ( 0.0 , 0.0 , -5.0 ) )
98
+ . looking_to ( Vec3 :: Z , Vec3 :: Y ) ,
99
+ ..default ( )
100
+ } ,
101
+ Fxaa :: default ( ) ,
102
+ bevy_atmosphere:: plugin:: AtmosphereCamera :: default ( ) ,
103
+ ) ;
104
+
105
+ cmds. spawn ( player_bundle) . with_children ( |player| {
106
+ player. spawn ( body_bundle) ;
107
+
108
+ player. spawn ( head_bundle) . with_children ( |head| {
109
+ // spawn camera as a child of head
110
+ head. spawn ( camera_bundle) ;
111
+ } ) ;
112
+ } ) ;
80
113
81
114
cmds. insert_resource ( AmbientLight {
82
115
color : Color :: WHITE ,
0 commit comments