Browse Source

Added new visualization for testing not finished

Furkan Karakocaoglu 1 year ago
parent
commit
8df0d89037

+ 8 - 0
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/TestingFunctions.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: add6c4210c10f8741872d600d171eda2
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 254 - 0
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/TestingFunctions/SpatialTimeSimulation.cs

@@ -0,0 +1,254 @@
+using UnityEngine;
+using UnityEngine.UI;
+using UnityEngine.AI;
+using System.Collections.Generic;
+using System.IO;
+using System;
+
+[DefaultExecutionOrder(40)]
+[RequireComponent(typeof(InstantiatePrefab), typeof(WriteInCSV), typeof(ReadFromCSV))]
+public class SpatialTimeSimulation : MonoBehaviour
+{
+    // Waypoints and Rotations
+    public Tuple<List<float>, List<Vector3>, List<Quaternion>, List<float>>[][] timePosRotList;
+
+    // Private Journey Settings
+    private int currentStartPoint;
+    private float startTime;
+
+    // Global GameObjects
+    private GameObject[][] humansGO;
+
+    // Playback variables
+    private int[] maxIJ;
+    private int indexChangeRate;
+    [HideInInspector]
+    public bool rewind, pause, play; //PlaybackController
+
+    // Slider Settings
+    public Slider slider;
+    private float prevSliderValue;
+
+    // Thief Settings
+    private Vector3 stealHere;
+
+    // Testing
+    public float thickness = 0.1f;
+
+    private void Start()
+    {
+        // Get information from InstatiatePrefab
+        humansGO = gameObject.GetComponent<InstantiatePrefab>().humanGameObject;
+        NavMeshAgent[][] humansNMA = gameObject.GetComponent<InstantiatePrefab>().humanNavMeshAgent;
+        stealHere = gameObject.GetComponent<ControllingThief>().stealHere;
+
+        // Read from CSV file and save time, position, rotation in matrix
+        int index = gameObject.GetComponent<WriteInCSV>().index;
+        string dir = Directory.GetCurrentDirectory();
+        string reference = @"\Assets\Data_position\Walk" + index + ".csv";
+        timePosRotList = gameObject.GetComponent<ReadFromCSV>().ReadFromCSVFile(dir + reference);
+
+        // Set initial position and rotation
+        currentStartPoint = 0;
+        for (int i = 0; i < humansGO.Length; ++i)
+        {
+            for (int j = 0; j < humansGO[i].Length; ++j)
+            {
+                humansGO[i][j].SetActive(false);
+
+                humansNMA[i][j].enabled = false;
+            }
+        }
+
+        // Set the Slider settings
+        if (slider == null)
+        {
+            Debug.Log("No Slider instance attached");
+            return;
+        }
+        maxIJ = GetHumanWithLongestScreenTime();
+        float maxTime = (float)Math.Round(timePosRotList[maxIJ[0]][maxIJ[1]].Item1[timePosRotList[maxIJ[0]][maxIJ[1]].Item1.Count - 1], 2);
+        slider.minValue = 0;
+        slider.maxValue = (maxTime / Time.deltaTime);
+        slider.wholeNumbers = true;
+        prevSliderValue = slider.value;
+
+        //SetTransform(currentStartPoint);
+        //currentStartPoint++;
+        slider.value = currentStartPoint;
+        startTime = Time.time;
+
+        int count = 0;
+        // Create all cubes for every human and disable/enable them with time.
+        GameObject[][] cubes = new GameObject[humansGO.Length][];
+        for (int i = 0; i < cubes.Length; ++i)
+        {
+            cubes[i] = new GameObject[humansGO[i].Length];
+
+            for (int j = 0; j < cubes[i].Length; ++j)
+            {
+                currentStartPoint = 0;
+                while (currentStartPoint < timePosRotList[i][j].Item2.Count)
+                {
+                    //if(currentStartPoint == 0 || currentStartPoint >= timePosRotList[i][j].Item2.Count - 1)
+                    //{
+                    //    cubes[i][j] = GameObject.CreatePrimitive(PrimitiveType.Cube);
+                    //    cubes[i][j].transform.position = new Vector3(timePosRotList[i][j].Item2[currentStartPoint].x, 0.5f + timePosRotList[i][j].Item1[currentStartPoint], timePosRotList[i][j].Item2[currentStartPoint].z);
+                    //    cubes[i][j].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
+                    //    cubes[i][j].GetComponent<MeshRenderer>().material.color = Color.green;
+                    //    count++;
+                    //}
+                    //else if(currentStartPoint < timePosRotList[i][j].Item2.Count - 1)
+                    //{
+                    //    if (Vector3.Distance(timePosRotList[i][j].Item2[currentStartPoint - 1], timePosRotList[i][j].Item2[currentStartPoint]) <= 0.2f)
+                    //    {
+                    //        cubes[i][j] = GameObject.CreatePrimitive(PrimitiveType.Cube);
+                    //        cubes[i][j].transform.position = new Vector3(timePosRotList[i][j].Item2[currentStartPoint].x, 0.5f + timePosRotList[i][j].Item1[currentStartPoint], timePosRotList[i][j].Item2[currentStartPoint].z);
+                    //        cubes[i][j].transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
+                    //        cubes[i][j].GetComponent<MeshRenderer>().material.color = Color.green;
+                    //        count++;
+                    //    }
+                    //}
+                    //currentStartPoint++;
+
+                    GameObject newPath = new GameObject();
+                    LineRenderer drawPath = newPath.AddComponent<LineRenderer>();
+                    drawPath.material = new Material(Shader.Find("Sprites/Default"));
+                    drawPath.startColor = Color.green;
+                    drawPath.endColor = Color.green;
+                    drawPath.startWidth = thickness;
+                    drawPath.endWidth = thickness;
+
+                    drawPath.positionCount = timePosRotList[i][j].Item2.Count;
+
+                    List<Vector3> newList = new List<Vector3>(); 
+                    foreach(var vec in timePosRotList[i][j].Item2)
+                    {
+                        var z = new Vector3(vec.x, 0.5f + timePosRotList[i][j].Item1[currentStartPoint], vec.z);
+                        newList.Add(z);
+                        currentStartPoint++;
+                    }
+
+                    drawPath.SetPositions(newList.ToArray());
+
+                }
+            }
+        }
+        Debug.Log("Count: " + count);
+
+    }
+
+    //private void FixedUpdate()
+    //{
+    //    if (pause)
+    //        indexChangeRate = 0;
+    //    if (play)
+    //        indexChangeRate = 1;
+    //    if (rewind)
+    //        indexChangeRate = -1;
+
+    //    if (play || rewind)
+    //    {
+    //        if ((currentStartPoint + indexChangeRate) < timePosRotList[maxIJ[0]][maxIJ[1]].Item2.Count && (currentStartPoint + indexChangeRate) >= 0)
+    //        {
+    //            if (slider.value - prevSliderValue == -1 || slider.value - prevSliderValue == 0 || slider.value - prevSliderValue == 1) // rewind || play
+    //            {
+    //                prevSliderValue = slider.value;
+    //                currentStartPoint += indexChangeRate;
+    //                slider.value = currentStartPoint;
+    //            }
+    //            else
+    //            {
+    //                prevSliderValue = slider.value;
+    //                currentStartPoint = (int)slider.value;
+    //            }
+    //            SetTransform(currentStartPoint);
+    //        }
+    //        else if (slider.value - prevSliderValue != -1 || slider.value - prevSliderValue != 0 || slider.value - prevSliderValue != 1)
+    //        {
+    //            currentStartPoint = (int)slider.value;
+    //        }
+    //    }
+    //    else
+    //    {
+    //        // upper else-Statement only for pause
+    //        if (slider.value - prevSliderValue != 0)
+    //        {
+    //            //prevSliderValue = slider.value;
+    //            currentStartPoint = (int)slider.value;
+    //        }
+
+    //        for (int i = 0; i < humansGO.Length; ++i)
+    //        {
+    //            for (int j = 0; j < humansGO[i].Length; ++j)
+    //            {
+    //                if (currentStartPoint < timePosRotList[i][j].Item2.Count)
+    //                {
+    //                    humansGO[i][j].transform.position = timePosRotList[i][j].Item2[currentStartPoint]; // First entry of Position
+    //                    humansGO[i][j].transform.rotation = timePosRotList[i][j].Item3[currentStartPoint]; // First entry of Rotation
+    //                }
+    //            }
+    //        }
+    //    }
+    //}
+
+    //private void SetTransform(int currentStartPoint)
+    //{
+    //    for (int i = 0; i < humansGO.Length; ++i)
+    //    {
+    //        for (int j = 0; j < humansGO[i].Length; ++j)
+    //        {
+    //            // if so ArgumentOutOfRangeException
+    //            if ((currentStartPoint + indexChangeRate) >= (timePosRotList[i][j].Item2.Count - 1) || (currentStartPoint + indexChangeRate) < 0)
+    //            {
+    //                continue;
+    //            }
+
+    //            Vector3 startPos = timePosRotList[i][j].Item2[currentStartPoint];
+    //            Vector3 endPos = timePosRotList[i][j].Item2[currentStartPoint + indexChangeRate];
+    //            Quaternion startRot = timePosRotList[i][j].Item3[currentStartPoint];
+    //            Quaternion endRot = timePosRotList[i][j].Item3[currentStartPoint + indexChangeRate];
+
+    //            float distCovered = (Time.time - startTime) * timePosRotList[i][j].Item4[currentStartPoint];
+    //            float fracJourney = 1f;
+    //            float journeyLength = Vector3.Distance(startPos, endPos);
+    //            if (journeyLength != 0 && distCovered != 0) fracJourney = distCovered / journeyLength;
+
+    //            // Animation Idle, if startPoint == endPoint and startRot == endRot
+    //            //if (journeyLength <= 0 && startRot.Equals(endRot) || currentStartPoint == 0 || currentStartPoint == timePosRotList[i][j].Item2.Count)
+    //            //{
+    //            //    humansA[i][j].SetBool("isWalking", false);
+    //            //}
+    //            //else if (journeyLength > 0)
+    //            //{
+    //            //    humansA[i][j].SetBool("isWalking", true);
+    //            //}
+    //            //humansA[i][j].speed = 2*(journeyLength / 0.2f);
+
+    //            humansGO[i][j].transform.position = Vector3.Lerp(startPos, endPos, fracJourney);
+    //            humansGO[i][j].transform.rotation = Quaternion.Lerp(startRot, endRot, fracJourney);
+    //        }
+    //    }
+    //}
+
+    private int[] GetHumanWithLongestScreenTime()
+    {
+        int[] maxIJ = new int[2] { 0, 0 };
+        float currentMaxTime = 0;
+
+        for (int i = 0; i < humansGO.Length; ++i)
+        {
+            for (int j = 0; j < humansGO[i].Length; ++j)
+            {
+                if (currentMaxTime < timePosRotList[i][j].Item1.Count)
+                {
+                    currentMaxTime = timePosRotList[i][j].Item1.Count;
+                    maxIJ[0] = i;
+                    maxIJ[1] = j;
+                }
+            }
+        }
+
+        return maxIJ;
+    }
+}

+ 11 - 0
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/TestingFunctions/SpatialTimeSimulation.cs.meta

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

+ 1 - 1
testumgebung/CrowdModelling/Assets/Depictions_Years/Scripts/WanderingAI/WalkLerpPlayback.cs

@@ -10,7 +10,7 @@ using System;
 public class WalkLerpPlayback : MonoBehaviour
 {
     // Waypoints and Rotations
-    private Tuple<List<float>, List<Vector3>, List<Quaternion>, List<float>>[][] timePosRotList;
+    public Tuple<List<float>, List<Vector3>, List<Quaternion>, List<float>>[][] timePosRotList;
 
     // Animation
     private const string isWalking = "isWalking";

+ 118 - 7
testumgebung/CrowdModelling/Assets/Scenes/Origin_OnlyYears.unity

@@ -3499,6 +3499,99 @@ MonoBehaviour:
     serializedVersion: 2
     m_Bits: 32
   m_MaxRayIntersections: 0
+--- !u!1 &351241250
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 351241254}
+  - component: {fileID: 351241253}
+  - component: {fileID: 351241252}
+  - component: {fileID: 351241251}
+  m_Layer: 0
+  m_Name: Cube (2)
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 0
+--- !u!65 &351241251
+BoxCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 351241250}
+  m_Material: {fileID: 0}
+  m_IsTrigger: 0
+  m_Enabled: 1
+  serializedVersion: 2
+  m_Size: {x: 1, y: 1, z: 1}
+  m_Center: {x: 0, y: 0, z: 0}
+--- !u!23 &351241252
+MeshRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 351241250}
+  m_Enabled: 1
+  m_CastShadows: 1
+  m_ReceiveShadows: 1
+  m_DynamicOccludee: 1
+  m_MotionVectors: 1
+  m_LightProbeUsage: 1
+  m_ReflectionProbeUsage: 1
+  m_RayTracingMode: 2
+  m_RenderingLayerMask: 1
+  m_RendererPriority: 0
+  m_Materials:
+  - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
+  m_StaticBatchInfo:
+    firstSubMesh: 0
+    subMeshCount: 0
+  m_StaticBatchRoot: {fileID: 0}
+  m_ProbeAnchor: {fileID: 0}
+  m_LightProbeVolumeOverride: {fileID: 0}
+  m_ScaleInLightmap: 1
+  m_ReceiveGI: 1
+  m_PreserveUVs: 0
+  m_IgnoreNormalsForChartDetection: 0
+  m_ImportantGI: 0
+  m_StitchLightmapSeams: 1
+  m_SelectedEditorRenderState: 3
+  m_MinimumChartSize: 4
+  m_AutoUVMaxDistance: 0.5
+  m_AutoUVMaxAngle: 89
+  m_LightmapParameters: {fileID: 0}
+  m_SortingLayerID: 0
+  m_SortingLayer: 0
+  m_SortingOrder: 0
+--- !u!33 &351241253
+MeshFilter:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 351241250}
+  m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
+--- !u!4 &351241254
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 351241250}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 35, y: 0.5, z: 0.5}
+  m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_RootOrder: 16
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
 --- !u!1 &360616009
 GameObject:
   m_ObjectHideFlags: 0
@@ -14668,7 +14761,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1295373001}
-  m_Enabled: 1
+  m_Enabled: 0
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 568ed49b4b8006b4fa310cf199aece90, type: 3}
   m_Name: 
@@ -14707,7 +14800,7 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 4fc82bce38e12654e8a9b827cccab15f, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  interactable: 1
+  interactable: 0
   legend: {fileID: 1981258667}
 --- !u!114 &1295373008
 MonoBehaviour:
@@ -14716,7 +14809,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1295373001}
-  m_Enabled: 0
+  m_Enabled: 1
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 227613f03a19cc9488c2f36c25f6c116, type: 3}
   m_Name: 
@@ -22358,6 +22451,7 @@ GameObject:
   - component: {fileID: 2070248952}
   - component: {fileID: 2070248954}
   - component: {fileID: 2070248956}
+  - component: {fileID: 2070248958}
   m_Layer: 0
   m_Name: 2019
   m_TagString: 2019
@@ -22464,7 +22558,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2070248948}
-  m_Enabled: 0
+  m_Enabled: 1
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 53868b5ff78c70644a8569e9382640a9, type: 3}
   m_Name: 
@@ -22478,7 +22572,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2070248948}
-  m_Enabled: 1
+  m_Enabled: 0
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 2354d50fe89f7164587e0edb796d81ce, type: 3}
   m_Name: 
@@ -22510,7 +22604,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 2070248948}
-  m_Enabled: 1
+  m_Enabled: 0
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: edb15c177d3c52140a9d8eb65de61a65, type: 3}
   m_Name: 
@@ -22519,10 +22613,27 @@ MonoBehaviour:
   waypointsList: []
   wanderTimer: []
   targetScattering: 2
-  leaveTimer: 20
+  leaveTimer: 100
   leavePosition: {x: 11, y: 0.5, z: 15}
   ignoreThief: 0
   globalTimer: 0
+--- !u!114 &2070248958
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 2070248948}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 3d37e36cd8c5bcf4fb9ba88f0470112b, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  rewind: 0
+  pause: 0
+  play: 0
+  slider: {fileID: 1594303656}
+  thickness: 0.1
 --- !u!1 &2071883079 stripped
 GameObject:
   m_CorrespondingSourceObject: {fileID: 8716330276743338538, guid: 968d356209aa0774eaf076909046744e,