diff --git a/engine/physics/src/model.rs b/engine/physics/src/model.rs index 2c4aece..f5c752d 100644 --- a/engine/physics/src/model.rs +++ b/engine/physics/src/model.rs @@ -215,7 +215,42 @@ impl PhysicsMesh{ } } pub fn unit_cylinder()->Self{ - Self::unit_cube() + const N:usize=24; + let mut mb=model::MeshBuilder::new(); + let color=mb.acquire_color_id(model::Color4::ONE); + let tex=mb.acquire_tex_id(model::TextureCoordinate::ZERO); + let normal=mb.acquire_normal_id(vec3::ZERO); + let mut verts=Vec::with_capacity(2*N); + for i in 0..N{ + let (x,z)=integer::Angle32::raw((integer::Angle32::PI.get() as usize*i/N) as i32).cos_sin(); + //top + let pos=mb.acquire_pos_id(Planar64Vec3::new([x,Planar64::ONE,z])); + verts.push(mb.acquire_vertex_id(model::IndexedVertex{pos,color,tex,normal})); + //bottom + let pos=mb.acquire_pos_id(Planar64Vec3::new([x,Planar64::NEG_ONE,z])); + verts.push(mb.acquire_vertex_id(model::IndexedVertex{pos,color,tex,normal})); + } + let mut polygon_list=Vec::with_capacity(N+2); + // side faces + for i in 0..N{ + polygon_list.push(vec![ + verts[i*2], + verts[(i*2+2)%N], + verts[(i*2+3)%N], + verts[(i*2+1)%N], + ]); + } + // top face + polygon_list.push((0..N).map(|i|verts[2*i]).collect()); + // bottom face + polygon_list.push((0..N).map(|i|verts[2*i+1]).collect()); + let polygon_groups=vec![model::PolygonGroup::PolygonList(model::PolygonList::new(polygon_list))]; + let graphics_groups=vec![]; + let physics_groups=vec![model::IndexedPhysicsGroup{ + groups:vec![model::PolygonGroupId::new(0)], + }]; + let mesh=&mb.build(polygon_groups,graphics_groups,physics_groups); + mesh.try_into().unwrap() } #[inline] pub const fn complete_mesh(&self)->&PhysicsMeshTopology{