Permalink
Browse files

Project 2 Examples

  • Loading branch information...
1 parent 8fd9e51 commit a452e9900fce3769f3ce9ec602512c3b9004a207 @obviousjim committed Feb 1, 2012
Showing with 1,093 additions and 1 deletion.
  1. +3 −1 .gitignore
  2. +94 −0 Assets/Plugins/OSC.NET/jsOSCBundle.cs
  3. +126 −0 Assets/Plugins/OSC.NET/jsOSCMessage.cs
  4. +166 −0 Assets/Plugins/OSC.NET/jsOSCPacket.cs
  5. +52 −0 Assets/Plugins/OSC.NET/jsOSCReceiver.cs
  6. +55 −0 Assets/Plugins/OSC.NET/jsOSCTransmitter.cs
  7. +52 −0 Assets/Plugins/TSPS/OpenTSPSPerson.cs
  8. +140 −0 Assets/Plugins/TSPS/OpenTSPSUnityListener.cs
  9. +99 −0 Assets/Plugins/UnityOSC/UnityOSCReceiver.cs
  10. BIN Assets/Project2BAccelerometer.unity
  11. BIN Assets/Resources/Images/background.png
  12. BIN Assets/Resources/Materials/Canvas.mat
  13. BIN Assets/Resources/Materials/Floor Material.mat
  14. BIN Assets/Resources/Materials/PersonMaterial1.mat
  15. BIN Assets/Resources/Materials/PersonMaterial2.mat
  16. BIN Assets/Resources/Materials/PersonMaterial3.mat
  17. BIN Assets/Resources/Materials/PersonMaterial4.mat
  18. BIN Assets/Resources/Materials/PersonMaterial5.mat
  19. BIN Assets/Resources/Prefabs/OpenTSPSReceiver.prefab
  20. BIN Assets/{ → Resources/Scenes}/Project1Example.unity
  21. BIN Assets/Resources/Scenes/Project2ASineCubes.unity
  22. BIN Assets/Resources/Scenes/Project2BAccelerometer.unity
  23. BIN Assets/Resources/Scenes/Project2COpenTSPSReceiver.unity
  24. +11 −0 Assets/Resources/Scripts/Bootstrap.js
  25. +58 −0 Assets/Resources/Scripts/OscelerometerReceiver.js
  26. +12 −0 Assets/Resources/Scripts/SinWave.js
  27. +85 −0 Assets/Resources/Scripts/csOpenTSPSListener.cs
  28. +41 −0 Assets/Resources/Scripts/jsOpenTSPSListener.js
  29. +42 −0 Assets/Resources/Scripts/jsOpenTSPSListener_particleTest.js
  30. BIN Library/AssetServerCacheV3
  31. BIN Library/InspectorExpandedItems.asset
  32. BIN Library/assetDatabase3
  33. BIN Library/guidmapper
  34. BIN Library/metadata/07/0722023f905554fd09caa594c6c5441a
  35. BIN Library/metadata/08/0812b5983811d462b98186190636d254
  36. BIN Library/metadata/0b/0b918cc8acf0941e8a99fa42f7586b7c
  37. BIN Library/metadata/14/14a9d2938704c47119a414487177173a
  38. BIN Library/metadata/17/17584a0f2db8643719af47e3cc3cfe27
  39. BIN Library/metadata/19/199e1fef3184b4f33a9a5a50e7954f35
  40. BIN Library/metadata/29/29ab53d882a3a4726a4d9adaec43361a
  41. BIN Library/metadata/33/33c0de84708de4506b71772127e18402
  42. BIN Library/metadata/3a/3ac267447d7704915a877880665cc07c
  43. BIN Library/metadata/46/46ece44ec0b18417c9b01acb3bdebc6d
  44. BIN Library/metadata/47/47db0b941ae8d4aadb9c03af8c8c23d8
  45. BIN Library/metadata/55/551980c67ad4c47cdbb677bbb730b6cf
  46. BIN Library/metadata/59/593d06f792b1940ff867a18edc0ff778
  47. BIN Library/metadata/62/6210acf9d8c3f40f28fc57b44714dd0a
  48. BIN Library/metadata/65/657b8bdabce83440c8cd4ee30ea4d941
  49. BIN Library/metadata/6a/6ae42d8170a5842de938caf91218d9f8
  50. BIN Library/metadata/70/70ae4e425e5864c8fa951dffc7e8e9a2
  51. BIN Library/metadata/71/716d82244346b4252bd9fa5c4b649d12
  52. BIN Library/metadata/77/7714d76630b584449a289f3a112d253c
  53. BIN Library/metadata/7f/7f7b7778f037e474ca19e6bf6ca2994d
  54. BIN Library/metadata/80/801e9392158bd49ac960cfefd909b264
  55. BIN Library/metadata/89/89f365ac610e44058b71e2a483dddef1
  56. BIN Library/metadata/99/995d5c1c9d09943ba8b5835a49373d2a
  57. BIN Library/metadata/a7/a7dd92e39d3e54c97b4be026824ecd9e
  58. BIN Library/metadata/af/af4a9dd599ed74fcf8a739515a74be3b
  59. BIN Library/metadata/b2/b2216b727921b4cbe82b7a30ffac3e66
  60. BIN Library/metadata/bd/bd665a833f37349c79563f6ecd5dcca1
  61. BIN Library/metadata/be/bee6a3b687da048a8b60f815c5fe681a
  62. BIN Library/metadata/c0/c08f2297050f246b7b720d2a046cc9fd
  63. BIN Library/metadata/c7/c75993c9929c749ddb5e2cd9d56ad68a
  64. BIN Library/metadata/c9/c9cd58320ef64441691a61b3d7640bfa
  65. BIN Library/metadata/ca/ca89acbdf02cd445f9bf3c94f598e70c
  66. BIN Library/metadata/d7/d73beb6a302364b44b20f6fda7809971
  67. BIN Library/metadata/d8/d87b67f17d1b24294a80dd9ffba14300
  68. BIN Library/metadata/db/db19309c897064246abbd8deb1348158
  69. BIN Library/metadata/df/dfba48c2f2fea48b58ba1774a7b5f138
  70. BIN Library/metadata/e2/e297540dcf5f341ed95ccd16bdf4df10
  71. BIN Library/metadata/e7/e7d72a99411da4d48ab8bf5a827945aa
  72. BIN Library/metadata/eb/eb6e10dff9f514759be66f421e410678
  73. BIN Library/metadata/f7/f7a32129fcc6e42fab433b89ba254292
  74. BIN Library/metadata/ff/ff9719f2a72624757a8af0366ab316bf
  75. +12 −0 Utilities/accelerometer_for_unity/accelerometer_for_unity.ino
  76. +45 −0 Utilities/serial_osc_bridge/serial_osc_bridge.pde
View
@@ -14,4 +14,6 @@ Library/assetDatabase3
!Library/guidmapper
!Library/unity default resources
!Library/unity editor resources
-!Library/metadata/
+!Library/metadata/
+
+!Utilities
@@ -0,0 +1,94 @@
+using System;
+using System.Collections;
+
+public class jsOSCBundle {}
+
+namespace OSC.NET
+{
+ /// <summary>
+ /// OSCBundle
+ /// </summary>
+ public class OSCBundle : OSCPacket
+ {
+ protected const string BUNDLE = "#bundle";
+ private long timestamp = 0;
+
+ public OSCBundle(long ts)
+ {
+ this.address = BUNDLE;
+ this.timestamp = ts;
+ }
+
+ public OSCBundle()
+ {
+ this.address = BUNDLE;
+ this.timestamp = 0;
+ }
+
+ override protected void pack()
+ {
+ ArrayList data = new ArrayList();
+
+ addBytes(data, packString(this.Address));
+ padNull(data);
+ addBytes(data, packLong(0)); // TODO
+
+ foreach(object value in this.Values)
+ {
+ if(value is OSCPacket)
+ {
+ byte[] bs = ((OSCPacket)value).BinaryData;
+ addBytes(data, packInt(bs.Length));
+ addBytes(data, bs);
+ }
+ else
+ {
+ // TODO
+ }
+ }
+
+ this.binaryData = (byte[])data.ToArray(typeof(byte));
+ }
+
+ public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
+ {
+
+ string address = unpackString(bytes, ref start);
+ //Console.WriteLine("bundle: " + address);
+ if(!address.Equals(BUNDLE)) return null; // TODO
+
+ long timestamp = unpackLong(bytes, ref start);
+ OSCBundle bundle = new OSCBundle(timestamp);
+
+ while(start < end)
+ {
+ int length = unpackInt(bytes, ref start);
+ int sub_end = start + length;
+ //Console.WriteLine(bytes.Length +" "+ start+" "+length+" "+sub_end);
+ bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end));
+
+ }
+
+ return bundle;
+ }
+
+ public long getTimeStamp() {
+ return timestamp;
+ }
+
+ override public void Append(object value)
+ {
+ if( value is OSCPacket)
+ {
+ values.Add(value);
+ }
+ else
+ {
+ // TODO: exception
+ }
+ }
+
+ override public bool IsBundle() { return true; }
+ }
+}
+
@@ -0,0 +1,126 @@
+using System;
+using System.Collections;
+using System.Text;
+
+public class jsOSCMessage {}
+
+namespace OSC.NET
+{
+ /// <summary>
+ /// OSCMessage
+ /// </summary>
+ public class OSCMessage : OSCPacket
+ {
+ protected const char INTEGER = 'i';
+ protected const char FLOAT = 'f';
+ protected const char LONG = 'h';
+ protected const char DOUBLE = 'd';
+ protected const char STRING = 's';
+ protected const char SYMBOL = 'S';
+ //protected const char BLOB = 'b';
+ //protected const char ALL = '*';
+
+ public OSCMessage(string address)
+ {
+ this.typeTag = ",";
+ this.Address = address;
+ }
+ public OSCMessage(string address, object value)
+ {
+ this.typeTag = ",";
+ this.Address = address;
+ Append(value);
+ }
+
+ override protected void pack()
+ {
+ ArrayList data = new ArrayList();
+
+ addBytes(data, packString(this.address));
+ padNull(data);
+ addBytes(data, packString(this.typeTag));
+ padNull(data);
+
+ foreach(object value in this.Values)
+ {
+ if(value is int) addBytes(data, packInt((int)value));
+ else if(value is long) addBytes(data, packLong((long)value));
+ else if(value is float) addBytes(data, packFloat((float)value));
+ else if(value is double) addBytes(data, packDouble((double)value));
+ else if(value is string)
+ {
+ addBytes(data, packString((string)value));
+ padNull(data);
+ }
+ else
+ {
+ // TODO
+ }
+ }
+
+ this.binaryData = (byte[])data.ToArray(typeof(byte));
+ }
+
+
+ public static OSCMessage Unpack(byte[] bytes, ref int start)
+ {
+ string address = unpackString(bytes, ref start);
+ //Console.WriteLine("address: " + address);
+ OSCMessage msg = new OSCMessage(address);
+
+ char[] tags = unpackString(bytes, ref start).ToCharArray();
+ //Console.WriteLine("tags: " + new string(tags));
+ foreach(char tag in tags)
+ {
+ //Console.WriteLine("tag: " + tag + " @ "+start);
+ if(tag == ',') continue;
+ else if(tag == INTEGER) msg.Append(unpackInt(bytes, ref start));
+ else if(tag == LONG) msg.Append(unpackLong(bytes, ref start));
+ else if(tag == DOUBLE) msg.Append(unpackDouble(bytes, ref start));
+ else if(tag == FLOAT) msg.Append(unpackFloat(bytes, ref start));
+ else if(tag == STRING || tag == SYMBOL) msg.Append(unpackString(bytes, ref start));
+ else Console.WriteLine("unknown tag: "+tag);
+ }
+
+ return msg;
+ }
+
+ override public void Append(object value)
+ {
+ if(value is int)
+ {
+ AppendTag(INTEGER);
+ }
+ else if(value is long)
+ {
+ AppendTag(LONG);
+ }
+ else if(value is float)
+ {
+ AppendTag(FLOAT);
+ }
+ else if(value is double)
+ {
+ AppendTag(DOUBLE);
+ }
+ else if(value is string)
+ {
+ AppendTag(STRING);
+ }
+ else
+ {
+ // TODO: exception
+ }
+ values.Add(value);
+ }
+
+ protected string typeTag;
+ protected void AppendTag(char type)
+ {
+ typeTag += type;
+ }
+ public string TypeTag {get {return typeTag;}}
+
+ override public bool IsBundle() { return false; }
+ }
+}
@@ -0,0 +1,166 @@
+using System;
+using System.Collections;
+using System.Text;
+
+public class jsOSCPacket {}
+
+namespace OSC.NET
+{
+ /// <summary>
+ /// OSCPacket
+ /// </summary>
+ abstract public class OSCPacket
+ {
+ public OSCPacket()
+ {
+ this.values = new ArrayList();
+ }
+
+ protected static void addBytes(ArrayList data, byte[] bytes)
+ {
+ foreach(byte b in bytes)
+ {
+ data.Add(b);
+ }
+ }
+
+ protected static void padNull(ArrayList data)
+ {
+ byte zero = 0;
+ int pad = 4 - (data.Count % 4);
+ for (int i = 0; i < pad; i++)
+ {
+ data.Add(zero);
+ }
+ }
+
+ protected static byte[] swapEndian(byte[] data)
+ {
+ byte[] swapped = new byte[data.Length];
+ for(int i = data.Length - 1, j = 0 ; i >= 0 ; i--, j++)
+ {
+ swapped[j] = data[i];
+ }
+ return swapped;
+ }
+
+ protected static byte[] packInt(int value)
+ {
+ byte[] data = BitConverter.GetBytes(value);
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return data;
+ }
+
+ protected static byte[] packLong(long value)
+ {
+ byte[] data = BitConverter.GetBytes(value);
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return data;
+ }
+
+ protected static byte[] packFloat(float value)
+ {
+ byte[] data = BitConverter.GetBytes(value);
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return data;
+ }
+
+ protected static byte[] packDouble(double value)
+ {
+ byte[] data = BitConverter.GetBytes(value);
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return data;
+ }
+
+ protected static byte[] packString(string value)
+ {
+ return System.Text.Encoding.ASCII.GetBytes(value);
+ }
+
+ abstract protected void pack();
+ protected byte[] binaryData;
+ public byte[] BinaryData
+ {
+ get
+ {
+ pack();
+ return binaryData;
+ }
+ }
+
+ protected static int unpackInt(byte[] bytes, ref int start)
+ {
+ byte[] data = new byte[4];
+ for(int i = 0 ; i < 4 ; i++, start++) data[i] = bytes[start];
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return BitConverter.ToInt32(data, 0);
+ }
+
+ protected static long unpackLong(byte[] bytes, ref int start)
+ {
+ byte[] data = new byte[8];
+ for(int i = 0 ; i < 8 ; i++, start++) data[i] = bytes[start];
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return BitConverter.ToInt64(data, 0);
+ }
+
+ protected static float unpackFloat(byte[] bytes, ref int start)
+ {
+ byte[] data = new byte[4];
+ for(int i = 0 ; i < 4 ; i++, start++) data[i] = bytes[start];
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return BitConverter.ToSingle(data, 0);
+ }
+
+ protected static double unpackDouble(byte[] bytes, ref int start)
+ {
+ byte[] data = new byte[8];
+ for(int i = 0 ; i < 8 ; i++, start++) data[i] = bytes[start];
+ if(BitConverter.IsLittleEndian) data = swapEndian(data);
+ return BitConverter.ToDouble(data, 0);
+ }
+
+ protected static string unpackString(byte[] bytes, ref int start)
+ {
+ int count= 0;
+ for(int index = start ; bytes[index] != 0 ; index++, count++) ;
+ string s = Encoding.ASCII.GetString(bytes, start, count);
+ start += count+1;
+ start = (start + 3) / 4 * 4;
+ return s;
+ }
+
+ public static OSCPacket Unpack(byte[] bytes)
+ {
+ int start = 0;
+ return Unpack(bytes, ref start, bytes.Length);
+ }
+
+ public static OSCPacket Unpack(byte[] bytes, ref int start, int end)
+ {
+ if(bytes[start] == '#') return OSCBundle.Unpack(bytes, ref start, end);
+ else return OSCMessage.Unpack(bytes, ref start);
+ }
+
+
+ protected string address;
+ public string Address
+ {
+ get { return address; }
+ set
+ {
+ // TODO: validate
+ address = value;
+ }
+ }
+
+ protected ArrayList values;
+ public ArrayList Values
+ {
+ get { return (ArrayList)values.Clone(); }
+ }
+ abstract public void Append(object value);
+
+ abstract public bool IsBundle();
+ }
+}
Oops, something went wrong.

0 comments on commit a452e99

Please sign in to comment.