This tutorial program shows how to add textures, materials, and animation to meshes representing a model (in this case, a
cube). Operations include:
High level operations |
Low level operations |
Constructing the baseline scene |
- Defining the animation stack and animation layer that will contain the animation.
- Creating a marker to be used as a reference point.
- Creating a camera.
- Creating one texture available to all cubes.
- Embedding media files in an FBX file.
- Processing FBX files that contain embedded media.
- Processing scene files with references to media.
- Creating an array of materials to be shared.
- Pointing the camera at the marker.
- Setting the position of the marker.
- Setting the position of the camera.
|
Adding animation to the camera |
- Constructing the initial scene graph.
- Setting a camera as the scene’s default camera.
- Adding a cube to the scene.
- Setting the cube’s name, position, and rotation.
- Applying the user’s specifications to the cube.
- Setting the cube’s position in the scene.
- Creating a mesh for the cube.
- Defining the cube’s vertices and the normals.
- Defining the cube’s faces.
- Using layer 0 to store a normal to each face.
- Creating a layer element for the materials and textures.
- Saving memory by sharing a mesh among multiple nodes.
- Adding animation to a cube.
- Adding a texture to a cube.
|
Adding a material to a cube |
No lower-level operations. |
NoteBuilds and runs on Windows only.
Project Organization
The CubeCreator project is located at <yourFBXSDKpath>\examples\UI Examples\CubeCreator\.
CubeCreator has two source files:
Source file |
Description |
SDK_Utility.cxx |
Contains all the code that calls FBX SDK to create the scene, add the cubes, and add materials, textures and animation to
the cubes.This tutorial explains much of the code in this file.
|
UI.cxx |
Contains the code that displays the tree view of the scene and that interacts with the user. The code uses FBX SDK to retrieve
the scene data that the UI displays in its tree view.This tutorial does not explain any of the code in this file.
|
User Interface
The CubeCreator sample program shows you how to add textures, materials, and animation to models in a scene.
At startup, CubeCreator displays a tree view of a scene containing only a marker and a camera.
As a user, you can add cubes one at a time to the scene. For each cube, you can opt to:
- Add a texture.
- Add materials.
- Add an animation.
You can save the scene as an FBX file (or in any file format exported by FBX SDK).
Here is what 8cubes.fbx (the scene shown as a tree, above) looks like when opened in FBX for QuickTime:
Location of a Texture File at Run Time
<yourFBXSDKpath>\examples\UI Examples\CubeCreator\ contains a file named crate.jpg, which CubeCreator uses as a texture file.
You must copy this texture file into the folder where the executable for CubeCreator will start. Unless you change the settings
for the CubeCreator project:
- At build time, CubeCreator.exe will be saved in a subdirectory of <yourFBXSDKpath>\bin\CubeCreator\.
- At run time, CubeCreator.exe will execute in that same directory. It will search for the texture file in that location.
If FBX for QuickTime cannot find a texture file for a surface, it renders the surface as a checkerboard pattern. Here is how
that looks for the faces of our cubes:
Main Logic
CubeCreator does the following operations:
- Constructs a baseline scene containing a marker, a camera, and a light.
- Points the camera at the marker, then adds animation to the camera. The animation is always the same: a view of the cubes
that sweeps back and up.
- Defines one material that you (the user) can apply to any or all cubes.
- Defines one texture that you can apply to any or all cubes.
- Defines animation that you can apply to any or all cubes. If applied to a cube, the animation causes the cube to rotate around
its axis of rotation.
- Lets you add cubes, one at a time. The cubes are mesh objects.
- Places the first cube near the marker.
- Places subsequent cubes alternately: left of and above the leftmost cube, then right of and above the rightmost cube.
- Gives each cube an axis of rotation: either X, Y, or Z.
- Lets you (the user) add 0 to n cubes. To each cube added, you have the option of adding any or all of a material, a texture, and animation.
- Lets you save the scene as an FBX file (or in another FBX-supported file format).
- Invites you to use FBX for QuickTime to view and interact with the scene stored in the saved file.