Example #1
0
 public static void Lerp(ref PoseData buffor, PoseData first, PoseData next, float factor)
 {
     for (int i = 0; i < first.Count; i++)
     {
         buffor.SetBone(BoneData.Lerp(first.GetBoneData(i), next.GetBoneData(i), factor), i);
     }
 }
Example #2
0
        public float CalculateCost(PoseData toPose, PoseCostType type)
        {
            float cost = 0f;

            for (int i = 0; i < Count; i++)
            {
                cost += bones[i].CalculateCost(toPose.GetBoneData(i), type);
            }
            return(cost);
        }
        /*
         * public void CreateFutureLocalPositionFromStartToEnd()
         * {
         *  Matrix4x4 m;
         *  Vector3 startPos = GetStartPositionXY();
         *  Quaternion startRot = GetStartRotationY();
         *  Vector3 endPos = GetEndPositionXY();
         *  Quaternion endRot = GetEndRotationY();
         *  deltaRotStartEnd = endRot * Quaternion.Inverse(startRot);
         *  m = Matrix4x4.TRS(startPos, startRot, Vector3.one);
         *
         *  endLocalPosition = m.inverse.MultiplyPoint3x4(endPos);
         * }
         *
         * public void CreatePastLocalPositionFromEndToSTart()
         * {
         *  Matrix4x4 m;
         *  Vector3 startPos = GetStartPositionXY();
         *  Quaternion startRot = GetStartRotationY();
         *  Vector3 endPos = GetEndPositionXY();
         *  Quaternion endRot = GetEndRotationY();
         *  deltaRotEndStart = startRot * Quaternion.Inverse(endRot);
         *  m = Matrix4x4.TRS(endPos, endRot, Vector3.one);
         *
         *  startLocalPosition = m.inverse.MultiplyPoint3x4(startPos);
         * }
         *
         * public TrajectoryPoint GetFutureTrajectoryPoint(float futureTime, float currentTime, Transform root, float deltaTime, float animSpeedMulti = 1f)
         * {
         *  if (curves.Count == 0)
         *  {
         *      throw new System.Exception("Array of curves is empty!");
         *  }
         *  float trajectoryPointFutureTime = futureTime;
         *  Vector3 fPos = Vector3.zero;
         *  Quaternion fRot = root.rotation;
         *
         *  float actuallAnimTime = currentTime * animSpeedMulti;
         *  //float frameTime = 1f / frameRate;
         *
         *  // obliczenie czasu lokalnego nie wiekszego niz dlugosc animacji
         *  int timeLoops = Mathf.FloorToInt(actuallAnimTime / length);
         *  float localTime = actuallAnimTime - timeLoops * length;
         *
         *  // potrzebne macierze:
         *  Matrix4x4 m = new Matrix4x4();    // macierz transformacji pomiędzy pozycjami i rotacjiami z krzywych animacji
         *  Matrix4x4 fm = new Matrix4x4();   // macierz transformacji przyszłej pozycji (wykorzystuemy tu fPos i fRot)
         *                                    // ptrzebne wektory;
         *  Vector3 actualPos; // pozycja pobrana z krzywych
         *  Vector3 futurePos; // pozycja pobrana z krzywych
         *  Vector3 localFuturePos; // przyszła pozycja lokalna wzgledem actualPos i actualrot
         *                          // potrzebne quaterniony
         *  Quaternion actualRot; // rotacja pobrana z krzywych
         *  Quaternion futureRot; // rotacja pobrana z krzywych
         *  Quaternion deltaRotation; // delta pomiedzy actualRot i futureRot
         *
         *  float ft = trajectoryPointFutureTime + localTime;
         *  if (ft > length)
         *  {
         *      // pobranie pozycji i rotacji z krzywych animacji w local time
         *      actualPos = GetPositionInTimeXY(localTime);
         *      actualRot = GetRotationInTimeY(localTime);
         *      // stworzenie macierzy transformacji
         *      m.SetTRS(actualPos, actualRot, Vector3.one);
         *      // pobranie pozycji i rotacji z krzywych animacji na koncu animacji
         *      futurePos = GetEndPositionXY();
         *      futureRot = GetEndRotationY();
         *      // Obliczenie rozncy rotacji
         *      deltaRotation = futureRot * Quaternion.Inverse(actualRot);
         *      // Obliczenie przyszłej pozycji w local space
         *      localFuturePos = m.inverse.MultiplyPoint3x4(futurePos);
         *      // Obliczenie nowej rotacji
         *      fRot *= deltaRotation;
         *      // obliczenie nowej pozycji
         *      fPos = root.TransformPoint(localFuturePos);
         *      fm = Matrix4x4.TRS(fPos, fRot, Vector3.one);
         *      // obliczenie pozostałego czasu do sprawdzenia pozycji
         *      trajectoryPointFutureTime -= (length - localTime);
         *      // obliczenie ile razy futureTime przekracza długość animacji
         *      int FTLoops = Mathf.FloorToInt(trajectoryPointFutureTime / length);
         *      if (FTLoops > 0)
         *      {
         *          for (int i = 0; i < FTLoops; i++)
         *          {
         *              fPos = fm.MultiplyPoint3x4(endLocalPosition);
         *              fRot *= deltaRotStartEnd;
         *              fm.SetTRS(fPos, fRot, Vector3.one);
         *          }
         *          trajectoryPointFutureTime -= (FTLoops * length);
         *          if (trajectoryPointFutureTime > 0)
         *          {
         *              actualPos = GetStartPositionXY();
         *              actualRot = GetStartRotationY();
         *              futurePos = GetPositionInTimeXY(trajectoryPointFutureTime);
         *              futureRot = GetRotationInTimeY(trajectoryPointFutureTime);
         *              m.SetTRS(actualPos, actualRot, Vector3.one);
         *              localFuturePos = m.inverse.MultiplyPoint3x4(futurePos);
         *              deltaRotation = futureRot * Quaternion.Inverse(actualRot);
         *              fRot *= deltaRotation;
         *              fPos = fm.MultiplyPoint3x4(localFuturePos);
         *          }
         *      }
         *      else
         *      {
         *          if (trajectoryPointFutureTime > 0)
         *          {
         *              actualPos = GetStartPositionXY();
         *              actualRot = GetStartRotationY();
         *              futurePos = GetPositionInTimeXY(trajectoryPointFutureTime);
         *              futureRot = GetRotationInTimeY(trajectoryPointFutureTime);
         *              m = Matrix4x4.TRS(actualPos, actualRot, Vector3.one);
         *              localFuturePos = m.inverse.MultiplyPoint3x4(futurePos);
         *              deltaRotation = futureRot * Quaternion.Inverse(actualRot);
         *              fRot *= deltaRotation;
         *              fPos = fm.MultiplyPoint3x4(localFuturePos);
         *          }
         *      }
         *  }
         *  else
         *  {
         *      actualPos = GetPositionInTimeXY(localTime);
         *      actualRot = GetRotationInTimeY(localTime);
         *      futurePos = GetPositionInTimeXY(ft);
         *      futureRot = GetRotationInTimeY(ft);
         *      m = Matrix4x4.TRS(actualPos, actualRot, Vector3.one);
         *      localFuturePos = m.inverse.MultiplyPoint3x4(futurePos);
         *      deltaRotation = futureRot * Quaternion.Inverse(actualRot);
         *      fRot *= deltaRotation;
         *      fPos = root.TransformPoint(localFuturePos);
         *  }
         *
         *  fm.SetTRS(fPos, fRot, Vector3.one);
         *
         *  Vector3 vel = fm.MultiplyVector(GetVelocityInTimeXY(localTime, deltaTime));
         *
         *  return new TrajectoryPoint(fPos, vel, Vector3.zero, futureTime);
         * }
         *
         * public TrajectoryPoint GetPastTrajectoryPoint(float pastTime, float currentTime, Transform root, float deltaTime, float animSpeedMulti = 1f)
         * {
         *  if (curves.Count == 0)
         *  {
         *      throw new System.Exception("Array of curves is empty!");
         *  }
         *
         *  float trajectoryPointPastTime = pastTime;
         *  Vector3 fPos = Vector3.zero;
         *  Quaternion fRot = root.rotation;
         *
         *  float actuallAnimTime = currentTime * animSpeedMulti;
         *  //float frameTime = 1f / frameRate;
         *
         *  // obliczenie czasu lokalnego nie wiekszego niz dlugosc animacji
         *  int timeLoops = Mathf.FloorToInt(actuallAnimTime / length);
         *  float localTime = actuallAnimTime - timeLoops * length;
         *
         *  // potrzebne macierze:
         *  Matrix4x4 m = new Matrix4x4();    // macierz transformacji pomiędzy pozycjami i rotacjiami z krzywych animacji
         *  Matrix4x4 fm = new Matrix4x4();   // macierz transformacji przyszłej pozycji (wykorzystuemy tu fPos i fRot)
         *                                    // ptrzebne wektory;
         *  Vector3 actualPos; // pozycja pobrana z krzywych
         *  Vector3 pastPos; // pozycja pobrana z krzywych
         *  Vector3 localPastPos; // przyszła pozycja lokalna wzgledem actualPos i actualrot
         *                        // potrzebne quaterniony
         *  Quaternion actualRot; // rotacja pobrana z krzywych
         *  Quaternion pastRot; // rotacja pobrana z krzywych
         *  Quaternion deltaRotation; // delta pomiedzy actualRot i futureRot
         *
         *  float ft = trajectoryPointPastTime + localTime;
         *  if (ft < 0f)
         *  {
         *      // pobranie pozycji i rotacji z krzywych animacji w local time
         *      actualPos = GetPositionInTimeXY(localTime);
         *      actualRot = GetRotationInTimeY(localTime);
         *      // stworzenie macierzy transformacji
         *      m.SetTRS(actualPos, actualRot, Vector3.one);
         *      // pobranie pozycji i rotacji z krzywych animacji na poczatku animacji
         *      pastPos = GetStartPositionXY();
         *      pastRot = GetStartRotationY();
         *      // Obliczenie rozncy rotacji
         *      deltaRotation = pastRot * Quaternion.Inverse(actualRot);
         *      // Obliczenie przyszłej pozycji w local space
         *      localPastPos = m.inverse.MultiplyPoint3x4(pastPos);
         *      // Obliczenie nowej rotacji
         *      fRot *= deltaRotation;
         *      // obliczenie nowej pozycji
         *      fPos = root.TransformPoint(localPastPos);
         *      fm = Matrix4x4.TRS(fPos, fRot, Vector3.one);
         *      // obliczenie pozostałego czasu do sprawdzenia pozycji
         *      trajectoryPointPastTime += (localTime);
         *      // obliczenie ile razy futureTime przekracza długość animacji
         *      int FTLoops = Mathf.FloorToInt(Mathf.Abs(trajectoryPointPastTime) / length);
         *      if (FTLoops > 0)
         *      {
         *          for (int i = 0; i < FTLoops; i++)
         *          {
         *              fPos = fm.MultiplyPoint3x4(startLocalPosition);
         *              fRot *= deltaRotEndStart;
         *              fm.SetTRS(fPos, fRot, Vector3.one);
         *          }
         *          trajectoryPointPastTime += (FTLoops * length);
         *          if (trajectoryPointPastTime < 0)
         *          {
         *              actualPos = GetEndPositionXY();
         *              actualRot = GetEndRotationY();
         *              pastPos = GetPositionInTimeXY(trajectoryPointPastTime + length);
         *              pastRot = GetRotationInTimeY(trajectoryPointPastTime + length);
         *              m.SetTRS(actualPos, actualRot, Vector3.one);
         *              localPastPos = m.inverse.MultiplyPoint3x4(pastPos);
         *              deltaRotation = pastRot * Quaternion.Inverse(actualRot);
         *              fRot *= deltaRotation;
         *              fPos = fm.MultiplyPoint3x4(localPastPos);
         *          }
         *      }
         *      else
         *      {
         *          if (trajectoryPointPastTime < 0)
         *          {
         *              actualPos = GetEndPositionXY();
         *              actualRot = GetEndRotationY();
         *              pastPos = GetPositionInTimeXY(trajectoryPointPastTime + length);
         *              pastRot = GetRotationInTimeY(trajectoryPointPastTime + length);
         *              m = Matrix4x4.TRS(actualPos, actualRot, Vector3.one);
         *              localPastPos = m.inverse.MultiplyPoint3x4(pastPos);
         *              deltaRotation = pastRot * Quaternion.Inverse(actualRot);
         *              fRot *= deltaRotation;
         *              fPos = fm.MultiplyPoint3x4(localPastPos);
         *          }
         *      }
         *  }
         *  else
         *  {
         *      actualPos = GetPositionInTimeXY(localTime);
         *      actualRot = GetRotationInTimeY(localTime);
         *      pastPos = GetPositionInTimeXY(ft);
         *      pastRot = GetRotationInTimeY(ft);
         *      m = Matrix4x4.TRS(actualPos, actualRot, Vector3.one);
         *      localPastPos = m.inverse.MultiplyPoint3x4(pastPos);
         *      deltaRotation = pastRot * Quaternion.Inverse(actualRot);
         *      fRot *= deltaRotation;
         *      fPos = root.TransformPoint(localPastPos);
         *  }
         *
         *  fm.SetTRS(fPos, fRot, Vector3.one);
         *
         *  Vector3 vel = fm.MultiplyVector(GetVelocityInTimeXY(localTime, deltaTime));
         *
         *  return new TrajectoryPoint(fPos, vel, Vector3.zero, pastTime);
         * }
         *
         * private Vector3 GetPositionInTime(float time)
         * {
         *  return new Vector3(curves[0].Evaluate(time),
         *                      curves[1].Evaluate(time),
         *                      curves[2].Evaluate(time));
         * }
         *
         * private Vector3 GetStartPosition()
         * {
         *  return new Vector3(curves[0].Evaluate(0f),
         *                      curves[1].Evaluate(0f),
         *                      curves[2].Evaluate(0f));
         * }
         *
         * private Vector3 GetLastVPosition()
         * {
         *  return new Vector3(curves[0].Evaluate(length),
         *                      curves[1].Evaluate(length),
         *                      curves[2].Evaluate(length));
         * }
         *
         * private Quaternion GetRotationInTime(float time)
         * {
         *  return new Quaternion(curves[3].Evaluate(time),
         *                          curves[4].Evaluate(time),
         *                          curves[5].Evaluate(time),
         *                          curves[6].Evaluate(time)).normalized;
         * }
         *
         * private Quaternion GetStartRotation()
         * {
         *  return new Quaternion(curves[3].Evaluate(0f),
         *                          curves[4].Evaluate(0f),
         *                          curves[5].Evaluate(0f),
         *                          curves[6].Evaluate(0f)).normalized;
         * }
         *
         * private Quaternion GetEndRotation()
         * {
         *  return new Quaternion(curves[3].Evaluate(length),
         *                          curves[4].Evaluate(length),
         *                          curves[5].Evaluate(length),
         *                          curves[6].Evaluate(length)).normalized;
         * }
         *
         * private Vector3 GetPositionInTimeXY(float time)
         * {
         *  return new Vector3(curves[0].Evaluate(time),
         *                      0f,
         *                      curves[2].Evaluate(time));
         * }
         *
         * private Vector3 GetStartPositionXY()
         * {
         *  return new Vector3(curves[0].Evaluate(0f),
         *                      0f,
         *                      curves[2].Evaluate(0f));
         * }
         *
         * private Vector3 GetEndPositionXY()
         * {
         *  return new Vector3(curves[0].Evaluate(length),
         *                      0f,
         *                      curves[2].Evaluate(length));
         * }
         *
         * private Quaternion GetRotationInTimeY(float time)
         * {
         *  return new Quaternion(0f,
         *                          curves[4].Evaluate(time),
         *                          0f,
         *                          curves[6].Evaluate(time)).normalized;
         * }
         *
         * private Quaternion GetStartRotationY()
         * {
         *  return new Quaternion(0f,
         *                          curves[4].Evaluate(0f),
         *                          0f,
         *                          curves[6].Evaluate(0f)).normalized;
         * }
         *
         * private Quaternion GetEndRotationY()
         * {
         *  return new Quaternion(0f,
         *                          curves[4].Evaluate(length),
         *                          0f,
         *                          curves[6].Evaluate(length)).normalized;
         * }
         *
         * private Vector3 GetVelocityInTime(float time)
         * {
         *  Vector3 vel;
         *  if (time < Time.deltaTime)
         *  {
         *      vel = (GetPositionInTime(Time.deltaTime) - GetStartPosition()) / Time.deltaTime;
         *      return vel;
         *  }
         *  vel = (GetPositionInTime(time) - GetPositionInTime(time - Time.deltaTime)) / Time.deltaTime;
         *  return vel;
         * }
         *
         * public Vector3 GetVelocityInTimeXY(float time, float deltaTime)
         * {
         *  float localTime = GetLocalTime(time);
         *  Vector3 vel;
         *  Vector3 actual;
         *  Vector3 previu;
         *  Quaternion actualRot;
         *  if (time < deltaTime)
         *  {
         *      actual = GetPositionInTimeXY(deltaTime);
         *      previu = GetStartPositionXY();
         *      actualRot = GetRotationInTimeY(deltaTime);
         *  }
         *  else
         *  {
         *      actual = GetPositionInTimeXY(localTime);
         *      previu = GetPositionInTimeXY(localTime - deltaTime);
         *      actualRot = GetRotationInTimeY(localTime);
         *  }
         *  vel = (actual - previu) / deltaTime;
         *
         *  Matrix4x4 m = Matrix4x4.TRS(actual, actualRot, Vector3.one);
         *  return m.inverse.MultiplyVector(vel);
         * }
         */
        #endregion

        public void GetPoseInTime(ref PoseData buffor, float actuallTime, float animSpeedMulti = 1f)
        {
            float localTime = this.GetLocalTime(actuallTime) * animSpeedMulti;
            //float frameTime = 1f / frameRate;
            //int timeLoops = Mathf.FloorToInt(actuallAnimTime / length);
            //float localTime = actuallAnimTime - timeLoops * length;

            int   backFrame  = Mathf.FloorToInt(localTime / frameTime);
            int   nextFrame  = backFrame == (frames.Count - 1) ? 0 : backFrame + 1;
            float lerpFactor = (localTime - backFrame * frameTime) / frameTime;

            FrameData.GetLerpedPose(ref buffor, this.frames[backFrame], this.frames[nextFrame], lerpFactor);
        }
 public FrameData(
     int frameNumber,
     float localTime,
     FrameSections sections
     )
 {
     //this.frameNumber = frameNumber;
     this.localTime     = localTime;
     this.sections      = sections;
     this.trajectory    = new Trajectory();
     this.pose          = new PoseData();
     this.contactPoints = new FrameContact[0];
 }
        protected override void Enter(PoseData currentPose, Trajectory previouStateGoal, List <float2> whereCanFindingBestPose)
        {
            NativeArray <float2>       findingIntervals    = new NativeArray <float2>(whereCanFindingBestPose.ToArray(), Allocator.TempJob);
            NativeArray <FrameContact> contactPointsNative = new NativeArray <FrameContact>(logicLayer.contactPoints.Count, Allocator.TempJob);

            //making native contactsl
            for (int i = 0; i < logicLayer.contactPoints.Count; i++)
            {
                contactPointsNative[i] = logicLayer.contactPoints[i].frameContact;
            }
            // Geting native pose
            for (int i = 0; i < currentPose.Count; i++)
            {
                logicLayer.nativePose[i] = currentPose.GetBoneData(i);
            }

            //Geting natve trajectory
            for (int i = 0; i < previouStateGoal.Length; i++)
            {
                logicLayer.nativeTrajectory[i] = previouStateGoal.GetPoint(i);
            }

            ImpactAnimationFinding(
                logicLayer.nativePose,
                findingIntervals,
                contactPointsNative,
                logicLayer.nativeTrajectory
                );

            findingIntervals.Dispose();
            contactPointsNative.Dispose();

            currentDataIndex     = logicLayer.bestPoseInfo.clipIndex;
            currentClipLocalTime = (float)logicLayer.bestPoseInfo.localTime;

            playableGraph.CreateBlendMotionMatchingAnimation(
                dataState.motionDataGroups[currentMotionDataGroupIndex].animationData[currentDataIndex],
                currentDataIndex,
                stateMixer,
                currentClipLocalTime,
                1f,
                blendingSpeeds,
                currentWeights,
                animationsSequences,
                this.logicLayer.GetPassIK(),
                this.logicLayer.GetFootPassIK(),
                1f
                );
            currentPlayedClipsIndexes.Add(currentDataIndex);
        }
Example #6
0
        public bool SwitchToContactState(
            PoseData currentPose,
            Trajectory goal,
            List <SwitchStateContact> contactPoints,
            int nextStateIndex,
            float blendTime,
            string startSectionName = null
            )
        {
#if UNITY_EDITOR
            if (logicStates[nextStateIndex].dataState.GetStateType() != MotionMatchingStateType.ContactAnimationState)
            {
                throw new System.Exception(
                          string.Format("This method can only switch to contact state. {0} state type is {1}",
                                        logicStates[nextStateIndex].dataState.GetName(),
                                        logicStates[nextStateIndex].dataState.GetStateType().ToString()
                                        ));
            }
#endif

            if (logicStates[nextStateIndex].IsBlockedToEnter())
            {
                return(false);
            }


            if (currentStateIndex >= 0 && currentStateIndex < logicStates.Count)
            {
                previousStateIndex = currentStateIndex;
                stateWeightsSpeedChanging[stateWeightsSpeedChanging.Count - 1] = (-(1f / blendTime));
            }

            currentStateIndex = nextStateIndex;
            stateWeightsSpeedChanging.Add((1f / blendTime));
            currentBlendedStates.Add(currentStateIndex);

            SetContactPoints(contactPoints.ToArray());

            logicStates[currentStateIndex].StateEnter(
                currentPose,
                goal,
                logicStates[nextStateIndex].dataState.whereCanFindingNextPose,
                startSectionName
                );

            return(true);
        }
        protected override void Enter(PoseData currentPose, Trajectory previouStateGoal, List <float2> whereCanFindingBestPose)
        {
            for (int i = 0; i < currentPose.Count; i++)
            {
                logicLayer.nativePose[i] = currentPose.GetBoneData(i);
            }

            for (int i = 0; i < previouStateGoal.Length; i++)
            {
                logicLayer.nativeTrajectory[i] = previouStateGoal.GetPoint(i);
            }

            if (this.dataState.sectionsDependencies != null)
            {
                SetCurrentSection(this.dataState.startSection);
            }

            SwitchMotionDataGroup();
            GetCurrentClipsInfo();
            MotionMatchingFinding(
                logicLayer.nativePose,
                logicLayer.nativeTrajectory
                );
            JobHandle.ScheduleBatchedJobs();
            JobHandle.CompleteAll(jobsHandle);
            JoinJobsOutput();

            currentDataIndex = logicLayer.bestPoseInfo.clipIndex;
            currentPlayedClipsIndexes.Add(currentDataIndex);
            playableGraph.CreateBlendMotionMatchingAnimation(
                dataState.motionDataGroups[currentMotionDataGroupIndex].animationData[currentDataIndex],
                logicLayer.bestPoseInfo.clipIndex,
                stateMixer,
                logicLayer.bestPoseInfo.localTime,
                this.dataState.mmFeatures.blendTime,
                blendingSpeeds,
                currentWeights,
                animationsSequences,
                this.logicLayer.GetPassIK(),
                this.logicLayer.GetFootPassIK(),
                1.0f,
                this.dataState.mmFeatures.minWeightToAchive
                );

            //CreateMMAnimation(this.dataState.mmFeatures.blendTime, 1f);
        }
        protected override void Enter(
            PoseData currentPose,
            Trajectory previouStateGoal,
            List <float2> whereCanFindingBestPose
            )
        {
            NativeArray <float2> findingIntervals = new NativeArray <float2>(whereCanFindingBestPose.ToArray(), Allocator.TempJob);

            for (int i = 0; i < currentPose.Count; i++)
            {
                logicLayer.nativePose[i] = currentPose.GetBoneData(i);
            }

            for (int i = 0; i < previouStateGoal.Length; i++)
            {
                logicLayer.nativeTrajectory[i] = previouStateGoal.GetPoint(i);
            }

            SingleAnimationFinding(
                logicLayer.nativePose,
                logicLayer.nativeTrajectory,
                findingIntervals
                );

            findingIntervals.Dispose();

            currentDataIndex     = logicLayer.bestPoseInfo.clipIndex;
            currentClipLocalTime = (float)logicLayer.bestPoseInfo.localTime;

            playableGraph.CreateBlendMotionMatchingAnimation(
                dataState.motionDataGroups[currentMotionDataGroupIndex].animationData[currentDataIndex],
                currentDataIndex,
                stateMixer,
                currentClipLocalTime,
                dataState.saFeatures.blendTime,
                blendingSpeeds,
                currentWeights,
                animationsSequences,
                this.logicLayer.GetPassIK(),
                this.logicLayer.GetFootPassIK(),
                1f
                );

            currentPlayedClipsIndexes.Add(currentDataIndex);
        }
Example #9
0
        public void Start()
        {
            // For geting current pose
            stateInputTrajectoryLocalSpace = new Trajectory(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].trajectory.Length);
            currentAnimationTrajectory     = new Trajectory(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].trajectory.Length);
            currentPose      = new PoseData(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].pose.Count);
            bufforPose       = new PoseData(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].pose.Count);
            nativePose       = new NativeArray <BoneData>(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].pose.Count, Allocator.Persistent);
            nativeTrajectory = new NativeArray <TrajectoryPoint>(logicStates[0].dataState.motionDataGroups[0].animationData[0][0].trajectory.Length, Allocator.Persistent);

#if UNITY_EDITOR
            //else
            //{
            //    throw new System.Exception(string.Format("State {0} have no animation Data", logicStates[0].dataState.GetName()));
            //}
#endif

            logicStatesIndexes = new Dictionary <string, int>();
            for (int i = 0; i < logicStates.Count; i++)
            {
                logicStatesIndexes.Add(logicStates[i].GetName(), i);
            }

            currentStateIndex         = layer.startStateIndex;
            stateWeightsSpeedChanging = new List <float>();

            playableGraph.AddLayerPlayable(this);

            currentBlendedStates.Clear();
            currentBlendedStates.Add(currentStateIndex);
            stateWeightsSpeedChanging.Add(1f);

            logicStates[currentStateIndex].StateStart();
            mixer.SetInputWeight(0, 1f);
            currentWeights.Add(1f);


            if (this.layer.avatarMask != null)
            {
                playableGraph.SetLayerAvatarMask((uint)layer.index, layer.avatarMask);
            }

            playableGraph.SetLayerAdditive((uint)layer.index, layer.isAdditive);
        }
 public static void GetLerpedPose(ref PoseData buffor, FrameData first, FrameData second, float factor)
 {
     PoseData.Lerp(ref buffor, first.pose, second.pose, factor);
 }
 public void SetPose(PoseData newPose)
 {
     this.pose = newPose;
 }
        protected override void Enter(
            PoseData currentPose,
            Trajectory previouStateGoal,
            List <float2> whereCanFindingBestPose
            )
        {
            // valus initzialization
            gettingAdaptedPoints    = true;
            targetContactPointIndex = 0;

            NativeArray <float2>       findingIntervals    = new NativeArray <float2>(whereCanFindingBestPose.ToArray(), Allocator.TempJob);
            NativeArray <FrameContact> contactPointsNative = new NativeArray <FrameContact>(logicLayer.contactPoints.Count, Allocator.TempJob);

            //making native contactsl
            for (int i = 0; i < logicLayer.contactPoints.Count; i++)
            {
                contactPointsNative[i] = logicLayer.contactPoints[i].frameContact;
            }

            // making native pose
            for (int i = 0; i < currentPose.Count; i++)
            {
                logicLayer.nativePose[i] = currentPose.GetBoneData(i);
            }


            for (int i = 0; i < previouStateGoal.Length; i++)
            {
                logicLayer.nativeTrajectory[i] = previouStateGoal.GetPoint(i);
            }

            ContactAnimationFinding(
                logicLayer.nativePose,
                findingIntervals,
                contactPointsNative,
                logicLayer.nativeTrajectory
                );

            findingIntervals.Dispose();
            contactPointsNative.Dispose();


            currentDataIndex     = logicLayer.bestPoseInfo.clipIndex;
            currentClipLocalTime = (float)logicLayer.bestPoseInfo.localTime;

            playableGraph.CreateBlendMotionMatchingAnimation(
                dataState.motionDataGroups[currentMotionDataGroupIndex].animationData[currentDataIndex],
                currentDataIndex,
                stateMixer,
                currentClipLocalTime,
                1f,
                blendingSpeeds,
                currentWeights,
                animationsSequences,
                this.logicLayer.GetPassIK(),
                this.logicLayer.GetFootPassIK(),
                1f
                );

            currentPlayedClipsIndexes.Add(currentDataIndex);

            if (dataState.csFeatures.contactStateType == ContactStateType.NormalContacts)
            {
                switch (this.contactType)
                {
                case ContactStateMovemetType.StartContact:
                    SC_Enter();
                    break;

                case ContactStateMovemetType.ContactLand:
                    CL_Enter();
                    break;

                case ContactStateMovemetType.StartContactLand:
                    SCL_Enter();
                    break;

                case ContactStateMovemetType.StartLand:
                    SL_Enter();
                    break;

                case ContactStateMovemetType.Contact:
                    CL_Enter();
                    break;
                }

                if (dataState.csFeatures.rotateToStart)
                {
                    Vector3 dir = logicLayer.contactPoints[1].frameContact.position - logicLayer.contactPoints[0].frameContact.position;
                    dir = Vector3.ProjectOnPlane(dir, Vector3.up);
                    dir = this.GetCurrentMMData().fromFirstToSecondContactRot *dir;

                    rotationToContact = Quaternion.LookRotation(dir, Vector3.up);

                    float rotationTime = (this.GetCurrentMMData().GetContactStartTime(0) - currentClipLocalTime) / dataState.speedMultiplier;

                    if (rotationTime == 0)
                    {
                        rotationTime = 0.00001f;
                    }
                    else if (rotationTime < 0)
                    {
                        rotationTime = Mathf.Abs(rotationTime);
                    }

                    degreeSpeed = Quaternion.Angle(this.Transform.rotation, rotationToContact) / rotationTime;
                }

#if UNITY_EDITOR
                startTime  = currentClipLocalTime;
                previewPos = Transform.position;
#else
                if (dataState.csFeatures.postionCorrection == ContactPointPositionCorrectionType.LerpPosition)
                {
                    startTime  = currentClipLocalTime;
                    previewPos = Transform.position;
                }
#endif
            }
        }