Skip to content

Commit

Permalink
Add AirQuality viz and Data Label
Browse files Browse the repository at this point in the history
  • Loading branch information
vorg committed Feb 24, 2017
1 parent ed41296 commit 68fa23c
Show file tree
Hide file tree
Showing 44 changed files with 250 additions and 27 deletions.
Binary file modified unity/PointCloudViz/Assets/Day02.unity
Binary file not shown.
Binary file added unity/PointCloudViz/Assets/Day03.unity
Binary file not shown.
8 changes: 8 additions & 0 deletions unity/PointCloudViz/Assets/Day03.unity.meta

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

Binary file not shown.
8 changes: 8 additions & 0 deletions unity/PointCloudViz/Assets/Materials/CubeMaterial.mat.meta

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

Binary file not shown.
8 changes: 8 additions & 0 deletions unity/PointCloudViz/Assets/Materials/Highlight.mat.meta

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

Binary file not shown.

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

Binary file added unity/PointCloudViz/Assets/Materials/pm2.mat
Binary file not shown.
8 changes: 8 additions & 0 deletions unity/PointCloudViz/Assets/Materials/pm2.mat.meta

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

Binary file modified unity/PointCloudViz/Assets/Resources/Center.mat
Binary file not shown.
32 changes: 32 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/AirQuality.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;

public class AirQuality : MonoBehaviour {

public string token;
public string stationId;
public string property;

// Use this for initialization
IEnumerator Start () {
Debug.Log("LoadData.Loading data");
WWW w = new WWW("http://api.waqi.info/feed/@" + stationId + "/?token=" + token);
yield return w;

JsonData json = JsonMapper.ToObject(w.text);
string name = (string)json["data"]["city"]["name"];
Debug.Log("LoadData.name " + name);

float value = float.Parse(json["data"]["iaqi"][property]["v"].ToString());
Vector3 scale = this.transform.localScale;
scale.y *= value;
this.transform.localScale = scale;
}

// Update is called once per frame
void Update () {

}
}
12 changes: 12 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/AirQuality.cs.meta

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

6 changes: 3 additions & 3 deletions unity/PointCloudViz/Assets/Scripts/CatmullRom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct DistanceResult {


public class Vector3CatmullRomSpline {
private List<Vector3> values;
public List<Vector3> values;
//have length for each segment, last ratio is 0
private List<float> lengths;
//starts with 0 and ends with 1
Expand Down Expand Up @@ -82,8 +82,8 @@ public void Precalc() {
}
lengths.Add(length);
totalLength += length;
//Debug.Log("Segment i:" + i + " length:" + length + " t:" + t + " len:" + (values[i+1]-values[i]).magnitude);
}
//Debug.Log("Segment i:" + i + " length:" + length + " t:" + t + " len:" + (values[i+1]-values[i]).magnitude + " " + values[i].ToString());
}
//last segment is 0, adding for easier ratio calculations
lengths.Add(0);

Expand Down
61 changes: 61 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/DataLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;

[ExecuteInEditMode]
public class DataLabel : MonoBehaviour {
[TextArea]
public string data;

public float animationSpeed = 1.0f;

private string[] values;
private float valueIndex = 0;
private string label = "";

// Use this for initialization
void Start () {
try {
this.values = this.data.Split(new Char[] {'\n'});
} catch (Exception e) {
this.data = "" + e;
}
}

// Update is called once per frame
void Update () {
if (values == null || values.Length == 0) return;

int currIdx = (int)Mathf.Floor(this.valueIndex);

currIdx %= this.values.Length;

this.label = this.values[currIdx];
this.valueIndex += Time.deltaTime * animationSpeed;
if (this.valueIndex > this.values.Length) {
this.valueIndex -= this.values.Length;
}
}

void OnSceneGUI () {
Handles.BeginGUI();

//GUILayout.Window(2, new Rect(10, 0, 100, 100), (id)=> {
// Content of window here
GUILayout.Button("A Button");
//}, "Title");

Handles.EndGUI();
}

void OnGUI () {
GUI.color = Color.white;
//GUI.backgroundColor = Color.white;
GUI.Button (new Rect (25, 25, 100, 30), this.label);
}



}
12 changes: 12 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/DataLabel.cs.meta

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

27 changes: 24 additions & 3 deletions unity/PointCloudViz/Assets/Scripts/DataStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class DataStream : MonoBehaviour
private Vector3 initialScale;

Vector3CatmullRomSpline positionSpline;
float[] radiusSpline;
float[] alphaSpline;

public Vector3CatmullRomSpline Spline {
get { return positionSpline; }
Expand Down Expand Up @@ -78,13 +80,21 @@ void InitSpline ()

nodes = new List<DataStreamNode> ();
positionSpline = new Vector3CatmullRomSpline ();

List<float> radiusSplineList = new List<float> ();
List<float> alphaSplineList = new List<float> ();

DataStreamNode node = first;
while (node != null) {
Debug.Log("Add add add");
nodes.Add (node);
positionSpline.Add (node.transform.position);
radiusSplineList.Add(node.radius);
alphaSplineList.Add(node.alpha);
node = node.next;
}
radiusSpline = radiusSplineList.ToArray();
alphaSpline = alphaSplineList.ToArray();

}

void InitParticles ()
Expand Down Expand Up @@ -140,7 +150,16 @@ void Update ()
particleData [i].prevPosition = positionSpline.GetPosition (particleData [i].t);
}
Vector3 positionOnCurve = positionSpline.GetPosition (particleData [i].t);
Vector3 positionOnSurface = GetPositionOnSurface (particleData [i].t, particleData [i].angle, Radius * particleData [i].r);
float tlen = particleData [i].t * radiusSpline.Length;
int ri = (int)Mathf.Floor(tlen);
float ra = radiusSpline[ri];
float rb = radiusSpline[Math.Min(ri + 1, radiusSpline.Length - 1)];
float r = this.Radius * Mathf.Lerp(ra, rb, tlen - ri);
float aa = alphaSpline[ri];
float ab = alphaSpline[Math.Min(ri + 1, alphaSpline.Length - 1)];
float a = Mathf.Lerp(aa, ab, tlen - ri);

Vector3 positionOnSurface = GetPositionOnSurface (particleData [i].t, particleData [i].angle, r * particleData [i].r);
Vector3 normal = (positionOnSurface - positionOnCurve).normalized;
//float d = 0.25f + 0.75f*Mathf.Max(0.0f, Vector3.Dot(normal, lightPos)); //that's the proper version
//float d = 0.5f + 0.5f * Vector3.Dot (normal, lightPos); //this looks cooler
Expand All @@ -154,7 +173,9 @@ void Update ()
// } else if (particleData [i].t > 0.8f) {
// a = 1.0f - (particleData [i].t - 0.8f) / 0.2f;
// }
particles [i].startColor = ParticleColor;
Color color = ParticleColor;
color.a = a;
particles [i].startColor = color;
particles [i].startSize = (i < particles.Length * value) ? ParticleSize : 0;
particleData [i].angle += 0.5f * Time.deltaTime;
particleData [i].prevPosition = particles [i].position;
Expand Down
3 changes: 2 additions & 1 deletion unity/PointCloudViz/Assets/Scripts/DataStreamNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class DataStreamNode : MonoBehaviour {
/// <summary>
/// radius of spline at this position
/// </summary>
public float radius = 1.0f;
public float radius = 1.0f;
public float alpha = 1.0f;

/// <summary>
/// Is this the first node in the spline?
Expand Down
Binary file added unity/PointCloudViz/Assets/Scripts/LitJson.dll
Binary file not shown.
25 changes: 25 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/LitJson.dll.meta

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

14 changes: 7 additions & 7 deletions unity/PointCloudViz/Assets/Scripts/OpenStreetMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public WWW loadTileImage(int xOffset, int yOffset) {
int tileX = x + xOffset;
int tileY = y + yOffset;
string url = "https://api.mapbox.com/v4/mapbox.streets/" + zoom + "/" + tileX + "/" + tileY + ".png?access_token=" + accessToken;
Debug.Log("OSM " + url);
//Debug.Log("OSM " + url);
return this.getCachedWWW (url);
}

Expand All @@ -51,7 +51,7 @@ public WWW getCachedWWW (string url)
}
if (System.IO.File.Exists (filePath)) {
string pathforwww = "file://" + loadFilepath;
Debug.Log ("TRYING FROM CACHE " + url + " file " + pathforwww);
//Debug.Log ("TRYING FROM CACHE " + url + " file " + pathforwww);
www = new WWW (pathforwww);
} else {
web = true;
Expand All @@ -68,23 +68,23 @@ static IEnumerator doLoad (WWW www, string filePath, bool web)
if (www.error == null) {
if (web) {
//System.IO.Directory.GetFiles
Debug.Log ("SAVING DOWNLOAD " + www.url + " to " + filePath);
//Debug.Log ("SAVING DOWNLOAD " + www.url + " to " + filePath);
// string fullPath = filePath;
File.WriteAllBytes (filePath, www.bytes);
Debug.Log ("SAVING DONE " + www.url + " to " + filePath);
//Debug.Log ("SAVING DONE " + www.url + " to " + filePath);
//Debug.Log("FILE ATTRIBUTES " + File.GetAttributes(filePath));
//if (File.Exists(fullPath))
// {
// Debug.Log("File.Exists " + fullPath);
// }
} else {
Debug.Log ("SUCCESS CACHE LOAD OF " + www.url);
//Debug.Log ("SUCCESS CACHE LOAD OF " + www.url);
}
} else {
if (!web) {
File.Delete (filePath);
}
Debug.Log ("WWW ERROR " + www.error);
//Debug.Log ("WWW ERROR " + www.error);
}
}

Expand Down Expand Up @@ -133,7 +133,7 @@ IEnumerator Start () {
float planeSize = 10; // default Unity plane is 10x10
float scale = this.TileSizeInMeters() / (planeSize);

Debug.Log("Tile size " + this.TileSizeInMeters() + " radius: " + radius);
//Debug.Log("Tile size " + this.TileSizeInMeters() + " radius: " + radius);

for (int i = -radius; i <= radius; i++) {
for (int k = -radius; k <= radius; k++) {
Expand Down
16 changes: 16 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/Replicator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Replicator : MonoBehaviour {

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
}
12 changes: 12 additions & 0 deletions unity/PointCloudViz/Assets/Scripts/Replicator.cs.meta

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

Binary file modified unity/PointCloudViz/Library/CurrentLayout.dwlt
Binary file not shown.
Binary file modified unity/PointCloudViz/Library/CurrentMaximizeLayout.dwlt
Binary file not shown.
Binary file modified unity/PointCloudViz/Library/InspectorExpandedItems.asset
Binary file not shown.
2 changes: 1 addition & 1 deletion unity/PointCloudViz/Library/LastSceneManagerSetup.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sceneSetups:
- path: Assets/Day02.unity
- path: Assets/Day02_final.unity
isLoaded: 1
isActive: 1
Binary file not shown.
Binary file not shown.
Binary file modified unity/PointCloudViz/Library/assetDatabase3
Binary file not shown.
Binary file modified unity/PointCloudViz/Library/expandedItems
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
Base path: /Applications/Unity/Unity.app/Contents
Cmd: getPlatforms
Cmd: compileSnippet
api=15 type=0 insize=1020 outsize=832 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Cmd: compileSnippet
api=15 type=1 insize=1020 outsize=0 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Cmd: compileSnippet
api=15 type=0 insize=1907 outsize=2520 kw=SOFTPARTICLES_ON pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Cmd: compileSnippet
api=15 type=1 insize=1907 outsize=0 kw=SOFTPARTICLES_ON pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Cmd: compileSnippet
api=15 type=0 insize=1907 outsize=1265 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Cmd: compileSnippet
api=15 type=1 insize=1907 outsize=0 kw= pd=UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP UNITY_COLORSPACE_GAMMA ok=1
Binary file not shown.
Binary file modified unity/PointCloudViz/Temp/__Backupscenes/0.backup
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/Mono.Cecil.Mdb.dll
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/UnityEditor.iOS.Extensions.Xcode.dll
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/UnityEditor.iOS.Extensions.Xcode.xml
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/LitJson.dll
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/Unity.CecilTools.dll
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/Mono.Cecil.Pdb.dll
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/Mono.Cecil.Mdb.dll
/Users/vorg/Workspace/var-bartlett-point-cloud/var-bartlett-point-cloud/unity/PointCloudViz/Temp/bin/Debug/LitJson.dll
Binary file modified unity/PointCloudViz/obj/Debug/Assembly-CSharp-firstpass.dll
Binary file not shown.
Binary file modified unity/PointCloudViz/obj/Debug/Assembly-CSharp-firstpass.dll.mdb
Binary file not shown.
Loading

0 comments on commit 68fa23c

Please sign in to comment.