# Creating an Avatar

{% embed url="<https://www.youtube.com/watch?v=0m5xAzhoGkQ>" %}

## **Software you will need:**

* Blender 4.0+: <https://www.blender.org/download/>
  * (tested on 4.0.2, but should work on newer versions)
* Download these three Blender add-on files:

{% file src="<https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-681760a926dc0b582f5418a1c0bbcbcba7fff32a%2Fimprobable_geometry_utils.py?alt=media>" %}
The repo is private, so this file is the latest one
{% endfile %}

{% file src="<https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-3f980860844b479f1e9ee0ac7c4cdc9926748641%2Fshd.zip?alt=media&token=2f7a0875-4e77-432e-98dc-631f71a1fb57>" %}
Surface Heat Skinning Tool
{% endfile %}

{% file src="<https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-8be6a498df50b991a9250a70d66fddc6bcd66b61%2FGame_Rig_Tools_Unreal_Blender4.0.zip?alt=media>" %}
Game Rig Tools (Support the creators if possible)
{% endfile %}

(These files are the Improbable Blender add-on for the geometry utilities from [this private repo](https://github.com/improbable/BlenderGeometryUtilities/tree/feature/geometry_process_addon), the Game Rig Tools from <https://toshicg.gumroad.com/l/game_rig_tools> and the Surface Heat Skinning tool <http://www.mesh-online.net/shd-blender-addon.zip> from [this ](https://github.com/meshonline/Surface-Heat-Diffuse-Skinning)repo)

### Plugin installation in Blender

In Blender, go to Edit -> Preferences -> Add-ons and press the `Install` button

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-7987a0e35d1aac3c943f42fe79be2976ff675415%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Install both of the .zip files and the .py file in turn. When each one has been installed, you must enable it by checking the box:

If the python file is updated you can re-download, replace it and it will be updated in Blender. For the other addons (zip files), you'll need to download the file, remove the old one from Blender and re-add the newest zip file. Game Rig Tools is in active development and it has updates in a regular basis.

## Importing your character

First you will need a character model file. This can either be a character you've authored yourself, or one you have downloaded. There are many free character meshes available online, for example at <https://sketchfab.com/>.

For best results your mesh should be humanoid and in an A-pose or T-pose. Meshes with lots of accessories or sticking out parts don't tend to work well, as the auto-skinning step can get confused and attach parts of them to the wrong joints.

Once you've found a character mesh, you're ready to start converting it into a file that's compatible with the MSquared avatar system. For a detailed explanation see the video above, but here you will find a summary of the most important steps. If you're completely new to Blender you can also see a [basic introduction to the controls](#appendix-basic-blender-controls).

* Create a new empty scene in Blending. If there are default Camera, Cube and Light objects in the overview you can click them and press Delete to remove them.
* Use File -> Import to import your character file. If you see an Icosphere object in the overview, delete it:<br>
* Tip: If your character doesn't import nicely or looks wrong, you can try re-exporting it from a different tool. If your source file is a glTF/GLB file you can go to <https://www.gltfeditor.com/> and import your avatar, and then Save again. Import this re-saved file into Blender instead and it make work better.
* You need to remove any existing skeleton on the character, and for ease we can merge all meshes together. Press N to bring up the tools menu and select `Improbable geometry process`. Click `Remove Armature`, `Remove Transform Groups` and then `Merge Vertices` to perform all the clean-up steps. This will also erase any non-geometry elements in your scene and remove all parent transform groups.
* Select the Game Rig Tool tool and press `Initiate Mannequin` to add the skeletons.
* Ensure your mesh is the right scale and rotation to match the skeleton. Ensure you are in Object mode, select your mesh and press S to scale, and R to rotate it. You are now ready to set up the skeleton.\
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-78f327b31b8e9cbf18371d36bb8ec45a34807b17%2Fimage.png?alt=media)

### Setting up the skeleton

You can now fine tune the joint positions to match your character geometry.

* In the `Game Rig Tool` isolate the `Tweak` skeleton by pressing the white circle next to it. Go into `Pose` mode to edit the joints.
* Enable the `Body Parts` and/or `Joint Tweak` options, and move the joints into the right place to match you mesh. Select the wireframe squares (body parts) and circles (joints) and move them by pressing `G` and rotate by pressing `R`.
* See the video for advanced methods of matching the fingers.
* When you're happy, press `Apply Rig`.\
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-d86f0b56b6fd45ab292dd1d3530ffef8e887476c%2Fimage.png?alt=media)

Now the joints are set up, the geometry needs skinning to the skeleton.

* In the `Game Rig Tool` isolate the `Deform` skeleton by pressing the white circle next to it. Go into `Object` mode to use the skinning tool.
* Click the `Mesh Online` tool and set the `Influence Bones` to `4`.
* Select the Deform skeleton and then `Ctrl + Click` the mesh itself so that both are selected.\
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-894d7a312a4551d85760f0a4081073f88b4afac5%2Fimage.png?alt=media)
* Press the `Surface Heat Diffuse Skinning` button to calculate this skinning. This will take a few seconds.
* Go back into `Pose` mode to test the skinning, by selecting joints and pressing `R` to rotate them. Press `Esc` to cancel each rotation after testing.
* Go back into the `Game Rig Tool` and press `Switch Parent Armature` to apply the changes to the Unreal skeleton.
* Isolate the `Unreal` skeleton in the `Game Rig Tool` with the circle button, where you can test the skinning again in `Pose` mode.
* Go back to the `Improbable geometry process` tool and select an Export location and a filename.\
  \
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-c06b45d5ada59d65a98389bee2f2bc46a792ea0d%2Fimage.png?alt=media)
* Go back into Object mode, isolate the `Unreal` skeleton again and `Ctrl + Click` the mesh to ensure both the skeleton and the mesh are selected. Now you can press `Export GLB`.\
  \
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-1c4ea597b2b36d25c9d4252896e7dd6f4d471a4f%2Fimage.png?alt=media)
* Finally press the `Open Web Avatar Exporter` button to open the web page where we carry out the final stage.

### Fixing the rotations

We're now done in Blender, but we need to use the GLTF Avatar Exporter web tool to fix up the skeleton rotations.

* Go to <https://mml-io.github.io/avatar-tools/main/tools/gltf-avatar-exporter/>\
  (this is where the `Open Web Avatar Exporter` button should take you).
* Drag the GLB file you exported in the previous step into the top left window. If everything exported correctly you should see your character.
* Press the `Use Sample Animation` button, and if everything is set up correctly you will see your character performing an animation.\
  ![](https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-c954ff437a0161a39fc4f5d1cfe71712fa1adf73%2Fimage.png?alt=media)
* Assuming this all works, press the `Export` button at the top right to save your final GLB file!

## Turning your GLB file into an MML character

You now have a compatible GLB avatar file. But to use it you need to create an MML avatar using the file.

{% hint style="info" %}
From v21 of the platform, we also support [DRACO](https://google.github.io/draco/) compressed glTFs and GLBs
{% endhint %}

* Go to <https://mmleditor.com/projects> and `Create a Project`
* Upload the .glb file you previously exported by going to the `Assets` tab and dragging your file in.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-cf6e0e6799adf3d312740d3b1fc8fa0fcc22cbaf%2Fimage.png?alt=media" alt=""><figcaption><p>Upload your Asset to IPFS</p></figcaption></figure>

* Now drag the asset to the Code window, and rename the `m-model` tag to `m-character` at the start and end of the code. This is all you need in your MML file.

```xml
<m-character src="https://mmlstorage.com/[ASSET_CODE]"></m-character>
```

* Now you need to permanently store the MML. Click the `Static Versions` button at the top right and press `Publish`. The click `Copy` to copy the URL of your MML avatar.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-7373e154da69c8d44f14235ed05799a08318f897%2Fimage.png?alt=media" alt=""><figcaption><p>Getting the static URL</p></figcaption></figure>

* The MML avatar link should now be ready to use! Try one of the following:
  * View your Url online: [the-mml-viewer](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/the-mml-viewer "mention")
  * Add your Avatar to your game: [using-an-avatar-in-game](https://docs.msquared.io/creation/unreal-development/features-and-tutorials/avatars/using-an-avatar-in-game "mention")

## Further demo

Here is another quick demo using a different character.

{% embed url="<https://youtu.be/O8mpzWHAtsg?feature=shared>" %}

### Generative AI Character Demo

You can also use generative AI to create your avatar. Here is another quick demo of this process.

{% embed url="<https://youtu.be/rReyMIdxQVc?feature=shared>" %}

## Appendix: Basic Blender controls

If you're new to Blender it can be confusing to use. Here are some basic controls to get you started. The extra controls are covered in the tutorial video at the top of the page.

Camera controls:

* Spin the camera by holding the middle mouse button.
* Move the camera by holding `Shift` and the middle mouse button
* Zoom with the mouse wheel, or by holding `Ctrl` and the middle mouse button

Change the 'edit mode' in the top left corner (the actual menu depends on what you have selected). In this tutorial you'll dealing with skeletons, and will need to use `Object Mode` (for selecting entire objects) and `Pose Mode` (for manipulating individual joints).

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-c217e22c19d3cbc51a84e8381a3bba2e61d90890%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Press `N` to show the tools the you will be using, on the right hand side.

Click the axis letters to enter an orthographic view. This is useful for moving joints about in a single plane - for example click the X axis to move spine joints around without the risk of them moving off the centre line.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-ed9eb308eaaabb2a1efc37d224389d44e1e8ec3f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Some steps require multiple objects to be selected at once. In the top right tree view, you can select a second object by holding `Ctrl` and clicking. For example, some steps require you to use the white circle icon to select a specific skeleton, and then also select your mesh. You can hold Ctrl and click the mesh either in the main viewport, or in the tree view.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-614f3cad3ad9c7c1ad326eda9f26f199ef99de2e%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
