smplx
v0.0.3
Published
A wasm implement of SMPL-X
Downloads
2
Readme
SMPLX.js
SMPLX-X
JavaScript/WebAssembly implementation in smplxcpp
and emscripten
Features
- Type safety through TypeScript
Usage
Get started
import fs from 'node:fs/promises';
import loader, { Gender } from 'smplx';
async function loadFileTo(sourcePath: string, targetPath: string) {
const data = await fs.readFile(sourcePath);
FS.createDataFile('/', targetPath, data, true, true, true);
}
const path = 'name';
const uvPath = 'uv.txt';
const outputPath = '/output.obj';
await loadFileTo('data/models/smpl/uv.txt', uvPath);
await loadFileTo('data/models/smpl/SMPL_FEMALE.npz', path);
const model = new Model(path, uvPath, Gender.female);
const body = new Body(model, false);
body.setRandom();
body.update(false, true);
body.saveObj(outputPath);
const content = FS.readFile(outputPath) as Uint32Array;
const decoder = new TextDecoder();
const str = decoder.decode(content);
console.log(str);
body.delete();
model.delete();
Contribution
Build
To be able to build WebAssembly code from C++ using Emscripten, you must first install and activate the emsdk. To compile the C++ code to WebAssembly, run the following command from the project's root directory.
pnpm install
Run tests
The following command will build and run the test suite.
pnpm test
For rapid developing, tests can also be started in watch mode, which will automatically run on any code change to the TypeScript or JavaScript sources.
pnpm start
Fix code style
The following command will run prettier on the TypeScript and clang-format on the C++ source code.
pnpm run lint:fix
Acknowledges
- smplxpp: super fast SMPL/+H/-X implementation in C++, with CUDA support and a built-in OpenGL renderer
- modern-wasm-starter: A starter template to easily create WebAssembly packages for npm using type-safe C++ code with automatic declarations