(longitude_segments: u32, latitude_segments: u32)
| 204 | } |
| 205 | |
| 206 | fn sphere(longitude_segments: u32, latitude_segments: u32) -> (Vec<BuiltinMeshVertex>, Vec<u16>) { |
| 207 | let lon = longitude_segments.max(3); |
| 208 | let lat = latitude_segments.max(2); |
| 209 | let mut vertices = Vec::new(); |
| 210 | let mut indices = Vec::new(); |
| 211 | |
| 212 | for y in 0..=lat { |
| 213 | let v = y as f32 / lat as f32; |
| 214 | let phi = v * std::f32::consts::PI; |
| 215 | let sin_phi = phi.sin(); |
| 216 | let cos_phi = phi.cos(); |
| 217 | for x in 0..=lon { |
| 218 | let u = x as f32 / lon as f32; |
| 219 | let theta = u * std::f32::consts::TAU; |
| 220 | let n = [sin_phi * theta.cos(), cos_phi, sin_phi * theta.sin()]; |
| 221 | vertices.push(BuiltinMeshVertex { |
| 222 | pos: scale3(n, 0.5), |
| 223 | normal: n, |
| 224 | uv: [u, v], |
| 225 | }); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | let row = lon + 1; |
| 230 | for y in 0..lat { |
| 231 | for x in 0..lon { |
| 232 | let i0 = y * row + x; |
| 233 | let i1 = i0 + 1; |
| 234 | let i2 = i0 + row; |
| 235 | let i3 = i2 + 1; |
| 236 | push_index_triangle_outward(&vertices, &mut indices, i0 as u16, i2 as u16, i1 as u16); |
| 237 | push_index_triangle_outward(&vertices, &mut indices, i1 as u16, i2 as u16, i3 as u16); |
| 238 | } |
| 239 | } |
| 240 | (vertices, indices) |
| 241 | } |
| 242 | |
| 243 | fn triangular_prism() -> (Vec<BuiltinMeshVertex>, Vec<u16>) { |
| 244 | let mut vertices = Vec::new(); |
no test coverage detected