three-mediapipe-rig 0.0.2 → 0.0.4

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.
package/README.md CHANGED
@@ -1,16 +1,38 @@
1
1
 
2
2
  ![cover](cover.jpg)
3
3
 
4
- # three-mediapipe-rig
4
+ # Control a skeleton with the webcam
5
5
 
6
- Integrate [Google MediaPipe](https://ai.google.dev/edge/mediapipe/solutions/guide)'s **webcam motion tracking** with [Three.js](https://threejs.org/) skeletal rigs. Load a GLTF/GLB character, bind it, and drive its body, hands, and face from a webcam or video — in just a few lines of code.
6
+ Integrate [Google MediaPipe](https://ai.google.dev/edge/mediapipe/solutions/guide)'s **webcam motion tracking** with [Three.js](https://threejs.org/) skeletal rigs.
7
7
 
8
- Use your webcam ( or a video ) to drive a skeleton.
8
+ The motion from the webcam will be applied to a skeleton. Angle based so it works with any size skeleton.
9
9
 
10
10
  This will run 3 models: face, body, hands. So expect a FPS drop.
11
11
 
12
12
  LIVE EXAMPLE: https://bandinopla.github.io/three-mediapipe-rig/
13
13
 
14
+ ---
15
+
16
+ ## Table of Contents
17
+
18
+ - [Features](#features)
19
+ - [Installation](#installation)
20
+ - [Quick Start](#quick-start)
21
+ - [Skeleton](#skeleton)
22
+ - [Facial Animation](#facial-animation)
23
+ - [API](#api)
24
+ - [`setupTracker(config?)`](#setuptrackerconfig)
25
+ - [Tracker API](#tracker-api-return-value-of-setuptracker)
26
+ - [Bone Naming](#bone-naming)
27
+ - [Default bone names](#default-bone-names)
28
+ - [Custom bone map example](#custom-bone-map-example)
29
+ - [Multiple Characters](#multiple-characters)
30
+ - [Debugging with Video](#debugging-with-video)
31
+ - [Recording](#recording)
32
+ - [License](#license)
33
+
34
+ ---
35
+
14
36
  ## Features
15
37
 
16
38
  - **Full-body pose tracking** — shoulders, arms, hips, legs, and head
@@ -19,6 +41,7 @@ LIVE EXAMPLE: https://bandinopla.github.io/three-mediapipe-rig/
19
41
  - **Automatic bone binding** — maps MediaPipe landmarks to your rig's skeleton using a configurable bone-name map
20
42
  - **Webcam & video input** — use a live webcam feed or a pre-recorded video for motion capture
21
43
  - **Debug tools** — preview the video/image feed overlaid with landmark visualizations
44
+ - **Recording** — record the motion capture to a file ( .glb )
22
45
 
23
46
  ## Installation
24
47
  ```
@@ -29,41 +52,32 @@ npm install three-mediapipe-rig
29
52
 
30
53
  ## Quick Start
31
54
 
32
- ```ts
33
- // 1. Create your renderer
34
- const renderer = new THREE.WebGPURenderer({ antialias: true });
35
- renderer.setSize(window.innerWidth, window.innerHeight);
36
- document.body.appendChild(renderer.domElement);
55
+ ```ts
37
56
 
38
- // 2. Initialize the tracker (loads MediaPipe models)
57
+ // 1. Initialize the tracker (loads MediaPipe models)
39
58
  await setupTracker({ ...config... })
40
59
 
41
60
  const rig = scene.getObjectByName("rig")!;
42
61
 
43
- // 3. Bind the rig to the tracker
62
+ // 2. Bind the rig to the tracker
44
63
  const binding = tracker.bind(rig);
45
64
 
46
65
 
47
- // 4. Start the webcam ( must be initialized by a user triggered event like a click )
48
- tracker.start();
49
-
50
- // 5. Update in your render loop
51
- const clock = new THREE.Timer();
52
- renderer.setAnimationLoop((time: number) => {
53
- const delta = clock.update(time).getDelta();
66
+ // 3. Start the webcam ( must be initialized by a user triggered event like a click )
67
+ button.addEventListener('click', () => {
68
+ tracker.start(); //<-- will ask webcam access!
69
+ })
54
70
 
55
- // 6. update the skeleton...
56
- binding?.update(delta);
57
71
 
58
- renderer.render(scene, camera);
59
- });
72
+ // 4. Update the rig in your render loop ( this keels the skeleton in-sync)
73
+ binding?.update(delta);
60
74
  ```
61
75
 
62
76
  ### Skeleton
63
- You can use the skeleton provided in `rig.blend` or use your own and provide a bone name mapping so we know where the bones are in the second argument for the `.bind` method. But pay attention to the bone role of the provided skeleton, as it is the one expected by this module.
77
+ You can use the skeleton provided in `rig.blend` or use your own and provide a bone name mapping so we know where the bones are in the second argument for the `.bind` method. But pay attention to the [**bone roll**](https://docs.blender.org/manual/en/latest/animation/armatures/bones/editing/bone_roll.html) of the provided skeleton, as it is the one expected by this module.
64
78
 
65
79
  ### Facial Animation
66
- Media Pipe provides blend shape keys for the face ( estimated from the webcam ). The face it is expected to be a separated mesh, just the face, with blend shape keys named as the ones provided by Media Pipe. See [Blend Shape Keys reference](/face-blendshapekeys.md) You don't have to have all of them, if they are not found, they will be ignored.
80
+ Media Pipe provides blend shape keys for the face ( estimated from the webcam ). The face it is expected to be a separated mesh with a name that starts with "face", with blend shape keys named as the ones provided by Media Pipe. See [Blend Shape Keys reference](/face-blendshapekeys.md) You don't have to have all of them, if they are not found, they will be ignored.
67
81
 
68
82
 
69
83
  ## API
@@ -251,6 +265,24 @@ const tracker = await setupTracker({
251
265
  });
252
266
  ```
253
267
 
268
+ ## Recording
269
+ You can record the motion of a rig by doing this. Notice the track names of the clip will use the names of the bones from the currently recorded rig.
270
+
271
+ ```ts
272
+ // Start recording
273
+ yourRigBindHandler.startRecording()
274
+
275
+ // after a while...
276
+ const result = yourRigBindHandler.stopRecording();
277
+
278
+ // to save the recording to a file....
279
+ result.saveToFile();
280
+
281
+ // or if you just want the AnimationClip...
282
+ result.clip
283
+ ```
284
+ But this will save a .glb containing the rig (mesh, textures, etc...) You would have to strip the mesh data after export or just accept the full GLB and strip it with a post-process tool like [gltf-transform](https://gltf-transform.dev/). The saved .glb will contain the animation clip, the rig and the textures. Still havent figured out a way to export a minimal file like just the animation...
285
+
254
286
  ---
255
287
 
256
288
  ## License