oxigaf-flame
FLAME parametric 3D head model implementation in Pure Rust.
Overview
This crate implements the FLAME (Faces Learned with an Articulated Model and Expressions) parametric 3D head model in pure Rust, with no dependencies on Python or C/C++ libraries.
FLAME is a statistical 3D head model that represents shape, expression, and pose variations using a Linear Blend Skinning (LBS) framework. It's widely used in computer vision and graphics for facial animation, avatar creation, and 3D reconstruction.
v0.1.0 — what's included:
- Linear Blend Skinning (LBS) forward pass with SIMD/parallel acceleration
- CPU software rasterizer for normal map generation
- Mesh surface sampling for Gaussian initialization
- Safetensors I/O — load/save FLAME models in
.safetensorsformat (io_safetensors.rs) - FlameSequence — video frame processing with LRU caching and temporal interpolation (
sequence.rs) - 124 tests (all passing)
Installation
[]
= "0.1"
Features
| Feature | Description | Performance Gain |
|---|---|---|
default |
Standard CPU implementation | Baseline |
simd |
SIMD-accelerated operations (requires nightly Rust) | 2-4× faster |
parallel |
Parallel batch processing with rayon | Near-linear with cores |
full |
Enable both simd and parallel |
Combined benefits |
Feature Details
-
simd: Enables SIMD acceleration for:- Rodrigues rotation computation (axis-angle to rotation matrix)
- Blend shape evaluation (weighted sum of deformations)
- Normal map rendering (vectorized pixel operations)
- Requires nightly Rust with
portable_simdfeature
-
parallel: Enables parallel processing for:forward_batch_par()— parallel mesh generationcompute_normals_batch_par()— parallel normal computation- Scales with CPU core count
Example Usage
# Standard CPU implementation
= { = "0.1" }
# With parallel processing
= { = "0.1", = ["parallel"] }
# Maximum performance (requires nightly)
= { = "0.1", = ["full"] }
Usage
Basic FLAME Forward Pass
use ;
Customize Shape and Expression
use ;
use nalgebra as na;
Safetensors I/O (v0.1.0)
use ;
use Path;
Video Sequence Processing (v0.1.0)
use FlameSequence;
use Path;
Render Normal Maps
use ;
use nalgebra as na;
Sample Mesh Surface for Gaussian Initialization
use ;
Batch Processing with Parallel Feature
use ;
FLAME Parameters
The FLAME model is controlled by:
-
Shape parameters (β): Control identity-specific features (typically 100-300 coefficients)
- Examples: face width, nose size, overall head shape
-
Expression parameters (ψ): Control facial expressions (typically 50-100 coefficients)
- Examples: smile, frown, raised eyebrows, mouth open
-
Pose parameters (θ): Control joint rotations (5 joints × 3 = 15 values)
- Root rotation (global head orientation)
- Neck rotation
- Jaw rotation (open/close mouth)
- Left eye rotation
- Right eye rotation
-
Translation: Global 3D translation applied after posing
Coordinate System
FLAME uses a right-handed coordinate system:
- +X: Right (from the subject's perspective)
- +Y: Up
- +Z: Forward (out of the face)
Rotations are specified as axis-angle vectors and converted to rotation matrices using Rodrigues' formula.
Performance
The LBS forward pass is optimized for real-time performance:
- ~1-2ms for standard FLAME mesh (5023 vertices) on modern CPUs
- 3-4× faster with
simdfeature (nightly Rust required) - Near-linear scaling with
parallelfeature on multi-core CPUs
Run benchmarks with:
Statistics
- Tests: 124 (all passing)
- Benchmark files: 5 (
flame_bench,lbs_forward,rodrigues,normal_map,simd_ops) - Key source files:
model.rs,sequence.rs,normal_map.rs,io_safetensors.rs,io.rs
Documentation
License
Licensed under the Apache License, Version 2.0 (LICENSE)