Skip to main content

Crate mocari

Crate mocari 

Source
Expand description

A pure Rust runtime for reading and driving Live2D/Cubism-compatible model data.

Mocari is split into a small set of layers so applications can choose how much control they need:

  • assets loads a .model3.json file, its referenced .moc3 data, pose file, and PNG textures from disk.
  • ModelRuntime owns the mutable model state used by motions, expressions, pose fading, and drawable mesh generation.
  • motion and expression provide lightweight players for Cubism motion and expression JSON files.
  • render::common contains backend-neutral draw ordering, clipping, and vertex helpers for custom renderers.
  • render::wgpu provides a ready-to-use renderer when the wgpu feature is enabled.

The usual flow is to load a runtime model, update its parameters each frame, apply motions or expressions, rebuild meshes, then pass those meshes to a renderer.

use mocari::{assets::load_model_runtime, MotionPlayer};

let mut model = load_model_runtime("assets/models/Hiyori/Hiyori.model3.json")?;
let runtime = model.runtime_mut();

runtime.set_parameter_normalized("ParamAngleX", 0.75);
runtime.update_meshes();

for mesh in runtime.meshes() {
    // Upload mesh.vertices() and mesh.indices() to your renderer.
}

Re-exports§

pub use crate::core::DrawableId;
pub use crate::core::Id;
pub use crate::core::ParameterId;
pub use crate::core::PartId;
pub use crate::error::Error;
pub use crate::error::Result;
pub use crate::expression::ExpressionManager;
pub use crate::expression::ExpressionPlayer;
pub use crate::motion::MotionPlayer;
pub use crate::runtime::HitAreaInfo;
pub use crate::runtime::ModelRuntime;
pub use crate::runtime::ParameterInfo;

Modules§

assets
Filesystem helpers for loading model assets and decoded textures. Convenience loaders for complete Cubism model folders.
core
Math, interpolation, parameter, and physics primitives used by the runtime. Low-level math and runtime primitives.
error
Shared error types returned by parsers and lower-level runtime code. Shared parser and runtime error types.
expression
Expression playback and blending against a ModelRuntime. Cubism expression playback and blending.
json
Parsers and data models for Cubism JSON sidecar files. Parsers and typed representations for Cubism JSON files.
moc3
Parsers and mesh builders for .moc3 model data. Parsers and mesh builders for .moc3 binary model data.
motion
Motion playback against a ModelRuntime. Cubism motion playback.
render
Renderer-facing helpers and optional backend implementations. Renderer-facing helpers.
runtime
Mutable model state used for parameter edits, pose updates, and mesh output. Mutable state for driving a loaded model.