EEC-693/793EEC-693/793Applied Computer Vision Applied Computer Vision
with Depth Cameraswith Depth Cameras
Lecture 13Lecture 13
Wenbing ZhaoWenbing Zhao
[email protected]@ieee.org
OutlineOutline Introduction to Unity3D Based on Book:
Beginning 3D Game Development with Unity 4
Creating a New Unity ProjectCreating a New Unity Project Open Unity Select the Create New Project tab, change location folder to
KinectUnity Select packages for import, then click Create
Unity 3DUnity 3DLayoutLayout
Scene ViewScene View Where you plan and execute your ideasWhere you plan and execute your ideas
To show the grid, toggle off the game overlay buttonTo show the grid, toggle off the game overlay button
Hierarchy ViewHierarchy View Shows what’s in the currently active scene. GameObjects that are dynamically added and removed from
the scene during runtime will appear here when they are active in the scene
By default, the maincamera is added
Project ViewProject View Contains all the assets available to the current
project, as well as all scenes or levels available for the finished game or application
InspectorInspector Inspector is used to access
various properties and components for objects you’ve selected in either the Hierarchy or Project views
ToolbarToolbar
Transform tools: provide functionality for navigating the scene and transforming objects Left most button: pan, orbit, zoom tools for navigating and
adjusting scene view Pan tool: default, left click and drag to move the view
around Orbit tool: hold the Alt key while clicking left click and
dragging Zoom tool: Alt + right mouse click Other three buttons: move, rotate, and scale
ToolbarToolbar Privot point and coordinate system tools:
Objects can be transformed in different coordinate systems and from different pivot points
Play mode controls
Layers control: Layers are used in Unity for controlling which objects are rendered by which cameras or lit by which lights
Layout control
Elements to Build a SceneElements to Build a Scene Assets: non-mesh special effects, physics materials,
and scripts GameObject: base container for objects, scripts, and
other components in Unity Contains its transforms (location and orientation) and a few
other properties Component: items associated with objects, such as
meshes, rendering types, sound, scripts, and colliders, as well as those that create or extend functionality with predefined behaviors
Creating Simple Game Objects: Creating Simple Game Objects: CubeCube
Creating Simple Game ObjectsCreating Simple Game Objects To zoom, use middle
mouse roller or Alt-right mouse click
To set the camera to match the scene view Select the main camera in
the hierarchy view From the GameObject menu,
choose Align with View
Creating Simple Game ObjectsCreating Simple Game Objects Toggle the built-in
lighting off and the scene lighting on, by clicking the light button The cube is now lit only
with the scene ambient light, as in the Game window
Try out zoom, orbit and pan
Selecting and FocusingSelecting and Focusing To focus the viewport back to the cube, or to “find”
the cube, do the following Make sure the cube is selected in the Hierarchy view. Put the cursor over the Scene window. Press the F key on your keyboard
You can view scene objects in several other modes Wireframe, textured wire, textured (default)
Transforming ObjectsTransforming Objects In 3D space, the Cartesian coordinate
system is used X, Y, Z are color-coded with red, green, blue Objects can be transformed (moved,
rotated, scaled) around the scene Select the cube, select the move button, click
and drag on any of the three axis; Rotate is similar
Can also do these in inspector
Lights Lights Because there are no lights in the viewport yet, it went dark,
just as in the Game window, when you toggle off the lighting button
Adding light Focus the Scene view on the cube again and zoom out a bit From the GameObject menu, choose Create Other ➤
Create a Directional Light. Directional lights emit parallel rays, no matter where they are in
the scene. Move the light up and out of the way of the cube. Rotate it in the Scene window until the cube is lit nicely in
the Game window Use alt-left mouse click, drag/orbit the viewport so you are
facing the unlit side of the cube
Lights Lights Changing light
color: in inspector for light Click and drag in the
Color’s image/color swatch and watch the light’s color on the cube change
Choose something subtle.
Close the dialog
Material Material In the Inspector,
select the Cube 2. In the Mesh
Renderer section, click to open the Materials array list
Material Material From the Assets menu, choose Create Folder, ➤
Rename the folder My Materials
Material Material Right-click the new My Materials folder and, from the
same Create submenu, choose Material
Material Material A New Material entry appears in the Inspector, Name the new
material TestBark Drag and drop the material from the folder onto the cube in the
Scene window. In the Texture thumbnail window (not the Preview window),
pick the Select button and, with the preview slider all the way to the left in the Asset Selector, choose Palm Bark Diffuse.
Material Material In the Texture thumbnail window (not the Preview window),
pick the Select button and, with the preview slider all the way to the left in the Asset Selector, choose Palm Bark Diffuse.
ScriptingScripting A script is a program that controls the game objects in the
scene dynamically, Unity support a number of programming languages We will be using C#
To create a new script Create a New Folder in the Project view using the right-click menu
or Assets menu in the menu bar Name the new folder My Scripts With the new folder selected, right-click it to bring up the contents
of the right-click menu. Select C# Script from the Create submenu
ScriptingScripting To edit the script, click the open button. The MonoDevelop
editor will open
using UnityEngine;using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () {
}}
ScriptingScripting The Start function is only called once as the scene is started and is a
good place to initialize values that don’t exist until the game has been loaded
The Update function is checked at least every frame during runtime to see if anything needs to be executed It can make a transform such as a rotation continuously loop, check to see
if a particular condition is met, and many other things To attach the script to the game object, drag the script file to the game
object Add the following line in the Update function, save the script, click play
If you want to animate the object on a per-second basis, use Time.deltaTime
transform.Rotate(0,5,0);
(0,5,0) refers to the X, Y, and Z rotations parameters that are needed by the Rotate function
transform.Rotate(0,5 * Time.deltaTime,0);
ScriptingScripting We can also move the game object
using the Translate function
You can also add private or public variables into script Public variables are listed in the inspector
and their values can be set their Challenge Task:
Animate the cube such that it drops to the ground and then bounce back like a ball
transform.Translate(2 * Time.deltaTime,0,0);