Thursday, June 30, 2016

Make Your Own Virtual Reality App for Google Cardboard on iOS

I thought Google Cardboard was neat when I first saw it but a couple days ago I started playing around with creating 3D content for it and I'm blown away with the possibilities. I want to give a survey of some ways 3D content can be experienced in a Cardboard VR app but I'm not going to go super in-depth with any of them because each one is its own endless rabbit hole. The biggest hurdle, especially for making an app for iOS (as opposed to Android) is getting your Unity and XCode environment set up. Once that's working the rest is pure fun and amazement.

Set Up the Environment

If you want to load VR apps on iPhone you have to use a Mac because there's no XCode for Windows. By the way, all of this is free unless you want to distribute your apps to others. For that you need to pay the $100 Apple developer license fee. Keep in mind you're going to fill up around 7 GB of disk space just with Unity, XCode, and iOS development tools. And each project is big, too, around 1 GB. Here's what I did to get started:
  • Download Unity Personal Edition. Unity is basically your environment for putting whatever content you want from other sources together into one world.
  • Follow this excellent tutorial on setting up and running a demo app on an iPhone. I highly recommend this because it will give you an introduction to working with Unity, including how the UI and code work together. Plus you will go through the whole workflow and get used to the multitude of details and steps.
  • The last step will require downloading XCode from the App Store. When you select Build & Run in Unity it opens XCode and "side-loads" the app onto your connected phone. To do the side-loading you have to set up a free developer account with an Apple ID.

Blank Slate

Stationary view or Mobility view? I have stripped down a couple Unity projects to the bare essentials so you can add whatever content from there.
  • Here is a standing view project. In Google Cardboard you will just be able to look around at the world but not move.
  • Here is a view that offers mobility. When you press and hold the button on the Cardboard viewer you will move in the direction you are looking. I had a hard time figuring this out and ended up adapting this project. It uses an older version of Cardboard SDK but nothing I could find in the newer one worked.
So download and unzip one of those and open in Unity. You will have a flat plane with your viewer camera in the center. The "walking" version has all the movement controls and scripts in the VRController object in the hierarchy pane.

Add Some Content

Download it!

There's lots available on the web, just search "collada dae models." I found this just now. Unzip it and drag the folder containing the .dae file and graphics into the Assets pane in Unity.
To add it to your scene, open the model for the folder and drag the .dae file onto the floor. It will often be too big and oriented incorrectly, so you can use the editing controls at the upper left to scale, rotate, and position it where you like, or input your parameters in the inspector on the right. 
I find that some models don't appear with their textures and I have to select individual parts and re-select the correct image files. In this case I was only partially successful.

Scan it

To scan small objects I use the 123D Catch app. You are guided through taking a lot of photos from all angles and it uploads and processes for a while. Go on the website and log in and you will be able to download the mesh package for the scan. Open Meshlab and import the mesh so you can edit out the unwanted parts of the scan. 
I won't go over a whole how-to on Meshlab, but I find the region selection tool 
and the paintbrush selection tool suffice.
After selecting with each I delete the regions with the face and vertice delete button, 
and it's pretty well cleaned up!
Now export mesh as .obj format and drag that folder into Unity Assets pane, then the obj file into the scene. I can't figure out how to get the textures to come with it yet.

Scan People

We have a setup for scanning people: an XBOX 360 Kinect sensor, Skanect software, and a heavy duty turntable we made. The scans can be cropped in Skanect and exported as STL format, then imported to Meshlab and exported as Collada format, then dragged into Unity.

Sim Builds

If you have access to a sim, student builds can be exported and imported to Unity as Collada files. I set up a sim for our school using the Diva distribution of OpenSimulator, which is a reverse engineered version of Second Life. I will not go into how to set up a sim as it is involved, but we've had students do some great builds, like the Parthenon and St. Peter's Basilica. To get a model out of OpenSim I followed these steps.  The short of it is:
  • Use Singularity viewer
  • Link all the prims for a build
  • Use the circle menu to export as DAE format
  • Drag the folder into Unity the same way as the other models
Any textures that have transparency won't show it by default, so you have to select those prims individually and change their shader settings to Unlit > Transparent.

Collision Detection

If you are using the template with the mobile viewpoint you might want to add collision detection to the models so you can't go through them. You can select a part of the model, then in the inspector click Add component > Physics, and choose the shape of collider that best matches your object. If you need to, you can stretch the collider to cover more area than just the part of the model you selected.

Here I put one big box collider across this whole multi-prim model.

What else?

I know there are many other ways to get 3D content into Unity, like making models in Blender and stuff. If you have any good suggestions, please post in the comments!

Saturday, May 07, 2016

LilyPad Arduino In the Classroom: Interactive Shirts

Last summer as a participant in the Constructing Modern Knowledge conference I had the opportunity to develop a project with the LilyPad Arduino (and meet Leah Buechley!). I worked with a wonderful group of educators to prototype a hat that lets you know with LEDs when you should apply sunscreen. I had only prototyped circuits with the LilyPad before, never actually sewing one into a project, so one big thing I learned during that project is that embedding the components into fabric involves as much problem solving and time as programming and prototyping the circuit.

Thursday, May 05, 2016

Code a Photobooth Program with P5 and a MaKey MaKey Controller

Creative student controller design!
This turned out to be a really fun project that my students can do quickly. We're using P5 to code a Photobooth program that streams the webcam and applies different filters the students choose. Plus we're adding a MaKey MaKey as a controller to work a little with

Friday, March 25, 2016

Daisy Chained NeoPixel Ring Flower Garden

I've had this recessed frame kicking around for a long time and finally came across a good use for it. Inspired by the story of a student's flower garden Logo program in Teaching With Logo by Molly and Daniel Watt, I picked up some NeoPixel rings at my local go to hobby store, Tinkersphere, and set about learning how to daisy chain them into one circuit.
Lynn's flower garden

Sunday, March 13, 2016

More Generative Art with the Logo Turtle

My first idea for making generative art with Drawson, my Logo Turtle, was along these lines. Here are a couple more ideas I am playing with. These are a little harder to code than the earlier "exploded shapes." My fascination with these is split between finding the beauty in the shapes that come out of them and in the process by which the overall composition is built up over time out of small random decisions.

Thursday, March 03, 2016

Add an LED to your Logo Turtle

Erin Riley has a great project using an LED throwy and taking a long exposure picture of her Logo Turtle in a dark box to make drawings with light. So we put our heads together and found a way to add an LED directly into the Logo Turtle's circuitry so you can add on and off commands for it in your drawing program. Here's how!

Sunday, February 21, 2016

Logo Turtle: Get Mac OS Working with the Adafruit Metro Mini

Getting a Mac to run Logo Turtle on the Logo Floor Turtle robot can be challenging. Windows users can run the Logo Turtle assembler program on the Adafruit Metro Mini right out of the box. But it was discovered that the Metro ships with a pre-loaded sketch that wreaks havoc on a Mac computer if it is not first overwritten by a simple Arduino sketch like Blink. Something about how Mac handles USB serial communication. Note that once you replace the sketch it ships with and load the Logo Assembler on one computer, you should be able to skip the Assembler and run Logo Turtle on any other Mac. If you are setting up several Logo Turtles, say, for a classroom or workshop, you might want load Blink then the Logo Assembler on all your Metros from one Mac, then any other Macs people use should be able to go straight to opening Logo Turtle and getting down to coding.

Tuesday, January 26, 2016

Rotating Squares in Phases with Gif Loop Coder

All of these sketches, made with Gif Loop Coder, are the same save for the phase frequency. From the first with a phase of 0.01*i to the last with a phase of i the squares create remarkable iterative designs.

function onGLC(glc) {
     glc.size(400, 400);
    glc.styles.backgroundColor = "black";

Monday, January 25, 2016

Generative Art with the LogoTurtle

The LogoTurtle is a programmable turtle that can draw. I like running simple programs with small aspects of randomness because the resulting drawings are always a surprise, and often beautiful. When randomness is part of a program the robot will draw a different composition every time, but it's also fun to look at several drawings resulting from the same program and see the similarities. The robot is enacting controlled chaos, and both the controlled parameters and the chaos within those limits can be seen after several runs. I also like how the robot is a kind of partner in creativity as it makes its own decisions within the framework it's been given.

Monday, November 30, 2015

Troubleshooting NeoPixel Problems

The NeoPixel packs a lot into a tiny package, millions of intense colors! As I developed the 24 NeoPixel ring Arduino shield I encountered a couple problems and had to learn more about the NeoPixel to solve them. I found the ring needs a very stable power supply and any jostling of the pins connecting it to the Arduino or the pins connecting to the ring were likely to reset the Arduino or cause the ring to do weird things, like become dim, flash suddenly, etc. So a couple modifications I