In PV3D there are two Collada parsers: Collada and DAE. The DAE parser is actually an improved version of Collada parser which includes animation.
When working with Collada files, there are five commonly used scenarios found in PV3D:
- Single Objects with UVMaps
- Multiple Objects with UVMaps
- Single Objects with Multiple Images
- Interactive Objects (or Vehicles) and Environments
- Animated Objects
In this post, you learn about Single and Multiple Objects with Simple Images. Click the image below to see a demo:
Single and Multiple Objects with Simple Images are obviously the simplest of all the scenarios in PV3D. In the example above of the moon orbiting the earth, 3DSMax is used to do the modeling. But the procedure presented in this post is similar for other modeling software packages as well.
This is how you do it!
An object is created by a modeling program, such as 3DSMax, and a simple image is placed on that object. In 3DSMax this is done using the material editor. Each material and object is given a name so that it can be controlled by the PV3D program once the Collada file, created by your modeling program, is imported into PV3D.
Once the Collada file is exported from 3DSMax and brought into PV3D, the created objects can be easily manipulated by referring to the object names contained in the exported Collada file. If you forget what you called them during the modeling process, these names can be viewed by opening the Collada file in an editor such as Dreamweaver or Flex and navigating to the geometries library and geometry tags.
<geometry id=”earth-mesh” name=”earth”>
<geometry id=”moon-mesh” name=”moon”>
In this case the names are earth and moon.
Manipulating objects in a Collada file using AS3 is key to creating dynamic game content and use this procedure often. Importing a Collada file into PV3D is an easy 3 step process:
Importing Collada files into PV3D
Step 1: Import the Collada parser
Step 2: Declare collada var and datatype it to Collada
private var collada:Collada;
Step 3: Instantiate the Collada class and fill in the appropriate parameters
collada = new Collada(“MoonEarth.DAE”,null,.1);
In this case, the material parameter of the Collada parser is set to null since the material is imported from the reference inside of the Collada file, found in the images library, as shown below.
<image id=”earth.jpg” name=”earth_jpg”>
</image><image id=”moon.jpg” name=”moon_jpg”>
Once the images are loaded, the onColladaDone method is executed which sets the planets into place and motion.
To see the rest of the discussion check out Chapter 5 of the book. To see the complete code click the more button below or download the source