Skip to content

Latest commit

 

History

History
114 lines (87 loc) · 3.6 KB

README.md

File metadata and controls

114 lines (87 loc) · 3.6 KB

Rust FFI bindings for Live2D® Cubism SDK Core 🦀

License: MIT

Rust bindings to the Live2D Cubism SDK Core library. Provides:

  • direct, unsafe Rust bindings to the C interface for Native
  • a higher-level interface for Native and Web (optional but enabled by default)

License

This Rust crate is in no way endorsed, certified or otherwise approved by Live2D Inc., nor is its author affiliated with them.

By using this crate, and therefore Live2D Cubism Core, you agree to and accept the Live2D Proprietary Software License Agreement.

This crate is licensed under the MIT license.

SDK version support

Only these versions are tested:

Version
Native 5-r.1
Web 5-r.1

Build target support

Windows Linux
x86_64-pc-windows-msvc
aarch64-linux-android
x86_64-unknown-linux-gnu
wasm32-unknown-unknown

aarch64-unknown-linux-gnu support is unfortunately not possible, due to Live2D Inc. not providing a binary for this target in the SDK.

Building

An enviroment variable MUST be set that points to an existing Live2D Cubism SDK directory, for Native and Web, respectively:

Enviroment variable name
Native LIVE2D_CUBISM_SDK_NATIVE_DIR
Web LIVE2D_CUBISM_SDK_WEB_DIR

e.g.

LIVE2D_CUBISM_SDK_NATIVE_DIR=D:/Development/live2d/CubismSdkForNative-4-r.5.1
LIVE2D_CUBISM_SDK_WEB_DIR=D:/Development/live2d/CubismSdkForWeb-4-r.5

Live2D Cubism SDK Core is included in Live2D Cubism SDK for Native, or Web, downloaded from: https://www.live2d.com/en/download/cubism-sdk/

Optional features

Feature Default Description
core Yes Provides a high-level interface on top of the direct unsafe bindings.

Usage

Cargo.toml:

[dependencies]
live2d-cubism-core-sys = { git = "https://github.com/James2022-rgb/live2d-cubism-core-sys" }

Rust code (C interface):

unsafe {
  live2d_cubism_core_sys::csmReviveMocInPlace(...);
}

Rust code (high-level interface):

use live2d_cubism_core_sys::core as live2d_core;

#[cfg(not(target_arch = "wasm32"))]
let cubism_core = live2d_core::CubismCore::default();
#[cfg(target_arch = "wasm32")]
let cubism_core = live2d_core::CubismCore::new().await;

let moc = cubism_core.moc_from_bytes(moc_bytes).unwrap();

let model = live2d_core::Model::from_moc(&moc);

{
  let mut dynamic = model.dynamic.write();

  dynamic.reset_drawable_dynamic_flags();
  dynamic.update();
}

Running tests

Native:

cargo test

Web:

wasm-pack test --chrome