How to Upload an Avatar From Unity?

Allow's talk about avatars!!

Avatars are mostly used to visualize characters in a 3D game/feel. Mostly, having uncanny avatars in your game can make the users uncomfortable. Now that the metaverse is gaining popularity, avatars are becoming more pregnant.  And, having bad avatars can ruin whatsoever VR experience too.

Having looked at various avatar creating platforms like Spatial, avatarsdk, IMVU etc. One that stood out was Ready Player Me. The all-time part about this is you can not only create avatars, just you can also download the models and animation and employ information technology in your project. And then, this web log will be focusing on creating your own avatar using Set up Thespian Me and integrating information technology into Unity. Later on we'll tell how you can easily add together rig your avatar using Blitheness Rigging and IK.

1. Creating Your Avatar

It's really elementary to create an avatar in Ready Actor Me.

  • Head over to the Ready Player Me website and click on Create avatar.
  • Then, you lot need to choose your torso type 🚻
  • At present yous will have two options, either to upload your selfie or to go on with a default avatar.
  • Later on you lot chose ane of the two options, y'all can customize your avatar!
    • Yous can choose the habiliment πŸ‘• from a selected range.
    • You tin modify your facial features similar skin colour 🎨, cheekbone, hairstyle πŸ’‡, eyes πŸ‘€, etc.
    • Accessories similar bags πŸ›️, hats 🎩, caps πŸŽ“, spectacles πŸ•Ά️ and more.

    Ready Player Me

  • Click on Enter Hub and your avatar is at present ready.
  • You can claim your avatar by signing in.

    Ready player me Avatar

Wasn't that really simple? Importing that into Unity is also as simple as that! So allow's see how it's done.

two. Importing the Avatar into Unity

To import the avatar into Unity y'all need to download the Unity Avatar SDK provided by Set up Player Me. To download it:

  • Open up the Ready Role player Me documentation, then click on Unity Avatar SDK Download. This volition open a new web page.
  • Under the Latest release section, click on Download the latest version of the Unity SDK. This will open a Google Drive folio.
  • Right-click on Prepare Player Me_v1.7.0.unitypackage → Then, click on Download → Save information technology in a path of your choice.

    Ready player me SDK

One time you lot have the SDK downloaded, create a new Unity project or open an existing ane and permit'due south see how we tin get the Avatar into Unity.

Note: Make sure you are using Unity version 2019LTS and above
  • To import the SDK into Unity, you can either drag and driblet information technology into the scene or you can import the package from the top Unity Editor toolbar via AssetsImport PackageCustom Packet → And then from the file explorer select the ReadyPlayerMe Unity parcel.
  • A window will popular upwardly. ⚠️ Make sure you uncheck Newtonsoft Json before hitting Import to start importing the package into the project.

    Import SDK

  • Become to the Ready Player Me website and navigate to the My Avatars tab. Click on the 3 dots at the top right corner of the Avatar and click on Copy .glb URL.

    Import SDK

  • Go dorsum to Unity and in the Avatar Loader window paste the copied .glb URL in the URL or Short Cord field and click on Load Avatar.

    Load Avatar

That was simple, right? At present that we have an Avatar with us, nosotros can use the XR Interaction Toolkit and Blitheness Rigging packages to add together VR components and changed kinematics to the Avatar. Inverse kinematics is goose egg but adding movement to other parts by moving one of the continued parts. Thus, enabling u.s. to utilize the avatar in VR.

3. Setting up Unity for VR

In this section, we volition see how nosotros can fix Unity for VR and convert this regular avatar into an avatar that can be used in the metaverse! We will be making utilise of the XR Interaction Toolkit and the XROrigin Unity package that'due south custom made by us.

Notation: If you already know how to set up your project for VR or if you already have your own XROrigin, and so please feel gratuitous to leap to the adjacent section.
  • In Unity, click on WindowsParcel Manager → select the setting icon ⚙️ → Advanced Project Setting → Check the box for Enable Preview Packages and select I empathise. It's just a warning that it'south a preview package and not yet released then it could potentially have bugs.

  • To import the XR Interaction Toolkit:

    • Open the Package Manager → select Unity Registry from the drop-downwards → search for "XR Interaction Toolkit" or scroll down to observe it.
    • Select that package and make sure the version is two.0.0-pre.6 → click on Install.
    • After installing, a window will pop up asking you to restart Unity, click on Yeah to continue. Make sure you have saved the scene and the projection.

    XR Interaction Toolkit

  • Later on Unity restarts, navigate back to XR Interaction Toolkit package in the Package Managing director. Import Default Input Action and XR Device Simulator.

    XR Simulator

  • Download the XROrigin parcel from here → Import the package from the acme Unity Editor toolbar via AssetsImport PacketCustom Package → Then from the file explorer select the XROrigin Unity bundle.

    Importing XR Origin

  • Delete the Main Camera πŸŽ₯.

  • In the project folder, navigate to FeaturesXROriginPrefabs. Drag and drib the XROrigin into the scene.

    XR Origin

4. Setting upwardly the Avatar and Animation Rigging

In this section, we'll fix the avatar and use the Blitheness Rigging package to add together changed kinematics to it to have a realistic body motion in VR.

  • In Unity, click on WindowsPackage Manager → search for Animation Rigging and install information technology.

    Animation Rigging

  • From the hierarchy, select the Avatar GameObject and remove the Controller and Avatar from the Animator component. → Add Rig Builder and Os Renderer Components to it.

    Rig builder

  • Click on the Avatar GameObject and lock πŸ”’ the Inspector window → Press and hold the Alt cardinal and click on the Avatar to open up all its children → Select the Hips Game object, scroll downwards and select the final child GameObject while holding the Shift key → Drag and driblet it into the Transforms field of the Bone Renderer component. With that, you will exist able to see the bones 🦴 of the avatar.

    Bone renderer

  • Click on the Avatar GameObject and from the toolbar select Blitheness Rigging → click on Rig Setup, this will create a Rig as a child of the avatar → remove the empty layer from the Rig Builder component → unlock πŸ”“the Inspector window → select the Rig1 GameObject and rename it as VRRig.

    VR rig

  • Select the VRRig GameObject,

    • Create an empty GameObject as a child and name information technology as IKRightArm → create two GameObjects as a child of this and name them as Target and Hint respectively.
    • And then, select the IKRightArm GameObject, add Two Os IK Constraint component and lock πŸ”’ the Inspector window → from the Scene view select the right arm and, drag and drop the GameObject into the Root field of the 2 Bone IK Constraint component → similarly, select and, elevate and drop the right forearm and right mitt into the Mid and Tip field respectively. Finally, drag and drib the Target and the Hint GameObjects into the respective Source Objects field.

    Right IK

  • Select the Target GameObject and while holding the Shift primal select the right hand from the Scene view → from the toolbar select Animation Rigging → click on Align transform.
    Similarly, select the Hint GameObject and while holding the Shift key select the correct forearm from the Scene view and align their transforms as well. Then, motion the Hint GameObject slight dorsum.

    Align Transform

  • Indistinguishable the IKRightArm GameObject and name it every bit IKLeftArm → Drag and drop the LeftArm, LeftForeArm and LeftHand GameObjects into the Root, Mid and Tip fields of the Two Bone IK Constraint component respectively → Align the Target GameObject with the left hand and Hint GameObject with the left forearm. Also, motion the Hint GameObject slightly dorsum (same value as the Hint GameObject of IKRightArm).

    Left IK

  • Information technology'due south time to test it! Hit the Play ▶️ push → select both the targets and move them around in the scene view. If they are moving with the elbow as the swivel then yous have successfully set the arms. If not experience free to go through all the steps above and brand sure everything is set upwardly correctly. Leave the Play way and permit'due south motility on to the concluding footstep in this section.

    Testing VR

  • Select the VRRig Game object, create an empty GameObject and proper name it IKHead → add the Multi-Parent Constraint component and lock πŸ”’ the Inspector window → from the Scene view select the head and, drag and drib the GameObject into the Constrained Object field → drag and drib the Head GameObject into to the Source Objects field. Finally, marshal the IKHead GameObject to the Head GameObject.

    Head IK

That completes setting up the Avatar with an blitheness rig. Next, was want the Avatar's head and easily to follow the XROrigin's camera and the hands respectively. So, let'due south move on to the side by side section.

five. Scripting and Avatar configuration

Let's write a script that will allow us to movement the avatar along with the XROrigin. The script will non work direct, nosotros need to make a few adjustments to the avatar'south transform subsequently in the Unity editor so that it matches the XROrigin.

  • In the Project window, create a new C# script, name it as AvatarController and copy the following lawmaking. In the code, we are using Tardily Update to make sure we have captured the movement that might have occurred in the Update.

                  using UnityEngine;   [System.Serializable] public class MapTransform {     public Transform vrTarget;     public Transform IKTarget;     public Vector3 trackingPositionOffset;     public Vector3 trackingRotationOffset;      public void MapVRAvatar()     {         IKTarget.position = vrTarget.TransformPoint(trackingPositionOffset);         IKTarget.rotation = vrTarget.rotation * Quaternion.Euler(trackingRotationOffset);     } }  public grade AvatarController : MonoBehaviour {     [SerializeField] private MapTransform caput;     [SerializeField] private MapTransform leftHand;     [SerializeField] private MapTransform rightHand;      [SerializeField] individual bladder turnSmoothness;      [SerializeField] private Transform IKHead;      [SerializeField] private Vector3 headBodyOffset;      private void LateUpdate()     {         transform.position = IKHead.position + headBodyOffset;         transform.forward = Vector3.Lerp(transform.forward, Vector3.ProjectOnPlane(IKHead.forward, Vector3.up).normalized, Time.deltaTime * turnSmoothness); ;         head.MapVRAvatar();         leftHand.MapVRAvatar();         rightHand.MapVRAvatar();     } }                          
  • Add this script to the avatar → Drag and drop the MainCamera, LeftBaseController and RightBaseController GameObjects into the VRTarget of Head, Left Paw and Right Paw fields respectively → Drag and drop the IKHead, Targets of IKRightArm and IKLeftArm GameObjects into the IKTarget of Head, Left Hand and Right Hand fields respectively → Elevate and drop the IKHead GameObject into the IKHead field at the bottom.

    Avatar controller

  • To align the transforms together, y'all demand to hit Play ▶️ and utilize the XROrigin'due south hand as a reference to correctly orient the Avatar'southward hands. I made use of the XRSimulator for the initial orientation and after played it on my Vive to make terminal adjustments. Feel free to use the same values to start with and then you tin tweak information technology as per your requirement.

    VR values

    Controller values

  • Yous can see that the avatars' head is blocking the camera vision. To correct that we'll create a new layer called Ignore and assign it to the avatar's eyes, head, hair, glasses and teeth. Then, we will uncheck the Ignore layer from the Camera's Culling Mask field. Culling Mask is used to render parts of the Scene selectively, since nosotros are unchecking Ignore layer, that photographic camera volition not render GameObjects with the Ignore layer.

    Culling Mask

  • You can create a mirror to meet yourself in VR past making utilize of a Quad, a Photographic camera and a Render Texture.

    Note: You can refer to Section ii.4 of the Selfie Stick weblog to know how to create a Render Texture and display the Camera'due south output on a Quad.>

    Render Texture

  • Finally, disable the XROigin's mitt prefabs past setting the Model Prefab field of the XR Controller (Activity-based) Component of the Left and Right base of operations controller GameObjects to None.

    VR hands

  • Hit Play ▶️ and test it in VR.

    Play testing

With that, we have successfully rigged our Avatar for VR.

Decision

In this blog postal service, we've learned how to create an avatar, import it to Unity and rig our Ready Player Me avatar for VR.

And then, what to do side by side? Well, we rigged only the upper body but you can go further and rig the lower body also (Maybe something that we will cover in the next web log mail service). Also, the hands can be animated when the grip and trigger buttons are pressed.

See you next time!

____________________

Thank you

Thank you for reading this weblog mail. 🧑 If you are interested in creating your own AR and VR apps, you lot can acquire more about it here on immersive insiders. Also, if yous accept any questions, don't hesitate to achieve out! Nosotros're e'er happy to assistance.

brittontolved60.blogspot.com

Source: https://blog.immersive-insiders.com/animate-avatar-for-vr-in-unity/

0 Response to "How to Upload an Avatar From Unity?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel