I found the following article interesting, so I have roughly translated it.
・Pose Animator - An open source tool to bring SVG characters to life in the browser via motion capture
1. Introduction
With "PoseNet" and "Facemesh", it has become possible to animate SVG characters in the browser via a webcam. As an animation enthusiast who struggles to master character animation, I felt hopeful and experimented with using these models for interactive animation control.
The result was the web animation tool "Pose Animator."
This brings SVG characters to life using pose estimation from a webcam. In this blog post, I will explain the technical information behind "Pose Animator" and the steps for designers to animate their own characters.
2. Animating characters with PoseNet and FaceMesh
The idea behind "Pose Animator" is to take a 2D vector illustration and update the curves it contains in real-time based on the recognition results from "PoseNet" and "FaceMesh." To achieve this, "Pose Animator" takes the idea of skeletal animation from computer graphics and applies it to vector characters.
A skeletal animation character is represented in two parts:
・A surface used to draw the character
・Interconnected bones used to animate the surface
In "Pose Animator," the surface is defined by the 2D vector paths of the input SVG file. "Pose Animator" provides a predefined "rig" based on keypoints from "PoseNet" and "FaceMesh." The initial pose of these bones is specified in the input SVG file along with the character illustration. Then, the bone positions are updated in real-time based on the recognition results from the ML models.
Please refer to this documentation to create an SVG character for "Pose Animator."
3. Overview of the rigging flow
The complete rigging flow requires the following steps:
(1) Parse the input SVG file to set both the vector illustration and the predefined skeleton to a T-pose (initial pose).
(2) Iterate through all segments of the vector path and calculate the influence of weights and transformations from each bone using linear blend skinning.
(3) Run "FaceMesh" and "PoseNet" on each input frame and update the bone positions using the resulting keypoints.
(4) Calculate the new positions of the vector segments from the updated bone positions, bone weights, and transformations.
While there are other tools that provide similar functionality, most of them only update the asset bounding box and do not deform the actual geometry of the character with keypoints. Also, very few tools provide full-body animation. By deforming individual curves, "Pose Animator" is adept at capturing the nuances of facial and full-body movement, allowing for more expressive animation.
4. Defining the rig
The rig is designed according to the output keypoints of "PoseNet" and "FaceMesh." "PoseNet" returns the positions of 17 body parts. This is an optimal number to include directly in the rig. Since "FaceMesh" provides 486 keypoints, it was necessary to be more selective about which keypoints to include. Ultimately, we selected 73 keypoints from the "FaceMesh output."
As shown below, there is a full-body rig with 90 keypoints and 78 bones.
The input SVG file is expected to contain this skeleton in its default position. More specifically, "Pose Animator" looks for a group called "skeleton" and includes anchor elements named after the respective joints they represent. The sample rig SVG can be found here.
Designers are free to move joints within the design file to best embed the rig into their characters. "Pose Animator" calculates skinning according to the default position of the SVG file, but extreme cases (such as very short leg/arm bones) are not well supported by the rigging algorithm and may lead to unnatural results.
5. Linear Blend Skinning of Vector Paths
"Pose Animator" uses "Linear Blend Skinning" (LBS), one of the most common rigging algorithms for deforming surfaces using a skeletal structure. "Linear Blend Skinning" (LBS) transforms vertices on a surface by blending transformations controlled by each bone, weighted by the influence of each bone. In this example, vertices refer to anchor points on vector paths, and bones are defined by two keypoints connected in the rig above. For example, the "leftWrist" and "leftElbow" keypoints define the "leftWrist-leftElbow" bone.
The world-space position of vertex vi' is calculated as follows:
• w_i: Influence of bone i on vertex i.
• v_i: Initial position of vertex i.
• T_j: Spatial transformation that aligns the initial pose of bone j to the current pose.
Bone influences are either generated automatically or assigned manually through weight painting. "Pose Animator" currently only supports automatic weight assignment.
The influence of bone j on vertex i is calculated as follows:
where d is the distance from v_i to the closest point on bone j. Finally, we normalize the weights of all bones so that the sum of the vertices equals 1.
Here, to apply LBS to 2D vector paths consisting of straight lines and Bezier curves, special handling is required for Bezier curve segments with in-handles and out-handles. The weights for the curve point, in-control point, and out-control point must be calculated separately. This yields better results because the bone influence of the control points is captured more accurately.
There is one exceptional case. If the in-control point, curve point, and out-control point are collinear, we use the curve point's weight for all three points to ensure they remain collinear when animated. This allows the smoothness of the curve to be maintained.
9. Motion Stabilization
While LBS already provides animation frames, the raw output from "FaceMesh" and "PoseNet" contains significant jitter. To reduce jitter and smooth out the animation, we can use the confidence scores of the prediction results to weight each input frame unevenly, reducing the influence of frames with lower confidence.
Pose Animator calculates the smoothed position of joint i at frame t as follows:
The smoothed confidence score for frame i is calculated as follows:
Consider the extreme case: if both of two consecutive frames have a confidence score of 1, the position approaches the latest position at 50% speed. To increase responsiveness further, you can fine-tune the approach speed by changing the weight of the latest frame. If the confidence score of the latest frame is 0, its influence is completely ignored, preventing low-confidence results from suddenly introducing jitter.
10. Clipping based on confidence scores
In addition to interpolating joint positions with confidence scores, we also introduce a minimum threshold to determine whether a path should be rendered.
The confidence score of a path is the average confidence score of its segment points. This is a weighted average of the scores of the influencing bones. When the score falls below a certain threshold, the entire path for that specific frame is hidden.
This is useful for hiding paths in low-confidence areas, which are often body parts outside the camera view. Imagine a shot of the upper body. PoseNet will always return keypoint predictions for the legs and hips, even if the confidence score is low. This clamping mechanism ensures that the lower body parts are properly hidden rather than appearing as strangely distorted paths.
11. Future outlook
◎ Mesh
The current rigging algorithm centers on 2D curves. This is because 2D rigs built with PoseNet and FaceMesh have a wide range of motion and varying bone lengths, unlike game animations where bones are of relatively fixed length. Currently, since Bezier curves better maintain the curvature/linearity of input lines, deforming Bezier curves yields smoother results than deforming triangular meshes from input paths.
We would like to improve the mesh rigging algorithm. Furthermore, we would like to explore more advanced rigging algorithms than linear blend skinning, which has limitations such as volume thinning around bent areas.
◎ New editing features
Pose Animator delegates illustration editing to software like Illustrator. While Illustrator is powerful for editing vector graphics, it does not meet the requirements for animation and skinning. Through an in-browser UI, we would like to support animation features such as:
・Skinning with a weight painting tool. This allows for manual fine-tuning of individual weights for keypoints. This improves accuracy over automatic weight assignment.
・Support for raster images in input SVG files, allowing artists to use photos/drawings in their designs. Since the bounding box of an image can be easily represented as a vector path, it is simple to calculate deformations using the current rigging algorithm.
12. Conclusion
Please try out the live demo where you can play with existing characters or add your own SVG characters to see them in action.
We look forward to seeing what kind of interactive animations the creative community will create. For creating your own animated illustrations, please refer to this guide.
Please share your work with us on social media using #PoseAnimator . If you have any questions, please feel free to contact us on Twitter. If you would like to view the source code directly, you can fork it on GitHub.
Happy hacking!
[Guide] Animating your original character
(1) Download the sample skeleton SVG from here.
(2) Create a new file in your chosen vector graphics editor and copy the above file into a group named "skeleton".
• Do not add, remove, or rename the joints (circles). "Pose Animator" relies on these named paths to read the initial position of the skeleton. Without joints, an error will occur. • You can move the joints to embed them into your illustration. See step 4.
(3) Create a new group named "illustration". This will be the group where you place your illustration paths.
• Flatten all subgroups so that the illustration contains only path elements. • Compound paths are currently not supported. • Your working file structure should look like this.
[Layer 1]
|---- skeleton
|---- illustration
|---- path 1
|---- path 2
|---- path 3(4) Move the joints to embed the sample skeleton from the "skeleton" group into your illustration.
(5) Export as an SVG file.
(6) Open the Pose Animator camera demo. Once everything is loaded, drop your SVG file into the browser tab.