Browse Source

add new visualization FadeInSeries

Kenkart 2 years ago
parent
commit
82f31b7ee2

+ 88 - 39
Assets/Scenes/Main.unity

@@ -182,6 +182,7 @@ MonoBehaviour:
   boneMaterial: {fileID: 2100000, guid: f2ea145c63353784985576f08398a815, type: 2}
   transparentMat: {fileID: 2100000, guid: 803645c956e5ae64a9b99ae13a11cd41, type: 2}
   vfi: {fileID: 1896464126}
+  vfis: {fileID: 1143995017}
 --- !u!4 &65057766
 Transform:
   m_ObjectHideFlags: 0
@@ -258,11 +259,11 @@ PrefabInstance:
     - target: {fileID: 2348914, guid: 4d293c8e162f3874b982baadd71153d2, type: 3}
       propertyPath: m_Materials.Array.data[0]
       value: 
-      objectReference: {fileID: 1576511250}
+      objectReference: {fileID: 1168904058}
     - target: {fileID: 3380982, guid: 4d293c8e162f3874b982baadd71153d2, type: 3}
       propertyPath: m_Mesh
       value: 
-      objectReference: {fileID: 1041936322}
+      objectReference: {fileID: 1543728346}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: 4d293c8e162f3874b982baadd71153d2, type: 3}
 --- !u!4 &110216683 stripped
@@ -408,7 +409,7 @@ Transform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 0}
-  m_RootOrder: 11
+  m_RootOrder: 12
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1001 &833043381
 PrefabInstance:
@@ -689,7 +690,90 @@ PrefabInstance:
       objectReference: {fileID: 0}
     m_RemovedComponents: []
   m_SourcePrefab: {fileID: 100100000, guid: 4f35fa249b5008c44ac2998be6f82d4d, type: 3}
---- !u!43 &1041936322
+--- !u!1 &1143995016
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1143995018}
+  - component: {fileID: 1143995017}
+  m_Layer: 0
+  m_Name: Visualizer_FadeInSeries
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!114 &1143995017
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1143995016}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 07434bc363a59a34f950591f091e038f, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  boneMaterial: {fileID: 2100000, guid: f2ea145c63353784985576f08398a815, type: 2}
+  transparentMat: {fileID: 2100000, guid: 803645c956e5ae64a9b99ae13a11cd41, type: 2}
+  bsv: {fileID: 189736995}
+  wristLeftTriggered: 0
+  wristRightTriggered: 0
+--- !u!4 &1143995018
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 1143995016}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 11
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!21 &1168904058
+Material:
+  serializedVersion: 6
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_Name: Sprites/Default
+  m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
+  m_ShaderKeywords: 
+  m_LightmapFlags: 4
+  m_EnableInstancingVariants: 0
+  m_DoubleSidedGI: 0
+  m_CustomRenderQueue: -1
+  stringTagMap: {}
+  disabledShaderPasses: []
+  m_SavedProperties:
+    serializedVersion: 3
+    m_TexEnvs:
+    - _AlphaTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    - _MainTex:
+        m_Texture: {fileID: 0}
+        m_Scale: {x: 1, y: 1}
+        m_Offset: {x: 0, y: 0}
+    m_Floats:
+    - PixelSnap: 0
+    - _EnableExternalAlpha: 0
+    m_Colors:
+    - _Color: {r: 1, g: 1, b: 1, a: 1}
+    - _Flip: {r: 1, g: 1, b: 1, a: 1}
+    - _RendererColor: {r: 1, g: 1, b: 1, a: 1}
+  m_BuildTextureStacks: []
+--- !u!43 &1543728346
 Mesh:
   m_ObjectHideFlags: 0
   m_CorrespondingSourceObject: {fileID: 0}
@@ -853,41 +937,6 @@ Mesh:
     offset: 0
     size: 0
     path: 
---- !u!21 &1576511250
-Material:
-  serializedVersion: 6
-  m_ObjectHideFlags: 0
-  m_CorrespondingSourceObject: {fileID: 0}
-  m_PrefabInstance: {fileID: 0}
-  m_PrefabAsset: {fileID: 0}
-  m_Name: Sprites/Default
-  m_Shader: {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
-  m_ShaderKeywords: 
-  m_LightmapFlags: 4
-  m_EnableInstancingVariants: 0
-  m_DoubleSidedGI: 0
-  m_CustomRenderQueue: -1
-  stringTagMap: {}
-  disabledShaderPasses: []
-  m_SavedProperties:
-    serializedVersion: 3
-    m_TexEnvs:
-    - _AlphaTex:
-        m_Texture: {fileID: 0}
-        m_Scale: {x: 1, y: 1}
-        m_Offset: {x: 0, y: 0}
-    - _MainTex:
-        m_Texture: {fileID: 0}
-        m_Scale: {x: 1, y: 1}
-        m_Offset: {x: 0, y: 0}
-    m_Floats:
-    - PixelSnap: 0
-    - _EnableExternalAlpha: 0
-    m_Colors:
-    - _Color: {r: 1, g: 1, b: 1, a: 1}
-    - _Flip: {r: 1, g: 1, b: 1, a: 1}
-    - _RendererColor: {r: 1, g: 1, b: 1, a: 1}
-  m_BuildTextureStacks: []
 --- !u!1 &1715140921
 GameObject:
   m_ObjectHideFlags: 0

+ 34 - 2
Assets/Scripts/PlayerReplay.cs

@@ -15,6 +15,7 @@ public class PlayerReplay : MonoBehaviour
     public Material transparentMat;
 
     public Visualizer_FadeIn vfi;
+    public Visualizer_FadeInSeries vfis;
 
     private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
     {
@@ -124,7 +125,8 @@ public class PlayerReplay : MonoBehaviour
                 float distance = Vector3.Distance(prevJointPosition, jointPosition);
 
                 // If a joint is bigger than a certain distance, add it to the replay, else ignore it
-                if (distance >= 2)
+                // TODO: maybe distance need to be adjusted
+                if (distance >= 0.2f)
                 {
                     newJointsData.Add(jd);
                     newRecordingTimes.Add(recordingTimes[i]);
@@ -135,7 +137,8 @@ public class PlayerReplay : MonoBehaviour
         }
 
         //StartCoroutine(Visualize(newJointsData, newRecordingTimes));
-        StartCoroutine(VisualizeFadeIn(newJointsData, newRecordingTimes));
+        //StartCoroutine(VisualizeFadeIn(newJointsData, newRecordingTimes));
+        StartCoroutine(VisualizeFadeInSeries(newJointsData, newRecordingTimes));
     }
 
     private IEnumerator Visualize(List<JointsData> newJointsData, List<float> newRecordingTimes)
@@ -210,4 +213,33 @@ public class PlayerReplay : MonoBehaviour
             yield return wait;
         }
     }
+
+    private IEnumerator VisualizeFadeInSeries(List<JointsData> newJointsData, List<float> newRecordingTimes)
+    {
+        float waitTime = 2;
+        List<JointsData> jointsDataSeries = new List<JointsData>();
+        List<float> recordingTimesSeries = new List<float>();
+
+        for (int i = 0; i < newJointsData.Count; i++)
+        {
+            if (newRecordingTimes[i] < waitTime)
+            {
+                jointsDataSeries.Add(newJointsData[i]);
+                recordingTimesSeries.Add(newRecordingTimes[i]);
+            } else
+            {
+                waitTime += 2;
+                
+                Visualizer_FadeInSeries body = Instantiate(vfis) as Visualizer_FadeInSeries;
+                body.SetData(jointsDataSeries, recordingTimesSeries);
+                body.ShowBody();
+
+                jointsDataSeries.Clear();
+                recordingTimesSeries.Clear();
+
+                WaitForSeconds wait = new WaitForSeconds(2);
+                yield return wait;
+            }
+        }
+    }
 }

+ 26 - 0
Assets/Scripts/TriggerDetectorSeries.cs

@@ -0,0 +1,26 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class TriggerDetectorSeries : MonoBehaviour
+{
+    private void OnTriggerEnter(Collider other)
+    {
+        if (other.CompareTag("WristLeft"))
+        {
+            other.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
+            BodySourceView bsv = other.GetComponentInParent<BodySourceView>();
+            bsv.wristLeftLate = false;
+            Visualizer_FadeInSeries vfi = GetComponentInParent<Visualizer_FadeInSeries>();
+            vfi.wristLeftTriggered = true;
+        }
+        else if (other.CompareTag("WristRight"))
+        {
+            other.GetComponent<Renderer>().material.color = new Color(1, 1, 1);
+            BodySourceView bsv = other.GetComponentInParent<BodySourceView>();
+            bsv.wristRightLate = false;
+            Visualizer_FadeInSeries vfi = GetComponentInParent<Visualizer_FadeInSeries>();
+            vfi.wristRightTriggered = true;
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/TriggerDetectorSeries.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1f856aaaee4de2348a18eb25771dbb6d
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 3 - 3
Assets/Scripts/Visualizer_FadeIn.cs

@@ -119,10 +119,10 @@ public class Visualizer_FadeIn : MonoBehaviour
             LineRenderer lr = jointObj.AddComponent<LineRenderer>();
             lr.positionCount = 2;
             lr.material = boneMaterial;
-            lr.startWidth = 0.3f;
-            lr.endWidth = 0.3f;
+            lr.startWidth = 0.05f;
+            lr.endWidth = 0.05f;
 
-            jointObj.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
+            jointObj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
             jointObj.name = jt.ToString();
             jointObj.transform.position = new Vector3(data.jointsPositionsX[(int)jt], data.jointsPositionsY[(int)jt], data.jointsPositionsZ[(int)jt]);
             jointObj.transform.parent = body.transform;

+ 159 - 0
Assets/Scripts/Visualizer_FadeInSeries.cs

@@ -0,0 +1,159 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using Kinect = Windows.Kinect;
+
+public class Visualizer_FadeInSeries : MonoBehaviour
+{
+    public Material boneMaterial;
+    public Material transparentMat;
+    public BodySourceView bsv;
+
+    public bool wristLeftTriggered;
+    public bool wristRightTriggered;
+
+    private List<JointsData> jointsDataSeries = new List<JointsData>();
+    private List<float> recordingTimesSeries = new List<float>();
+    private Dictionary<Kinect.JointType, Kinect.JointType> _BoneMap = new Dictionary<Kinect.JointType, Kinect.JointType>()
+    {
+        { Kinect.JointType.FootLeft, Kinect.JointType.AnkleLeft },
+        { Kinect.JointType.AnkleLeft, Kinect.JointType.KneeLeft },
+        { Kinect.JointType.KneeLeft, Kinect.JointType.HipLeft },
+        { Kinect.JointType.HipLeft, Kinect.JointType.SpineBase },
+
+        { Kinect.JointType.FootRight, Kinect.JointType.AnkleRight },
+        { Kinect.JointType.AnkleRight, Kinect.JointType.KneeRight },
+        { Kinect.JointType.KneeRight, Kinect.JointType.HipRight },
+        { Kinect.JointType.HipRight, Kinect.JointType.SpineBase },
+
+        { Kinect.JointType.HandTipLeft, Kinect.JointType.HandLeft },
+        { Kinect.JointType.ThumbLeft, Kinect.JointType.HandLeft },
+        { Kinect.JointType.HandLeft, Kinect.JointType.WristLeft },
+        { Kinect.JointType.WristLeft, Kinect.JointType.ElbowLeft },
+        { Kinect.JointType.ElbowLeft, Kinect.JointType.ShoulderLeft },
+        { Kinect.JointType.ShoulderLeft, Kinect.JointType.SpineShoulder },
+
+        { Kinect.JointType.HandTipRight, Kinect.JointType.HandRight },
+        { Kinect.JointType.ThumbRight, Kinect.JointType.HandRight },
+        { Kinect.JointType.HandRight, Kinect.JointType.WristRight },
+        { Kinect.JointType.WristRight, Kinect.JointType.ElbowRight },
+        { Kinect.JointType.ElbowRight, Kinect.JointType.ShoulderRight },
+        { Kinect.JointType.ShoulderRight, Kinect.JointType.SpineShoulder },
+
+        { Kinect.JointType.SpineBase, Kinect.JointType.SpineMid },
+        { Kinect.JointType.SpineMid, Kinect.JointType.SpineShoulder },
+        { Kinect.JointType.SpineShoulder, Kinect.JointType.Neck },
+        { Kinect.JointType.Neck, Kinect.JointType.Head },
+    };
+
+    private float t;
+    private List<GameObject> jointObjs = new List<GameObject>();
+    private bool beginUpdate;
+    private List<GameObject> bodies = new List<GameObject>();
+
+    void Update()
+    {
+        if (!beginUpdate)
+            return;
+
+        if (t >= 1)
+        {
+            foreach (GameObject go in bodies)
+            {
+                Destroy(go);
+            }
+            Destroy(gameObject);
+            return;
+        }
+
+        t += Time.deltaTime / 2;
+
+        // TODO: different way to do it
+        // After half time, report if player WristLeft or WristRight late or not
+        if (t > 0.5f)
+        {
+            if (!wristLeftTriggered)
+            {
+                bsv.wristLeftLate = true;
+            }
+            if (!wristRightTriggered)
+            {
+                bsv.wristRightLate = true;
+            }
+        }
+    }
+
+    public void SetData(List<JointsData> jointsDataSeries, List<float> recordingTimesSeries)
+    {
+        this.jointsDataSeries = jointsDataSeries;
+        this.recordingTimesSeries = recordingTimesSeries;
+    }
+
+    public void ShowBody()
+    {
+        for (int i = 0; i < jointsDataSeries.Count; i++)
+        {
+            // Create GameObject body
+            GameObject body = new GameObject("Recorded Body (Visualizer_FadeInSeries) " + i);
+            body.transform.parent = gameObject.transform;
+            bodies.Add(body);
+
+            for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
+            {
+                // Skip these joints
+                if (jt == Kinect.JointType.Head || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
+                        || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
+                        || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
+                    continue;
+
+                // Create GameObject cubes for joints
+                GameObject jointObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
+                jointObj.GetComponent<MeshRenderer>().material = transparentMat;
+
+                // Give BoxCollider.isTrigger true and TriggerDetector to WristLeft and WristRight
+                if (jt == Kinect.JointType.WristLeft || jt == Kinect.JointType.WristRight)
+                {
+                    jointObj.GetComponent<BoxCollider>().isTrigger = true;
+                    jointObj.AddComponent<TriggerDetectorSeries>();
+                }
+
+                LineRenderer lr = jointObj.AddComponent<LineRenderer>();
+                lr.positionCount = 2;
+                lr.material = boneMaterial;
+                lr.startWidth = 0.05f;
+                lr.endWidth = 0.05f;
+
+                jointObj.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
+                jointObj.name = jt.ToString();
+                jointObj.transform.position = new Vector3(jointsDataSeries[i].jointsPositionsX[(int)jt], jointsDataSeries[i].jointsPositionsY[(int)jt], jointsDataSeries[i].jointsPositionsZ[(int)jt]);
+                jointObj.transform.parent = body.transform;
+
+                // Set alpha depends on i
+                Color newColor = new Color(1, 1, 1, Mathf.Lerp(0, 1, (float) (i + 1) / jointsDataSeries.Count));
+                jointObj.GetComponent<MeshRenderer>().material.color = newColor;
+                jointObj.GetComponent<LineRenderer>().startColor = newColor;
+                jointObj.GetComponent<LineRenderer>().endColor = newColor;
+            }
+
+            // Connect the joints with LineRenderer
+            for (Kinect.JointType jt = Kinect.JointType.SpineBase; jt <= Kinect.JointType.ThumbRight; jt++)
+            {
+                // Skip if dictionary not contains the joint or other these joints
+                if (!_BoneMap.ContainsKey(jt) || jt == Kinect.JointType.Neck
+                    || jt == Kinect.JointType.ThumbLeft || jt == Kinect.JointType.ThumbRight
+                        || jt == Kinect.JointType.HandLeft || jt == Kinect.JointType.HandRight
+                        || jt == Kinect.JointType.HandTipLeft || jt == Kinect.JointType.HandTipRight)
+                    continue;
+
+                Transform jointObj = body.transform.Find(jt.ToString());
+                Transform targetJoint = body.transform.Find(_BoneMap[jt].ToString());
+                LineRenderer lr = jointObj.GetComponent<LineRenderer>();
+
+                lr.SetPosition(0, jointObj.localPosition);
+                lr.SetPosition(1, targetJoint.localPosition);
+            }
+        }
+
+        beginUpdate = true;
+    }
+}

+ 11 - 0
Assets/Scripts/Visualizer_FadeInSeries.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 07434bc363a59a34f950591f091e038f
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: