Search form

'3D for Beginners': Exporting Our Character

In this last excerpt from 3D for Beginners, authors Carol MacGillivray and Anthony Head discuss how to export a character into Director.

All images from 3D for the Web by Carol MacGillivray and Anthony Head. Reprinted with permission.

All images from 3D for the Web by Carol MacGillivray and Anthony Head. Reprinted with permission.

Check out the first five excerpts in this series from 3D for Beginners.

Building a Simple World

Now that the animation is complete we need to export our character into Director. Before we do this, we should give him a ground to stand on. The simple way to do this will be to create a plane in the top view that is big enough for our character to walk around on. The ground plane is there to give the character a sense of scale and position. Without it he may as well be floating or treading water. As our character should be about 170 units tall we need to make our ground plane an appropriate size; 25,000 by 25,000 units should be sufficient, we are only making it for demonstration purposes (Chapter 7 is where we will be investigating world creation in detail). Make sure you name the plane clearly, e.g., ground. Otherwise it will have default name like Plane01, which could be confusing if there are many other planes in your scene.

Once you have created our ground plane, we might as well give it a texture. You could choose one of the standard materials, bearing in mind that they do not all export well (see Chapter 3). Perhaps create a grass material from a photo, or a concrete one. It is best to make your texture a tiling one. The size of the bitmap used is very important and there are restrictions, so generally tiling is the best solution. Apply a UVW map modifier and change the U and V tiling settings to 20. This is how many times the image will repeat. If your material looks too repetitive then decrease the tiling value, until you are happy with it (Figure 14).

[Figure 14] UVW mapping settings for a simple ground plane.

[Figure 14] UVW mapping settings for a simple ground plane.

Note There is no need to tile in the W direction as the plane is only a 2D shape. In fact, most materials only map in two dimensions, even if they wrap around a 3D object. Some materials, e.g., the Wood material, are 3D. They give you the ability to take chunks out of an object and see how the grain looks inside. The other materials are in effect skins that are stretched over an object.

If you want, you can add some other objects to your scene to help improve the sense of motion, when he is walking about. The character will not collide into these, though he will walk straight through them. Collision is something we will deal with in Chapter 8, where we will be assembling a game. For now we are just making our character controllable in realtime, using the keyboard.

Creating a Control Box

You have already grouped your character and he has his animation setup. Make a note of the name of the group, in our case Keystone. This will be the name of the model that we are looking to animate in Director. The next thing to do will be to create a control box, this acts like the Master Dummy used in 3ds Max for the eyes, and will be the object that is actually moved. Create a normal box shape starting in the top view that fits the shape and size of our character and in the same position. He will turn around the center point of this box, so make sure its center lines up with the characters center axis.

It is essential that you create the control box in the top view, looking down on the character. This ensures that the axes match with the axes expected by the Director file, which you will be using. If you make this box differently then the character will not walk and turn correctly. This is a compromise solution, allowing you to control a character without you having to do any programming (Figure 15).

[Figure 15] The Link and Unlink buttons in the main tool bar.

[Figure 15] The Link and Unlink buttons in the main tool bar.

Create a material that has zero opacity and apply it to the box. Link the Keystone group to this box. Press the Link tool, selecting your Keystone group and dragging the mouse over the edge of the box. Releasing the mouse button here will briefly highlight the box, indicating that it has been linked.

The purpose of the control box is twofold. The first reason is to provide a stable object that we can move around. As our character walks he moves from side to side, and the rotation of his axes change. This means that when we move him (using Directors Translate command) he would move in a wobbly manner. We want him to move in straight lines, and to turn correctly. In effect he does not walk anywhere, but will stay in treadmill mode, whilst it is the box that he is in that is moved around the environment. This may seem a bit awkward, but it works and the control box has another useful purpose; for collision detection.

[Figure 16] The box surrounding the Keystone character, with zero opacity.

[Figure 16] The box surrounding the Keystone character, with zero opacity.

We will talk about this in Chapter 8, but in essence, the simpler the object that you are testing collisions for, the simpler the calculation is to do this. We always need to be aware of the frame rate so anything we can do to improve time is worthwhile. When creating a game, as we will later, it is not just the character we have to take into consideration, but every computationally expensive element (like collisions, other object movements, scoring system, etc.). As we do not want to see the box, we have made it transparent, but it will export correctly (Figure 16).

Although you will have created several files for your animation, you only need to put the box on to one of them. This is the file that you will use for all your environment modeling, the other files are only needed for the animation information.

[Figure 17] The Shockwave 3D Export window, with settings for exporting a still scene.

[Figure 17] The Shockwave 3D Export window, with settings for exporting a still scene.

Exporting From Your 3D package

You should have five 3D files, a master file, which will be your 3D world, containing your character, control box and any other objects that you have created (e.g., ground plane). The other four files need only contain the character. Open the master file and make sure the perspective viewport is selected. Go to File > Export and choose Shockwave 3D (.w3d). For this file you need to export all the 3D resources (including animation). However, you only need to set the range to start and end to frame 0. This way the bone structure and mesh deformation information is exported but not the actual animation (Figure 17).

If you have selected the View w3D scene after export option you will be able to preview your character. When you are happy that it has exported correctly you can open one of the files that you have used for your animation. Once again, make sure the perspective viewport is selected before exporting. This is good practice and stops an Orthographic camera being used. In the Export Options window, you can deselect all the resources except for the animations. Make sure the animation range is set to last as long as your animation and keep the sampling interval at 1 and the animation quality at 100.0. Ideally you do not want your animations to be compressed, unless they were really large files (Figure 18).

[Figure 18] The Shockwave 3D Export window, with settings for exporting just the animation.

[Figure 18] The Shockwave 3D Export window, with settings for exporting just the animation.

Make sure you give your .w3d files clearly understandable names like walk motion or standing motion. You do not want to get confused later by trying to remember what file does what motion. There will be nothing to preview when you export just the animation, only the background color will be visible. This is perfectly fine and should not worry you. Looking at the exporters report will show you a file size indicated for animation, probably around 8 kilobytes in size. This means the animation data has exported and you can confidently repeat the process with the other motion files. If the size is zero then something has gone wrong. Make sure you did choose Export selected and that you have selected the correct options in the export window.

Importing into Director

That should be it for now in your 3D package, but if your computer has enough memory, keep it loaded and load up Director. It can be quite handy to have these two programs open at once, in order to quickly alter your scene, but if your computer slows down too much then quit your 3D application.

From the 3D for the Web disk open up the tutorial file ControlCharacter.dir in Chapter 6 folder. This is a nearly blank Director file. It contains just three behaviors, which will enable you to move your character around the simple world that you have created and view it.

[Figure 19] Directors Score and Cast windows, showing the position of the Loop.

[Figure 19] Directors Score and Cast windows, showing the position of the Loop.

Stage 1 Looping the Director movie If you have been working through this book chapter by chapter, then it has probably been a while since you have used Director. It is good practice to make sure the playhead of the movie loops around one frame. To do this first open up the Score and the Cast windows from the Window menu. Then select the Loop Frame behavior from the cast and drag it into the frame script window (above the timeline bar and next to the Script icon) and in frame position one. It should only be one frame in length (Figure 19).

Stage 2 Setting up the Shockwave 3D Files Now go to the File > Import menu and import all five of your W3D files (the scene and the four motion files). You should see that the main file has a small image of your ground and character, whereas the other four are blank. Open up the Stage window from the Window menu and drag your scene file (in our case it is called Keystone) onto the Stage. Make sure your movie is at a suitable size, Window > Property Inspector > Movie. I suggest you set it to 640x480 for now, as we will not be exporting it for the web as yet. Stretch your 3D sprite on the Stage to fill the whole window (Figure 20).

[Figure 20] Resizing the 3D sprite to fill the Stage window.

[Figure 20] Resizing the 3D sprite to fill the Stage window.

Check the Score window, you should see the 3D sprite in Sprite Channel 1. It will probably be more than one frame long but this will not matter, as the playhead will loop around only frame one.

Applying the Character Control Behavior

If you play your movie at this stage, nothing will happen, as we need to use the Character Control behavior that I have made up for you to use. There is a lot of programming in this behavior but you should not have to worry about it. I have incorporated a degree of customization, giving you options to select, which will be explained in a moment. There are always pros and cons in creating a standard, one size fits all, piece of code. They are fairly easy to use, but troubleshooting can be awkward if there are problems. If you are familiar with Lingo coding then you are welcome to adapt this behavior for your own uses. In essence it is a part of a block-by-block method for creating a game. This will be achieved in Chapter 8, but for now we will get on with just controlling our character.

Drag the Control Character behavior from the Cast to the Stage window and drop it on our 3D scene sprite. A pop-up window should appear with many options (Figure 21).

[Figure 21] The Parameters pop-up window for the Control Character behavior.

[Figure 21] The Parameters pop-up window for the Control Character behavior.

Select the control box object as the object that you want to control. You should have linked the character to this object, so moving it around means that the character follows it. In other words the character actually stays on the spot and it is the box that moves around.

The character to animate will be our Keystone group that you should have already named. This selection affects the motion settings later on, as the behavior looks for motions that have the same name as the animated character. I should point out that if you select the wrong object, playing your movie will cause an error. The object you select must be the one you animated previously. If you get an error, then cancel it and go to the Behavior Inspector, then select the correct object to animate.

Choosing the ground object is important as this dictates the vertical position of our character. As he jumps up, the behavior checks for the objects that are below and makes sure that the control box object does not fall down below the ground object. This works even for bumpy terrains (these are discussed in the next chapter). There is a gravity value that forces the character to stick to the ground.

The walking speed is adjustable so that you can closely match the speed of his/her footsteps with the distance that the control box is moved every frame. This figure is in world units and defaults to a value that will be roughly right. If your character appears to be sliding on the ground then you can change this value later, by selecting the behavior in the Behavior Inspector.

The next four options allow you to choose the motions that you should have set up and imported already. These motions have been set up to be triggered by pressing the appropriate keys. When you select the forward key, not only does the control box move forward, the walk motion animation is told to start playing and to loop. This will continue until the key is released. Then the previous animation will play. The previous animation is the standing motion that also loops, but works only when a key is not pressed. When you press the walk backwards key, then the animation is told to play in reverse.

[Figure 22] The Keystone character waiting and tapping his truncheon.

[Figure 22] The Keystone character waiting and tapping his truncheon.

Animation Blending

A good thing about Director is that these animations do not just stop and start they blend smoothly from one to the other, known as animation blending. This is a very useful feature, as it will make our character look a lot more believable than if there was an abrupt, unnatural change between the two motions. Blending also happens when the bash motion is played, whereupon the control box is told not to move forward.

The main advantage of blending is that you may have a motion that finishes in a slightly different body motion to the next motions start position, but it will not be noticeable. Also a motion does not have to be finished playing for it to blend into the next motion. So you can quickly and smoothly change between bashing, jumping and walking (Figure 22).

Note Animation blending does not occur at the point where a looped animation jumps back to the beginning. It only occurs between two different motions. This means that any looped animations you create in your 3D application must repeat smoothly. You may have done this by careful adjustment of the keyframes, or by copying the first keys to the last frame of the loop. If you did the latter, then you do not need to export the last frame.

As the bashing is not looped, it will only play once and return to the previous motion. However, if you keep the bash key held down it does, in effect, loop. What is actually happening here is that the bash animation is being told to play again.

You have a few choices of keys to control the movement; the defaults are the cursor (or arrow) keys. These are the most commonly used keys for moving characters forward, backwards, left and right. You can also select keys to control the bash motion and the jump motion. There is no key to trigger the standing motion as it is triggered by not pressing a key.

The final two options in the pop-up window are to control how the character behaves when he is jumping and falling. This is why we have created a jumping animation that does not actually jump. (See example file on the CD).

To learn more about designing and making characters, check out 3D for the Web by Carol MacGillivray and Anthony Head; Burlington, Massachusetts: Focal Press, 2005; 328 pages with illustrations and CD-ROM. ISBN 0-240-51910-8 ($36.95).

Carol MacGillivray was already a successful film editor before forming the pop video production company, Giblets with three friends who were animators and directors. Giblets specialized in combining media, mixing live action with 2D and 3D animation in an almost pre-digital era. Although they worked with many stars, Giblets, are most famous for bringing about the re-release of a trilogy of Jackie Wilson songs, starting with the clay animation video for Reet Petite that was a number 1 hit in 1987. Carol still has the gold disc hanging in her loo! After teaching at the Royal College of Art, Carol became interested in the new digital technology and was given an AHRB award to study an MA in Digital Moving Image at London Guildhall. She is now a senior lecturer in Digital Animation and Digital Arts at The London College of Music and Media, Thames Valley University.

Anthony Head worked in design and printing industry for seven years before pursuing his digital art full time, he has a First in BA Digital Art and a Distinction in MA Computer Art, awards include D&AD Student Award for E-Toy Design 2001, Peterborough Prize for Digital Art, joint prize with Jeremy Gardiner for Purbeck Light Years. A digital artist who combines creative intelligence with a strong design background, Anthony specializes in interactive 3D and immersive environments. He recently exhibited at SIGGRAPH 2004, Art Gallery Synaesthesia and has won many cans of Pepsi for a digital picture of The Haywain for Amiga Format Magazine! Anthony is course leader at Bath Spa University College Design for Digital Technologies, after being a fellow Lecturer in Digital Art at Thames Valley University.Both Anthony and Carol are passionate about their roles as teachers, keen to pass on their knowledge and share ideas and information. They are equally passionate in their role as learners; digital media moves so quickly and there is always something new just around the corner.

Tags