-
Notifications
You must be signed in to change notification settings - Fork 1
Avatar Creation
This page details the process of creating a full-body avatar using Ready Player Me integration in the application. It covers the technical aspects of the implementation, including how to customize the avatar creation process and handle the resulting avatar data.
- Overview
- Implementation Details
- Ready Player Me Subsite Configuration
- Handling Avatar Creation Events
- Customizing Avatar URL
- Known Limitations
- Troubleshooting
The avatar creation process utilizes Ready Player Me's web-based avatar creator, embedded within our application using an iframe. This approach allows users to create personalized 3D avatars without leaving our app's environment.
The avatar creation page is implemented in AvatarPage.tsx
. Here's a breakdown of the key components:
-
State Management:
-
showAvatarCreator
: Boolean to toggle the avatar creator iframe visibility. -
avatarCreatorUrl
: URL of the Ready Player Me subsite.
-
-
useEffect Hook:
- Listens for messages from the Ready Player Me iframe.
- Handles avatar creation events and updates the application state.
-
Render Functions:
-
renderAppBar()
: Renders the top navigation bar. -
renderAvatarCreator()
: Renders the iframe containing the Ready Player Me avatar creator. -
renderButtons()
: Renders buttons for initiating avatar creation or choosing other options.
-
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
if (event.origin !== 'https://*****.readyplayer.me') {
return;
}
if (typeof event.data === 'string' && event.data.startsWith('https://models.readyplayer.me/')) {
const modifiedUrl = `${event.data}?morphTargets=mouthOpen,Oculus Visemes`;
setAvatarUrl(modifiedUrl);
setShowAvatarCreator(false);
} else if (event.data.eventName === 'v1.frame.ready') {
if (iframeRef.current?.contentWindow) {
iframeRef.current.contentWindow.postMessage(
JSON.stringify({
target: 'readyplayerme',
type: 'subscribe',
eventName: 'v1.**'
}),
'*'
);
}
}
};
window.addEventListener('message', handleMessage);
return () => window.removeEventListener('message', handleMessage);
}, [setAvatarUrl]);
This code handles messages from the Ready Player Me iframe, including the final avatar URL and initial frame ready event.
The Ready Player Me subsite URL is set in the renderButtons
function:
setAvatarCreatorUrl('https://*****.readyplayer.me');
To use a different subsite:
- Replace the URL with your custom Ready Player Me subsite URL.
- Update the origin check in the
handleMessage
function to match your new subsite's origin.
Using a custom subsite allows for greater control over the avatar creation process, including available customization options and items.
The application listens for the v1.avatar.exported
event from the Ready Player Me iframe. When received, it processes the avatar URL and updates the application state.
To modify this behavior:
- Update the condition in the
handleMessage
function that checks for the avatar URL. - Adjust the
setAvatarUrl
call to handle the avatar data as needed for your application.
The avatar URL is modified to include specific morph targets:
const modifiedUrl = `${event.data}?morphTargets=mouthOpen,Oculus Visemes`;
To customize the avatar further:
- Modify the
morphTargets
parameter to include different morph targets. - Add additional parameters as needed. Refer to the Ready Player Me API documentation for available options.
Example of adding more parameters:
const modifiedUrl = `${event.data}?morphTargets=mouthOpen,Oculus Visemes&textureAtlas=1024&textureSizeLimit=1024`;
-
Demo Subsite Limitations: Using the demo subsite (
https://demo.readyplayer.me
) results in a model with only theWolf3D_Avatar
mesh, which has all morph targets coupled on it. This reduces animation flexibility. -
Mesh Availability: The full set of meshes (e.g.,
Wolf3D_Head
,Wolf3D_Teeth
,Wolf3D_Beard
) is only available when using a development or production subsite.
-
Avatar URL not received:
- Check that the origin in the
handleMessage
function matches your Ready Player Me subsite's origin. - Verify that the Ready Player Me iframe is loading correctly.
- Check that the origin in the
-
Missing meshes or morph targets:
- Ensure you're not using the demo subsite.
- Check the avatar URL parameters to confirm the correct morph targets are being requested.
-
Customization options not appearing:
- If using a custom subsite, verify that it's correctly configured with your desired options.
- Check the Ready Player Me dashboard for your subsite configuration.
For more detailed information on the Ready Player Me API and available options, refer to the official documentation.