Now that I have a full textured, rigged and animated head model in 3D Studio Max, I want to export it and bring it into Unity to start exploring ways of controlling it inside the game engine. To do so I select everything, mesh and bones, and export the selection as an FBX file. The FBX file is able to hold not only the mesh and bones but also the bitmap texture files and the animation keyframes that I have laid out for my model. I then start a new Unity project and import the FBX file.
Using the Project folder menu in combination with the Inspector menu in Unity, I can see both the fully assembled head model and the individual pieces that make it up.
There are three items that get imported during the FBX file import. One item is the head model the other two items are folders. One folder contains the bitmap texture files and the other folder contains the actual materials that will be used, by Unity, to render the model to the screen. The difference between materials and textures can be a bit confusing but just know that the material is a parent of the texture when it comes to rendering. One material can actually contain many different textures or “maps” that can be used to change the rendered look of an object. For instance a material might contain a map that controls the transparency of an object or how shiny the object is.
I have placed the three imported items into a folder called Prefabs because this is essentially what we have here. We have a prefabricated object, created outside of Unity, that we have imported into our project. This way we can continue to make changes to it, outside of Unity, and reimport it as though those changes were there all along.
I can now take the head Prefab model and place it in my Unity scene.
In part one of this series I went into some detail about baking lights into textures and about how I chose to model the eyes of the character. Now is the time for the pay off of that effort. First I must add a Point Light to my scene and place it somewhere in front and slightly above the head.
With a light placed in the scene we get that nice lifelike white highlight on the cornea of the eyes and it will react realistically later, as our character moves his eyes. However, now the face of our head appears too washed out by the added light. Worse than that, the processor is now forced to handle the rendering of the texture in one pass and the effects of our newly added light in another pass, what a slow down! Well not really; since it’s just a head right now and nothing else is in our scene. But if the scene were full of objects, say 1,000 heads, that had to go through that same rendering process, then you we might start seeing performance issues. But remember, we baked the lights for our head already into the texture so there is no reason why we need to light it again. So to stop the light from effecting the face we move it onto a Layer that we tell the light not to effect. We will keep the corneas of the eyes on a separate layer, we modeled them separate, so that they are the only thing the lighting rendering pass needs to calculate in our scene.
Now that the head looks good in our scene it’s time to get it moving!
Importing the FBX file into Unity brings all the animation contained in the file in a single Track. To use different parts of that track and play and blend them on command, we first need to break up the long track into smaller chunks. We can also setup what Unity calls Masks, on the smaller chunks, so that they only contain the key frames of certain bones. For example, we will use one chunk to just effect the keyframes of the eye lid bones. This will allow our character to close his eyes and blink regardless of what the mouth or eye brows are doing.
After I have broken down the large track into smaller ones I create an Animation Controller object in Unity. This is what will control the states of animation that my model is exhibiting and the transitions between them. The Animation Controller also allows me to set up layers for different sections of my model. For the head, I have chosen to make layers for the Eyes, Jaw, Lips and Brow.
Using these layers, I can drag and drop in different states of animation. The states are the smaller chunks of the animation track. I also use the animation controller to make transitions between these states. In addition, I can define some variables that I can reference, and change with code, to trigger the transitions and ultimately change animation states. For this first experiment, I am going to have variables that trigger the transitions linked to keys on the keyboard. Later, they will more likely be tied to game functions.
The web player is not the ideal method of viewing Unity content but it will do as a demo for this experiment. The keys to control the animation states are as follows: A – close eyes, S – open mouth, D – smile, F – frown, G – eye brows down, H – eye brows up, J – one up one down eye brows, K – wide open eyes. You can check out how this first experiment turned out here. (Make sure you click inside the Unity window in the browser, to give it focus, and then use the keys to change the animation states)
There are a additional features I built into this first experiment. First, I added an object in the scene for the eyes of the character to look at. You can move the look at object using the arrow keys on the keyboard. Second, you can rotate the character’s head using the Q key for down rotation; the W key for up rotation; the E key for right and the R key for left. This is all done with code.
You will notice that regardless of the head rotation, the eyes stay focused on the look at object. This will be and important function as this project moves forward because we will most likely want to control where the visual focus of each character lies.
In the next post I will talk about building the body for the character.
design your t shirt says
My partner and I stumbled over here different web page and thought I might check things out.
I like what I see so i am just following you. Look forward to looking
into your web page yet again.
online tshirt design says
Thanks for sharing such a fastidious thinking, post is good, thats why i
have read it fully