@@ -14,7 +14,7 @@ pub struct BlockFace {
14
14
pub struct Block {
15
15
pub position : glam:: Vec3 ,
16
16
pub absolute_position : glam:: Vec3 ,
17
- pub faces : Option < Vec < BlockFace > > ,
17
+ pub faces : Option < Vec < FaceDirections > > ,
18
18
pub block_type : BlockType ,
19
19
pub is_translucent : bool ,
20
20
}
@@ -45,23 +45,12 @@ pub enum FaceDirections {
45
45
Top ,
46
46
Bottom ,
47
47
}
48
-
49
- #[ repr( C ) ]
50
- #[ derive( Pod , Copy , Clone , Zeroable ) ]
51
- pub struct BlockVertexData {
52
- pub position : [ f32 ; 3 ] ,
53
- pub normal : [ f32 ; 3 ] ,
54
- pub tex_coords : [ f32 ; 2 ] ,
55
- }
56
-
57
- impl BlockFace {
48
+ impl FaceDirections {
58
49
pub fn create_face_data (
59
50
& self ,
60
- block : & MutexGuard < ' _ , Block > , // To prevent deadlocks
51
+ block : & MutexGuard < ' _ , Block > ,
61
52
) -> ( Vec < BlockVertexData > , Vec < u32 > ) {
62
- let face_direction = self . face_direction ;
63
-
64
- let indices = face_direction. get_indices ( ) ;
53
+ let indices = self . get_indices ( ) ;
65
54
66
55
let mut unique_indices: Vec < u32 > = Vec :: with_capacity ( 4 ) ;
67
56
@@ -85,8 +74,8 @@ impl BlockFace {
85
74
* indices_map = index_of as u32 ;
86
75
}
87
76
88
- let face_texcoords = block. block_type . get_texcoords ( face_direction ) ;
89
- let normals = face_direction . get_normal_vector ( ) ;
77
+ let face_texcoords = block. block_type . get_texcoords ( * self ) ;
78
+ let normals = self . get_normal_vector ( ) ;
90
79
91
80
unique_indices. iter ( ) . enumerate ( ) . for_each ( |( i, index) | {
92
81
vertex_data. push ( BlockVertexData {
@@ -107,9 +96,7 @@ impl BlockFace {
107
96
& self ,
108
97
block : & MutexGuard < ' _ , Block > , // To prevent deadlocks
109
98
) -> ( Vec < BlockVertexData > , Vec < u32 > ) {
110
- let face_direction = self . face_direction ;
111
-
112
- let indices = face_direction. get_indices ( ) ;
99
+ let indices = self . get_indices ( ) ;
113
100
114
101
let mut unique_indices: Vec < u32 > = Vec :: with_capacity ( 4 ) ;
115
102
@@ -133,8 +120,8 @@ impl BlockFace {
133
120
* indices_map = index_of as u32 ;
134
121
}
135
122
136
- let face_texcoords = block. block_type . get_texcoords ( face_direction ) ;
137
- let normals = face_direction . get_normal_vector ( ) ;
123
+ let face_texcoords = block. block_type . get_texcoords ( * self ) ;
124
+ let normals = self . get_normal_vector ( ) ;
138
125
139
126
unique_indices. iter ( ) . enumerate ( ) . for_each ( |( i, index) | {
140
127
vertex_data. push ( BlockVertexData {
@@ -151,6 +138,15 @@ impl BlockFace {
151
138
( vertex_data, indices_map)
152
139
}
153
140
}
141
+
142
+ #[ repr( C ) ]
143
+ #[ derive( Pod , Copy , Clone , Zeroable ) ]
144
+ pub struct BlockVertexData {
145
+ pub position : [ f32 ; 3 ] ,
146
+ pub normal : [ f32 ; 3 ] ,
147
+ pub tex_coords : [ f32 ; 2 ] ,
148
+ }
149
+
154
150
impl Block {
155
151
pub fn get_vertex_data_layout ( ) -> wgpu:: VertexBufferLayout < ' static > {
156
152
wgpu:: VertexBufferLayout {
0 commit comments