You are on page 1of 10

SM4125 Computer Animation for Interactive Content I

Week 07: Prepare 3D models for interactive works - II

3D Model Format: OBJ

If you prepare your models using other 3D software, you have to export your model into a file,

and import it into TouchDesigner. There are a lot of 3D file format exists. Some of them are
software specific (such as Maya .mb format or 3DMax .max format). These formats are not open
specification; therefore, other software doesn’t know how to read this format, and it is hard to
use them in interactive applications.

For open specification file format, the most commonly used one is the OBJ format. OBJ file can
be used to store a polygonal model. Most software can export OBJ file format. Note that OBJ

file is in ASCII format; therefore, you can open it using Wordpad. This is a sample OBJ files:

mtllib head.mtl Line specify the material filename

v -0.209961 -0.270381 -0.249295

v -0.250772 -0.251252 -0.223251


Lines specify the vertex position
……

vt 0.097491 0.216394
Lines specify the vertex texture coordinate
vt 0.118324 0.225427

……

vn -0.542929 -0.593713 -0.593913


Lines specify the vertex normal
vn -0.642582 -0.541776 -0.541819

……

g Mesh Lines specify the grouping information of faces

usemtl blinn1SG
Lines specify the material being used
f 1/1/1 2/2/2 3/3/3 4/4/4

f 5/5/5 6/6/6 7/7/7 8/8/8


Lines specify the faces
……

However, OBJ format does not support animation. Moreover, the “material” specification for OBJ
is not a “standard”. A file with extension .mtl (stands for the material) will usually be created

together with the .obj file, but most software will ignore this .mtl file when it reads the .obj file.

Import .OBJ file into TouchDesigner

You can import an OBJ file into TouchDesigner (e.g. W:\SM4125\week07\head.obj and
Prepared by Kam Wong 1
SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

head.mtl):
1. File > Import File….
2. Locate your OBJ file, and click “Import”. (If the file size is large, it will take a few seconds

to load it.)
After that, a Geometry COMP is created, which contains the models and the materials:

A Geometry COMP is created

after imported an OBJ file.

Note that the converted models are stored externally in your project folder, under a
sub-folder named “Import”. Note also that TouchDesigner can preserve simple material only;

if a material file .mtl contains a texture, TouchDesigner cannot preserve it. In this case, you

have to go all the way down to the imported model’s materials, and adjust the material
parameters by yourselves:

Go all the way down the Geometry COMP You can also find the SOP of the model.

you can find the material. If the Of course, you can attach other SOPs

material is not preserved, you can adjust afterward to further modify your model.

the parameters here.

Prepared by Kam Wong 2


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

3D Model Format: FBX

There doesn’t exist a “standard” 3D file format that contains animation data. Recently,
Autodesk defines a 3D file format called .FBX file, and it also provides a utility libraries for us to
read and manipulate those .FBX files. Moreover, as it is defined by Autodesk, the 3D software
Maya is shipped with a plug-in to export this file format. Lastly, there are free 3D models on the

Internet with this file format. So, FBX may be one of the best formats for 3D models exchange
between different software.

There are some features of .FBX file that you may want to know:

 FBX file can be in text (ASCII) format, i.e. you can open it using WordPad.
 FBX file contains all the information about a 3D model, including the mesh (i.e. the
triangles), materials, textures, animation, skinning information and object hierarchy.
 FBX file stores animation data as “takes”. A file can contain more than one “takes”. For

example, a FBX file can contain a take for “walk”, another take for “jump”, another take for

“die”, etc. However, the Maya exporter cannot output more than one takes.
 Usually we will not use the lights and camera included in an FBX file. Lights and camera will

be created inside TouchDesigner, and will be manipulated separately.


 FBX file stores the texture names instead of the texture. Be careful about the file name of

the texture. The Maya exporter will store the absolute filename as
“G:\abc\def\texture.tga”. However, if you move the files to other folder (or to other

machine), the absolute filename may not be valid again. In this case, you can modify the
stored texture name directly using Wordpad: just open the .FBX file, and search for the

filename of your texture.


 Even though the Autodesk library claimed that it will convert NURBS into polygon, I will
suggest using polygonal objects only.
 Not every Maya material is supported. According to the manual, only the two basic

materials are supported: Lambert and Phong.


 I have tested the UV mapping texture only. I haven’t tested the other texture mapping

methods (such as projective mapping or 3D texture).

Open the file robot.fbx using WordPad, and get a feeling how a FBX file looks like. Also search
for the word “Grid.tga”. You will find that texture name is stored in the FBX file; so you need to
copy the texture file “Grid.tga” to your folder as well.

Prepared by Kam Wong 3


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

Import .FBX file into TouchDesigner

You can import a FBX file into TouchDesigner:

1. File > Import File…


2. Locate your FBX file, and click “Import”
After that, a Geometry COMP is created, which contains the models, the animation, and the
materials. For example, after you import the robot.fbx, you can find a new Geometry COMP.

Go inside it, you can find:

Several Geometry COMP are


Animation channels are read in inside
created, depends on how complex
this component. Animation data are
your object is. Converted
stored externally under the sub-folder
geometry are stored externally
“Import”
under the sub-folder “Import”

MovieIn TOPs are put inside this

NULL CHOP, for exporting the to read the textures. Textures

animation to the models. are stored externally under the

sub-folder “Import”

Select the Component “takes” and go inside. You can find the following:

A File CHOP, which is used to read A Switch CHOP, which is used to switch

in the converted animation data. between different takes, in case you

have more than one take.

Prepared by Kam Wong 4


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

Because the Maya exporter cannot output more than one takes, when I prepared this
robot.fbx file, I arranged the animation inside Maya in the following manner:

Frame 1 to 15: a loop-able Frame 24 to 36: a “jump” Frame 40 to 52: a “die”

“rotate” animation. Can either animation, supposed to be play animation, supposed to be play

be played by trigger, or keep once when trigger, and stop at once when trigger, and stop at

playing in TouchDesigner. first frame (i.e. frame 24) last frame (i.e. frame 52)

Therefore, in order to use the animation inside the TouchDesigner, I have to modify the network

inside the “takes”. I need to “split the time-line” back into 3 animation segments.

Before I modify the network, it is better the change the option of the “exportAnim” OP to “Cook
Type: always”, so to force it to calculate at every frame. Otherwise, in some situation it will not

compute the most updated value of “takes”, as a result making your object doesn’t move:

Before we go ahead, you should also pay attention about the frame-per-second and frame
number issue: by default, TouchDesigner uses 60 fps (suitable for real-time applications), but
animation created in Maya is usually 24 fps. After import into TouchDesigner, the speed of the
animation will be kept the same, but the “frame number” is stretched to fit the new rate 60
fps. Therefore, a frame number “5” in Maya may not be “5” inside TouchDesigner after imported.

So if you need to specify “frame number” in any parameters of TouchDesigner OPs, you should be
careful.

Moreover, TouchDesigner will start the animation at frame#0, and in Maya I start the animation
at frame#1. Middle-click on the “Take_001” OP, you will find that the animation is from frame 0
to frame 129. A simple formula can be written down:

Prepared by Kam Wong 5


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

Frame number in TouchDesigner = frame number in Maya * 60 / 24 - 1


Therefore, the frame numbers for the 3 animation segments after imported into TouchDesigner
will become:

“Rotate”: frame 1*60/24-1 to frame 15*60/24-1; therefore, from frame 1.5 to 29


“Jump”: frame 24*60/24-1 to frame 36*60/24-1; therefore, from frame 59 to 89
“Die”: frame 40*60/24-1 to frame 52*60/24-1; therefore, from frame 99 to 129

So my next step is to separate my animations into 3 segments, using Trim CHOP to take out the
frames, and Shift CHOP to shift all the animation segments to start at frame#1 (i.e. second 0).
Moreover, by default the animation will be looped; but for animation that should be triggered,
such as “jump” and “die”, I attach an Extend CHOP to prevent the animation becomes “cycle” at

the end:

Trim CHOP
Unit Values: Absolute Shift CHOP

Start: 1.5 (frame) Unit Values: Absolute

End: 29 (frame) Start: 0 (second)

Start: 59 (frame)

End: 89 (frame) Start: 0 (second)

Start: 99 (frame) Start: 0 (second) Extend CHOP


End: 129 (frame) Right Behavior: Hold

I also want to create a “do nothing” action: the object holds at its first frame and do nothing. I
can use the Lookup CHOP to create a “new action” and plug it into Switch CHOP:

Prepared by Kam Wong 6


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

Lookup CHOP

If first input is 0, Lookup output

the value at first frame of the

second input. If first input is 1, it

output the value at last frame of

the second input. If first input is

between 0 and 1, the output will

be the value at the intermediate

frame of second input.

Now I have 4 actions, and I can modify the Switch CHOP so that I can use a “radio button”

network (taught in previous class) to be the index for choosing one of the actions. Suppose I use
keypad-0 as dummy key, keypad-1 for “do nothing”, keypad-2 for “rotate”, keypad-3 for “jump”,

and keypad-4 for “die”:

Fan CHOP Hold CHOP Math CHOP

Operation: fan in Sample: While On Minus 1

First input is Index

The next step is to attach different CHOP network to “activate” each animation segment, and loop
it or stop it at the suitable frame.
(1) For the “rotate” sequence, I don’t need to do extra thing, because the default is “looping”.

(2) For the “jump” sequence (i.e. play once and stop at the first frame), I can use the Lookup
CHOP again. Whenever keypad-3 is pressed, I want to pass a “ramp” to the first input of
Lookup CHOP. It will then output the “animation channels” to the Switch CHOP:

Prepared by Kam Wong 7


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

A standard “ramp” will be passed to the Lookup CHOP


Trigger happens
for the “jump” action

A standard “ramp” (see p.2 of Week04 note)

Attack Length = length of animation

(3) And for the “die” sequence, I want to trigger the animation (i.e. a ramp for the Lookup CHOP),
but then hold it at the last frame (i.e. a value “1” for the Lookup CHOP). Therefore, I want to

pass this pattern to the first input of Lookup CHOP:

Trigger happens I want to pass this to the Lookup

CHOP for the “die” action.

The first attempt is to use the technique taught in previous class:

Count CHOP

Limit: Loop Min/Max Lag CHOP

Maximum: 1 Lag: 0.5 0

However, the above answer is not prefect, as the Lag CHOP will output a non-linear ramp. A
better approach will be more complicate: use a Count CHOP to output 1 when the “ramp” has

Prepared by Kam Wong 8


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

reached its end, and the output of Count CHOP will be used to control a Switch CHOP:

Trigger Threshold 0.9

A standard “ramp” When the trigger comes to its

Attack Length = length of animation end (0.9), this Count CHOP

will output 1, and then it

changes the Switch CHOP.

(Optionally you can use some

key to reset this CHOP.)

Constant CHOP

Always output 1. First input is Index

Now, I can use keyboard (or any kinds of pulse) to trigger the 4 actions (“do nothing”, “rotate”,
“jump” and “die”).

Class exercise: create inputs for the geometry


Continue on the previous example, convert all the Keyboard CHOP into In CHOP, so that
all the keyboard control can be moved up to the Geometry’s top level.

Class exercise: import FBX model

You are given the file W:\SM4125\week07\cubic.fbx (24 fps), which


contains the following animation:
1. Frame 1 to 130: animation sequence 1
2. Frame 140 to 245: animation sequence 2
3. Frame 260 to 411: animation sequence 3

Try to import it into TouchDesigner, and modify the “takes” component as


mentioned above:
1. Use Trim CHOP, Shift CHOP and Extend CHOP to separate the
animations into 3 sequences.
2. Use Keyboard CHOP, Trigger CHOP and Lookup CHOP to trigger
the 3 animations instead of looping.
3. Use Keyboard CHOP, Fan CHOP, Hold CHOP and Math CHOP to
implement the “radio button” technique, so that you can select the
animation to be played using keyboard.

Prepared by Kam Wong 9


SCM, City University of Hong Kong
Jan 2009
SM4125 Computer Animation for Interactive Content I

Extra tutorial: export .OBJ or .FBX file from Maya

Maya comes with a .OBJ exporter and a .FBX exporter. To enable the plug-in:

1. Choose Window > Settings/Preferences > Plug-in Manager.


2. Find the plug-in “objExport.mll” or “fbxmaya.mll”, and check the box besides “Loaded”.

Create your Maya scene, and then:


1. Choose File > Export All….
2. In the option window, choose OBJexport or Fbx
3. Choose a file name.
4. In the pop-up option manual, I mainly use the default setting. For FBX file export, the only

option that I would like to change is to turn off the “lights” and “cameras” export options,
and also export the file in ASCII format, so that I can edit the .FBX file directly using

WordPad:

** Week 07 END **

Prepared by Kam Wong 10


SCM, City University of Hong Kong
Jan 2009