MCPcopy
hub / github.com/yeemachine/kalidokit / animateVRM

Function animateVRM

docs/script.js:143–249  ·  view source on GitHub ↗
(vrm, results)

Source from the content-addressed store, hash-verified

141
142/* VRM Character Animator */
143const animateVRM = (vrm, results) => {
144 if (!vrm) {
145 return;
146 }
147 // Take the results from `Holistic` and animate character based on its Face, Pose, and Hand Keypoints.
148 let riggedPose, riggedLeftHand, riggedRightHand, riggedFace;
149
150 const faceLandmarks = results.faceLandmarks;
151 // Pose 3D Landmarks are with respect to Hip distance in meters
152 const pose3DLandmarks = results.ea;
153 // Pose 2D landmarks are with respect to videoWidth and videoHeight
154 const pose2DLandmarks = results.poseLandmarks;
155 // Be careful, hand landmarks may be reversed
156 const leftHandLandmarks = results.rightHandLandmarks;
157 const rightHandLandmarks = results.leftHandLandmarks;
158
159 // Animate Face
160 if (faceLandmarks) {
161 riggedFace = Kalidokit.Face.solve(faceLandmarks, {
162 runtime: "mediapipe",
163 video: videoElement,
164 });
165 rigFace(riggedFace);
166 }
167
168 // Animate Pose
169 if (pose2DLandmarks && pose3DLandmarks) {
170 riggedPose = Kalidokit.Pose.solve(pose3DLandmarks, pose2DLandmarks, {
171 runtime: "mediapipe",
172 video: videoElement,
173 });
174 rigRotation("Hips", riggedPose.Hips.rotation, 0.7);
175 rigPosition(
176 "Hips",
177 {
178 x: riggedPose.Hips.position.x, // Reverse direction
179 y: riggedPose.Hips.position.y + 1, // Add a bit of height
180 z: -riggedPose.Hips.position.z, // Reverse direction
181 },
182 1,
183 0.07
184 );
185
186 rigRotation("Chest", riggedPose.Spine, 0.25, 0.3);
187 rigRotation("Spine", riggedPose.Spine, 0.45, 0.3);
188
189 rigRotation("RightUpperArm", riggedPose.RightUpperArm, 1, 0.3);
190 rigRotation("RightLowerArm", riggedPose.RightLowerArm, 1, 0.3);
191 rigRotation("LeftUpperArm", riggedPose.LeftUpperArm, 1, 0.3);
192 rigRotation("LeftLowerArm", riggedPose.LeftLowerArm, 1, 0.3);
193
194 rigRotation("LeftUpperLeg", riggedPose.LeftUpperLeg, 1, 0.3);
195 rigRotation("LeftLowerLeg", riggedPose.LeftLowerLeg, 1, 0.3);
196 rigRotation("RightUpperLeg", riggedPose.RightUpperLeg, 1, 0.3);
197 rigRotation("RightLowerLeg", riggedPose.RightLowerLeg, 1, 0.3);
198 }
199
200 // Animate Hands

Callers 1

onResultsFunction · 0.70

Calls 4

rigFaceFunction · 0.70
rigRotationFunction · 0.70
rigPositionFunction · 0.70
solveMethod · 0.45

Tested by

no test coverage detected