Animate a 3D face
A wink button and a smile slider need different kinds of control. A performance plays an authored movement from start to finish. A facial channel lets your interface set the strength of a pose at any moment.
Read the guidePlay a complete expression
Choose an ID from avatar.actions in the web player. An action can coordinate eyelids, brows, head movement, hands and sticker effects. For example, the catalog includes winking_face, person_waving and face_with_tears_of_joy. Give the button a readable label and keep the ID in the code.
The play promise resolves once the player prepares the performance. Its animation continues after that point. A second play request can restart or replace the active gesture. To expose a Replay button, send the same ID again.
const wink = document.querySelector('#wink');
wink.onclick = () => avatar.play('winking_face').catch(console.error);Drive a smile with a slider
Add a labeled range input with id smile and a Return to idle button with id release. The web player exposes 52 channel names on avatar.channels. Values are finite numbers from 0 through 1. Each call supplies the whole pose, so put both sides of the smile in the same object.
const slider = document.querySelector('#smile');
Object.assign(slider, { min: '0', max: '1', step: '0.01', value: '0' });
slider.oninput = () => {
const weight = Number(slider.value);
avatar.setExpression({ 'Smile left': weight, 'Smile right': weight });
};
document.querySelector('#release').onclick = () => {
slider.value = '0';
avatar.setExpression(null);
};Release the face and test both controls
Set the slider halfway and check that both corners of the mouth rise. Press Wink to hand control back to the authored performance. Then set the slider again and press Return to idle. Passing null releases the manual pose. Sending an empty object holds a neutral pose.
The SwiftUI integration plays named performances. Create a fresh ClayfacesPerformance("winking_face") for each tap and assign it to the state passed into ClayfacesView. When an expression is triggered by a notification or a reaction, provide an intentional replay control for people who prefer to watch it on demand.