Sunday, September 23, 2012

3D Real Time Twitter Visualization

Woo! Finally finished v0.1 of my Twitter visualization. 



The goal of the visualizer was to provide a different experience for viewing the tons and tons and tons of random stuff that's poured of Twitter's firehose. Twitter only allows access to 1% of all real-time tweets from all over the world and even with this limitation, there's about 30 - 50 tweets per second coming in and these tweets are displayed as text and thrown about this empty universe.

Here's a screen cast of it. Soon as I get a more powerful laptop, I'll be able to run the visualizer and a screencast and get a nice frame rate. But for now, this will have to do just so you get the effect. 




In the near future, I'll offer downloadable versions of the visualizer. Maybe I'll be able to throw some music in there too and make a really immersive visualization.

Part of the work I had to do was figure out a way to get tweets into Unity. So I found a nice project on GitHub and forked it to provide a nice C# API to use in Unity. 

Unfortunately, the C# library I wrote uses HttpWebRequest which doesn't work right in Unity. Within the Editor, it'll work great. But as soon as I build the game for OSX (10.6.8), I get an ArgumentException "Not supported" when calling WebRequest.Create(url). Further research online shows this is a bug in Unity builds for OSX.

This led me to go on another chase for another C# implementation of an HTTP GET Request. I found one project called UniWeb but that's $55 and doesn't provide support for HTTP streaming. However, if you don't require HTTP streaming, and you need Unity support, this project looks great. 

I ended up finding UnityWeb (which I believe has something to do with UniWeb but UnityWeb has an MIT license) which kind of fit my needs. It's a raw implementation of an HTTP request over TCP. Very low level. I ended up modifying most of it to stream the responses from Twitters servers correctly. As it stands, it only works for the Twitter Streaming API (no filter support either and no oAuth support yet). If I ever get around to making a very reusable (non WebRequest) library for C#, I'll throw it on GitHub.

After mucking around with the low level TCP details, I finally managed to get Unity to build my OSX binary correctly and finally got the screen cast!

I'd like to make a build for the Web Player, but it's currently a pain in the ass to work around the security sandbox for Unity. What I might end up doing is getting a web server and writing a server-side script to connect to the Twitter stream and forward all the JSON messages to whatever Web Player is requesting it. This will let me place a crossdomain.xml file on my web server and let everyone get a real juicy visualization.


No comments:

Post a Comment