string GetCostInformation(ref Binary binary, ref DeviationTable deviationTable, SamplingTime samplingTime)
        {
            if (!deviationTable.IsValid || !samplingTime.IsValid)
            {
                return("");
            }

            DeviationScore deviation = deviationTable.GetDeviation(ref binary, samplingTime.timeIndex);

            if (!deviation.IsValid)
            {
                return($"\nThis fragment wasn't considered during the query");
            }

            if (deviation.trajectoryDeviation >= 0.0f)
            {
                return($"\n<b>Pose cost:</b> {deviation.poseDeviation:0.000}, <b>Trajectory:</b> {deviation.trajectoryDeviation:0.000}, <b>Total:</b> {deviation.poseDeviation + deviation.trajectoryDeviation:0.000}");
            }
            else
            {
                return($"\n<b>Pose cost:</b> {deviation.poseDeviation:0.000}");
            }
        }
示例#2
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 void Draw(Camera camera, ref MotionSynthesizer synthesizer, DebugMemory debugMemory, SamplingTime debugSamplingTime, ref DebugDrawOptions options)
        {
            int fragmentSlot = 0;

            DebugDraw.SetMovableTextTitle(options.textWindowIdentifier, DebugWindowTitle);

            DeviationTable deviationTable = this.deviationTable.IsValid ? debugMemory.ReadObjectFromIdentifier <DeviationTable>(this.deviationTable) : DeviationTable.CreateInvalid();

            SamplingTime samplingTime = GetSamplingTime(debugMemory, this.samplingTime);

            if (samplingTime.IsValid)
            {
                if ((options.drawFlags & DebugDrawFlags.InputFragment) > 0)
                {
                    DebugDraw.DrawFragment(ref synthesizer, samplingTime, options.inputOutputFragmentColor, options.timeOffset, synthesizer.WorldRootTransform);
                    ++fragmentSlot;
                }
                DebugDraw.AddMovableTextLine(options.textWindowIdentifier, GetFragmentDebugText(ref synthesizer, "Input Clip", samplingTime, options.timeOffset, ref deviationTable), options.inputOutputFragTextColor);
            }

            SamplingTime    closestMatch         = GetSamplingTime(debugMemory, this.closestMatch);
            DebugIdentifier outputTimeIdentifier = this.closestMatch;

            if (closestMatch.IsValid)
            {
                if ((options.drawFlags & DebugDrawFlags.BestFragment) > 0)
                {
                    DebugDraw.DrawFragment(ref synthesizer, closestMatch, options.bestFragmentColor, options.timeOffset, GetAnchor(synthesizer.WorldRootTransform, fragmentSlot++ *options.distanceOffset, camera));

                    DebugDraw.AddMovableTextLine(options.textWindowIdentifier, GetFragmentDebugText(ref synthesizer, "Best Match Fragment", closestMatch, options.timeOffset, ref deviationTable), options.bestFragTextColor);
                    if (maxDeviation >= 0.0f)
                    {
                        string deviationMsg = GetDeviationText();
                        DebugDraw.AddMovableTextLine(options.textWindowIdentifier, deviationMsg, options.bestFragTextColor);
                    }

                    Nullable <TrajectoryHeuristicDebug> trajectoryHeuristic = FindTrajectoryHeuristic(debugMemory);
                    if (trajectoryHeuristic.HasValue)
                    {
                        trajectoryHeuristic.Value.DrawDebugText(ref options);

                        outputTimeIdentifier = trajectoryHeuristic.Value.outputTime;
                    }
                }
            }

            SamplingTime outputTime = GetOutputPlayTime(debugMemory, samplingTime, closestMatch, outputTimeIdentifier);

            if ((options.drawFlags & DebugDrawFlags.OutputFragment) > 0)
            {
                DebugDraw.DrawFragment(ref synthesizer, outputTime, options.inputOutputFragmentColor, options.timeOffset, GetAnchor(synthesizer.WorldRootTransform, fragmentSlot++ *options.distanceOffset, camera));
                DebugDraw.AddMovableTextLine(options.textWindowIdentifier, GetFragmentDebugText(ref synthesizer, "Output Clip", outputTime, options.timeOffset, ref deviationTable, false), options.inputOutputFragTextColor);
            }

            if (debugSamplingTime.IsValid)
            {
                if ((options.drawFlags & DebugDrawFlags.SelectedFragment) > 0)
                {
                    int slot = fragmentSlot > 0 ? -1 : 0;
                    DebugDraw.DrawFragment(ref synthesizer, debugSamplingTime, options.selectedFragmentColor, options.timeOffset, GetAnchor(synthesizer.WorldRootTransform, slot * options.distanceOffset, camera));
                    DebugDraw.AddMovableTextLine(options.textWindowIdentifier, GetFragmentDebugText(ref synthesizer, "Selected Clip", debugSamplingTime, options.timeOffset, ref deviationTable), options.selectedFragTextColor);
                }
            }

            deviationTable.Dispose();

            if ((options.drawFlags & DebugDrawFlags.Trajectory) > 0 && this.trajectory.IsValid)
            {
                using (Trajectory trajectory = debugMemory.ReadObjectFromIdentifier <Trajectory>(this.trajectory))
                {
                    Binary.TrajectoryFragmentDisplay.Options trajectoryOptions = Binary.TrajectoryFragmentDisplay.Options.Create();

                    DebugExtensions.DebugDrawTrajectory(synthesizer.WorldRootTransform,
                                                        trajectory,
                                                        synthesizer.Binary.SampleRate,
                                                        options.inputTrajectoryColor,
                                                        options.inputTrajectoryColor,
                                                        trajectoryOptions.showForward);
                }
            }
        }
        internal string GetFragmentDebugText(ref MotionSynthesizer synthesizer, string fragmentName, SamplingTime time, float timeOffset, ref DeviationTable deviationTable, bool addCost = true)
        {
            Assert.IsTrue(time.IsValid);

            string text = synthesizer.Binary.GetFragmentDebugText(time, fragmentName, timeOffset);

            if (!addCost)
            {
                return(text);
            }


            string costInfo = GetCostInformation(ref synthesizer.Binary, ref deviationTable, time);

            if (!string.IsNullOrEmpty(costInfo))
            {
                text = text + costInfo;
            }

            return(text);
        }