Skip to main content

HumanEngine

Struct HumanEngine 

Source
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

Source

pub fn new(base: ObjMesh, policy: Policy) -> Self

Create engine from a parsed base mesh and a policy.

Source

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).

Source

pub fn load_targets_from_dir<F>( &mut self, dir: &Path, weight_fn_factory: F, ) -> Result<usize>
where F: Fn(&str) -> Box<dyn Fn(&ParamState) -> f32 + Send + Sync>,

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.

Source

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).

Source

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.0
Source

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.

Source

pub fn vertex_count(&self) -> usize

Number of vertices in base mesh.

Source

pub fn target_count(&self) -> usize

Number of morph targets loaded into the library.

Source

pub fn set_policy(&mut self, policy: Policy)

Replace the policy used for target filtering.

Source

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.

Source

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().

Source

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 at last_params
  • Compute new_weight = weight evaluated at current params
  • 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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.