(&mut self, w: f32, h: f32, d: f32)
| 132 | } |
| 133 | |
| 134 | pub fn gen_mesh_cube(&mut self, w: f32, h: f32, d: f32) -> f64 { |
| 135 | let hw = w * 0.5; |
| 136 | let hh = h * 0.5; |
| 137 | let hd = d * 0.5; |
| 138 | let white = [1.0, 1.0, 1.0, 1.0]; |
| 139 | |
| 140 | #[rustfmt::skip] |
| 141 | let faces: &[([f32; 3], [f32; 3], [f32; 2])] = &[ |
| 142 | // Front face (+Z) |
| 143 | ([-hw, -hh, hd], [0.0, 0.0, 1.0], [0.0, 1.0]), |
| 144 | ([ hw, -hh, hd], [0.0, 0.0, 1.0], [1.0, 1.0]), |
| 145 | ([ hw, hh, hd], [0.0, 0.0, 1.0], [1.0, 0.0]), |
| 146 | ([-hw, hh, hd], [0.0, 0.0, 1.0], [0.0, 0.0]), |
| 147 | // Back face (-Z) |
| 148 | ([ hw, -hh, -hd], [0.0, 0.0, -1.0], [0.0, 1.0]), |
| 149 | ([-hw, -hh, -hd], [0.0, 0.0, -1.0], [1.0, 1.0]), |
| 150 | ([-hw, hh, -hd], [0.0, 0.0, -1.0], [1.0, 0.0]), |
| 151 | ([ hw, hh, -hd], [0.0, 0.0, -1.0], [0.0, 0.0]), |
| 152 | // Right face (+X) |
| 153 | ([ hw, -hh, hd], [1.0, 0.0, 0.0], [0.0, 1.0]), |
| 154 | ([ hw, -hh, -hd], [1.0, 0.0, 0.0], [1.0, 1.0]), |
| 155 | ([ hw, hh, -hd], [1.0, 0.0, 0.0], [1.0, 0.0]), |
| 156 | ([ hw, hh, hd], [1.0, 0.0, 0.0], [0.0, 0.0]), |
| 157 | // Left face (-X) |
| 158 | ([-hw, -hh, -hd], [-1.0, 0.0, 0.0], [0.0, 1.0]), |
| 159 | ([-hw, -hh, hd], [-1.0, 0.0, 0.0], [1.0, 1.0]), |
| 160 | ([-hw, hh, hd], [-1.0, 0.0, 0.0], [1.0, 0.0]), |
| 161 | ([-hw, hh, -hd], [-1.0, 0.0, 0.0], [0.0, 0.0]), |
| 162 | // Top face (+Y) |
| 163 | ([-hw, hh, hd], [0.0, 1.0, 0.0], [0.0, 1.0]), |
| 164 | ([ hw, hh, hd], [0.0, 1.0, 0.0], [1.0, 1.0]), |
| 165 | ([ hw, hh, -hd], [0.0, 1.0, 0.0], [1.0, 0.0]), |
| 166 | ([-hw, hh, -hd], [0.0, 1.0, 0.0], [0.0, 0.0]), |
| 167 | // Bottom face (-Y) |
| 168 | ([-hw, -hh, -hd], [0.0, -1.0, 0.0], [0.0, 1.0]), |
| 169 | ([ hw, -hh, -hd], [0.0, -1.0, 0.0], [1.0, 1.0]), |
| 170 | ([ hw, -hh, hd], [0.0, -1.0, 0.0], [1.0, 0.0]), |
| 171 | ([-hw, -hh, hd], [0.0, -1.0, 0.0], [0.0, 0.0]), |
| 172 | ]; |
| 173 | |
| 174 | let vertices: Vec<Vertex3D> = faces.iter().map(|(pos, norm, uv)| Vertex3D { |
| 175 | position: *pos, |
| 176 | normal: *norm, |
| 177 | color: white, |
| 178 | uv: *uv, |
| 179 | joints: [0.0; 4], |
| 180 | weights: [0.0; 4], |
| 181 | tangent: [0.0; 4], |
| 182 | }).collect(); |
| 183 | |
| 184 | let mut indices = Vec::with_capacity(36); |
| 185 | for face in 0..6u32 { |
| 186 | let base = face * 4; |
| 187 | indices.extend_from_slice(&[base, base + 1, base + 2, base, base + 2, base + 3]); |
| 188 | } |
| 189 | |
| 190 | let model = ModelData { |
| 191 | meshes: vec![MeshData { vertices, indices, texture_idx: None, normal_texture_idx: None, metallic_roughness_texture_idx: None, emissive_texture_idx: None, occlusion_texture_idx: None, metallic_factor: 0.0, roughness_factor: 1.0, emissive_factor: [0.0; 3], alpha_cutoff: 0.0 }], |
no test coverage detected