pub struct FlameModel {
pub v_template: Array2<f32>,
pub faces: Vec<[u32; 3]>,
pub shapedirs: Array3<f32>,
pub expressiondirs: Array3<f32>,
pub posedirs: Array3<f32>,
pub j_regressor: Array2<f32>,
pub parents: Vec<i32>,
pub lbs_weights: Array2<f32>,
pub n_joints: usize,
}Expand description
The loaded FLAME parametric head model.
Immutable after construction — call forward with
different FlameParams to produce posed meshes.
Fields§
§v_template: Array2<f32>Template (rest-pose) vertex positions [N, 3].
faces: Vec<[u32; 3]>Triangle face indices.
shapedirs: Array3<f32>Shape blend-shape directions [N, 3, n_shape].
expressiondirs: Array3<f32>Expression blend-shape directions [N, 3, n_expr].
posedirs: Array3<f32>Pose corrective blend-shape directions [N, 3, (n_joints-1)*9].
j_regressor: Array2<f32>Joint regressor matrix [n_joints, N].
parents: Vec<i32>Parent joint index for each joint (root = -1).
lbs_weights: Array2<f32>LBS skinning weights [N, n_joints].
n_joints: usizeNumber of joints (5 for FLAME).
Implementations§
Source§impl FlameModel
impl FlameModel
Sourcepub fn load(dir: impl AsRef<Path>) -> Result<Self, FlameError>
pub fn load(dir: impl AsRef<Path>) -> Result<Self, FlameError>
Load a FLAME model from a directory of .npy files produced by
scripts/convert_flame.py.
§Errors
Returns an error if:
- The directory does not exist
- Required
.npyfiles are missing - Array shapes do not match expected dimensions
Sourcepub fn num_vertices(&self) -> usize
pub fn num_vertices(&self) -> usize
Number of template vertices (5023 for standard FLAME).
Sourcepub fn forward(&self, params: &FlameParams) -> Mesh
pub fn forward(&self, params: &FlameParams) -> Mesh
Compute the posed mesh from FLAME parameters.
Sourcepub fn forward_batch(&self, params_batch: &[FlameParams]) -> Vec<Mesh>
pub fn forward_batch(&self, params_batch: &[FlameParams]) -> Vec<Mesh>
Sourcepub fn forward_batch_optimized(
&self,
params_batch: &[FlameParams],
) -> BatchedFlameOutput
pub fn forward_batch_optimized( &self, params_batch: &[FlameParams], ) -> BatchedFlameOutput
Process multiple parameter sets with pre-allocated output buffers.
This method is more memory-efficient than forward_batch when processing
many batches repeatedly, as it returns a BatchedFlameOutput with
pre-allocated buffers that can be reused.
§Arguments
params_batch- Slice of FLAME parameters for each mesh
§Returns
BatchedFlameOutput containing all vertices and normals with shared faces.
Sourcepub fn forward_batch_with_pool(
&self,
params_batch: &[FlameParams],
buffer_pool: &mut BatchBufferPool,
) -> BatchedFlameOutput
pub fn forward_batch_with_pool( &self, params_batch: &[FlameParams], buffer_pool: &mut BatchBufferPool, ) -> BatchedFlameOutput
Process multiple parameter sets with buffer pool for intermediate values.
This method reuses intermediate buffers across the batch to minimize memory allocations during the forward pass.
§Arguments
params_batch- Slice of FLAME parameters for each meshbuffer_pool- Pre-allocated buffer pool for intermediate values
§Returns
BatchedFlameOutput containing all vertices and normals.
§Example
let model = FlameModel::load("path/to/flame")?;
let mut pool = BatchBufferPool::new(16, model.num_vertices(), 5);
// Reuse pool across multiple batch calls
for _ in 0..100 {
let params_batch: Vec<FlameParams> = vec![/* ... */];
let output = model.forward_batch_with_pool(¶ms_batch, &mut pool);
}Sourcepub fn create_buffer_pool(&self, batch_size: usize) -> BatchBufferPool
pub fn create_buffer_pool(&self, batch_size: usize) -> BatchBufferPool
Sourcepub fn forward_into(
&self,
params: &FlameParams,
vertices_out: &mut [Point3<f32>],
normals_out: &mut [Vector3<f32>],
)
pub fn forward_into( &self, params: &FlameParams, vertices_out: &mut [Point3<f32>], normals_out: &mut [Vector3<f32>], )
Compute the posed mesh, writing directly to provided output buffers.
This method avoids allocation by writing vertices and normals directly to the provided slices.
§Arguments
params- FLAME parametersvertices_out- Output buffer for vertices (must have correct size)normals_out- Output buffer for normals (must have correct size)
Auto Trait Implementations§
impl Freeze for FlameModel
impl RefUnwindSafe for FlameModel
impl Send for FlameModel
impl Sync for FlameModel
impl Unpin for FlameModel
impl UnsafeUnpin for FlameModel
impl UnwindSafe for FlameModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.