Skip to content

AbaoFromCUG/smplx.js

Repository files navigation

Check npm version

SMPLX.js

SMPLX-X JavaScript/WebAssembly implementation in smplxcpp and emscripten

Features

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

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors