Skip to main content

TriMesh

Struct TriMesh 

Source
pub struct TriMesh {
    pub vertices: Vec<f32>,
    pub indices: Vec<i32>,
    pub vert_count: usize,
    pub tri_count: usize,
}
Expand description

A simple triangle mesh

Fields§

§vertices: Vec<f32>

Flat array of [x, y, z] coordinates

§indices: Vec<i32>

Triangle indices, 3 per triangle

§vert_count: usize§tri_count: usize

Implementations§

Source§

impl TriMesh

Source

pub fn new() -> Self

Creates a new empty triangle mesh

Source

pub fn from_obj<P: AsRef<Path>>(path: P) -> Result<Self, MeshError>

Loads a mesh from an OBJ file

This method is only available when the std feature is enabled.

Source

pub fn from_obj_str(content: &str) -> Result<Self, MeshError>

Parses OBJ content from a string

This method is WASM-compatible and can parse OBJ data that has been loaded into memory through other means (e.g., fetch API in browser).

§Example
use landmark_common::TriMesh;

let obj_content = r#"
v 0.0 0.0 0.0
v 1.0 0.0 0.0
v 0.5 1.0 0.0
f 1 2 3
"#;

let mesh = TriMesh::from_obj_str(obj_content).unwrap();
assert_eq!(mesh.vert_count, 3);
assert_eq!(mesh.tri_count, 1);
Source

pub fn calculate_bounds(&self) -> (Vec3, Vec3)

Calculates the axis-aligned bounding box of the mesh

Trait Implementations§

Source§

impl Clone for TriMesh

Source§

fn clone(&self) -> TriMesh

Returns a duplicate 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 TriMesh

Source§

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

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

impl Default for TriMesh

Source§

fn default() -> TriMesh

Returns the “default value” for a type. Read more

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> 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.