static Transform BuildHierarchy(Transform parent, BvhNode node, float toMeter, Transform sparent)
        {
            //Debug.Log("Part : " + node.Name);
            var go = new GameObject(node.Name);

            go.transform.localPosition = node.Offset.ToXReversedVector3() * toMeter;
            go.transform.SetParent(parent, false);

            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere.name = node.Name;
            sphere.AddComponent <ShowBone>();
            sphere.GetComponent <ShowBone>().SetTransform(go.transform, true);
            if (sparent != null)
            {
                sphere.transform.SetParent(sparent, false);
                if (node.Name == "head")
                {
                    sphere.transform.localScale = new Vector3(1.1f, 1.1f, 1.1f);
                }
                else if (node.Name == "head" || node.Name == "rThumb1" || node.Name == "rIndex1" ||
                         node.Name == "rMid1" || node.Name == "rRing1" || node.Name == "rPinky1" ||
                         node.Name == "lThumb1" || node.Name == "lIndex1" || node.Name == "lMid1" ||
                         node.Name == "lRing1" || node.Name == "lPinky1" || node.Name == "leftEye" || node.Name == "rightEye")
                {
                    sphere.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                }
                else
                {
                    sphere.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f);
                }
            }
            else
            {
                GlobalData.SetFocusObj(sphere);

                sphere.transform.localScale = sphere.transform.localScale * 0.2f;
                sphere.tag = "sphere";
            }

            foreach (var child in node.Children)
            {
                BuildHierarchy(go.transform, child, toMeter, sphere.transform);
            }

            return(go.transform);
        }
        public void Load()
        {
            //
            // build hierarchy
            //
            GlobalData.clear();

            if (Root == null)
            {
                Root     = new GameObject(System.IO.Path.GetFileNameWithoutExtension(Path));
                Root.tag = "cubeman";
                GlobalData.SetFocusObj(Root);
                GlobalData.animeobjname = Root.name;

                var hips        = BuildHierarchy(Root.transform, Bvh.Root, 1.0f, null);
                var skeleton    = Skeleton.Estimate(hips);
                var description = AvatarDescription.Create(hips.Traverse().ToArray(), skeleton);
                //
                // scaling. reposition
                //
                scaling = 1.0f;
                {
                    //var foot = animator.GetBoneTransform(HumanBodyBones.LeftFoot);
                    var foot      = hips.Traverse().Skip(skeleton.GetBoneIndex(HumanBodyBones.LeftFoot)).First();
                    var hipHeight = hips.position.y - foot.position.y;
                    // hips height to a meter
                    scaling            = 1.0f / hipHeight;
                    GlobalData.m_scale = scaling;
                    foreach (var x in Root.transform.Traverse())
                    {
                        x.localPosition *= scaling;
                    }

                    var scaledHeight = hipHeight * scaling;
                    hips.position = new Vector3(0, scaledHeight, 0); // foot to ground
                }
                GlobalData.FrameCountList.Add(Bvh.FrameCount);
                Debug.Log("Bvh.FrameCount : " + Bvh.FrameCount);

                Avatar            = description.CreateAvatar(Root.transform);
                Avatar.name       = "Avatar";
                AvatarDescription = description;

                var animator = Root.AddComponent <Animator>();
                animator.avatar = Avatar;
                GlobalData.SetAvatar(Avatar);

                AnimationClip Animation = BvhAnimation.CreateAnimationClip(Bvh, scaling, true);
                Animation.name     = Root.name;
                Animation.legacy   = true;
                Animation.wrapMode = WrapMode.Loop;
                alginSec           = Animation.length;
                var animation = Root.AddComponent <Animation>();
                animation.AddClip(Animation, Animation.name);
                animation.clip = Animation;
                animation.Play();
                GlobalData.SetAnimationClip(Animation);

                var humanPoseTransfer = Root.AddComponent <HumanPoseTransfer>();
                humanPoseTransfer.Avatar = Avatar;

                // create SkinnedMesh for bone visualize
                var renderer = SkeletonMeshUtility.CreateRenderer(animator);
                Material = new Material(Shader.Find("Standard"));
                renderer.sharedMaterial = Material;
                Mesh      = renderer.sharedMesh;
                Mesh.name = "box-man";

                Root.AddComponent <BoneMapping>();
            }
            else
            {
                GlobalData.FrameCountList.Add(Bvh.FrameCount);
                Debug.Log("Bvh.FrameCount : " + Bvh.FrameCount);

                AnimationClip Animation = BvhAnimation.CreateAnimationClip(Bvh, scaling);
                Animation.name     = Root.name + bvhList.Count().ToString();
                Animation.legacy   = true;
                Animation.wrapMode = WrapMode.Loop;
                var animation = Root.GetComponent <Animation>();
                GlobalData.timeAlign = Animation.length / alginSec;
                animation.AddClip(Animation, Animation.name);
                animation.clip = Animation;

                animation.Play();
                //  GlobalData.SetAnimationClip(Animation);
            }

            // create AnimationClip
            //
        }