Пример #1
0
        /// <summary>
        /// Sets up the model.
        /// Bind the model with the animation.
        /// This funciton will use Macanim animator to find the right bones, 
        /// then it will store it in an array by animation segment id
        /// </summary>
        /// <param name='model'>
        /// Model.
        /// </param>
        /// <param name='modelRef'>
        /// Model reference.
        /// </param>
        /// <returns>
        /// true on success
        /// </returns>
        public bool setupModel(Transform model, Transform[] modelRef)
        {
            animator = model.GetComponent<Animator>();
            if (!animator)
            {
            	return false;
            }

            //face the input model same as our animation
            model.rotation = transform.rotation;
            model.position = transform.position;

            //go through the model's segments and store values
            for (int i = 0; i < XsMvnPose.MvnSegmentCount; i++)
            {

                XsAnimationSegment segID = (XsAnimationSegment)segmentOrder[i];
                HumanBodyBones boneID = mecanimBones[(XsAnimationSegment)segmentOrder[i]];

                try
                {

                    if (boneID == HumanBodyBones.LastBone)
                    {
                        //not used bones
                        modelRef[(int)segID] = null;
                        modelPosTP[(int)segID] = Vector3.zero;
                        modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);

                    }
                    else
                    {
                        //used bones
						Transform tmpTransf = animator.GetBoneTransform(boneID);

						modelRef[(int)segID] = tmpTransf;
	                    modelPosTP[(int)segID] = modelRef[(int)segID].position;
	                    modelRotTP[(int)segID] = modelRef[(int)segID].rotation;
                    }
                }
                catch (Exception e)
                {
                    Debug.Log("[xsens] Can't find " + boneID + " in the model! " + e);
                    modelRef[(int)segID] = null;
                    modelPosTP[(int)segID] = Vector3.zero;
                    modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);

                    return false;
                }

            }

            //calculate simple scale factor
            scale = (float)(modelPosTP[(int)XsAnimationSegment.Pelvis].y / pelvisPosTP.y);

            return true;

        }
Пример #2
0
		/// <summary>
		/// Setups the model.
		/// Bind the model with the animation.
		/// This funciton will use Macanim animator to find the right bones, 
		/// then it will store it in an array by animation segment id
		/// </summary>
		/// <param name='model'>
		/// Model.
		/// </param>
		/// <param name='modelRef'>
		/// Model reference.
		/// </param>
		/// <returns>
		/// true on success
		/// </returns>
		public bool setupModel(Transform model, Transform[] modelRef)
		{
			
			animator = model.GetComponent("Animator") as Animator;
			if(!animator)
			{
				Debug.LogError("No Animator found for the model!");
				return false;
			}
			
			//face the imput model same as our animation
			model.rotation = transform.rotation;
			model.position = transform.position;
	
			//go through the model's segments and store values
			for(int i = 0; i < NUM_SEGMENTS; i++)
			{
				
				XsAnimationSegment segID = (XsAnimationSegment)segmentOrder[i];
				HumanBodyBones boneID = macanimBones[(XsAnimationSegment)segmentOrder[i]];
				
				try
				{	
					
					if(boneID != HumanBodyBones.LastBone)
					{
						//used bones
						modelRef[(int)segID] = animator.GetBoneTransform(boneID);
						modelPosTP[(int)segID] = modelRef[(int)segID].position;
						modelRotTP[(int)segID] = modelRef[(int)segID].rotation;
					}
					else
					{
						//not used bones
						modelRef[(int)segID] = null;
						modelPosTP[(int)segID] = Vector3.zero;
						modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);
	
					}
				}
				catch(Exception e)
				{
					Debug.Log("Can't find "+boneID+" in the model!");
					modelRef[(int)segID] = null;
					modelPosTP[(int)segID] = Vector3.zero;
					modelRotTP[(int)segID] = Quaternion.Euler(Vector3.zero);

					//TODO IVO CHECK BONES
					//return false;
					return true;
				}
				
			}
			
			return true;
			
		}