(longitude_segments: u32, hemisphere_rings: u32)
| 345 | } |
| 346 | |
| 347 | fn capsule(longitude_segments: u32, hemisphere_rings: u32) -> (Vec<BuiltinMeshVertex>, Vec<u16>) { |
| 348 | let lon = longitude_segments.max(6); |
| 349 | let rings = hemisphere_rings.max(2); |
| 350 | let mut vertices = Vec::new(); |
| 351 | let mut indices = Vec::new(); |
| 352 | |
| 353 | for y in 0..=rings { |
| 354 | let v = y as f32 / rings as f32; |
| 355 | let phi = v * std::f32::consts::FRAC_PI_2; |
| 356 | let sin_phi = phi.sin(); |
| 357 | let cos_phi = phi.cos(); |
| 358 | for x in 0..=lon { |
| 359 | let u = x as f32 / lon as f32; |
| 360 | let theta = u * std::f32::consts::TAU; |
| 361 | let n = [sin_phi * theta.cos(), cos_phi, sin_phi * theta.sin()]; |
| 362 | let p = [n[0] * 0.5, n[1] * 0.5 + 0.25, n[2] * 0.5]; |
| 363 | vertices.push(BuiltinMeshVertex { |
| 364 | pos: p, |
| 365 | normal: n, |
| 366 | uv: [u, v * 0.5], |
| 367 | }); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | let base_offset = vertices.len() as u16; |
| 372 | for y in 0..=rings { |
| 373 | let v = y as f32 / rings as f32; |
| 374 | let phi = v * std::f32::consts::FRAC_PI_2; |
| 375 | let sin_phi = phi.sin(); |
| 376 | let cos_phi = phi.cos(); |
| 377 | for x in 0..=lon { |
| 378 | let u = x as f32 / lon as f32; |
| 379 | let theta = u * std::f32::consts::TAU; |
| 380 | let n = [sin_phi * theta.cos(), -cos_phi, sin_phi * theta.sin()]; |
| 381 | let p = [n[0] * 0.5, n[1] * 0.5 - 0.25, n[2] * 0.5]; |
| 382 | vertices.push(BuiltinMeshVertex { |
| 383 | pos: p, |
| 384 | normal: n, |
| 385 | uv: [u, 0.5 + (v * 0.5)], |
| 386 | }); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | let row = lon + 1; |
| 391 | for y in 0..rings { |
| 392 | for x in 0..lon { |
| 393 | let i0 = y * row + x; |
| 394 | let i1 = i0 + 1; |
| 395 | let i2 = i0 + row; |
| 396 | let i3 = i2 + 1; |
| 397 | push_index_triangle_outward(&vertices, &mut indices, i0 as u16, i2 as u16, i1 as u16); |
| 398 | push_index_triangle_outward(&vertices, &mut indices, i1 as u16, i2 as u16, i3 as u16); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | let top_equator = rings * row; |
| 403 | let bottom_equator = base_offset as u32 + rings * row; |
| 404 | for x in 0..lon { |
no test coverage detected