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

Function animateVRM

sample/3d/script.js:155–261  ·  view source on GitHub ↗
(vrm, results)

Source from the content-addressed store, hash-verified

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