diff --git a/ReViVD_unity_project/Assets/AirTrafficVisualization.cs b/ReViVD_unity_project/Assets/AirTrafficVisualization.cs index 4ebc80a..2ab860e 100644 --- a/ReViVD_unity_project/Assets/AirTrafficVisualization.cs +++ b/ReViVD_unity_project/Assets/AirTrafficVisualization.cs @@ -52,14 +52,22 @@ private void Start() { if (!LoadFromCSV("data_aviation")) { return; } - for (int i = 0; i < 10; i += 2) { - Paths[60].specialRadii.Add(i, 0.2f); - } - Debug.Log(Paths[60].ID); InitializeRendering(); + + startTime = Time.time; } + private float startTime = 0; + private void Update() { + if (Input.GetMouseButton(0)) { + startTime = Time.time; + } + + foreach (AirTrafficPath p in Paths) { + p.SetTimeWindow((Time.time - startTime) * 60 - 300, (Time.time - startTime) * 60 + 300); + } + UpdateRendering(); } diff --git a/ReViVD_unity_project/Assets/Scenes/SampleScene.unity b/ReViVD_unity_project/Assets/Scenes/SampleScene.unity index 01eb97f..178ce48 100644 --- a/ReViVD_unity_project/Assets/Scenes/SampleScene.unity +++ b/ReViVD_unity_project/Assets/Scenes/SampleScene.unity @@ -394,12 +394,14 @@ MonoBehaviour: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 2015733474} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 82895ded1d8113e469a102efaf3aca4e, type: 3} m_Name: m_EditorClassIdentifier: mainSpeed: 30 + shiftAdd: 100 + maxShift: 1000 camSens: 0.25 AZERTY: 1 --- !u!1 &2039570151 diff --git a/ReViVD_unity_project/Assets/TimeVizualisation.cs b/ReViVD_unity_project/Assets/TimeVizualisation.cs new file mode 100644 index 0000000..cd6446c --- /dev/null +++ b/ReViVD_unity_project/Assets/TimeVizualisation.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; + +public abstract class TimeVisualization : Visualization { + protected abstract float InterpretTime(string word); + + public abstract IReadOnlyList PathsAsTime { get; } +} + +public abstract class TimePath : Path { + public abstract IReadOnlyList AtomsAsTime { get; } + + public void SetTimeWindow(float startTime, float stopTime) { //Met à jour les atomes à afficher en fonction de si leur temps est dans la fenêtre recherchée + bool shouldUpdateTriangles = false; + foreach (TimeAtom a in AtomsAsTime) { + if (a.shouldDisplay != (a.time > startTime && a.time < stopTime)) { + a.shouldDisplay = !a.shouldDisplay; + shouldUpdateTriangles = true; + } + } + if (shouldUpdateTriangles) + GenerateTriangles(); + } +} + +public abstract class TimeAtom : Atom { + public float time; +} \ No newline at end of file diff --git a/ReViVD_unity_project/Assets/TimeVizualisation.cs.meta b/ReViVD_unity_project/Assets/TimeVizualisation.cs.meta new file mode 100644 index 0000000..ab24ddd --- /dev/null +++ b/ReViVD_unity_project/Assets/TimeVizualisation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7f42e027a87071646bc961d03afc816b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ReViVD_unity_project/Assets/Visualization.cs b/ReViVD_unity_project/Assets/Visualization.cs index 1328081..244364d 100644 --- a/ReViVD_unity_project/Assets/Visualization.cs +++ b/ReViVD_unity_project/Assets/Visualization.cs @@ -348,47 +348,54 @@ protected void CleanspecialRadii() { specialRadii.Remove(key); } - public void GenerateMesh() { - mesh.Clear(); + protected void GenerateTriangles() { + int totalAtoms = AtomsAsBase.Count; CleanspecialRadii(); - int AtomCount = AtomsAsBase.Count; - - int specialRadiiBonusTriangles = specialRadii.Count * 12 - - (specialRadii.ContainsKey(0) ? 6 : 0) - - (specialRadii.ContainsKey(AtomCount - 2) ? 6 : 0); - - Vector3[] vertices = new Vector3[AtomCount * 5 - 6]; - Color32[] colors = new Color32[vertices.Length]; - int[] triangles = new int[AtomCount * 12 - 18 + specialRadiiBonusTriangles]; + List trianglesL = new List(); int[] generator = { 0, 2, 1, 1, 2, 3, 2, 5, 4, 3, 4, 6 }; - for (int i = 0; i < triangles.Length - specialRadiiBonusTriangles; i++) { - triangles[i] = generator[i % 12] + 5 * (i / 12); - } + int[] bonusGenerator = { 2, 4, 5, 3, 6, 4 }; - int bonus_i = triangles.Length - specialRadiiBonusTriangles; - int[] bonusGenerator = { 2, 4, 5, 3, 6, 5 }; - foreach (KeyValuePair pair in specialRadii) { - int p = pair.Key; - int start = bonus_i; - if (p != 0) { - while (bonus_i < start + 6) { - triangles[bonus_i] = bonusGenerator[bonus_i - start] + 5 * (p - 1); - bonus_i++; + bool previousWasSpecial = false; + for (int i = 0; i < totalAtoms - 1; i++) { + if (AtomsAsBase[i].shouldDisplay) { + for (int j = 0; j < (i == totalAtoms - 2 ? 6 : 12); j++) { + trianglesL.Add(generator[j] + 5 * i); } - } - if (p != AtomCount - 2) { - while (bonus_i < start + 6) { - triangles[bonus_i] = bonusGenerator[bonus_i - start] + 5 * p; - bonus_i++; + + if (specialRadii.ContainsKey(i)) { + if (!previousWasSpecial && i != 0 && AtomsAsBase[i - 1].shouldDisplay) { + for (int j = 0; j < 6; j++) { + trianglesL.Add(bonusGenerator[j] + 5 * (i - 1)); + } + } + if (i != totalAtoms - 2 && AtomsAsBase[i + 1].shouldDisplay) { + for (int j = 0; j < 6; j++) { + trianglesL.Add(bonusGenerator[j] + 5 * (i)); + } + } + previousWasSpecial = true; } + else + previousWasSpecial = false; } } + mesh.triangles = trianglesL.ToArray(); + } + + public void GenerateMesh() { + mesh.Clear(); + + int AtomCount = AtomsAsBase.Count; + + Vector3[] vertices = new Vector3[AtomCount * 5 - 6]; + Color32[] colors = new Color32[vertices.Length]; + mesh.vertices = vertices; mesh.colors32 = colors; - mesh.triangles = triangles; + GenerateTriangles(); UpdateVertices(); } @@ -407,17 +414,17 @@ public void UpdateVertices(bool forceUpdateAll = false) { Color32 pointColor = Color32.Lerp(new Color32(255, 0, 0, 255), new Color32(0, 0, 255, 255), currentPoint.y / maxHeight); for (int p = 0; p < atomCount - 1; p++) { - if (!AtomsAsBase[p].shouldUpdate && !forceUpdateAll) { + if ((!AtomsAsBase[p].shouldUpdate || !AtomsAsBase[p].shouldDisplay) && !forceUpdateAll) { if (p == 0 || !AtomsAsBase[p - 1].shouldUpdate) { pointColor = Color32.Lerp(new Color32(255, 0, 0, 255), new Color32(0, 0, 255, 255), AtomsAsBase[p + 1].point.y / maxHeight); continue; } } + int i = 5 * p; currentPoint = AtomsAsBase[p].point; nextPoint = AtomsAsBase[p + 1].point; - int i = 5 * p; float radius; if (!specialRadii.TryGetValue(p, out radius)) radius = baseRadius; @@ -437,7 +444,7 @@ public void UpdateVertices(bool forceUpdateAll = false) { colors[i + 2] = pointColor; colors[i + 3] = pointColor; if (p < atomCount - 2) - colors[i+4] = pointColor; + colors[i + 4] = pointColor; } mesh.vertices = vertices; @@ -452,20 +459,5 @@ public abstract class Atom { public Vector3 point; public Path path; public bool shouldUpdate = false; -} - - - -public abstract class TimeVisualization : Visualization { - protected abstract float InterpretTime(string word); - - public abstract IReadOnlyList PathsAsTime { get; } -} - -public abstract class TimePath : Path { - public abstract IReadOnlyList AtomsAsTime { get; } -} - -public abstract class TimeAtom : Atom { - public float time; + public bool shouldDisplay = true; } \ No newline at end of file