forked from JLPM22/MotionMatching
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMSearchDebugEditorWindow.cs
More file actions
127 lines (115 loc) · 5.36 KB
/
Copy pathMMSearchDebugEditorWindow.cs
File metadata and controls
127 lines (115 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Unity.Collections;
namespace MotionMatching
{
public class MMSearchDebugEditorWindow : EditorWindow
{
private bool GroupCurrent;
private bool GroupQuery;
private bool GroupDiff;
[MenuItem("MotionMatching/SearchDebugWindow")]
private static void ShowWindow()
{
var window = GetWindow<MMSearchDebugEditorWindow>();
window.titleContent = new GUIContent("SearchDebugWindow");
window.Show();
}
private void OnGUI()
{
if (!Application.isPlaying)
{
EditorGUILayout.HelpBox("This window is only available at runtime.", MessageType.Info);
return;
}
var mmController = Selection.activeGameObject?.GetComponent<MotionMatchingController>();
if (mmController == null)
{
EditorGUILayout.HelpBox("Please select a MotionMatchingController.", MessageType.Info);
return;
}
MotionMatchingData mmData = mmController.MMData;
FeatureSet featureSet = mmController.FeatureSet;
GUI.enabled = false;
EditorGUILayout.IntField("Last Frame", mmController.LastMMSearchFrame);
GUI.enabled = true;
int currentFrame = EditorGUILayout.IntField("Current Frame", mmController.CurrentFrame);
if (currentFrame != mmController.CurrentFrame) mmController.SetCurrentFrame(currentFrame);
NativeArray<float> currentFeature = new NativeArray<float>(featureSet.FeatureSize, Allocator.Temp);
featureSet.GetFeature(currentFeature, currentFrame);
GroupCurrent = EditorGUILayout.BeginFoldoutHeaderGroup(GroupCurrent, "Current");
if (GroupCurrent)
{
DisplayFeatureVector(currentFeature, "Current Feature", mmData);
}
EditorGUILayout.EndFoldoutHeaderGroup();
NativeArray<float> queryFeature = mmController.QueryFeature;
GroupQuery = EditorGUILayout.BeginFoldoutHeaderGroup(GroupQuery, "Query");
if (GroupQuery)
{
DisplayFeatureVector(queryFeature, "Last MM Search Query Feature", mmData);
}
EditorGUILayout.EndFoldoutHeaderGroup();
GroupDiff = EditorGUILayout.BeginFoldoutHeaderGroup(GroupDiff, "Diff");
if (GroupDiff)
{
NativeArray<float> featureWeights = mmController.UpdateAndGetFeatureWeights();
float sqrDistance = 0.0f;
for (int i = 0; i < featureSet.FeatureSize; ++i)
{
float diff = currentFeature[i] - queryFeature[i];
sqrDistance += diff * diff * featureWeights[i];
currentFeature[i] = diff * diff * featureWeights[i];
}
DisplayFeatureVector(currentFeature, "Difference", mmData);
EditorGUILayout.LabelField("Sqr Distance", sqrDistance.ToString(), EditorStyles.boldLabel);
}
EditorGUILayout.EndFoldoutHeaderGroup();
currentFeature.Dispose();
}
private void DisplayFeatureVector(NativeArray<float> vector, string name, MotionMatchingData mmData)
{
var style = new GUIStyle(GUI.skin.textField) { alignment = TextAnchor.MiddleLeft };
GUILayout.ExpandWidth(false);
EditorGUILayout.BeginVertical(GUI.skin.box);
EditorGUILayout.LabelField(name);
int offset = 0;
for (int t = 0; t < mmData.TrajectoryFeatures.Count; t++)
{
var feature = mmData.TrajectoryFeatures[t];
int featureSize = feature.GetSize();
EditorGUILayout.LabelField(feature.Name);
for (int p = 0; p < feature.FramesPrediction.Length; p++)
{
EditorGUILayout.BeginHorizontal();
for (int i = 0; i < featureSize; i++)
{
EditorGUILayout.LabelField(vector[offset + i].ToString("F3"), style, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(60));
}
EditorGUILayout.EndHorizontal();
offset += featureSize;
}
}
for (int p = 0; p < mmData.PoseFeatures.Count; p++)
{
var feature = mmData.PoseFeatures[p];
EditorGUILayout.LabelField(feature.Name);
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(vector[offset + 0].ToString("F3"), style, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(60));
EditorGUILayout.LabelField(vector[offset + 1].ToString("F3"), style, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(60));
EditorGUILayout.LabelField(vector[offset + 2].ToString("F3"), style, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(60));
EditorGUILayout.EndHorizontal();
offset += 3;
}
EditorGUILayout.EndVertical();
}
void OnInspectorUpdate()
{
// Call Repaint on OnInspectorUpdate as it repaints the windows
// less times as if it was OnGUI/Update
Repaint();
}
}
}