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. 构造一个网格,校验不变式并计算平面法线。
§Errors
顶点列表为空、超过 MAX_VERTEX_COUNT、顶点数不是 3 的倍数,或 UV 数量与顶点数不符时返回相应错误。
Returns an error when the vertex list is empty or exceeds MAX_VERTEX_COUNT,
when the vertex count is not a multiple of three, or when the UV count
does not match the vertex count.
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 默认置零。
§Errors
顶点列表为空、超过 MAX_VERTEX_COUNT,或顶点数不是 3 的倍数时返回相应错误。
Returns an error when the vertex list is empty or exceeds MAX_VERTEX_COUNT,
or when the vertex count is not a multiple of three.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
The number of vertices. 顶点数量。
Sourcepub fn triangle_count(&self) -> usize
pub fn triangle_count(&self) -> usize
The number of triangles. 三角形数量。
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Whether the mesh has at least one full triangle. 网格是否至少包含一个完整三角形。
Sourcepub fn triangle_normals(&self) -> &[Vec3]
pub fn triangle_normals(&self) -> &[Vec3]
The per-triangle flat normals. 逐三角形平面法线。
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 平面上的三角形。
§Errors
width 或 height 不是正有限数时返回 Error::InvalidSize。
Returns Error::InvalidSize when width or height is not a positive finite number.
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 平面上的一个平面四边形(两个三角形)。
§Errors
width 或 depth 不是正有限数时返回 Error::InvalidSize。
Returns Error::InvalidSize when width or depth is not a positive finite number.
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 个顶点)。
§Errors
任一尺寸不是正有限数时返回 Error::InvalidSize。
Returns Error::InvalidSize when any dimension is not a positive finite number.
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 之内。
§Errors
radius 不是正有限数、总顶点数超过 MAX_VERTEX_COUNT,或计算过程溢出时返回相应错误。
Returns an error when radius is not a positive finite number, when the total
vertex count exceeds MAX_VERTEX_COUNT, or when the computation overflows.