As some of you know I’m focusing a lot of my personal time on Augmented and Virtual Reality. To create experiences in these platforms that are truly engaging you have to add 3D and animation or movement to your applications. In this blog post I will walk you through using Blender a free utility to create some 3D assets with a basic animation and import it into Unity. I will also show how to wire up the animation in Unity. In the end I will show what our creation looks like through the HoloLens.
To get started I first must cover some basics of how to navigate Blender. Interactions in blender utilize a three button mouse. The Right Mouse button is primarily used for selection while the left mouse button is for confirming things like scaling or rotation. The Middle mouse button is used for rotation, zoom and such.
Now open Blender. We are first going to delete Items in Blender to start fresh. Select the Lamp, Camera, and Cube and delete them by pressing the Delete key on the keyboard and then clicking Delete in the dialog that appears.
Add a UV Sphere
Next I switch to front view by pressing the #1 key on the number pad (Not the #1 above your qwerty section of your keyboard. I also ensure I’m in Ortho mode by pressing the #5 key on the number pad.
Next we will add a UV Sphere. There are a number of ways to do this. One is to click the Add menu below the view port and select Mesh -> UV Sphere. A shorter way to achieve this is to press Shift+A and a menu will appear in your view port.
Next we will duplicate the UV Sphere to create the head of our BB8. To do this we can use the Object Menu or just press Shift+D. This will create a duplicate move your mouse and you will see the object that is created. To place you left click. Next we will Scale this to make it smaller and place it to be the head of BB8.
Once you scale and position the head we will then add a cylinder for it robotic eye. This is done by pressing Shift+A and selecting Mesh->Cylinder. We will need to scale it by pressing “S” and making it the appropriate size. We also need to rotate it by pressing “R”. To rotate on a specific axis you can then press X, Y, or Z. In the end we should have something that looks like this.
Next to make our lives a bit easier we will parent our objects. First we will parent the Cylinder to the Head. To do this first make sure you have nothing selected. Then select the Cylinder by right clicking. The holding the shift key right click on the head. To parent you then press Control+P and select Object from the dialog. This will ensure that any manipulation to the head object will affect the robotic eye we have created. We now can parent the head to the body following the same process.
We are now ready for some animation.
The first animation we are going to do is just an Idle state where the head rotates back and forth. To do this we need to create some key frames. In my case I’m setting my view to Front (#1 on Number pad) I also rotated the cylinder to the left by pressing “R” and then typing 180 degrees. At this point it is time to add Key frames. To do that what you do is open the object menu on the right side of blender like below.
To insert a key frame on location, rotation, and scale you hover over the area in the menu and press “I”. If you successfully added a key frame you should have something like this.
The yellow tells you the value is key framed. Next we select a frame in the future like frame 20.
We now rotate the head by pressing “R” on the keyboard followed by “Z” this will rotate on only the Z-Axis. We position where we like and we will see the transform menu is now Green meaning the values have changed but are not key framed yet.
Again we hover over each value and press “I” to Key Frame them. Next we will move the head back and add one more key frame. In the video below I will show an alternative way to add the last point by using the Dope Sheet and copy pasting information.
Import into Unity
To import into Unity is very simple. By default you can just drag the Blender file into Unity’s Asset folder. This will automatically use the FBX Export from Blender. Once this is done you can now drag the asset into your scene.
This will not automatically animate our character at this time. Let’s first select our bb8 model and in the Inspector go to the Animations tab. Here we will see our animation but it has way to many frames. We need to trip it by changing the end time to match our last movement of our animation. We can also change the name here to Idle. We will use this name in the future as well. You also will want to check the loop time checkbox.
We now need to add an Animator Controller to our Assets by clicking Assets->Create->Animator Controller. You can also do this by Right Clicking in the Assets window and selecting Create->Animator Controller. Now you can double click on the Animator controller it created. This will open the Animator pane.
In the Project Asset folder click the right arror on our model. You should see something like this.
You should now see the Idle Animation. Click and drag it to our Animator pane. It will automatically attach to Entry.
Now we need to apply the Animator to our Model in the Scene to do this you can drag the animator from our Project folder to either the object in the scene or to the Inspector spot for the animator. Now if you hit play our animation should be playing.
Congratulations you have now created your first animation. In a future post I will make it so we can control another animation from code.
Here is a full video tutorial of this but with additional steps like adding basic materials to our model.