Exemple #1
0
        public static bool GetSkeleton(string name, out SkeletonDefinition def)
        {
            def = null;
            if (instance == null)
            {
                return(false);
            }

            if (instance.skeletons.ContainsKey(name))
            {
                def = instance.skeletons[name];
                return(true);
            }

            return(false);
        }
Exemple #2
0
        void HandleSkeleton(List <object> data)
        {
            int index = 0;

            //id
            //name
            string name = (string)data[index++];
            int    id   = (int)data[index++];

            SkeletonDefinition def;
            bool isNew = false;

            //check if this skeleton is already registered
            if (skeletons.ContainsKey(name))
            {
                def = skeletons[name];
            }
            else
            {
                def      = new SkeletonDefinition();
                def.name = name;
                def.id   = id;
                skeletons.Add(name, def);
                isNew = true;
            }


            int     jointIndex = 0;
            Vector3 vel        = Vector3.zero;

            while (index < data.Count)
            {
                //PER JOINT
                string  jointName = (string)data[index++];
                Vector3 pos;
                pos.x = (float)data[index++];
                pos.y = (float)data[index++];
                pos.z = (float)data[index++];

                Quaternion rot;
                rot.x = (float)data[index++];
                rot.y = (float)data[index++];
                rot.z = (float)data[index++];
                rot.w = (float)data[index++];

                //for retargeting
                int     parentId = (int)data[index++];
                Vector3 offset;
                offset.x = (float)data[index++];
                offset.y = (float)data[index++];
                offset.z = (float)data[index++];

                pos = pos * scale;

                FixValues(ref pos, ref vel, ref rot);

                if (isNew)
                {
                    //add everything
                    def.Add(jointName, mRotation * pos + mPosition, rot * mRotation, offset, parentId);
                }
                else
                {
                    //these are the only values that change
                    def.positions[jointIndex] = mRotation * pos + mPosition;
                    def.rotations[jointIndex] = rot * mRotation;
                }

                jointIndex++;
            }
        }
Exemple #3
0
        /// <summary>
        /// Constructs the source Avatar and pose handlers for Mecanim retargeting.
        /// </summary>
        /// <param name="rootObjectName"></param>
        private void MecanimSetup(string rootObjectName, SkeletonDefinition skeleton)
        {
            string[] humanTraitBoneNames = HumanTrait.BoneName;

            // Set up the mapping between Mecanim human anatomy and OptiTrack skeleton representations.
            List <HumanBone> humanBones = new List <HumanBone>(skeleton.Count);

            for (int humanBoneNameIdx = 0; humanBoneNameIdx < humanTraitBoneNames.Length; ++humanBoneNameIdx)
            {
                string humanBoneName = humanTraitBoneNames [humanBoneNameIdx];
                if (m_cachedMecanimBoneNameMap.ContainsKey(humanBoneName))
                {
                    HumanBone humanBone = new HumanBone();
                    humanBone.humanName = humanBoneName;
                    humanBone.boneName  = m_cachedMecanimBoneNameMap [humanBoneName];
                    humanBone.limit.useDefaultValues = true;

                    humanBones.Add(humanBone);
                }
            }

            // Set up the T-pose and game object name mappings.
            List <SkeletonBone> skeletonBones = new List <SkeletonBone>(skeleton.Count + 1);

            // Special case: Create the root bone.
            {
                SkeletonBone rootBone = new SkeletonBone();
                rootBone.name     = rootObjectName;
                rootBone.position = Vector3.zero;
                rootBone.rotation = Quaternion.identity;
                rootBone.scale    = Vector3.one;

                skeletonBones.Add(rootBone);
            }

            // Create remaining retargeted bone definitions.
            for (int boneDefIdx = 0; boneDefIdx < skeleton.Count; ++boneDefIdx)
            {
                //OptitrackSkeletonDefinition.BoneDefinition boneDef = m_skeletonDef.Bones[boneDefIdx];

                SkeletonBone skelBone = new SkeletonBone();
                skelBone.name     = skeleton.names [boneDefIdx];
                skelBone.position = skeleton.offsets [boneDefIdx];
                skelBone.rotation = Quaternion.identity;
                skelBone.scale    = Vector3.one;

                skeletonBones.Add(skelBone);
            }

            // Now set up the HumanDescription for the retargeting source Avatar.
            HumanDescription humanDesc = new HumanDescription();

            humanDesc.human    = humanBones.ToArray();
            humanDesc.skeleton = skeletonBones.ToArray();

            // These all correspond to default values.
            humanDesc.upperArmTwist     = 0.5f;
            humanDesc.lowerArmTwist     = 0.5f;
            humanDesc.upperLegTwist     = 0.5f;
            humanDesc.lowerLegTwist     = 0.5f;
            humanDesc.armStretch        = 0.05f;
            humanDesc.legStretch        = 0.05f;
            humanDesc.feetSpacing       = 0.0f;
            humanDesc.hasTranslationDoF = false;

            // Finally, take the description and build the Avatar and pose handlers.
            m_srcAvatar = AvatarBuilder.BuildHumanAvatar(m_rootObject, humanDesc);

            if (m_srcAvatar.isValid == false || m_srcAvatar.isHuman == false)
            {
                Debug.LogError(GetType().FullName + ": Unable to create source Avatar for retargeting. Check that your Skeleton Asset Name and Bone Naming Convention are configured correctly.", this);
                this.enabled = false;
                return;
            }

            m_srcPoseHandler  = new HumanPoseHandler(m_srcAvatar, m_rootObject.transform);
            m_destPoseHandler = new HumanPoseHandler(DestinationAvatar, this.transform);
        }