Skip to content

Instantly share code, notes, and snippets.

@emilianavt
Last active July 26, 2023 19:05
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save emilianavt/51d8399987d67544fdebfe2ebd9a5149 to your computer and use it in GitHub Desktop.
Save emilianavt/51d8399987d67544fdebfe2ebd9a5149 to your computer and use it in GitHub Desktop.
Converting an avatar to VRM format

Converting an avatar to VRM format

In this guide, I assume you already know the basics of Unity and probably have previously uploaded an avatar to VRChat. If you haven't, you can still try to follow along, but some descriptions might be a bit too brief.

A more in-depth guide with screenshots can be found here.


Setup

You need Unity 2018.1.1f1 or another recent version of unity. You will also need import the UniVRM package into your Unity project to create your VRM file.

If you know Japanese, you can also read the official the UniVRM documentation.


Preparing your avatar

I assume you have your rigged, humanoid avatar in FBX format already imported into Unity. Make sure the rig is set to humanoid and it is placed in a T-pose.

In VRM format, shape keys are a big contributor to file size. If your model's file size is too big, try splitting off the parts with shape keys into their own mesh and deleting the shapekeys on the other mesh objects in Blender.

On importing your avatar to Unity, you will want to set up the materials to use the shaders compatible with VRM. These shaders, according to the UniVRM documentation are:

  • Unity's Standard shader
  • VRM/UnlitTexture
  • VRM/UnlitCutout
  • VRM/UnlitTransparent
  • VRM/UnlitTransparentZWrite
  • VRM/MToon

If you cannot find the materials for your imported avatar, you can export them on the materials tab of the prefab.


Creating a base VRM file

Put your prefab into a scene, do any further basic setup you might need and then select the export humanoid option from the VRM menu on the menu bar. Enter your name as the author, make sure the two checkboxes are ticked and export the base VRM file.

After doing this, create a new folder in your Unity project and drag the VRM file there to reimport your avatar with all the VRM components applied.

If importing the VRM file fails with a JSON error, try to set your Windows region in such a way that floating numbers use the dot as a decimal symbol.


Customizing the VRM file

Open a new scene and drag the prefab created from the VRM file into it. On the avatar, there will be a number of components that can be customized. In the following, I will mention the components that are useful for customization.

VRM Meta: This component contains information about the model and the creator, as well as what types of content the model may be used for and under what license.

VRM Blend Shape Proxy: Double click on the BlendShape (BlendShapeAvatar) and you will be taken to an overview of blend shape clips. For each you want to set up (probably A, I, U, E, O, BLINK, JOY, ANGRY, SORROW, FUN), select it, then open the mesh at the bottom to adjust the blend shape values. When they are adjusted appropriately, press apply and work on the next one. After setting everything up, you can play the scene and test your blendshape clips using the component on the avatar.

VRM First Person: The first person offset is probably similar to what has to be setup for a VRChat avatar and specifies the camera position. I'm not sure if the offset is from the ground or from the specified bone. The renderer settings can be used to render different parts (e.g. with or without head) depending on how the avatar is viewed.

VRM Look At Head: I'm not sure if this usually needs to be customized. Probably not. However, it is useful for setting up the next component. To do this, add a small object to the scene, in front of your character's head and enter it as a target in this component. Also enable Draw Gizmo.

VRM Look At Bone Applyer: This component lets you customize the movement range of your avatar's eyes. After setting a target for the previous component, enable Draw Gizmo here and play the scene. By moving the target, you will be able to see your avatar's eyes following it. You can adjust the sliders of this component to adjust the range of movement, mainly by using the Curve Y Range Degrees sliders. When you are happy with your settings, right click the component, select copy component and stop the scene. The values will have reset, but you can put them back in by right clicking on the component name again and pasting the copied values.

You can add a Blinker script to preview the blinking animation of your avatar. There is also an AIUEO component you can add to preview the mouth animations.

VRM offers its own alternative to dynamic bones called spring bones. They are less flexible, but can work alright. Spring bones components can be added to the secondary object inside your avatar. Add the root bones of parts of your armature you want to animate to root bones and play with the values until you are happy with it. You can also have multiple components if you need different settings for different root bones. You can also add VRM Spring Bone Collider Group components to your skeleton, to prevent spring bones from clipping into your body.


Exporting

Once everything is set up, you can export your final VRM file. You do this once again by selecting the export humanoid entry from the VRM menu. This time, make sure the two check boxes are unchecked.

That should be all.

@juliusdx
Copy link

Hi I've been trying to make spring bones work with models imported/exported from blender using the vrm add-on into Unity. Do you have any ideas?

@emilianavt
Copy link
Author

I have never used the VRM blender add-on for exporting, so I'd recommend just setting them up in Unity.

@juliusdx
Copy link

Am trying to optimise the file size of my vrm file to be under 5mb. You mentioned above shape keys are a big contributor to large file size, and to reduce it is to separate meshes with shapekeys? Isn't shape keys just on the head? And the head is already a separate object from the rest of the body. Any more detailed advice pls?

@emilianavt
Copy link
Author

If the head is already a separate object on your model, it's fine already. For VRChat for example, it's recommended to have just one mesh for both face and body. In that case, splitting them would be preferable for VRM.

Other than shapekeys, I would look at texture resolutions. Those can also take a lot of space.

@cssddnnc9527
Copy link

HELP!
while exporting and importing, you mentioned "two check boxes", so what are they? which two check boxes?
THANKS!

@emilianavt
Copy link
Author

This guide is probably quite outdated. I recommend following this instead:

https://vrm.dev/en/vrm/how_to_make_vrm/index.html

There used to be only two checkboxes on the export dialogue in early versions of UniVRM, but I can't really remember what they were.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment