Skip to content

struct

Mesh

pub struct Mesh {
    pub positions: Vec<f32>,
    pub normals: Vec<f32>,
    pub uvs: Vec<f32>,
    pub colors: Option<Vec<f32>>,
    pub joints: Option<Vec<f32>>,
    pub weights: Option<Vec<f32>>,
    pub attributes: Vec<(String, u8, Vec<f32>)>,
    pub indices: Vec<u32>,
}

Triangle geometry: positions, normals, texture coordinates, optional colours and skinning, and the indices of its triangles.

Fields

positions

pub positions: Vec<f32>

xyz triples.

normals

pub normals: Vec<f32>

xyz triples, one per vertex.

uvs

pub uvs: Vec<f32>

uv pairs, one per vertex (0–1 across a face or around a surface).

colors

pub colors: Option<Vec<f32>>

rgba quadruples, one per vertex, if the mesh has vertex colours.

joints

pub joints: Option<Vec<f32>>

Skinning: up to four joints per vertex (indices into the skin's joints, as floats) and their weights, four of each per vertex.

weights

pub weights: Option<Vec<f32>>

See joints.

attributes

pub attributes: Vec<(String, u8, Vec<f32>)>

Extra per-vertex data for custom shaders: (name, components 1–4, values).

indices

pub indices: Vec<u32>

Vertex indices, three per triangle.

Methods

empty

pub fn empty() -> Mesh

A mesh with nothing in it.

cube

pub fn cube(size: f32) -> Mesh

Axis-aligned cube centred on the origin with flat-shaded faces.

plane

pub fn plane(width: f32, height: f32) -> Mesh

Rectangle in the XY plane facing +Z, as three.js's PlaneGeometry: width along x, height along y. Turn it with rotate-x: -90 to lay it flat as a floor.

sphere

pub fn sphere(radius: f32, segments: u32, rings: u32) -> Mesh

UV sphere with segments around and rings top-to-bottom.

push_vertex

pub fn push_vertex(&mut self, p: Vec3, n: Vec3, uv: (f32, f32))

Add a vertex at p, with normal n and texture coordinate uv.

torus

pub fn torus(radius: f32, tube: f32, segments: u32, rings: u32) -> Mesh

Ring torus in the XZ plane.

torus_knot

pub fn torus_knot(radius: f32, tube: f32, p: u16, q: u16, segments: u32, tube_segments: u32) -> Mesh

A (p, q) torus knot tube.

icosphere

pub fn icosphere(radius: f32, detail: u8) -> Mesh

Geodesic sphere: an icosahedron subdivided detail times.

cylinder

pub fn cylinder(radius: f32, height: f32, segments: u32) -> Mesh

Capped cylinder along Y, centred on the origin.

cone

pub fn cone(radius: f32, height: f32, segments: u32) -> Mesh

Capped cone along Y (apex at the top), centred on the origin.

append

pub fn append(&mut self, other: &Mesh, m: &Mat4)

Append other, its positions and normals through m.

compute_normals

pub fn compute_normals(&mut self)

Smooth normals from the triangles (area-weighted), for meshes that came without any.

vertex_count

pub fn vertex_count(&self) -> usize

How many vertices it has.

triangle_count

pub fn triangle_count(&self) -> usize

How many triangles it has.

bounds

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

Axis-aligned (min, max) corners; zero for an empty mesh.

Trait implementations