With my Mathematics coursework, metamorphosis to 31 years old and fixing my bicycle completed I thought I would share some R&D I was doing a little while back.

First of all though, I was spoilt all weekend by my wonderful girlfriend for my birthday. Went to Gaucho’s for the first time, which I have to say was bloody awesome! The steak was divine…

20170227_174438000_iOS.jpg
My Cheeky “This food looks great” Face

Then spent the rest of the evening getting drunk on some very good quality rum at the o2…

20170225_225543862_iOS.jpg
MmmmMMM… Rum!!!

Then topping it off by going to the Star Wars Identities Exhibition the next day where I found my Star Wars self…

20170226_142103000_iOS.jpg
About my height to be fair…

Admittedly, I was really hoping for this guy…

20170226_134215273_iOS.jpg
Again, about my height…

But, I won’t let that dissapoint me, it was a great Exhibition and I definitely recommend it. And most importantly, thank you Rachel for an amazing weekend! Anyway, back to the article…

A long time ago in a galaxy far, far away…

I was working on a bid for a stadium. Using Grasshopper (as I prefer to model in GH rather than Dynamo…Sorry if you are the John McClane of Dynamo, but GH is better in my opinion for geometry, far less complications that blow up Revit).

We had this design that we weren’t too sure about, it was hard to get a feel for the Geometry. It wasn’t complicated in the slightest, but looking at the 3D model on screen just felt a little short of what we imagined it to look like. So, that got me thinking…What if we could view this in VR? Well, these days that isn’t so tricky, there are a few apps that let you push out 3D Panoramic Photos and send to Gaming Engine based VR viewers, but none that I know of that are Parametric.

With a challenge in mind, I decided to give it a go. I had already been doing some work in Unity, which is by far my favourite Gaming Engine as I lean heavily towards C# and had already been testing Revit to Unity workflows. But this was something way different… not a simple drop model in template I made in 5 mins and hit play. This needed some thought and a small but fair amount of programming.

After a lot of messing around and learning (loosely) JSON (JavaScript Object Notation) I managed to create some new components in GH that spit out mesh data. I needed all the mesh of an object to be in the same JArray, so wrote a little class for this and then I could Serialise up to send to Unity as an array of mesh arrays. The reason this is important is that my initial try had me streaming about 90,000+ mesh vertices to unity into one prefab. For anyone who knows Unity, it likes to cap this at about 65,000 vertices. I also wanted to preserve Elements such as beams, columns or roof panels so I could also transmit other info, like Element Material data, Element Name, Element ID.. or whatever really. Another note, from my experience with this project, VR gets a little glitchy when you bloat a prefab like I was and try and optimise cylindrical shapes first as they are very mesh heavy.

Sweet, so I have my GH output, now to deserialise in Unity at runtime. Again, if you have used Unity a bit you will quickly realise that it uses the same .Net version as that of Apollo 13… Just kidding, but it’s still on 2/3.5 framework!!! That’s crazy! This is annoying as you can’t just load in some .Net 4.5 .dll (well, not without some fiddling I understand). So, the JSON parser I was using couldn’t be imported. Thankfully someone out there has made one specifically for Unity and this is called litJSON. I would have had to write my own very poor imitation of a JSON Parser if I hadn’t found this, so thank you very much litJSON, you saved me a very long time indeed.

Deserialising is pretty easy with litJSON and in no time I had built a script to read my JSON mesh data and procedurally build mesh at runtime where all my Model Elements are in their own prefab and have their materials assigned. But, just like Apollo 13, this is all about the return trip. I want to have the user control Grasshopper from VR. Well, I have just gotten to know JSON (sort of) so thought why not just send slider data back and forth. This is exactly what I did, I wrote a script in Grasshopper that Gets and Sets slider and toggle values (Note: this was very hacky and based on a blog post by Executable.IO), then wrote a twin in Unity and now I could just listen to changes an update one or the other.

This of course could be made a great deal better by having the data relayed over a network or via DB instead of a .txt file, but, it works pretty well as it stands. Have a look at the demo below…

In the Demo I haven’t used the stadium but just the basic parabolic cylinder thing that you do when you first learn GH. Other things I haven’t included in the demo are toggles or the Gallery View (where you make the model small enough to sit on a plinth and observe its awesomeness, it seemed silly to do this for this geometry, but the stadium had this feature and looked very nice)

Also, the materials are being assigned by Grasshopper at runtime, but as far as I’m aware, you can’t create materials at runtime, so you need to have a list of materials in Unity and pick from the list. I wrote a quick Component that found all the materials in the Asset Folder and used a drop down selector when serialising the mesh data from GH.

And finally, to get all this to work, you need to start GH via CMD. There is a great post by James Ramsden that shows you how to do this, check him out as he has a shed load of cool hacks. This allows you specify which Rhino and GH file to open and on launching GH we get the handshake we are looking for from Unity and away we go!

What I have learned from this is that when looking at your models in VR you truly get a feel for the Geometry and space. You can see the model in a new perspective and make more critical design decisions. Having the Parametric capabilities only adds to the design experience as you can optioneer (well, if you have set it up in GH first) in Virtual Reality and see the change at a scale of 1:1. This is priceless in my opinion and perhaps the next level of design. Who knows. But what I do know is that it was a very fun R&D project and I hope you guys like it and I’m looking to do something similar with Dynamo at some point.

Advertisement