public bool MatchPose(PoseSet candidates,
                              SamplingTime samplingTime,
                              MatchOptions options   = MatchOptions.None,
                              float maxPoseDeviation = -1.0f)
        {
            if ((options & MatchOptions.DontMatchIfCandidateIsPlaying) > 0 && IsTimeInSequences(samplingTime, candidates.sequences))
            {
                if ((options & MatchOptions.LoopSegment) > 0)
                {
                    LoopSegmentIfEndReached(samplingTime);
                }

                return(true);
            }

            DebugPushGroup();

            SamplingTime closestMatch = FindClosestPoseMatch(candidates, samplingTime, maxPoseDeviation);

            if (closestMatch.IsValid)
            {
                PlayAtTime(closestMatch);
                return(true);
            }
            else
            {
                if ((options & MatchOptions.LoopSegment) > 0)
                {
                    LoopSegmentIfEndReached(samplingTime);
                }

                return(false);
            }
        }
        public unsafe SamplingTime FindClosestPoseMatch(PoseSet candidates,
                                                        SamplingTime samplingTime,
                                                        float maxPoseDeviation = -1.0f)
        {
            if (!samplingTime.IsValid)
            {
                return(SamplingTime.Create(SelectFirstPose(candidates.sequences)));
            }

            ref Binary binary = ref Binary;
Exemplo n.º 3
0
        internal static DeviationTable Create(PoseSet candidates)
        {
            int numDeviations = 0;

            for (int i = 0; i < candidates.sequences.Length; ++i)
            {
                numDeviations += candidates.sequences[i].numFrames;
            }

            DeviationTable table = new DeviationTable()
            {
                allocator  = Allocator.Temp,
                sequences  = new NativeArray <PoseSequenceInfo>(candidates.sequences.Length, Allocator.Temp),
                deviations = new NativeArray <DeviationScore>(numDeviations, Allocator.Temp)
            };

            int deviationIndex = 0;

            for (int i = 0; i < candidates.sequences.Length; ++i)
            {
                table.sequences[i] = new PoseSequenceInfo()
                {
                    sequence            = candidates.sequences[i],
                    firstDeviationIndex = deviationIndex
                };

                deviationIndex += candidates.sequences[i].numFrames;
            }

            for (int i = 0; i < numDeviations; ++i)
            {
                table.deviations[i] = DeviationScore.CreateInvalid();
            }

            return(table);
        }
        public bool MatchPoseAndTrajectory(PoseSet candidates,
                                           SamplingTime samplingTime,
                                           Trajectory trajectory,
                                           MatchOptions options         = MatchOptions.None,
                                           float trajectoryWeight       = 0.6f,
                                           float minTrajectoryDeviation = 0.03f,
                                           float maxTotalDeviation      = -1.0f)
        {
            if ((options & MatchOptions.DontMatchIfCandidateIsPlaying) > 0 && IsTimeInSequences(samplingTime, candidates.sequences))
            {
                if ((options & MatchOptions.LoopSegment) > 0)
                {
                    LoopSegmentIfEndReached(samplingTime);
                }

                return(true);
            }


            if (!trajectory.debugIdentifier.IsValid)
            {
                DebugPushGroup();
                DebugWriteUnblittableObject(ref trajectory);
            }

            DebugWriteUnblittableObject(ref candidates);
            DebugWriteBlittableObject(ref samplingTime);


            SamplingTime closestMatch = FindClosestPoseAndTrajectoryMatch(candidates, samplingTime, trajectory, trajectoryWeight, maxTotalDeviation);

            if (closestMatch.IsValid)
            {
                bool validMatch = true;
                if (minTrajectoryDeviation >= 0.0f)
                {
                    float trajectoryDeviation = RelativeDeviation(closestMatch.timeIndex, trajectory);
                    validMatch = trajectoryDeviation >= minTrajectoryDeviation;

                    SamplingTime outputTime = closestMatch;
                    outputTime.debugIdentifier = DebugIdentifier.Invalid;
                    DebugWriteBlittableObject(ref outputTime, true);

                    TrajectoryHeuristicDebug heuristicDebug = new TrajectoryHeuristicDebug()
                    {
                        desiredTrajectory      = trajectory.debugIdentifier,
                        candidate              = samplingTime.debugIdentifier,
                        closestMatch           = closestMatch.debugIdentifier,
                        outputTime             = outputTime.debugIdentifier,
                        trajectoryDeviation    = trajectoryDeviation,
                        minTrajectoryDeviation = minTrajectoryDeviation
                    };
                    DebugWriteBlittableObject(ref heuristicDebug);

                    closestMatch = outputTime;
                }

                if (validMatch)
                {
                    PlayAtTime(closestMatch);
                    return(true);
                }
            }

            if ((options & MatchOptions.LoopSegment) > 0)
            {
                LoopSegmentIfEndReached(samplingTime);
            }

            return(false);
        }