Book Image

Papervision3D Essentials

Book Image

Papervision3D Essentials

Overview of this book

Papervision3D is a powerful real-time 3D engine for Flash. Papervision3D can take externally created 3D models and render them as Flash content, without requiring end-users to download or install an additional plug-in. It has an outstanding reputation within the Flash community and its ease of use has even impressed experienced 3D game developers. However, getting started with Papervision3D can be daunting and mastering it can be challenging. This book guides you through the easiest way to tackle challenges that you may normally face with Papervision3D and master them effectively. The book will show you how to build Papervision3D applications from scratch in the easiest way, providing plenty of examples that make sense even if you're not a Flash expert. Papervision3D Essentials serves as a comprehensive guide to getting you started, as well as being an invaluable reference for every Papervision3D user and developer. By the end of this book you will be able to create your own projects with real-time 3D rendering. Since the first release of Papervision3D in 2007, the authors have been involved in various commercial projects with Papervision3D, building up a deep understanding of the engine. In Papervision3D Essentials, the authors share their knowledge to help you create stunning 3D content in Flash and teach you how to work with one of the most exciting open-source Flash projects around. Papervision3D Essentials shows you how to download Papervsion3D and make it work in Flash, Flash Builder and Flex Builder. It provides a short introduction to Object Oriented Programming and classes for those who are new to non-timeline programming. Then, it takes a closer look at the engine, discussing a broad range of topics from how to work with built-in 3D objects to using and animating cameras, 3D objects, and light. Applying materials and textures, using filters and effects, particles and performance optimizations are also covered. Ultimately, this book will provide you with the information you need to build your first Papervision3D application. Covering the basics, but by no means limited to beginners, Papervision3D Essentials provides a thorough explanation of the engine and numerous tips and tricks, making it a valuable resource for every Papervision3D user.
Table of Contents (18 chapters)
Papervision3D Essentials
Credits
About the Authors
About the Reviewers
Preface

Configuring your authoring tool for Papervision3D


Now that we have downloaded the source code, we will configure the authoring tool of our choice so that we can actually use Papervision3D. If your authoring tool is Flex Builder or Flash Builder, you can continue reading Configuring Flex Builder and Flash Builder.

Configuring Flash

We have downloaded the source code, but how can we make it work? Normally, if you download a software program, like we did with our SVN client, you would need to install it. But keep in mind that Papervision3D is not a software program—it's a library of folders and classes. What we need to do now is tell Flash where these folders are located so that we can access them when we work in the Flash IDE. In other words, within Flash we must set the path to the source code in our papervision3d_source folder. This is what we mean by configuring Flash.

We have downloaded the source code, but how can we make it work? Normally, if you download a software program, like we did with our SVN client, you would need to install it. But keep in mind that Papervision3D is not a software program—it's a library of folders and classes. What we need to do now is tell Flash where these folders are located so that we can access them when we work in the Flash IDE. In other words, within Flash we must set the path to the source code in our papervision3d_source folder. This is what we mean by configuring Flash.

Flash can handle the following two ways of setting such a path:

  • You can set it separately for each FLA

  • You can set it globally, which means that every FLA that you open or create automatically has access to the source

We will use the second approach in this book, so we'll only have to set the path once.

Both Flash CS3 and CS4 lets you set the path to the non-compiled source, but only Flash CS4 allows for setting the path to a SWC or SWC folder. If you decided to work with the SWC, you can continue reading Set the path to the compiled source code in Flash (only CS4).

Set the path to the non-compiled source code in Flash (CS3 and CS4)

If you've downloaded the ZIP or used SVN, the following steps will set the path to the source code from within Flash:

  1. 1. Open Flash. You don't have to create a new FLA or open an existing one.

  2. 2. Go to Flash | Preferences. on MAC, or Edit | Preferences on Windows

  3. 3. Select Actionscript in the category list at the left. Click the Actionscript 3.0 Settings button.

  4. 4. The following step shows a slight difference between Flash CS4 and its predecessor CS3.

    • In Flash CS4: Click on the + icon next to Source path. Then click on the folder icon.

    • In Flash CS3: Click on the + icon next to Classpath. Then click on the browse icon.

  5. 5. Browse to the folder where the source code is located— papervision3d_source in our example.

  6. 6. Select src and click Choose. You will now see that the path has been added.

  7. 7. Click OK twice to close the dialog windows.

Now that the dialog windows are closed, it's a good idea to check if the process of downloading and setting paths went right. To do this, we will take a look at one of the examples that comes with this book. Continue reading Running an example in Flash.

Set the path to the compiled source code in Flash (Only CS4)

  1. 1. Open Flash. You don't have to create a new FLA or open an existing one.

  2. 2. Go to Flash | Preferences on MAC, or Edit | Preferences on Windows.

  3. 3. Select Actionscript in the category list at the left. Click the Actionscript 3.0 Settings button.

  4. 4. Click on the + icon next to Library path. Then click on the red SWC icon.

  5. 5. Browse to the folder where the SWC is located— papervision3d_source in our example.

  6. 6. Select the SWC and click Choose. You will now see that the path has been added.

  7. 7. Click OK twice to close the dialog windows.

Now that the dialog windows are closed and the path to the SWC is set, it may be a good idea to check if everything went right. To do this, we will take a look at one of the examples that comes with this book.

Running an example in Flash

Let's open the example that is shipped with this book using the Flash IDE. By doing this, we'll be able to find out if we installed and configured everything correctly. More than that, it gives us the chance to see some Papervision3D at work!

  1. 1. Open Flash.

  2. 2. Go to File | Open.

  3. 3. Browse to the examples folder, which can be found in the book downloads.

  4. 4. Browse to CH01 | Flash | SetupTest.

  5. 5. Open SetupTest.fla and publish it.

Do you see the earth turning and a 3D text? Congratulations, you've set up Papervision3D correctly!

If you get errors when compiling this project, please read the previous sections again. The most common error is:

Type was not found or was not a compile-time constant: [ class name ]

If you get this error, you probably have not set the path correctly.

Configuring Flex Builder and Flash Builder

By configuring Flex Builder and Flash Builder, we mean that we need to set the path to the Papervision3D source code. We will first import an existing project (that is, the example that is shipped with this book) and then set the path to the source code for this project.

Importing an example project

Both Flex Builder and Flash Builder allow you to import projects. Let's import one of the examples that come with this book.

  1. 1. Open the authoring tool of your choice.

  2. 2. Go to File | Import | Other.

  3. 3. Open the folder called General and select Existing Projects into workspace.

  4. 4. Click Next, and then select the radio-button Select root directory if it is not selected yet.

  5. 5. Click Browse and browse to the examples folder in the book download.

  6. 6. Go to CH01 | FlexBuilder.

  7. 7. By clicking Choose a list of projects will be displayed that are recognized as valid projects. Make sure that only the checkbox for SetupTest is selected.

  8. 8. Click Finish.

  9. 9. The project will now be imported. Flex Builder will display it in the Flex Navigator view, Flash Builder in the Package Explorer view. Open the project called SetupTest by double-clicking on it.

Take a look at the Problems view. Chances are that you will see some errors.

The project we imported uses the Papervision3D source code. The developer has set the path to the code from his authoring tool. But this path could be, and probably is, different on your computer, as it's most likely that we named our source folder differently and stored it somewhere else than the developer did. Therefore, let's fix that by changing the path.

Note

Whether you import an existing project, or create a new one, you must always set the correct path to the external source code you would like to use. Keep in mind that in this example we are importing an existing project and that we will change the path that has previously been added. However, if you create a new project, no path has been added yet. Therefore, every time you create a new project, you must add the path to the source code that you want to access.

Setting the path to the SWC requires a different approach than setting it to the non-compiled source code. We'll first set the path to the non-compiled source. If you decided to use the SWC, you can continue reading Setting the path to the SWC in Flex Builder and Flash Builder.

Setting the path to the non-compiled source code in Flex and Flash Builder

If you've downloaded the ZIP or used SVN, the following steps will set the path to the source code from your project:

  1. 1. Right-click on the SetupTest project folder. You can find this in the Flex Navigator view in the Flex Builder, and in the Project Explorer view in the Flash Builder.

  2. 2. Select Properties.

  3. 3. Select Actionscript Build Path and click on Source path if it is not selected yet. You'll see a path that points to an additional source folder. To edit the path, double-click on it and browse to our papervision3d_source folder. Then select src.

  4. 4. Click Choose and OK.

  5. 5. Click OK to close the Properties window.

The path that we've changed was set by the developer of the project, but would not have worked for us. We needed to set the path to the source folder on our computer.

Setting the path to the SWC in Flex and Flash Builder

If you've downloaded the SWC, the following steps will set the path to it from your project:

  1. 1. Right-click on the project folder in the Flex Navigator view (Flex Builder) or the Package Explorer view (Flash Builder).

  2. 2. Select Properties.

  3. 3. Select Actionscript Build Path and click on Source path if it is not selected yet. You'll see a path that points to an additional source folder. Highlight the folder by clicking on it and click the Remove button.

  4. 4. Select Library path.

  5. 5. Click on the Add SWC Folder button.

  6. 6. Browse to the papervision3d_source folder and select it. Click Choose and OK.

  7. 7. Click OK to close the Properties window.

The path we removed pointed to the Papervision3D source code that was stored on the developer's computer. We needed to remove this path because we have decided to use the SWC instead of the non-compiled source code.

Running the example in Flex Builder and Flash Builder

The errors in the Problems view should be gone now. But what just happened? First we imported an existing project that came with the examples. Then we edited the path so that it points to our Papervision3D source code. Now that we have configured this project correctly, we're ready to run the example. Select the project and publish it.

Your browser should open and show the compiled SWF. Do you see the earth turning accompanied by a 3D text? Congratulations, you've set up Papervision3D correctly!

If you get errors when compiling this project, please re-read the previous sections. The most common error is:

The definition of [ class name ] was not found.

If you get this error, you probably have not set the path correctly.