I tried animate avatar via coordinates. Here is my code.
In general I will have some list of coordinates (extracted via mediapipe) and I will apply this coordinates to avatar to animate it. I tried several solutions but it’s not works fine. Does anyone know how to solve this?
`
document.addEventListener(“DOMContentLoaded”, function() {
let scene, camera, renderer, avatar, controls;
function initThreeJS() {
const canvas = document.getElementById('avatar-canvas');
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(30, canvas.clientWidth / canvas.clientHeight, 0.1, 100);
camera.position.set(0, 1, 3);
renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, alpha: true });
renderer.setSize(canvas.clientWidth, canvas.clientHeight);
renderer.setPixelRatio(window.devicePixelRatio);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
directionalLight.position.set(5, 5, 5);
scene.add(directionalLight);
}
function loadAvatar() {
const gltfLoader = new THREE.GLTFLoader();
gltfLoader.load('https://models.readyplayer.me/658ba388fc8bec93d06753a7.glb', (gltf) => {
avatar = gltf.scene;
avatar.scale.set(0.5, 0.5, 0.5); // Scale the avatar to fit the scene
scene.add(avatar);
animate();
});
}
initThreeJS();
loadAvatar();
// Function to apply a pose to the avatar
function applyPose(avatar, pose) {
Object.keys(pose).forEach(boneName => {
let bone = avatar.getObjectByName(boneName);
if (bone) {
let rotation = pose[boneName];
bone.rotation.set(rotation.x, rotation.y, rotation.z);
}
});
}
function animate() {
// the next scene for applying foir this step
let poseDataArray = [
{
"Spine": { x: 0, y: 0.1, z: 0 },
"RightArm": { x: 0.2, y: 0, z: 0 },
"LeftHand": {x: 0.3, y: 0.3, z: 0.1},
// Add other bones as needed
},
{
"Spine": { x: 0, y: 0.2, z: 0 },
"RightArm": { x: 0.3, y: 0, z: 0 },
"LeftArm": {x: 0.9, y: -0.5, z: 0.15},
'LeftHandIndex1': {x: 0.9, y: -0.5, z: 0.15},
'RightUpLeg': {x: 0.2, y: 0.2, z: 0.25},
'LeftUpLeg': {x: 0.5, y: 0.2, z: 0.5}
// Add other bones for the next frame
},
];
// Example of iterating over the pose data and applying each pose
let currentPoseIndex = 0;
requestAnimationFrame(animate);
if (currentPoseIndex < poseDataArray.length) {
applyPose(avatar, poseDataArray[currentPoseIndex]);
currentPoseIndex++;
} else {
// Reset or stop the animation; depends on your needs
}
renderer.render(scene, camera);
}
});
</script>
`
In general I will have some list of coordinates (extracted via mediapipe) and I will apply this coordinates to avatar to animate it. I tried several solutions but it’s not works fine.

