Giter Club home page Giter Club logo

unity-avatar-generation's Introduction

Unity Humanoid Avatar Generation

Requirements

  • Unity 2020.1.17f1 (Version used, but will likely work with many newer and older versions)

Introduction

This repository contains a compact example demonstrating how to generate a Humanoid Avatar at runtime using the AvatarBuilder.BuildHumanAvatar API. The generated avatar can be supplied to an Animator component, which can then drive the avatar's animation using an AnimatorController.

Open the SampleScene scene which contains the default Mixamo avatar. It has been set up with an AnimationController supplied to the Animator. Note however that the Avatar property has been left empty. When hitting play, the attached HumanoidAvatarBuilder component will take care of creating the Avatar.

Some remarks

The sample was created because Unity's documentation contains very little information on how to use their API, nor does it supply a sample to the best of my knowledge. On various sites users have expressed that they are unable to use the API, or that it gives them non-functional results.

Invalid AABB errors

Some users report errors such as the following when applying an animation to their generated Avatar:

Invalid AABBa
IsFinite(outDistanceForSort)
IsFinite(outDistanceAlongView)
Invalid AABB aabb
Invalid AABB rkBox

This same issue may show itself by NaN values appearing in the positions of various transforms.

This issue appears in Unity's own issue tracker as well: AVATARBUILDER.BUILDHUMANAVATAR SETS NAN POSITIONS WITH SOME AVATARS

From what I have been able to tell this is due to an incorrect object name being supplied in the HumanDescription's HumanBone or SkeletonBone arrays. This in particular seems to happen when trying to generate an Avatar based on a (modified) HumanDescription retrieved from an existing Avatar. While object names may appear correct, an incorrect name in SkeletonBone's private member parentName may still cause issues. So build your HumanDescription from scratch.

Resizing avatars

Most people who I have seen trying to use this API, seem to want to do so to create avatars with different skeleton proportions. While this repository does not demonstrate that functionality, the principle is the same.

The avatar in the SampleScene scene is standing in a T-Pose. This T-Pose is stored in the Avatar's skeleton definition via the SkeletonBone array. This implies that you can change bone lengths by modifying the local positions of the bone/joint transforms to lengthen or shorten bones. Do this before creating the HumanDescription.

Note that it is not sufficient to just modify the bone length when modifying the legs. Make sure that any changes to the lengths of leg bones are reflected in the position of the hip bone. That is, move it up or down to ensure the avatar's feet are planted on the ground in their T-Pose. If not, your animation will either have feet hover above the floor, or see the avatar bend its knees to accomodate for an incorrectly placed hip joint.

Hardcoded definition

The repository contains a Mixamo avatar, and the code in AvatarUtils.cs contains a static dictionary mapping its bone/joint names to names Unity understands for Humanoid Avatars. If you use different software to create your skinned and rigged avatars, you will need to adapt this definition or generate the mapping at runtime. The hardcoded dictionary purely exists to explicitly show which GameObject in the Avatar's hierarchy gets mapped to which of Unity's Humanoid Avatar joints.

unity-avatar-generation's People

Contributors

bkevelham avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unity-avatar-generation's Issues

Arms bone error.

I created the avatar model on the readyplayer.me website, and then imported it into my project using blender. Now I want to create my unity avatar at runtime. The name of the model bone created on the website is as shown in the picture below, so I modified the hardcoding. But I found that the bone of the arm part is always wrong, and the effect is as shown in the picture. I repeatedly checked and found that the bone orientation of the avatar arm part created on this website is different from the example you gave. How do I need to fix this problem?

shoot3

shoot2
shoot1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.