Skip to main content

Mesh

Struct Mesh 

Source
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

Source

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.

Source

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.

Source

pub fn vertex_count(&self) -> usize

The number of vertices. 顶点数量。

Source

pub fn triangle_count(&self) -> usize

The number of triangles. 三角形数量。

Source

pub fn is_valid(&self) -> bool

Whether the mesh has at least one full triangle. 网格是否至少包含一个完整三角形。

Source

pub fn vertices(&self) -> &[Vec3]

The raw vertex list. 原始顶点列表。

Source

pub fn uvs(&self) -> &[Vec2]

The per-vertex UV list. 逐顶点 UV 列表。

Source

pub fn triangle_normals(&self) -> &[Vec3]

The per-triangle flat normals. 逐三角形平面法线。

Source

pub fn recalculate_normals(&mut self)

Recompute flat per-triangle normals from the current vertices. 根据当前顶点重新计算逐三角形平面法线。

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Mesh

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mesh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Mesh

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Mesh

Auto Trait Implementations§

§

impl Freeze for Mesh

§

impl RefUnwindSafe for Mesh

§

impl Send for Mesh

§

impl Sync for Mesh

§

impl Unpin for Mesh

§

impl UnsafeUnpin for Mesh

§

impl UnwindSafe for Mesh

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.