pub struct HumanEngine { /* private fields */ }Expand description
Main entry point for the OxiHuman morph engine.
Manages the base mesh, a library of morph targets, parameter state, and
three levels of result caching (exact-params cache, incremental SoA buffer,
and rayon parallel build). All parameter values are clamped to [0.0, 1.0]
before any computation.
§Examples
use oxihuman_core::parser::obj::parse_obj;
use oxihuman_core::policy::{Policy, PolicyProfile};
use oxihuman_morph::engine::HumanEngine;
use oxihuman_morph::params::ParamState;
let obj = "v 0 0 0\nv 1 0 0\nv 0 1 0\nvn 0 0 1\nvt 0 0\nf 1/1/1 2/1/1 3/1/1\n";
let base = parse_obj(obj).unwrap();
let policy = Policy::new(PolicyProfile::Standard);
let mut engine = HumanEngine::new(base, policy);
engine.set_params(ParamState::new(0.8, 0.5, 0.5, 0.5));
let mesh = engine.build_mesh();
assert_eq!(mesh.positions.len(), 3);Implementations§
Source§impl HumanEngine
impl HumanEngine
Sourcepub fn new(base: ObjMesh, policy: Policy) -> Self
pub fn new(base: ObjMesh, policy: Policy) -> Self
Create engine from a parsed base mesh and a policy.
Sourcepub fn load_target(
&mut self,
t: TargetFile,
weight_fn: Box<dyn Fn(&ParamState) -> f32 + Send + Sync>,
)
pub fn load_target( &mut self, t: TargetFile, weight_fn: Box<dyn Fn(&ParamState) -> f32 + Send + Sync>, )
Load a morph target with a weight function (if policy permits).
Sourcepub fn load_targets_from_dir<F>(
&mut self,
dir: &Path,
weight_fn_factory: F,
) -> Result<usize>
pub fn load_targets_from_dir<F>( &mut self, dir: &Path, weight_fn_factory: F, ) -> Result<usize>
Load all .target files from a directory using a shared weight function factory.
Targets that fail to parse are skipped with a warning (never panics).
Returns the number of targets successfully loaded.
Sourcepub fn load_targets_from_dir_auto(&mut self, dir: &Path) -> Result<usize>
pub fn load_targets_from_dir_auto(&mut self, dir: &Path) -> Result<usize>
Load all .target files from a directory using automatic weight functions
inferred from target filenames (via weight_curves::auto_weight_fn_for_target).
Sourcepub fn set_params(&mut self, p: ParamState)
pub fn set_params(&mut self, p: ParamState)
Set the current morph parameters, clamped to [0.0, 1.0].
This does not invalidate the incremental position cache, so the next
call to Self::build_mesh_incremental can compute only the delta
against the previous parameters.
§Examples
// Out-of-range values are silently clamped.
engine.set_params(ParamState::new(2.0, -0.5, 0.5, 0.5));
let mesh = engine.build_mesh();
// height was clamped to 1.0, weight to 0.0Sourcepub fn clear_incremental_cache(&mut self)
pub fn clear_incremental_cache(&mut self)
Explicitly clear the incremental position cache and last-params snapshot.
The next call to build_mesh_incremental will fall back to a full rebuild.
Sourcepub fn vertex_count(&self) -> usize
pub fn vertex_count(&self) -> usize
Number of vertices in base mesh.
Sourcepub fn target_count(&self) -> usize
pub fn target_count(&self) -> usize
Number of morph targets loaded into the library.
Sourcepub fn set_policy(&mut self, policy: Policy)
pub fn set_policy(&mut self, policy: Policy)
Replace the policy used for target filtering.
Sourcepub fn build_mesh(&self) -> MeshBuffers
pub fn build_mesh(&self) -> MeshBuffers
Apply all active morph targets and return the blended mesh.
If the current ParamState matches the last call’s state the cached
result is returned immediately without any arithmetic. Otherwise, all
target weight functions are evaluated and their deltas are scatter-added
into a clone of the SoA base buffers.
Use Self::build_mesh_parallel when many targets are loaded and you
need maximum throughput. Use Self::build_mesh_incremental for
interactive sliders where only one or two params change per frame.
Sourcepub fn build_mesh_parallel(&self) -> MeshBuffers
pub fn build_mesh_parallel(&self) -> MeshBuffers
Build the morphed mesh using rayon parallel target application.
Faster than build_mesh() when many targets are active.
Uses the same cache as build_mesh().
Sourcepub fn build_mesh_incremental(&mut self) -> MeshBuffers
pub fn build_mesh_incremental(&mut self) -> MeshBuffers
Build the morphed mesh incrementally, reusing the cached position buffer from the previous call and only reapplying deltas for targets whose weight changed.
§Strategy
For each target:
- Compute
old_weight= weight evaluated atlast_params - Compute
new_weight= weight evaluated at currentparams - If
old_weight == new_weight: skip (no change) - Otherwise: subtract old contribution, add new contribution
Falls back to a full build_mesh() on the first call (no cache) or after
load_target() / clear_incremental_cache().
Auto Trait Implementations§
impl !Freeze for HumanEngine
impl !RefUnwindSafe for HumanEngine
impl Send for HumanEngine
impl !Sync for HumanEngine
impl Unpin for HumanEngine
impl UnsafeUnpin for HumanEngine
impl !UnwindSafe for HumanEngine
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> 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 more