public static SkinnedMeshRenderer CreateRenderer(Animator animator)
        {
            //var bodyBones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones));
            var bones = animator.transform.Traverse().ToList();

            var builder = new MeshBuilder();

            foreach (var headTail in Bones)
            {
                var head = animator.GetBoneTransform(headTail.Head);
                var tail = animator.GetBoneTransform(headTail.Tail);
                if (head != null && tail != null)
                {
                    builder.AddBone(head.position, tail.position, bones.IndexOf(head));
                }
            }

            var mesh = builder.CreateMesh();

            mesh.bindposes = bones.Select(x =>
                                          x.worldToLocalMatrix * animator.transform.localToWorldMatrix).ToArray();
            var renderer = animator.gameObject.AddComponent <SkinnedMeshRenderer>();

            renderer.bones      = bones.ToArray();
            renderer.rootBone   = animator.GetBoneTransform(HumanBodyBones.Hips);
            renderer.sharedMesh = mesh;
            var bounds = new Bounds(Vector3.zero, mesh.bounds.size);

            renderer.localBounds = bounds;
            return(renderer);
        }
        public static SkinnedMeshRenderer CreateRenderer(Animator animator)
        {
            //var bodyBones = (HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones));
            var bones = animator.transform.Traverse().ToList();

            var builder = new MeshBuilder();

            foreach (var headTail in Bones)
            {
                var head = animator.GetBoneTransform(headTail.Head);
                if (head != null)
                {
                    Transform tail = null;
                    if (headTail.Tail != HumanBodyBones.LastBone)
                    {
                        tail = animator.GetBoneTransform(headTail.Tail);
                    }

                    if (tail != null)
                    {
                        builder.AddBone(head.position, tail.position, bones.IndexOf(head), headTail.XWidth, headTail.ZWidth);
                    }
                    else
                    {
                        builder.AddBone(head.position, head.position + headTail.TailOffset, bones.IndexOf(head), headTail.XWidth, headTail.ZWidth);
                    }
                }
                else
                {
                    Debug.LogWarningFormat("{0} not found", headTail.Head);
                }
            }

            var mesh = builder.CreateMesh();

            mesh.name      = "box-man";
            mesh.bindposes = bones.Select(x =>
                                          x.worldToLocalMatrix * animator.transform.localToWorldMatrix).ToArray();
            var renderer = animator.gameObject.AddComponent <SkinnedMeshRenderer>();

            renderer.bones      = bones.ToArray();
            renderer.rootBone   = animator.GetBoneTransform(HumanBodyBones.Hips);
            renderer.sharedMesh = mesh;
            //var bounds = new Bounds(Vector3.zero, mesh.bounds.size);
            //renderer.localBounds = bounds;
            return(renderer);
        }