Пример #1
0
 public void SetTransferSource()
 {
     Source = GlobalData.GetFocusObj().GetComponent <HumanPoseTransfer>();
 }
        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
            //
        }