Exemplo n.º 1
0
            // Call from Awake() or Editor Scripts.
            // Memo: transform is null yet.
            public static void Prefix(Bone[] bones, ref Bone bone, BoneLocation boneLocation, Bone parentBoneLocationBased = null)
            {
                Assert(bones != null);
                if (bone == null)
                {
                    bone = new Bone();
                }

                if (!bone._isPresetted ||
                    bone._boneLocation != boneLocation ||
                    (int)bone._boneType < 0 ||
                    (int)bone._boneType >= (int)BoneType.Max ||
                    bone._localAxisFrom == _LocalAxisFrom.Unknown ||
                    bone._localDirectionAs == _DirectionAs.Uknown)
                {
                    bone._PresetBoneLocation(boneLocation);
                }

                bone._parentBoneLocationBased = parentBoneLocationBased;

                if (bones != null)
                {
                    bones[(int)boneLocation] = bone;
                }
            }
Exemplo n.º 2
0
            // Call from Serializer.
            public static Bone Preset(BoneLocation boneLocation)
            {
                Bone bone = new Bone();

                bone._PresetBoneLocation(boneLocation);
                return(bone);
            }
Exemplo n.º 3
0
        public static FingerType ToFingerType(BoneLocation boneLocation)
        {
            if ((int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.LeftHandLittleTip)
            {
                return((FingerType)(((int)boneLocation - (int)BoneLocation.LeftHandThumb0) / MaxHandFingerLength));
            }

            if ((int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.RightHandLittleTip)
            {
                return((FingerType)(((int)boneLocation - (int)BoneLocation.RightHandThumb0) / MaxHandFingerLength));
            }

            return(FingerType.Unknown);
        }
Exemplo n.º 4
0
        public static int ToFingerIndex(BoneLocation boneLocation)
        {
            if ((int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.LeftHandLittleTip)
            {
                return(((int)boneLocation - (int)BoneLocation.LeftHandThumb0) % MaxHandFingerLength);
            }

            if ((int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.RightHandLittleTip)
            {
                return(((int)boneLocation - (int)BoneLocation.RightHandThumb0) % MaxHandFingerLength);
            }

            return(-1);
        }
Exemplo n.º 5
0
 void _PresetBoneLocation(BoneLocation boneLocation)
 {
     _isPresetted  = true;
     _boneLocation = boneLocation;
     _boneType     = ToBoneType(boneLocation);
     _boneSide     = ToBoneSide(boneLocation);
     if (_boneType == BoneType.HandFinger)
     {
         _fingerType  = ToFingerType(boneLocation);
         _fingerIndex = ToFingerIndex(boneLocation);
     }
     else
     {
         _fingerType  = FingerType.Unknown;
         _fingerIndex = -1;
     }
     _PresetLocalAxis();
 }
Exemplo n.º 6
0
		public static int ToFingerIndex( BoneLocation boneLocation )
		{
			if( (int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.LeftHandLittleTip ) {
				return ((int)boneLocation - (int)BoneLocation.LeftHandThumb0) % MaxHandFingerLength;
			}

			if( (int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.RightHandLittleTip ) {
				return ((int)boneLocation - (int)BoneLocation.RightHandThumb0) % MaxHandFingerLength;
			}

			return -1;
		}
Exemplo n.º 7
0
		public static FingerType ToFingerType( BoneLocation boneLocation )
		{
			if( (int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.LeftHandLittleTip ) {
				return (FingerType)(((int)boneLocation - (int)BoneLocation.LeftHandThumb0) / MaxHandFingerLength);
			}

			if( (int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.RightHandLittleTip ) {
				return (FingerType)(((int)boneLocation - (int)BoneLocation.RightHandThumb0) / MaxHandFingerLength);
			}

			return FingerType.Unknown;
		}
Exemplo n.º 8
0
		public static Side ToBoneSide( BoneLocation boneLocation )
		{
			switch( boneLocation ) {
			case BoneLocation.LeftEye:			return Side.Left;
			case BoneLocation.RightEye:			return Side.Right;

			case BoneLocation.LeftLeg:			return Side.Left;
			case BoneLocation.RightLeg:			return Side.Right;
			case BoneLocation.LeftKnee:			return Side.Left;
			case BoneLocation.RightKnee:		return Side.Right;
			case BoneLocation.LeftFoot:			return Side.Left;
			case BoneLocation.RightFoot:		return Side.Right;

			case BoneLocation.LeftShoulder:		return Side.Left;
			case BoneLocation.RightShoulder:	return Side.Right;
			case BoneLocation.LeftArm:			return Side.Left;
			case BoneLocation.RightArm:			return Side.Right;
			case BoneLocation.LeftElbow:		return Side.Left;
			case BoneLocation.RightElbow:		return Side.Right;
			case BoneLocation.LeftWrist:		return Side.Left;
			case BoneLocation.RightWrist:		return Side.Right;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.LeftHandLittleTip ) {
				return Side.Left;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftArmRoll0 &&
				(int)boneLocation <= (int)BoneLocation.LeftArmRoll0 + MaxArmRollLength - 1 ) {
				return Side.Left;
			}

			if( (int)boneLocation >= (int)BoneLocation.RightArmRoll0 &&
				(int)boneLocation <= (int)BoneLocation.RightArmRoll0 + MaxArmRollLength - 1 ) {
				return Side.Right;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftElbowRoll0 &&
				(int)boneLocation <= (int)BoneLocation.LeftElbowRoll0 + MaxElbowRollLength - 1 ) {
				return Side.Left;
			}

			if( (int)boneLocation >= (int)BoneLocation.RightElbowRoll0 &&
				(int)boneLocation <= (int)BoneLocation.RightElbowRoll0 + MaxElbowRollLength - 1 ) {
				return Side.Right;
			}

			if( (int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.RightHandLittleTip ) {
				return Side.Right;
			}

			return Side.None;
		}
Exemplo n.º 9
0
		public static BoneType ToBoneType( BoneLocation boneLocation )
		{
			switch( boneLocation ) {
			case BoneLocation.Hips:				return BoneType.Hips;
			case BoneLocation.Neck:				return BoneType.Neck;
			case BoneLocation.Head:				return BoneType.Head;
			case BoneLocation.LeftEye:			return BoneType.Eye;
			case BoneLocation.RightEye:			return BoneType.Eye;

			case BoneLocation.LeftLeg:			return BoneType.Leg;
			case BoneLocation.RightLeg:			return BoneType.Leg;
			case BoneLocation.LeftKnee:			return BoneType.Knee;
			case BoneLocation.RightKnee:		return BoneType.Knee;
			case BoneLocation.LeftFoot:			return BoneType.Foot;
			case BoneLocation.RightFoot:		return BoneType.Foot;

			case BoneLocation.LeftShoulder:		return BoneType.Shoulder;
			case BoneLocation.RightShoulder:	return BoneType.Shoulder;
			case BoneLocation.LeftArm:			return BoneType.Arm;
			case BoneLocation.RightArm:			return BoneType.Arm;
			case BoneLocation.LeftElbow:		return BoneType.Elbow;
			case BoneLocation.RightElbow:		return BoneType.Elbow;
			case BoneLocation.LeftWrist:		return BoneType.Wrist;
			case BoneLocation.RightWrist:		return BoneType.Wrist;
			}

			if( (int)boneLocation >= (int)BoneLocation.Spine &&
				(int)boneLocation <= (int)BoneLocation.SpineU ) {
				return BoneType.Spine;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftArmRoll0 &&
				(int)boneLocation <= (int)BoneLocation.RightArmRoll0 + MaxArmRollLength - 1 ) {
				return BoneType.ArmRoll;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftElbowRoll0 &&
				(int)boneLocation <= (int)BoneLocation.RightElbowRoll0 + MaxElbowRollLength - 1 ) {
				return BoneType.ElbowRoll;
			}

			if( (int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
				(int)boneLocation <= (int)BoneLocation.RightHandLittleTip ) {
				return BoneType.HandFinger;
			}

			return BoneType.Unknown;
		}
Exemplo n.º 10
0
        public static BoneType ToBoneType(BoneLocation boneLocation)
        {
            switch (boneLocation)
            {
            case BoneLocation.Hips:                         return(BoneType.Hips);

            case BoneLocation.Neck:                         return(BoneType.Neck);

            case BoneLocation.Head:                         return(BoneType.Head);

            case BoneLocation.LeftEye:                      return(BoneType.Eye);

            case BoneLocation.RightEye:                     return(BoneType.Eye);

            case BoneLocation.LeftLeg:                      return(BoneType.Leg);

            case BoneLocation.RightLeg:                     return(BoneType.Leg);

            case BoneLocation.LeftKnee:                     return(BoneType.Knee);

            case BoneLocation.RightKnee:            return(BoneType.Knee);

            case BoneLocation.LeftFoot:                     return(BoneType.Foot);

            case BoneLocation.RightFoot:            return(BoneType.Foot);

            case BoneLocation.LeftShoulder:         return(BoneType.Shoulder);

            case BoneLocation.RightShoulder:        return(BoneType.Shoulder);

            case BoneLocation.LeftArm:                      return(BoneType.Arm);

            case BoneLocation.RightArm:                     return(BoneType.Arm);

            case BoneLocation.LeftElbow:            return(BoneType.Elbow);

            case BoneLocation.RightElbow:           return(BoneType.Elbow);

            case BoneLocation.LeftWrist:            return(BoneType.Wrist);

            case BoneLocation.RightWrist:           return(BoneType.Wrist);
            }

            if ((int)boneLocation >= (int)BoneLocation.Spine &&
                (int)boneLocation <= (int)BoneLocation.SpineU)
            {
                return(BoneType.Spine);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftArmRoll0 &&
                (int)boneLocation <= (int)BoneLocation.RightArmRoll0 + MaxArmRollLength - 1)
            {
                return(BoneType.ArmRoll);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftElbowRoll0 &&
                (int)boneLocation <= (int)BoneLocation.RightElbowRoll0 + MaxElbowRollLength - 1)
            {
                return(BoneType.ElbowRoll);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.RightHandLittleTip)
            {
                return(BoneType.HandFinger);
            }

            return(BoneType.Unknown);
        }
Exemplo n.º 11
0
        public static Side ToBoneSide(BoneLocation boneLocation)
        {
            switch (boneLocation)
            {
            case BoneLocation.LeftEye:                      return(Side.Left);

            case BoneLocation.RightEye:                     return(Side.Right);

            case BoneLocation.LeftLeg:                      return(Side.Left);

            case BoneLocation.RightLeg:                     return(Side.Right);

            case BoneLocation.LeftKnee:                     return(Side.Left);

            case BoneLocation.RightKnee:            return(Side.Right);

            case BoneLocation.LeftFoot:                     return(Side.Left);

            case BoneLocation.RightFoot:            return(Side.Right);

            case BoneLocation.LeftShoulder:         return(Side.Left);

            case BoneLocation.RightShoulder:        return(Side.Right);

            case BoneLocation.LeftArm:                      return(Side.Left);

            case BoneLocation.RightArm:                     return(Side.Right);

            case BoneLocation.LeftElbow:            return(Side.Left);

            case BoneLocation.RightElbow:           return(Side.Right);

            case BoneLocation.LeftWrist:            return(Side.Left);

            case BoneLocation.RightWrist:           return(Side.Right);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.LeftHandLittleTip)
            {
                return(Side.Left);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftArmRoll0 &&
                (int)boneLocation <= (int)BoneLocation.LeftArmRoll0 + MaxArmRollLength - 1)
            {
                return(Side.Left);
            }

            if ((int)boneLocation >= (int)BoneLocation.RightArmRoll0 &&
                (int)boneLocation <= (int)BoneLocation.RightArmRoll0 + MaxArmRollLength - 1)
            {
                return(Side.Right);
            }

            if ((int)boneLocation >= (int)BoneLocation.LeftElbowRoll0 &&
                (int)boneLocation <= (int)BoneLocation.LeftElbowRoll0 + MaxElbowRollLength - 1)
            {
                return(Side.Left);
            }

            if ((int)boneLocation >= (int)BoneLocation.RightElbowRoll0 &&
                (int)boneLocation <= (int)BoneLocation.RightElbowRoll0 + MaxElbowRollLength - 1)
            {
                return(Side.Right);
            }

            if ((int)boneLocation >= (int)BoneLocation.RightHandThumb0 &&
                (int)boneLocation <= (int)BoneLocation.RightHandLittleTip)
            {
                return(Side.Right);
            }

            return(Side.None);
        }
Exemplo n.º 12
0
        public void ProcessAnimation(AnimationStream stream)
        {
            // Debug.Log($"Process animation {stream.isValid}");
            if (stream.inputStreamCount == 0)
            {
                return;
            }

            var streamA    = stream.GetInputStream(0);
            var streamB    = stream.GetInputStream(1);
            var numHandles = handles.Length;

            if (useBonesLastAsFirst &&
                streamA.isValid)
            {
                if (!isTransitioning)
                {
                    isTransitioning = true;
                    bonesLastFrame.CopyTo(bonesLastState);
                    // Debug.LogError("Start new mixer transition");
                }

                for (var i = 0; i < numHandles; ++i)
                {
                    var handle = handles[i];

                    var posA = bonesLastState[i].position;
                    var posB = handle.GetLocalPosition(streamA);
                    var pos  = Vector3Blend[blendMode](posA, posB, weight *boneWeights[i]);
                    handle.SetLocalPosition(stream, pos);

                    var rotA = bonesLastState[i].rotation;
                    var rotB = handle.GetLocalRotation(streamA);
                    var rot  = QuaternionBlend[blendMode](rotA, rotB, weight *boneWeights[i]);
                    handle.SetLocalRotation(stream, rot);

                    bonesLastFrame[i] = new BoneLocation(pos, rot);
                }

                return;
            }

            if (!streamA.isValid && !streamB.isValid)
            {
                return;
            }

            if (stream.inputStreamCount < 2 || !streamB.isValid)
            {
                for (var i = 0; i < numHandles; ++i)
                {
                    var handle = handles[i];

                    var posA = handle.GetLocalPosition(streamA);
                    handle.SetLocalPosition(stream, posA);

                    var rotA = handle.GetLocalRotation(streamA);
                    handle.SetLocalRotation(stream, rotA);

                    bonesLastFrame[i] = new BoneLocation(posA, rotA);
                }

                return;
            }

            for (var i = 0; i < numHandles; ++i)
            {
                var handle = handles[i];

                var posA = handle.GetLocalPosition(streamB);
                var posB = handle.GetLocalPosition(streamA);
                var pos  = Vector3Blend[blendMode](posA, posB, weight *boneWeights[i]);
                handle.SetLocalPosition(stream, pos);

                var rotA = handle.GetLocalRotation(streamB);
                var rotB = handle.GetLocalRotation(streamA);
                var rot  = QuaternionBlend[blendMode](rotA, rotB, weight *boneWeights[i]);
                handle.SetLocalRotation(stream, rot);

                bonesLastFrame[i] = new BoneLocation(pos, rot);
            }
        }
Exemplo n.º 13
0
		void _Prefix( ref Bone bone, BoneLocation boneLocation, Bone parentBoneLocationBased )
		{
			Assert( _bones != null );
			Bone.Prefix( _bones, ref bone, boneLocation, parentBoneLocationBased );
		}
Exemplo n.º 14
0
			// Call from Awake() or Editor Scripts.
			// Memo: transform is null yet.
			public static void Prefix( Bone[] bones, ref Bone bone, BoneLocation boneLocation, Bone parentBoneLocationBased = null )
			{
				Assert( bones != null );
				if( bone == null ) {
					bone = new Bone();
				}

				if( !bone._isPresetted ||
					bone._boneLocation != boneLocation ||
					(int)bone._boneType < 0 ||
					(int)bone._boneType >= (int)BoneType.Max ||
					bone._localAxisFrom == _LocalAxisFrom.Unknown ||
					bone._localDirectionAs == _DirectionAs.Uknown ) {
					bone._PresetBoneLocation( boneLocation );
				}

				bone._parentBoneLocationBased = parentBoneLocationBased;
				
				if( bones != null ) {
					bones[(int)boneLocation] = bone;
				}
			}
Exemplo n.º 15
0
			void _PresetBoneLocation( BoneLocation boneLocation )
			{
				_isPresetted = true;
				_boneLocation = boneLocation;
				_boneType = ToBoneType( boneLocation );
				_boneSide = ToBoneSide( boneLocation );
				if( _boneType == BoneType.HandFinger ) {
					_fingerType = ToFingerType( boneLocation );
					_fingerIndex = ToFingerIndex( boneLocation );
				} else {
					_fingerType = FingerType.Unknown;
					_fingerIndex = -1;
				}
				_PresetLocalAxis();
			}
Exemplo n.º 16
0
			// Call from Serializer.
			public static Bone Preset( BoneLocation boneLocation )
			{
				Bone bone = new Bone();
				bone._PresetBoneLocation( boneLocation );
				return bone;
			}