pub struct Mesh { /* private fields */ }Expand description
A triangle mesh owning its vertices, UVs, and per-triangle normals. 一个拥有顶点、UV 和逐三角形法线的三角形网格。
Storage is a flat vertex list where every three consecutive vertices form a triangle (no index buffer).
存储是一个扁平的顶点列表,每三个连续顶点构成一个三角形(没有索引缓冲)。
uvs.len() == vertices.len() and triangle_normals.len() == vertices.len() 3 are invariants maintained by Mesh::new. / uvs.len() == vertices.len() 与 triangle_normals.len() == vertices.len() / 3 是由 Mesh::new 维持的不变式。
Implementations§
Source§impl Mesh
impl Mesh
Sourcepub fn new(vertices: Vec<Vec3>, uvs: Vec<Vec2>) -> Result<Self, Error>
pub fn new(vertices: Vec<Vec3>, uvs: Vec<Vec2>) -> Result<Self, Error>
Construct a mesh, validating invariants and computing flat normals. 构造一个网格,校验不变式并计算平面法线。
Sourcepub fn from_vertices(vertices: Vec<Vec3>) -> Result<Self, Error>
pub fn from_vertices(vertices: Vec<Vec3>) -> Result<Self, Error>
Construct a mesh from vertices only, defaulting UVs to zero. 仅从顶点构造网格,UV 默认置零。
pub fn vertex_count(&self) -> usize
pub fn triangle_count(&self) -> usize
pub fn is_valid(&self) -> bool
pub fn vertices(&self) -> &[Vec3]
pub fn uvs(&self) -> &[Vec2]
pub fn triangle_normals(&self) -> &[Vec3]
Sourcepub fn recalculate_normals(&mut self)
pub fn recalculate_normals(&mut self)
Recompute flat per-triangle normals from the current vertices. 根据当前顶点重新计算逐三角形平面法线。
Sourcepub fn triangle(width: f32, height: f32) -> Result<Self, Error>
pub fn triangle(width: f32, height: f32) -> Result<Self, Error>
A single triangle lying in the XY plane. 一个位于 XY 平面上的三角形。
Sourcepub fn plane(width: f32, depth: f32) -> Result<Self, Error>
pub fn plane(width: f32, depth: f32) -> Result<Self, Error>
A flat quad on the XZ plane (two triangles). XZ 平面上的一个平面四边形(两个三角形)。
Sourcepub fn cube(width: f32, height: f32, depth: f32) -> Result<Self, Error>
pub fn cube(width: f32, height: f32, depth: f32) -> Result<Self, Error>
An axis-aligned cube (12 triangles, 36 vertices). 一个轴对齐的立方体(12 个三角形,36 个顶点)。
Sourcepub fn sphere(radius: f32, segments: u32, rings: u32) -> Result<Self, Error>
pub fn sphere(radius: f32, segments: u32, rings: u32) -> Result<Self, Error>
A UV sphere tessellated into segments × rings quads.
一个被细分为 segments × rings 个四边形的 UV 球体。
Sizing is checked: the total vertex count must fit within MAX_VERTEX_COUNT without overflowing.
尺寸经过校验:顶点总数必须在不溢出的前提下落在 MAX_VERTEX_COUNT 之内。