Skip to content

struct

Model

pub struct Model {
    pub nodes: Vec<Node>,
    pub meshes: Vec<ModelMesh>,
    pub materials: Vec<ModelMaterial>,
    pub textures: Vec<ModelTexture>,
    pub animations: Vec<Animation>,
    pub skins: Vec<Skin>,
}

A loaded 3D model (glTF, OBJ, STL, PLY): its nodes, meshes, materials, textures and animations.

Fields

nodes

pub nodes: Vec<Node>

Nodes, parents before children.

meshes

pub meshes: Vec<ModelMesh>

The drawable pieces, a mesh and material each.

materials

pub materials: Vec<ModelMaterial>

Materials, by index.

textures

pub textures: Vec<ModelTexture>

Textures, by index.

animations

pub animations: Vec<Animation>

Animation clips.

skins

pub skins: Vec<Skin>

Skeletons that deform meshes (glTF skins).

Methods

from_mesh

pub fn from_mesh(name: &str, mesh: Mesh) -> Model

A model of one mesh.

animation_index

pub fn animation_index(&self, which: &str) -> Option<usize>

An animation by name, or by index ("0").

world_matrices

pub fn world_matrices(&self, animation: Option<(usize, f32)>) -> Vec<Mat4>

Every node's world matrix, with animation at t seconds applied.

joint_matrices

pub fn joint_matrices(&self, skin: usize, world: &[Mat4]) -> Vec<f32>

A skin's joint matrices (model space: each joint's world matrix times its inverse bind matrix) for the node matrices world, as 16 floats each.

skin_point

pub fn skin_point(mesh: &Mesh, v: usize, joints: &[f32]) -> Vec3

Vertex v of mesh, skinned by joints (from [Model::joint_matrices]).

subtree

pub fn subtree(&self, name: Option<&str>) -> Vec<bool>

The nodes in name's subtree (all of them for None, none if there's no such node).

bounds

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

Bounds at rest, in model space.

triangle_count

pub fn triangle_count(&self) -> usize

How many triangles all its meshes have.

to_bytes

pub fn to_bytes(&self) -> Vec<u8>

The model as .wmodel bytes.

from_bytes

pub fn from_bytes(b: &[u8]) -> Result<Model, String>

A model from .wmodel bytes.

Trait implementations