Skip to content

Commit

Permalink
feat: added new animations for Male and Female avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepat0 committed Oct 4, 2024
1 parent c858262 commit 0d63458
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/components/Avatar/AvatarView/AvatarView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ Fullbody.args = {

export const FullbodyZoomed = Template.bind({});
FullbodyZoomed.args = {
sex: 'MALE',
sex: 'FEMALE',
eyeBlink: true,
headMovement: true,
rotateAvatar: true,
speaking: false,
isZoomed: true,
url: 'https://models.readyplayer.me/63b55751f17e295642bf07a2.glb',
url: 'https://assets.memori.ai/api/v2/asset/3f5ef41c-6c4c-449c-888d-cf9c89782528.glb',
fallbackImg:
'https://assets.memori.ai/api/v2/asset/3049582f-db5f-452c-913d-e4340d4afd0a.png',
halfBody: false,
Expand Down
20 changes: 12 additions & 8 deletions src/components/Avatar/AvatarView/components/fullbodyAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import useMouthSpeaking from '../utils/useMouthSpeaking';
import useHeadMovement from '../utils/useHeadMovement';
import useSmile from '../utils/useSmile';

interface BaseAction {
weight: number;
action?: string;
}

export interface FullbodyAvatarProps {
url: string;
sex: 'MALE' | 'FEMALE';
Expand All @@ -35,11 +40,11 @@ export interface FullbodyAvatarProps {

const AVATAR_POSITION = new Vector3(0, -1, 0);
const AVATAR_ROTATION = new Euler(0.175, 0, 0);
const AVATAR_POSITION_ZOOMED = new Vector3(0, -1.53, 0);
const AVATAR_POSITION_ZOOMED = new Vector3(0, -1.45, 0);
const ANIMATION_URLS = {
MALE: 'https://assets.memori.ai/api/v2/asset/5de7456f-0cd8-4e29-95a7-0cd0045a5325.glb',
MALE: 'https://assets.memori.ai/api/v2/asset/1c350a21-97d8-4add-82cc-9dc10767a26b.glb',
FEMALE:
'https://assets.memori.ai/api/v2/asset/84487a2b-377c-4565-800a-51459d580ec8.glb',
'https://assets.memori.ai/api/v2/asset/a1908dbf-8ce8-438d-90df-acf9dc2604ad.glb',
};

export default function FullbodyAvatar({
Expand All @@ -60,7 +65,6 @@ export default function FullbodyAvatar({
useEffect(() => {
correctMaterials(materials);
onLoaded?.();

return () => {
Object.values(materials).forEach(dispose);
Object.values(nodes).filter(isSkinnedMesh).forEach(dispose);
Expand Down Expand Up @@ -91,10 +95,10 @@ export default function FullbodyAvatar({
}, [currentBaseAction, timeScale]);

// Additive actions
useEyeBlink(additiveActions.blink.weight > 0, nodes);
useMouthSpeaking(additiveActions.speak.weight > 0, nodes);
useHeadMovement(additiveActions.headMovement.weight > 0, nodes);
useSmile(additiveActions.smile.weight > 0, nodes);
useEyeBlink(additiveActions.eyesClosed.weight > 0, nodes);
useMouthSpeaking(additiveActions.Talk.weight > 0, nodes);
// useHeadMovement(additiveActions.headMovement.weight > 0, nodes);
useSmile(additiveActions.mouthSmile.weight > 0, nodes);

useFrame((_, delta) => {
mixer.update(delta * 0.001);
Expand Down
74 changes: 45 additions & 29 deletions src/components/Avatar/AvatarView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ interface AdditiveAction {
action?: string;
}

const baseActions: Record<string, BaseAction> = {
'Gioia1': { weight: 0 },
'Gioia2': { weight: 0 },
'Gioia3': { weight: 0 },
'Idle1': { weight: 1 },
'Idle2': { weight: 0 },
'Idle3': { weight: 0 },
'Idle4': { weight: 0 },
'Idle5': { weight: 0 },
Loading: { weight: 0 },
'Rabbia1': { weight: 0 },
'Rabbia2': { weight: 0 },
'Rabbia3': { weight: 0 },
'Sorpresa1': { weight: 0 },
'Sorpresa2': { weight: 0 },
'Sorpresa3': { weight: 0 },
'Timore1': { weight: 0 },
'Timore2': { weight: 0 },
'Timore3': { weight: 0 },
'Tristezza1': { weight: 0 },
'Tristezza2': { weight: 0 },
'Tristezza3': { weight: 0 },
};

export interface Props {
url: string;
sex: 'MALE' | 'FEMALE';
Expand All @@ -36,18 +60,6 @@ export interface Props {
isZoomed?: boolean;
}

const baseActions: Record<string, BaseAction> = {
Idle: { weight: 1 },
'Idle 1': { weight: 0 },
'Idle 2': { weight: 0 },
'Idle 3': { weight: 0 },
Loading: { weight: 0 },
Sad: { weight: 0 },
'Talk 1': { weight: 0 },
'Talk 2': { weight: 0 },
'Talk 3': { weight: 0 },
};

const defaultStyles = {
halfBody: {
width: '100%',
Expand All @@ -74,7 +86,7 @@ const getCameraSettings = (halfBody: boolean, isZoomed?: boolean) =>
? {
// Zoomed in
fov: 44,
position: [0,0,1.25],
position: [0, 0, 1.25],
}
: { fov: 40, position: [0, 0.0000175, 3] };

Expand Down Expand Up @@ -124,15 +136,19 @@ const AvatarView = ({
isZoomed,
}: Props & { halfBody: boolean }) => {
const [currentBaseAction, setCurrentBaseAction] = useState({
action: animation || 'Idle',
action: animation || 'Idle1',
weight: 1,
});

const [additiveActions, setAdditiveActions] = useState({
smile: { weight: 0 },
blink: { weight: eyeBlink ? 1 : 0 },
speak: { weight: speaking ? 1 : 0 },
headMovement: { weight: headMovement ? 1 : 0 },
mouthSmile: { weight: 0 },
eyesClosed: { weight: eyeBlink ? 1 : 0 },
Rabbia: { weight: 0 },
Sorpresa: { weight: 0 },
Talk: { weight: speaking ? 1 : 0 },
Timore: { weight: 0 },
Tristezza: { weight: 0 },
Gioria: { weight: 0 },
});

const [timeScale, setTimeScale] = useState(0.8);
Expand All @@ -157,13 +173,13 @@ const AvatarView = ({

useEffect(() => {
// If loading and not speaking, set to loading animation
if (loading && currentBaseAction.action !== 'Loading' && !speaking) {
setCurrentBaseAction({
action: 'Loading',
weight: 1,
});
return;
}
// if (loading && currentBaseAction.action !== 'Loading' && !speaking) {
// setCurrentBaseAction({
// action: 'Loading',
// weight: 1,
// });
// return;
// }

// Otherwise, if speaking, set to random talking animation
if (speaking) {
Expand All @@ -173,21 +189,21 @@ const AvatarView = ({

setAdditiveActions({
...additiveActions,
speak: { weight: 1 },
Talk: { weight: 1 },
});

setCurrentBaseAction({
action: randomTalkingAnimation,
weight: 1,
});
} else if (!speaking && additiveActions.speak.weight !== 0) {
} else if (!speaking && additiveActions.Talk.weight !== 0) {
// Otherwise, if not speaking, set to idle
setAdditiveActions({
...additiveActions,
speak: { weight: 0 },
Talk: { weight: 0 },
});
setCurrentBaseAction({
action: 'Idle',
action: 'Idle 1 - neutral',
weight: 1,
});
}
Expand Down
11 changes: 4 additions & 7 deletions src/components/layouts/layouts.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,6 @@ ZoomedFullBody.args = {
uiLang: 'it',
showShare: true,
showSettings: true,
// memori,
// tenant,
memori: {
memoriID: '6573844d-a7cd-47ef-9e78-840d82020c21',
name: 'Nicola',
Expand Down Expand Up @@ -483,11 +481,11 @@ ZoomedFullBody.args = {
coverURL:
'https://assets.memori.ai/api/v2/asset/e9bb9f6d-8f34-45ab-af9e-6d630d9a51a8.png',
avatar3DURL:
'https://assets.memori.ai/api/v2/asset/893c41df-7619-436d-9e86-fe1d406fc933.glb',
'https://assets.memori.ai/api/v2/asset/3f5ef41c-6c4c-449c-888d-cf9c89782528.glb',
avatarOriginal3DURL:
'https://d1a370nemizbjq.cloudfront.net/c7c80a1d-deda-4fe1-96c6-fabad0771aa2.glb',
'https://assets.memori.ai/api/v2/asset/3f5ef41c-6c4c-449c-888d-cf9c89782528.glb',
needsPosition: false,
voiceType: 'MALE',
voiceType: 'FEMALE',
culture: 'it-IT',
categories: [
'biografico',
Expand Down Expand Up @@ -531,8 +529,7 @@ ZoomedFullBody.args = {
),
avatar: 'readyplayerme-full',
avatarURL:
'https://models.readyplayer.me/63b55751f17e295642bf07a2.glb#' +
// 'https://models.readyplayer.me/63b558263858282637c54115.glb#' +
'https://assets.memori.ai/api/v2/asset/f26b627f-a5d6-45e9-a000-a3d8f70cfd1c.glb'+
new Date(Date.now()).getTime(),
}),
},
Expand Down

0 comments on commit 0d63458

Please sign in to comment.