body-models-viser 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ /target
2
+ /generated
3
+ /client/dist
4
+ /client/node_modules
5
+ /dist
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: body-models-viser
3
+ Version: 0.0.1
4
+ Summary: Browser-side body model evaluation for viser
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: body-models
7
+ Requires-Dist: numpy
8
+ Requires-Dist: viser
9
+ Description-Content-Type: text/markdown
10
+
11
+ # body-models-viser
12
+
13
+ `body-models-viser` is a browser-oriented implementation of selected
14
+ `body-models` models. The goal is to evaluate body models directly in a web
15
+ viewer, without being limited by viser skinning constraints such as a fixed
16
+ maximum number of bones per vertex.
17
+
18
+ The package currently supports unbatched/default SMPL, SMPLH, SMPLX, MHR, ANNY,
19
+ and SOMA models. The Rust implementation is checked against Python `body-models` output
20
+ using JSON fixtures, and the Python wheel ships the JavaScript bundle that can
21
+ be injected into a viser frontend.
22
+
23
+ ## Layout
24
+
25
+ - `src/` contains the Rust model implementation and JSON CLI.
26
+ - `fixtures/` contains small input cases for each model.
27
+ - `scripts/generate_reference.py` exports model weights and Python reference
28
+ outputs into `generated/`.
29
+ - `tests/parity.rs` compares Rust output against the generated Python outputs.
30
+ - `client/` contains the small browser-side skinning helper.
31
+
32
+ `generated/`, `target/`, `client/dist/`, and `client/node_modules/` are local
33
+ build artifacts and are ignored.
34
+
35
+ ## How It Works
36
+
37
+ Reference data is generated from a local `body-models` checkout. The script
38
+ saves two kinds of JSON:
39
+
40
+ - `generated/model_data/<model>.json`: model weights needed by Rust.
41
+ - `generated/reference/<model>/<case>.json`: expected `skeleton` and `mesh`
42
+ outputs for each fixture.
43
+
44
+ Rust loads the same fixture JSON as Python, evaluates the model, and emits:
45
+
46
+ ```json
47
+ {
48
+ "model": "smpl",
49
+ "case": "rest",
50
+ "skeleton": [],
51
+ "mesh": []
52
+ }
53
+ ```
54
+
55
+ The Python package exposes the viser-facing API and injects the bundled browser
56
+ runtime into viser. Python sends custom body-model messages with unskinned
57
+ vertices, sparse weights, joint indices, and bone transforms. The browser
58
+ runtime intercepts those messages, applies skinning with every supplied weight,
59
+ and forwards a regular viser mesh message to the viewer.
60
+
61
+ ## User Usage
62
+
63
+ Install the Python package:
64
+
65
+ ```sh
66
+ uv add body-models-viser
67
+ ```
68
+
69
+ Get the bundled browser module from Python:
70
+
71
+ ```py
72
+ from body_models_viser import client_path
73
+
74
+ print(client_path())
75
+ ```
76
+
77
+ Add a model to a viser scene:
78
+
79
+ ```py
80
+ import body_models_viser as bmv
81
+ from body_models.smpl.numpy import SMPL
82
+
83
+ handle = bmv.add_body_model(scene, "/body", SMPL(gender="neutral"))
84
+ handle.body_pose = next_body_pose
85
+ ```
86
+
87
+ `add_body_model()` injects the browser runtime automatically. It does not call
88
+ `scene.add_mesh_simple()` or `scene.add_mesh_skinned()`; the mesh sent to viser
89
+ is produced by the runtime after browser-side skinning.
90
+
91
+ `client_path()` returns the packaged `body-models-viser.js` bundle. Advanced
92
+ browser integrations can import the same low-level skinning API directly:
93
+
94
+ ```ts
95
+ import { skinVertices } from "./body-models-viser.js";
96
+
97
+ const vertices = skinVertices({
98
+ vertices: bindVertices,
99
+ skinWeights,
100
+ skinJoints,
101
+ boneTransforms,
102
+ });
103
+ ```
104
+
105
+ For development against the TypeScript source, import from `client/src/index.ts`
106
+ and run `npm test` from `client/`. Do not commit `client/dist/`; CI builds the
107
+ JavaScript bundle for releases.
108
+
109
+ ## Commands
110
+
111
+ Generate Python references:
112
+
113
+ ```sh
114
+ uv run --project ../body-models --no-sync scripts/generate_reference.py
115
+ ```
116
+
117
+ Run Rust parity tests:
118
+
119
+ ```sh
120
+ cargo test --release
121
+ ```
122
+
123
+ Run the forward benchmark:
124
+
125
+ ```sh
126
+ cargo run --release --bin bench_forward
127
+ ```
128
+
129
+ Run one fixture through the Rust CLI:
130
+
131
+ ```sh
132
+ cargo run --release -- \
133
+ --model-data generated/model_data \
134
+ --input fixtures/smpl/rest.json
135
+ ```
136
+
137
+ Build and test the TypeScript package:
138
+
139
+ ```sh
140
+ cd client
141
+ npm test
142
+ ```
143
+
144
+ ## CI And Releases
145
+
146
+ GitHub Actions runs three checks:
147
+
148
+ - Rust formatting, clippy, and crate/bin tests.
149
+ - TypeScript build and tests from `client/src`.
150
+ - Python package build after generating the JavaScript bundle in CI.
151
+
152
+ The JavaScript bundle in `client/dist/` is not tracked by git. Releases build it
153
+ in GitHub Actions, package it into the Python wheel under
154
+ `body_models_viser/client/body-models-viser.js`, and publish with `uv publish`.
155
+ Configure `PYPI_USERNAME` and `PYPI_PASSWORD` repository secrets before creating
156
+ a GitHub release or running the publish workflow manually.
157
+
158
+ ## Notes
159
+
160
+ The Rust implementation keeps the JSON format simple and builds sparse runtime
161
+ caches for large sparse model matrices on first use. SOMA identity preparation
162
+ is intentionally done in Python during reference/model-data export; Rust consumes
163
+ the prepared identity state and handles pose evaluation, correctives, skinning,
164
+ and global translation. This keeps the generated data easy to inspect while
165
+ making repeated forwards fast enough for interactive viewer work.
@@ -0,0 +1,155 @@
1
+ # body-models-viser
2
+
3
+ `body-models-viser` is a browser-oriented implementation of selected
4
+ `body-models` models. The goal is to evaluate body models directly in a web
5
+ viewer, without being limited by viser skinning constraints such as a fixed
6
+ maximum number of bones per vertex.
7
+
8
+ The package currently supports unbatched/default SMPL, SMPLH, SMPLX, MHR, ANNY,
9
+ and SOMA models. The Rust implementation is checked against Python `body-models` output
10
+ using JSON fixtures, and the Python wheel ships the JavaScript bundle that can
11
+ be injected into a viser frontend.
12
+
13
+ ## Layout
14
+
15
+ - `src/` contains the Rust model implementation and JSON CLI.
16
+ - `fixtures/` contains small input cases for each model.
17
+ - `scripts/generate_reference.py` exports model weights and Python reference
18
+ outputs into `generated/`.
19
+ - `tests/parity.rs` compares Rust output against the generated Python outputs.
20
+ - `client/` contains the small browser-side skinning helper.
21
+
22
+ `generated/`, `target/`, `client/dist/`, and `client/node_modules/` are local
23
+ build artifacts and are ignored.
24
+
25
+ ## How It Works
26
+
27
+ Reference data is generated from a local `body-models` checkout. The script
28
+ saves two kinds of JSON:
29
+
30
+ - `generated/model_data/<model>.json`: model weights needed by Rust.
31
+ - `generated/reference/<model>/<case>.json`: expected `skeleton` and `mesh`
32
+ outputs for each fixture.
33
+
34
+ Rust loads the same fixture JSON as Python, evaluates the model, and emits:
35
+
36
+ ```json
37
+ {
38
+ "model": "smpl",
39
+ "case": "rest",
40
+ "skeleton": [],
41
+ "mesh": []
42
+ }
43
+ ```
44
+
45
+ The Python package exposes the viser-facing API and injects the bundled browser
46
+ runtime into viser. Python sends custom body-model messages with unskinned
47
+ vertices, sparse weights, joint indices, and bone transforms. The browser
48
+ runtime intercepts those messages, applies skinning with every supplied weight,
49
+ and forwards a regular viser mesh message to the viewer.
50
+
51
+ ## User Usage
52
+
53
+ Install the Python package:
54
+
55
+ ```sh
56
+ uv add body-models-viser
57
+ ```
58
+
59
+ Get the bundled browser module from Python:
60
+
61
+ ```py
62
+ from body_models_viser import client_path
63
+
64
+ print(client_path())
65
+ ```
66
+
67
+ Add a model to a viser scene:
68
+
69
+ ```py
70
+ import body_models_viser as bmv
71
+ from body_models.smpl.numpy import SMPL
72
+
73
+ handle = bmv.add_body_model(scene, "/body", SMPL(gender="neutral"))
74
+ handle.body_pose = next_body_pose
75
+ ```
76
+
77
+ `add_body_model()` injects the browser runtime automatically. It does not call
78
+ `scene.add_mesh_simple()` or `scene.add_mesh_skinned()`; the mesh sent to viser
79
+ is produced by the runtime after browser-side skinning.
80
+
81
+ `client_path()` returns the packaged `body-models-viser.js` bundle. Advanced
82
+ browser integrations can import the same low-level skinning API directly:
83
+
84
+ ```ts
85
+ import { skinVertices } from "./body-models-viser.js";
86
+
87
+ const vertices = skinVertices({
88
+ vertices: bindVertices,
89
+ skinWeights,
90
+ skinJoints,
91
+ boneTransforms,
92
+ });
93
+ ```
94
+
95
+ For development against the TypeScript source, import from `client/src/index.ts`
96
+ and run `npm test` from `client/`. Do not commit `client/dist/`; CI builds the
97
+ JavaScript bundle for releases.
98
+
99
+ ## Commands
100
+
101
+ Generate Python references:
102
+
103
+ ```sh
104
+ uv run --project ../body-models --no-sync scripts/generate_reference.py
105
+ ```
106
+
107
+ Run Rust parity tests:
108
+
109
+ ```sh
110
+ cargo test --release
111
+ ```
112
+
113
+ Run the forward benchmark:
114
+
115
+ ```sh
116
+ cargo run --release --bin bench_forward
117
+ ```
118
+
119
+ Run one fixture through the Rust CLI:
120
+
121
+ ```sh
122
+ cargo run --release -- \
123
+ --model-data generated/model_data \
124
+ --input fixtures/smpl/rest.json
125
+ ```
126
+
127
+ Build and test the TypeScript package:
128
+
129
+ ```sh
130
+ cd client
131
+ npm test
132
+ ```
133
+
134
+ ## CI And Releases
135
+
136
+ GitHub Actions runs three checks:
137
+
138
+ - Rust formatting, clippy, and crate/bin tests.
139
+ - TypeScript build and tests from `client/src`.
140
+ - Python package build after generating the JavaScript bundle in CI.
141
+
142
+ The JavaScript bundle in `client/dist/` is not tracked by git. Releases build it
143
+ in GitHub Actions, package it into the Python wheel under
144
+ `body_models_viser/client/body-models-viser.js`, and publish with `uv publish`.
145
+ Configure `PYPI_USERNAME` and `PYPI_PASSWORD` repository secrets before creating
146
+ a GitHub release or running the publish workflow manually.
147
+
148
+ ## Notes
149
+
150
+ The Rust implementation keeps the JSON format simple and builds sparse runtime
151
+ caches for large sparse model matrices on first use. SOMA identity preparation
152
+ is intentionally done in Python during reference/model-data export; Rust consumes
153
+ the prepared identity state and handles pose evaluation, correctives, skinning,
154
+ and global translation. This keeps the generated data easy to inspect while
155
+ making repeated forwards fast enough for interactive viewer work.
@@ -0,0 +1,33 @@
1
+ from __future__ import annotations
2
+
3
+ from importlib.resources import files
4
+ from pathlib import Path
5
+
6
+ from ._viser import (
7
+ AnnyBodyHandle,
8
+ MhrBodyHandle,
9
+ SmplBodyHandle,
10
+ SmplhBodyHandle,
11
+ SmplxBodyHandle,
12
+ SomaBodyHandle,
13
+ ViserBodyHandle,
14
+ add_body_model,
15
+ )
16
+
17
+ __version__ = "0.0.1"
18
+
19
+ __all__ = [
20
+ "AnnyBodyHandle",
21
+ "MhrBodyHandle",
22
+ "SmplBodyHandle",
23
+ "SmplhBodyHandle",
24
+ "SmplxBodyHandle",
25
+ "SomaBodyHandle",
26
+ "ViserBodyHandle",
27
+ "add_body_model",
28
+ "client_path",
29
+ ]
30
+
31
+
32
+ def client_path() -> Path:
33
+ return Path(str(files(__name__) / "client" / "body-models-viser.js"))