public void GuessBoneMapping_mocapdatacom()
        {
            var bvh      = Bvh.Parse(mocapdata_com_hierarchy);
            var detector = new BvhSkeletonEstimator();
            var skeleton = detector.Detect(bvh);

            Assert.AreEqual(0, skeleton.GetBoneIndex(HumanBodyBones.Hips));

            Assert.AreEqual("Hips", skeleton.GetBoneName(HumanBodyBones.Hips));
            Assert.AreEqual("Chest", skeleton.GetBoneName(HumanBodyBones.Spine));
            Assert.AreEqual("Chest2", skeleton.GetBoneName(HumanBodyBones.Chest));

            Assert.AreEqual("Neck", skeleton.GetBoneName(HumanBodyBones.Neck));
            Assert.AreEqual("Head", skeleton.GetBoneName(HumanBodyBones.Head));

            Assert.AreEqual("LeftCollar", skeleton.GetBoneName(HumanBodyBones.LeftShoulder));
            Assert.AreEqual("LeftShoulder", skeleton.GetBoneName(HumanBodyBones.LeftUpperArm));
            Assert.AreEqual("LeftElbow", skeleton.GetBoneName(HumanBodyBones.LeftLowerArm));
            Assert.AreEqual("LeftWrist", skeleton.GetBoneName(HumanBodyBones.LeftHand));

            Assert.AreEqual("RightCollar", skeleton.GetBoneName(HumanBodyBones.RightShoulder));
            Assert.AreEqual("RightShoulder", skeleton.GetBoneName(HumanBodyBones.RightUpperArm));
            Assert.AreEqual("RightElbow", skeleton.GetBoneName(HumanBodyBones.RightLowerArm));
            Assert.AreEqual("RightWrist", skeleton.GetBoneName(HumanBodyBones.RightHand));

            Assert.AreEqual("LeftHip", skeleton.GetBoneName(HumanBodyBones.LeftUpperLeg));
            Assert.AreEqual("LeftKnee", skeleton.GetBoneName(HumanBodyBones.LeftLowerLeg));
            Assert.AreEqual("LeftAnkle", skeleton.GetBoneName(HumanBodyBones.LeftFoot));

            Assert.AreEqual("RightHip", skeleton.GetBoneName(HumanBodyBones.RightUpperLeg));
            Assert.AreEqual("RightKnee", skeleton.GetBoneName(HumanBodyBones.RightLowerLeg));
            Assert.AreEqual("RightAnkle", skeleton.GetBoneName(HumanBodyBones.RightFoot));
        }
        public void GuessBoneMapping_daz_friendry()
        {
            var bvh      = Bvh.Parse(daz_friendry_herarchy);
            var detector = new BvhSkeletonEstimator();
            var skeleton = detector.Detect(bvh);

            Assert.AreEqual("hip", skeleton.GetBoneName(HumanBodyBones.Hips));
            Assert.AreEqual("abdomen", skeleton.GetBoneName(HumanBodyBones.Spine));
            Assert.AreEqual("chest", skeleton.GetBoneName(HumanBodyBones.Chest));

            Assert.AreEqual("neck", skeleton.GetBoneName(HumanBodyBones.Neck));
            Assert.AreEqual("head", skeleton.GetBoneName(HumanBodyBones.Head));

            Assert.AreEqual("lCollar", skeleton.GetBoneName(HumanBodyBones.LeftShoulder));
            Assert.AreEqual("lShldr", skeleton.GetBoneName(HumanBodyBones.LeftUpperArm));
            Assert.AreEqual("lForeArm", skeleton.GetBoneName(HumanBodyBones.LeftLowerArm));
            Assert.AreEqual("lHand", skeleton.GetBoneName(HumanBodyBones.LeftHand));

            Assert.AreEqual("rCollar", skeleton.GetBoneName(HumanBodyBones.RightShoulder));
            Assert.AreEqual("rShldr", skeleton.GetBoneName(HumanBodyBones.RightUpperArm));
            Assert.AreEqual("rForeArm", skeleton.GetBoneName(HumanBodyBones.RightLowerArm));
            Assert.AreEqual("rHand", skeleton.GetBoneName(HumanBodyBones.RightHand));

            Assert.AreEqual("lThigh", skeleton.GetBoneName(HumanBodyBones.LeftUpperLeg));
            Assert.AreEqual("lShin", skeleton.GetBoneName(HumanBodyBones.LeftLowerLeg));
            Assert.AreEqual("lFoot", skeleton.GetBoneName(HumanBodyBones.LeftFoot));

            Assert.AreEqual("rThigh", skeleton.GetBoneName(HumanBodyBones.RightUpperLeg));
            Assert.AreEqual("rShin", skeleton.GetBoneName(HumanBodyBones.RightLowerLeg));
            Assert.AreEqual("rFoot", skeleton.GetBoneName(HumanBodyBones.RightFoot));
        }
Exemplo n.º 3
0
        public void GuessBoneMapping()
        {
            var hips = Bones[(int)HumanBodyBones.Hips];

            if (hips == null)
            {
                Debug.LogWarning("require hips");
                return;
            }

            var estimator = new BvhSkeletonEstimator();
            var skeleton  = estimator.Detect(hips.transform);
            var bones     = hips.transform.Traverse().ToArray();

            for (int i = 0; i < (int)HumanBodyBones.LastBone; ++i)
            {
                var index = skeleton.GetBoneIndex((HumanBodyBones)i);
                if (index >= 0)
                {
                    Bones[i] = bones[index].gameObject;
                }
            }
        }
        public void GuessBoneMapping_mocap()
        {
            var bvh      = Bvh.Parse(bvh_mocap);
            var detector = new BvhSkeletonEstimator();
            var skeleton = detector.Detect(bvh);

            Assert.AreEqual(0, skeleton.GetBoneIndex(HumanBodyBones.Hips));

            Assert.AreEqual("Hips", skeleton.GetBoneName(HumanBodyBones.Hips));
            Assert.AreEqual("Spine", skeleton.GetBoneName(HumanBodyBones.Spine));
            Assert.AreEqual("Spine1", skeleton.GetBoneName(HumanBodyBones.Chest));

            Assert.AreEqual(null, skeleton.GetBoneName(HumanBodyBones.UpperChest));

            Assert.AreEqual("Neck", skeleton.GetBoneName(HumanBodyBones.Neck));
            Assert.AreEqual("Head", skeleton.GetBoneName(HumanBodyBones.Head));

            Assert.AreEqual("LeftShoulder", skeleton.GetBoneName(HumanBodyBones.LeftShoulder));
            Assert.AreEqual("LeftArm", skeleton.GetBoneName(HumanBodyBones.LeftUpperArm));
            Assert.AreEqual("LeftForeArm", skeleton.GetBoneName(HumanBodyBones.LeftLowerArm));
            Assert.AreEqual("LeftHand", skeleton.GetBoneName(HumanBodyBones.LeftHand));

            Assert.AreEqual("RightShoulder", skeleton.GetBoneName(HumanBodyBones.RightShoulder));
            Assert.AreEqual("RightArm", skeleton.GetBoneName(HumanBodyBones.RightUpperArm));
            Assert.AreEqual("RightForeArm", skeleton.GetBoneName(HumanBodyBones.RightLowerArm));
            Assert.AreEqual("RightHand", skeleton.GetBoneName(HumanBodyBones.RightHand));

            Assert.AreEqual("LeftUpLeg", skeleton.GetBoneName(HumanBodyBones.LeftUpperLeg));
            Assert.AreEqual("LeftLeg", skeleton.GetBoneName(HumanBodyBones.LeftLowerLeg));
            Assert.AreEqual("LeftFoot", skeleton.GetBoneName(HumanBodyBones.LeftFoot));
            Assert.AreEqual("LeftToeBase", skeleton.GetBoneName(HumanBodyBones.LeftToes));

            Assert.AreEqual("RightUpLeg", skeleton.GetBoneName(HumanBodyBones.RightUpperLeg));
            Assert.AreEqual("RightLeg", skeleton.GetBoneName(HumanBodyBones.RightLowerLeg));
            Assert.AreEqual("RightFoot", skeleton.GetBoneName(HumanBodyBones.RightFoot));
            Assert.AreEqual("RightToeBase", skeleton.GetBoneName(HumanBodyBones.RightToes));
        }
Exemplo n.º 5
0
        public static Skeleton Estimate(Transform hips)
        {
            var estimator = new BvhSkeletonEstimator();

            return(estimator.Detect(hips));
        }
Exemplo n.º 6
0
        public static void Import(ImporterContext context)
        {
            //
            // parse
            //
            context.Source = File.ReadAllText(context.Path, Encoding.UTF8);
            context.Bvh    = Bvh.Parse(context.Source);
            Debug.LogFormat("parsed {0}", context.Bvh);

            //
            // build hierarchy
            //
            context.Root = new GameObject(Path.GetFileNameWithoutExtension(context.Path));

            BuildHierarchy(context.Root.transform, context.Bvh.Root, 1.0f);

            var hips        = context.Root.transform.GetChild(0);
            var estimater   = new BvhSkeletonEstimator();
            var skeleton    = estimater.Detect(hips.transform);
            var description = AvatarDescription.Create();

            //var values= ((HumanBodyBones[])Enum.GetValues(typeof(HumanBodyBones)));
            description.SetHumanBones(skeleton.ToDictionary(hips.Traverse().ToArray()));

            //
            // scaling. reposition
            //
            float 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;
                foreach (var x in context.Root.transform.Traverse())
                {
                    x.localPosition *= scaling;
                }

                var scaledHeight = hipHeight * scaling;
                hips.position = new Vector3(0, scaledHeight, 0); // foot to ground
            }

            //
            // avatar
            //
            context.Avatar            = description.CreateAvatar(context.Root.transform);
            context.Avatar.name       = "Avatar";
            context.AvatarDescription = description;
            var animator = context.Root.AddComponent <Animator>();

            animator.avatar = context.Avatar;

            //
            // create AnimationClip
            //
            context.Animation          = BvhAnimation.CreateAnimationClip(context.Bvh, scaling);
            context.Animation.name     = context.Root.name;
            context.Animation.legacy   = true;
            context.Animation.wrapMode = WrapMode.Loop;

            var animation = context.Root.AddComponent <Animation>();

            animation.AddClip(context.Animation, context.Animation.name);
            animation.clip = context.Animation;
            animation.Play();

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

            humanPoseTransfer.Avatar = context.Avatar;

            // create SkinnedMesh for bone visualize
            var renderer = SkeletonMeshUtility.CreateRenderer(animator);

            context.Material        = new Material(Shader.Find("Standard"));
            renderer.sharedMaterial = context.Material;
            context.Mesh            = renderer.sharedMesh;
            context.Mesh.name       = "box-man";

            context.Root.AddComponent <BoneMapping>();
        }