Skip to content

Commit

Permalink
Rewrote triangles generation to be more flexible; implemented SetTime…
Browse files Browse the repository at this point in the history
…Window() of TimePath to allow for per-path control of display based on time.
  • Loading branch information
FHomps committed Jan 9, 2019
1 parent db6850f commit 59e7c69
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 53 deletions.
16 changes: 12 additions & 4 deletions ReViVD_unity_project/Assets/AirTrafficVisualization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion ReViVD_unity_project/Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions ReViVD_unity_project/Assets/TimeVizualisation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;

public abstract class TimeVisualization : Visualization {
protected abstract float InterpretTime(string word);

public abstract IReadOnlyList<TimePath> PathsAsTime { get; }
}

public abstract class TimePath : Path {
public abstract IReadOnlyList<TimeAtom> 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;
}
11 changes: 11 additions & 0 deletions ReViVD_unity_project/Assets/TimeVizualisation.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 40 additions & 48 deletions ReViVD_unity_project/Assets/Visualization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> trianglesL = new List<int>();
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<int, float> 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();
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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<TimePath> PathsAsTime { get; }
}

public abstract class TimePath : Path {
public abstract IReadOnlyList<TimeAtom> AtomsAsTime { get; }
}

public abstract class TimeAtom : Atom {
public float time;
public bool shouldDisplay = true;
}

0 comments on commit 59e7c69

Please sign in to comment.