Struct TriangleMesh

Source
pub struct TriangleMesh {
    pub positions: Vec<Vec3>,
    pub indices: Vec<u32>,
    pub face_normals: Vec<Vec3>,
}
Expand description

An indexed triangle mesh in the node’s local coordinates.

Positions are f64; see crate::math for why.

Fields§

§positions: Vec<Vec3>

Vertex positions, from points.

§indices: Vec<u32>

Three indices into positions per triangle, from faceVertexIndices. Every index is in range.

§face_normals: Vec<Vec3>

One unit normal per triangle, (b - a) × (c - a) normalised, so face_normals.len() == indices.len() / 3. Degenerate triangles get a zero vector. Renderers that want flat shading duplicate vertices per face and use these.

Implementations§

Source§

impl TriangleMesh

Source

pub fn from_attribute(value: &Value) -> Result<Self, DecodeError>

Decodes the value of a ATTRIBUTE (usd::usdgeom::mesh) attribute.

use openbim_ifcx_geometry::mesh::TriangleMesh;

let value = serde_json::json!({
    "points": [[0, 0, 0], [1, 0, 0], [0, 1, 0]],
    "faceVertexIndices": [0, 1, 2]
});
let mesh = TriangleMesh::from_attribute(&value)?;
assert_eq!(mesh.triangle_count(), 1);
assert_eq!(mesh.face_normals[0], [0.0, 0.0, 1.0]);
Source

pub fn new(positions: Vec<Vec3>, indices: Vec<u32>) -> Result<Self, DecodeError>

Builds a mesh from positions and triangle indices, checking the indices and computing face normals.

Source

pub fn triangle_count(&self) -> usize

Number of triangles.

Source

pub fn triangles(&self) -> impl Iterator<Item = [u32; 3]> + '_

Triangles as index triples.

Trait Implementations§

Source§

impl Clone for TriangleMesh

Source§

fn clone(&self) -> TriangleMesh

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TriangleMesh

Source§

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

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

impl PartialEq for TriangleMesh

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for TriangleMesh

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.