The package enables loading MetaPerson avatars in Unity in GLB/GLTF format.
- Unity 2021.3.19f1 or a more recent version
- Built-in render pipeline
- Linear color space for better rendering quality
- Supported platforms: Windows, MacOS, Android, iOS, WebGL
You have two options to get started: you can import this package and the sample via Unity Package Manager or clone the repository and run the sample from it.
1. Open Window->Package Manager, click the + icon in the top left corner, and select Add Package From Git URL.
2. Provide the Git URL of this project:
https://github.com/avatarsdk/metaperson-loader-unity.git
3. Import MetaPerson Loader Sample as well.
4. Open the Assets/Samples/MetaPerson Loader/[ver]/MetaPerson Loader Sample/Scenes/MetaPersonLoaderSample.unity
scene.
5. Run the scene and click the "Load Avatar" button.
6. The avatar will be downloaded and added to the scene.
1. Clone this repository to your computer.
2. Open the project from the metaperson-loader-unity\Samples~\MetaPersonLoaderSample
directory in Unity 2021.3.19f1 or a newer.
3. Open the Assets/AvatarSDK/MetaPersonLoader/Sample/Scenes/MetaPersonLoaderSample.unity
scene.
4. Run the scene and click the "Load Avatar" button.
5. The avatar will be downloaded and added to the scene.
To load another model, provide a URL to the GLB/GLTF model or a ZIP archive containing such a model. Update the Model Url field in the Meta Person Sample script.
This package uses glTFast to load MetaPerson models in GLB/GLTF format.
To load a MetaPerson model, follow these steps:
- Create an empty object in the scene.
- Add a MetaPersonLoader component to this object.
- Specify the Avatar Object field, which is the parent object of the instantiated avatar.
- It's recommended to create a MetaPersonMaterialGenerator component and assign it to the Material Generator field of the MetaPersonLoader. This component provides preconfigured materials and sets up avatar textures. When Material Generator isn't specified, default materials are used.
- Call the LoadModelAsync method of the MetaPersonLoader by passing a URL to a model.
bool isModelLoaded = await metaPersonLoader.LoadModelAsync(modelUrl, p => Debug.LogFormat("Downloading avatar: {0}%", (int)(p * 100)));
- Model Url: a URL to the GLB/GLTF or a ZIP with a MetaPerson model.
- Avatar Object: a parent object of the instantiated avatar. If it isn't specified, the MetaPersonLoader's object is a parent of the avatar.
- Material Generator: provides avatar's materials.
- Cache Models: if true, the downloaded model is saved to the persistent storage for caching.
- Configure Animator: if true, an Animator component is added to the avatar.
- Animator Controller: runtime animator contoller assigned to the Animator.
The MetaPersonMaterialGenerator component offers preconfigured materials to be used in place of the default materials provided by glTFast. It also ensures that textures are set up correctly.
This component includes the following materials:
- Default Material: This material is used by default.
- Body Material: This material is used to render the avatar's body.
- Head Material: This material is used to render the avatar's head.
- Eyelashes Material: This material is used to render eyelashes.
- Cornea Material: This material is used to render cornea when there is an opaque color texture.
- Cornea Transparent Material: This material is used to render transparent cornea without a texture.
- Eyeball Material: This material is used to render eyeballs.
- Outfit Material: This material is used to render outfits.
- Haircut Material: This material is used to render haircuts.
- Glasses Material: This material is used to render glasses.
This component lets you specify the template materials to meet your specific requirements. You may also implement a custom version of the MaterialGenerator.
By default, MetaPerson Creator exports models in FBX format. If you want to export a model in GLB format, follow these steps:
- Run MetaPerson Creator in business integration mode.
- Specify GLB format in export parameters using the JS API.
- Create and export the model.
- Once MetaPerson Creator exports the model in GLB format, it will provide a link to the model. You can copy and store this link and use it to load the model into your application. Note that this link does not expire.
For a demonstration, check out our web integration sample, which exports MetaPerson models in GLB. To run this sample, you'll need credentials from your avatar sdk developer account.
To integrate MetaPerson avatars into a URP (Universal Render Pipeline) project, follow these steps:
- Add an additional MetaPerson Loader URP package via Package Manager by Git URL:
https://github.com/avatarsdk/metaperson-loader-unity.git?path=/URP~
- Import MetaPerson Loader URP Sample.
- Run the
Assets/Samples/MetaPerson Loader URP/[ver]/MetaPerson Loader URP Sample/Scenes/MetaPersonLoaderURPSample.unity
scene.
For more details on implementation, refer to the URP Support documentation.
To animate eye movements (look up, down, left, right), follow these steps:
-
Attach the
EyesAnimator
component to the avatar object. -
Use the methods of the
EyesAnimator
component to set the eye movement weights. The weight parameter should be a float value in the range [0, 1].
EyesAnimator eyesAnimator = ...; // Obtain a reference to the EyesAnimator component
// Set the weights for eye movements
eyesAnimator.SetLookUpWeight(weight); // Look up
eyesAnimator.SetLookDownWeight(weight); // Look down
eyesAnimator.SetLookLeftWeight(weight); // Look left
eyesAnimator.SetLookRightWeight(weight); // Look right
Here's a quick example to illustrate how you might use these methods in a script:
// Assume you have a reference to the EyesAnimator component
EyesAnimator eyesAnimator = avatar.GetComponent<EyesAnimator>();
// Example: Make the eyes look up with half intensity
eyesAnimator.SetLookUpWeight(0.5f);
For more details, refer to the Eyes Animation Sample.
MetaPerson Creator web page can be integrated into your application, allowing your clients to create their custom avatars and import them into your product.
Unity samples:
- Windows and macOS
- Android and iOS
- Android and iOS via Vuplex webview
- VR Quest
- WebGL - integration via IFrame
- WebGL - integration via WebView
Native samples:
Other samples:
The Standalone Application enables the generation of point clouds for avatars, reducing data size and memory usage. The PointCloudLoading sample demonstrates how to achieve this efficiently.
If you have any questions or issues with the plugin, don't hesitate to contact us at support@avatarsdk.com.