Part XI: Extending Max with Plug-Ins
Chapter 41: Creating Your Own Plug-Ins
Max and Plug-Ins . . . 1139 Plug-In Requirements . . . 1140 Types of Plug-Ins . . . 1140
Setting up the Development Environment . . . 1142 Tutorial: Enabling Max SDK syntax highlighting . . . 1142 Tutorial: Loading a sample project . . . 1143 Tutorial: Setting project options . . . 1144 Creating Your First Plug-In . . . 1147 The goal . . . 1148 A look at the project files . . . 1148 Tutorial: Using the plug-in skeleton . . . 1151 Adding a new plug-in parameter . . . 1152 Tutorial: Debugging Plug-Ins . . . 1153 Finishing the Gear Plug-In . . . 1155 Capturing mouse input . . . 1155 Building an object’s mesh . . . 1158 Ideas for Enhancing Your Plug-In . . . 1168
Appendix A: Installing and Configuring 3ds max 4 . . . 1171
Appendix B: Max Keyboard Shortcuts . . . 1181
Appendix C: Exclusive Bible Plug-Ins . . . 1195
Appendix D: What’s on the CD-ROM? . . . 1207
Glossary . . . CD1–CD12
Index. . . 1211
Hungry Minds, Inc. End-User License Agreement. . . 1254
CD-ROM Installation Instructions. . . 1256
Getting Started
with 3ds max 4
✦
✦
✦
✦
In This Part
Quick Start Animating a Fighter Jet Fly-By Chapter 1Exploring the Max Interface
Chapter 2
Working with Viewports
Chapter 3
Working with Files
✦
✦
✦
✦
P A R T
I
I
Quick Start:
Animating a
Fighter Jet
Fly-By
W
hen you first got your hands on 3ds max 4, you were probably focused on one goal — to create cool 3D images and animations. I know many of you bought Max to make money, claim a tax write-off, earn a way to Hollywood, or impress your girl or boyfriend, but I’ll just ignore those rea- sons for now. The goal is to create something cool.If you’ve perused this book’s Table of Contents or thumbed through its many pages, you’ve seen sections on modeling, NURBS, dynamics, and other topics. But if you’re like me, you don’t want to wade through tons of material before you have something to show off to mom (actually, if you’re like me, then you’ve opened straight to the special effects section, in which case you won’t be reading this).
The purpose of this Quick Start is to give you a taste of what Max can do. This soaring view of the software from 20,000 feet is intended to show you the big picture before you delve into the details. It exposes you to the most common modeling, material, and animation features and whets your appetite for the more in-depth chapters to follow.
This part of the book is intended for those new to the soft- ware. If you’re an experienced user, then your mom is no doubt already impressed with your work, so you can happily advance to whichever chapter appeals to you. (Forgive me for catering to the “newbie,” but we were all beginners once.)
✦
✦
✦
✦
In This Chapter
Introducing the Quick Start projectImporting the jet model
Applying materials to the jet model
Loading a
background image Adding prop models, lights, and cameras Animating the jet Adding a smoke trail special effect Rendering the final animation
✦
✦
✦
✦
The Speed of Jets
It happens every Fourth of July during the parade. You hear a rumble of approach- ing thunder off in the distance, and everyone’s gaze turns to the skies. Then quick as a flash, the fighter jets roar by and are gone. I always love the tingling rush that sweeps over my body as they disappear.
Animating in Max isn’t bound by reality. You can animate anything you can imagine, and I’ll get to the unbelievable soon enough, but for this Quick Start I’ve elected to work with an example that is based in reality. This example lets you play with a jet plane. The tasks to be completed include the following:
✦Find a digital model of a jet and load it into Max.
✦Apply materials to all the different parts of the plane.
✦Create a scene or environment to fly our jet around.
✦Include some props like buildings.
✦Set a camera to watch the jet’s motion.
✦Animate the jet’s motion.
✦Add a smoke trail special effect.
✦Render the final animation.
This Quick Start is divided into separate tutorials, with each tutorial containing a series of easy-to-follow steps. These steps are intended to show you the results of performing certain Max operations, but feel free to deviate from these steps to cre- ate your own results. Being creative and exploring the software is the best way to learn.
After each of the following tutorials, I saved the scene file. You can find these files on the book’s CD along with the examples in the Quickstart directory.
Tutorial: Importing the Jet Model
Accurately modeling an object such as a jet fighter can take many months of skilled work, which brings me to my first tip of modeling — don’t build it when it’s already been done for you. You can find many repositories of digital models — from Web sites to software dealers, to the CD in the back of this book. An untold number of models exist, covering almost any possible subject matter you could think of. The difficult part is wading through all the available models to find the exact model you need. The answer to this dilemma is not to be afraid to alter an existing model to fit your needs.
Cross- Reference
5
Quick Start
The F14A Tomcat and building models were created and provided by Viewpoint Datalabs.
Follow these steps to learn the easiest method for modeling:
1.Reset the Max interface by choosing File ➪Reset, and click Yes in the alert box that appears, asking whether you really want to reset.
2.Insert the CD-ROM from the back of the book, then choose File ➪Import. The Select File to Import dialog box appears.
3.In the Files of Type drop-down list, select 3DStudio Mesh. Locate the Chapter Examples/Quickstart directory on the CD-ROM, and select the file named F14A Tomcat1.3ds. Click OK.
The 3DS Import dialog box appears.
4.Select the Merge Objects with Current Scene option, check the Convert Units check box, and click OK.
The jet model appears at the center of each viewport. The viewportsare the sections of the interface that provide a view into the scene. The default view- ports include Top, Front, Left and Perspective.
5.Save the file by choosing File ➪Save As to open the Save File As dialog box, shown in Figure QS-1. Select a directory in the Save in field where you want to save the file, type Imported Fighter Jetin the File Name field, and click the Save button.
The name of the current file appears in the title bar of the Max window.
Figure QS-1: The File Save As dialog box lets you save files.
The imported jet appears as shown in Figure QS-2.
Note
Figure QS-2: The viewports display the fighter jet after being imported into Max.
Tutorial: Applying Materials to the Jet Model
Nice jet, huh? Try a quick smooth rendering in the ActiveShade window by choos- ing Rendering ➪ActiveShade Floater to open the ActiveShade Floater and render the active viewport. Rendering the scene computes the effects of the lights, mate- rial, and environment into a single image. This process could take some time, depending on the complexity of the scene, but the ActiveShade window is a quick rendering window that lets you see the results of materials and lights. The results of the ActiveShade rendering show the jet model with simple materials on a black background, which doesn’t look very accurate. Well don’t worry; you’re just getting started. You can close the ActiveShade window by clicking the close icon in the upper-right corner of the window.
The next step is to choose individual parts of the plane and apply different materi- als to each. So, the windows will be glass, the wheels will be rubber, and the plane body will be a smooth, sleek silver metal.
7
Quick Start
To apply materials to the model parts, follow these steps:
1.To assign materials, you must first select the model parts. Open the Select Objects dialog box, shown in Figure QS-3, by choosing Edit ➪Select By ➪ Name (or press the H key).
Notice that the pane on the left displays all the various parts that make up this model.
Figure QS-3: The Select Objects dialog box lists all the objects in the scene.
2.Double-click the part called “cockpit” in the left pane. Doing so selects the part and causes you to exit the dialog box at the same time. Alternatively, click its name, then click the Select button at the bottom of the dialog box. (You can clear any selections by clicking the None button.)
The jet canopy will be highlighted white in the viewports.
3.Open the Material Editor by choosing Rendering ➪Material Editor (or press- ing the M key).
The Material Editor, shown in Figure QS-4, allows you to create, edit, and apply materials to objects in the scene.
4.In the Material Editor, click the Get Material button (the small, leftmost icon button with an arrow pointing to a sphere).
The Material/Map Browser dialog box opens, as shown in Figure QS-5. In it, you can load a library of preset materials.
Figure QS-4: The Material Editor can create a vast assortment of materials.
5.In the Browse From section, select the Mtl Library radio button. Several File buttons appear.
6.Click the Open button to access the Open Material Library dialog box. Using this dialog box, locate and select the quickstart.mat file from the Quickstart directory on the CD-ROM.
7.For the selected cockpit object, select the Cockpit Glass material in the Material/Map Browser by double-clicking it.
The glass material loads into the first Material Editor sample slot. Using the material parameters that appear in the Material Editor under the sample slots, you can alter the material.
Get Material Sample Slots
9
Quick Start
Figure QS-5: Use the Material/Map Browser dialog box to manage materials.
8.For now, stick with the preset library materials, and apply the material to the cockpit object by clicking the Assign Material to Selection button (the third small button from the left that has an icon with an arrow pointing from a sphere to a cube).
9.Close the Material Editor and Material/Map Browser windows by clicking the X button in the upper-right corner.
10.Repeat the preceding steps until all parts of the jet have materials, as listed in Table QS-1. Use a different sample slot for each unique material. This makes the material available to add to other objects. To work with a different sample slot, click one of the other sample spheres in the Material Editor before select- ing a new material in the Material/Map Browser.
You don’t need to close the Material Editor each time. You can leave it open while you work with the viewports behind it.
Tip
Table QS-1
Jet Fighter Material Assignments
Model Part Preset Materialcockpit Cockpit Glass
ctrim Metal Trim
elev Silver Metal
exhaust Black Metal
fuselage Silver Metal
insets Black Metal
intakes Black Metal
nose Black Metal
nozzle Fire Red
rudder Silver Metal
tabs Metal Trim
tubes Metal Trim
vents Black Metal
webs Black Metal
wing Silver Metal
11.Save the file by choosing File ➪Save As to open the Save File As dialog box. Type Materials Applied Fighter Jetin the File Name field and click the Save button.
Figure QS-6 shows the jet model with all materials that you applied to it rendered in the Virtual Frame Buffer. This image was created using the Render Scene dialog box, which you access by choosing Rendering ➪Render (or pressing F10 or Shift+R).
11
Quick Start
Figure QS-6: This rendered image shows how the jet looks with the materials applied.
Tutorial: Positioning the Background
Environment
Okay, I have a confession to make. Earlier I explained how jets flying over a parade are awesome and that is why I chose them as the subject for this tutorial. Well, the real reason is that you usually see jets when they’re flying in the sky, and the sky is a very easy backdrop to work with. You don’t need to match up the object with the ground plane, and you don’t need to worry about the perspective size of the objects in the scene. All you need are some clouds and a lot of light blue — no buildings, no trees, and no people. The same applies to space. That is one of the reasons why we see so many space animations.
So, all you need to create a realistic environment is an image of the sky and some clouds. Now you could use Max to create an original image, but the easier method is to find a bitmap image of the sky and some clouds. Plenty of these types of images are available. After you locate a perfect sky scene image, then you need to include it as the background image in the current project.
You can use two separate commands for dealing with background images:
✦Views ➪Viewport Background:Displays an image as a viewport background. Be aware that you mainly use this background image just for aligning the objects to the background, and it is not included as part of the rendered image.
✦Rendering ➪Environment:Assigns a rendered background image called an
Environment Map.
To add a background to a scene, follow these steps:
1.Open the Environment dialog box, shown in Figure QS-7, by choosing Rendering ➪Environment. Check the Use Map check box, and click the Environment Map button labeled “None.”
Figure QS-7:Use the Environment dialog box to set environment properties, such as a background image.
The Material/Map Browser dialog box appears.
2.To the right is a window with a list of material and map items — double-click Bitmap.
13
Quick Start
3.Locate the background image named Sky1.tif in the Quickstart directory on the CD-ROM, and click it to select it. You will need to select the TIF image for- mat in the File Type drop-down list for the image filename to appear.
When selected, the image will be shown in the Preview pane, as shown in Figure QS-8.
Figure QS-8: The Select Image File dialog box includes a preview pane to view images before opening them.
4.Click Open to load the background image.
This sky image was cropped from a Corel PhotoCD image.
5.Click the close icon in the upper-right corner of the Environment dialog box to close it.
6.Although a background image was specified, it doesn’t show up in the view- port background. To make the environment map appear in the viewport, you need to open the Viewport Background dialog box, shown in Figure QS-9, by choosing Views ➪Viewport Background (or pressing Alt+B).
Figure QS-9: Use the Viewport Background dialog box to make background images viewable in the viewport.
7.Check the Use Environment Background and the Display Background check boxes, and click OK.
The background appears in the viewport.
8.Save the file by choosing File ➪ Save As to open the Save File As dialog box. Save the file with the name “Environment Background,” and click the Save button.
Figure QS-10 shows the environment background in the active viewport. You can maximize the active viewport by clicking the Min/Max toggle (the icon button in the lower-right corner of the Max window).
15
Quick Start
Figure QS-10: This maximized viewport displays the background image.
Tutorial: Adding a Building Model
The sky background works to a small degree, but to really show off the speed of your jet, you need a building in the scene. Because buildings are static, they are rel- atively easy to add. For a building model, we could simply create some elongated rectangle primitives, but instead we are once again going to load them from the model clip art library created by Viewpoint Datalabs.
To load and position the building model, follow these steps:
1.Before importing the building model, group all the parts of the jet together. Select all the parts for the jet by choosing Edit ➪Select All. Then group all the parts into one by choosing Group ➪Group.
2.In the Group dialog box that opens, shown in Figure QS-11, give the group the name “Fighter Jet,” and click OK.
Now when you import the buildings, the building parts won’t be confused with the jet parts.
Figure QS-11: Use the Group command to group several objects together.
3.To add a building model to the existing scene, choose File ➪Import to open the 3DS Import dialog box.
The model name is building1.3ds located in the Quickstart directory on the CD-ROM.
4.Select the option to Merge the objects with the current scene, and check the Convert Units check box.
This model already has materials applied to it.
5.While all the building parts are selected, group them together with the Group➪Group command and name the group “Skyscraper.”
The building model was also created and provided by Viewpoint Datalabs.
6.Next, scale the jet model to be proportional to the building model. Press the H key to open the Select Objects dialog box, and double-click the Fighter Jet group to select it.
7.Click the Select and Move button in the main toolbar (it has four arrows point- ing in each direction). Position the mouse over the axes in the top viewport, and drag the axes over to the left beyond the building edges.
This is actually the jet model, but it is so small compared to the building that it is hardly visible.
8.Next, click the Select and Uniform Scale button (it has a small, red outlined box inside a larger gray box) and drag on the axes again until the size of the jet looks proportional to the building.
9.When the jet is the right scale, click the Select and Move button again and right-click the left viewport to make it the active viewport. Move the jet object to the left of and above the building.