Skip to main content

Browser-side body model evaluation for viser

Project description

body-models-viser

Browser-side body model evaluation for viser.

Python owns the body model asset loaders and the prepare_identity() / prepare_pose() calls. TypeScript owns the browser model lifecycle and WASM buffers. Rust owns the stateless forward_vertices() kernel.

Usage

Skinned Body Models

Use add_body_model() for non-rigid skinned body models such as SMPL, SMPL-X, MANO, FLAME, MHR, SKEL, ANNY, GarmentMeasurements, and SOMA.

import body_models_viser as bmv
import viser
from body_models.smpl.numpy import SMPL

server = viser.ViserServer()
model = SMPL(gender="neutral")
handle = bmv.add_body_model(server.scene, "/smpl", model, color=(173, 216, 230))

pose = handle.body_pose.copy()
pose[2, 0] = 0.5
handle.body_pose = pose

translation = handle.global_translation.copy()
translation[1] = 0.25
handle.set_transform(global_translation=translation)

shape = handle.shape.copy()
shape[0] = 1.0
handle.set_identity(shape=shape)

add_body_model() returns a model-specific handle with set_identity(...), set_pose(...), set_transform(...), remove(), global_rotation, global_translation, and the pose properties supported by that model.

Skeletons

Use add_skeleton() for a standalone clickable skeleton. It takes joint positions and a parent index for each joint.

import body_models_viser as bmv

pose = model.get_rest_pose()
skeleton = model.forward_skeleton(**pose)
joint_positions = skeleton[:, :3, 3]

handle = bmv.add_skeleton(
    server.scene,
    "/skeleton",
    joint_positions,
    model.parents,
    joint_names=tuple(model.joint_names),
)

handle.visible = True
handle.joint_positions = joint_positions

Rigid Body Models

Use add_rigid_body_model() for rigid articulated models that expose link_names, link_mesh(link_name), and forward_links(...).

import body_models_viser as bmv

handle = bmv.add_rigid_body_model(server.scene, "/robot", model)
handle.set_pose(body_pose=handle.pose["body_pose"])

The rigid-body helper renders one static mesh per link, then updates link transforms when the pose changes.

Runtime

bmv.add_body_model(scene, name, model) does three things:

  1. Injects body-models-viser.js and body-models-viser.wasm.
  2. Sends faces, material props, current identity, and current pose as little-endian binary buffers.
  3. Returns a body model handle.

handle.set_identity(...) recomputes prepare_identity(), then prepares and sends updated skinning data. handle.set_pose(...) reuses the cached identity and sends updated pose-dependent skinning data. handle.set_transform(...) updates only global transform buffers. TypeScript copies changed buffers into persistent WASM memory, calls the Rust forward_vertices() kernel, and forwards the resulting vertex buffer to viser as a regular mesh message.

The browser protocol is model-agnostic: Python adapts each model to a shared runtime payload containing skinning weights, rest vertices, skinning transforms, and pose offsets. Adding another body model should only require a Python preparation adapter when its body-models outputs need normalization.

Development

Build the Rust crate:

cargo test

Build the browser bundle and WASM:

cd client
npm test

The browser build requires a Rust toolchain with wasm32-unknown-unknown installed, for example:

rustup target add wasm32-unknown-unknown

Run the small visualizer:

uv run --no-sync scripts/visualize_models.py

Check NumPy/WASM vertex parity for all supported models:

uv run scripts/check_model_parity.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

body_models_viser-0.3.2.tar.gz (46.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

body_models_viser-0.3.2-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file body_models_viser-0.3.2.tar.gz.

File metadata

  • Download URL: body_models_viser-0.3.2.tar.gz
  • Upload date:
  • Size: 46.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for body_models_viser-0.3.2.tar.gz
Algorithm Hash digest
SHA256 6c63cfbffed6a83a61c9209eaf94559eaccd8f3ef6bfbabff7a216b35f4e906f
MD5 68507540d0972fa0ec30ed5c7bdac920
BLAKE2b-256 8dc53c87b83e6bc4b5ab61d6fcf0163948d61b54ab6b9427a845be7225fed883

See more details on using hashes here.

File details

Details for the file body_models_viser-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: body_models_viser-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for body_models_viser-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c241d0208edc38d9d64b9a7f5419f751f44d233a52651f7f854bc2493d8aa1f9
MD5 52f825ac637b3f9732ad5bfd001d6a77
BLAKE2b-256 27066c3543c1774b977c45d4b1ecba4d6d49b52cc20f48c9eb8da97a367b764d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page