MCPcopy Create free account
hub / github.com/PerroEngine/Perro / cylinder

Function cylinder

perro_source/core/perro_builtin_meshes/src/lib.rs:260–306  ·  view source on GitHub ↗
(segments: u32)

Source from the content-addressed store, hash-verified

258}
259
260fn cylinder(segments: u32) -> (Vec<BuiltinMeshVertex>, Vec<u16>) {
261 let seg = segments.max(3);
262 let mut vertices = Vec::new();
263 let mut indices = Vec::new();
264 let top_y = 0.5;
265 let bot_y = -0.5;
266 let r = 0.5;
267
268 for i in 0..seg {
269 let a0 = i as f32 / seg as f32 * std::f32::consts::TAU;
270 let a1 = (i + 1) as f32 / seg as f32 * std::f32::consts::TAU;
271 let p0 = [r * a0.cos(), bot_y, r * a0.sin()];
272 let p1 = [r * a1.cos(), bot_y, r * a1.sin()];
273 let p2 = [r * a1.cos(), top_y, r * a1.sin()];
274 let p3 = [r * a0.cos(), top_y, r * a0.sin()];
275 let n0 = [a0.cos(), 0.0, a0.sin()];
276 let n1 = [a1.cos(), 0.0, a1.sin()];
277 let u0 = i as f32 / seg as f32;
278 let u1 = (i + 1) as f32 / seg as f32;
279 let base = vertices.len() as u16;
280 vertices.push(BuiltinMeshVertex {
281 pos: p0,
282 normal: n0,
283 uv: [u0, 0.0],
284 });
285 vertices.push(BuiltinMeshVertex {
286 pos: p1,
287 normal: n1,
288 uv: [u1, 0.0],
289 });
290 vertices.push(BuiltinMeshVertex {
291 pos: p2,
292 normal: n1,
293 uv: [u1, 1.0],
294 });
295 vertices.push(BuiltinMeshVertex {
296 pos: p3,
297 normal: n0,
298 uv: [u0, 1.0],
299 });
300 push_index_triangle_outward(&vertices, &mut indices, base, base + 1, base + 2);
301 push_index_triangle_outward(&vertices, &mut indices, base, base + 2, base + 3);
302 push_triangle(&mut vertices, &mut indices, [0.0, top_y, 0.0], p2, p3);
303 push_triangle(&mut vertices, &mut indices, [0.0, bot_y, 0.0], p0, p1);
304 }
305 (vertices, indices)
306}
307
308fn cone(segments: u32) -> (Vec<BuiltinMeshVertex>, Vec<u16>) {
309 let seg = segments.max(3);

Callers 3

build_builtin_meshFunction · 0.85
shared_shape_3dFunction · 0.85
collider_builder_3dFunction · 0.85

Calls 6

push_triangleFunction · 0.85
sinMethod · 0.80
maxMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected