Flash_and_Flex_03_2009

Blender to Flash workflow

note that the file type (in this case PNG) should be indicated at the bottom of the dialog. Exporting the 3D object The exporter is a Python script that needs to be added to Blender’s scripts folder. The script can be downloaded from my blog: http:/ /www.rozengain.com/blog/exporter.htmI . Save the Blender project and then exit the program. Save the script in the following folder: Settings\ \Application Data\Blender • Foundation\Blender\.blender\scripts • Mac: • /Applications/blender/blender.app/ Contents/MacOS/.blender/scripts/ • Windows: • C:\Documents and

There is one thing left to do before we can export the file. We need to convert the polygons to a format that Flash 3D engines can understand. This means we have to convert quads to triangles. This can be done by clicking on [ Ctrl ]+[ T ]. Please note that this can only be done in Edit Mode, see (Figure 4). Now we’re all set to do the export. Click on the File menu item on the main application menu and roll over Export . Here you can see all the exporter scripts that exist in the scripts folder. The exporter we have just installed is named ActionScript 3.0 Class (.as) , see (Figure 16). Clicking on this opens the ActionScript 3.0 Exporter dialog window. Within this window we can enter the specifics for our 3D object class: • Package name: leave this empty • Class name: BlenderCube • 3D Engine: Sandy • File location: the same location as the texture image. the Export button will create the ActionScript class and save it to disc. Now it’s time to switch to Flash and do some coding. Setting up the Sandy 3D engine The Sandy 3D engine classes are packaged up in a Zip file that can be downloaded here: http: //www.flashsandy.org/download . The version we’re using in this article is 3.1. Unzip this file in the same location as the texture image and the ActionScript class we just generated. Create a new Fla file in this folder and an ActionScript 3.0 class named Main.as .

This is going to be our main application class. Open up the Flash IDE and type Main in the Document class field in the properties window, see (Figure 17). Let’s put together the code. The first thing we need to do is to set up the 3D scene. This can be done with just a few lines of code. The Sandy 3D engine already does a lot for you. Start by creating an instance of the Camera3D class. The constructor of this class needs two parameters, width and height. We’ll use the stage width and height for this. Now we must set the x, y and z coordinates to position the camera in 3D space. After the camera has been created and positioned we can create a Scene3D object, see (Listing 1). Before we can create an instance of the BlenderCube class we need to load the texture. This can be done by using a regular Loader and two event listeners, one for the Event.COMPLETE event and one for the IOErrorEvent.IO_ERROR event. When the texture has finished loading we get the bitmap from the LoaderInfo object, see (Listing 2). Now we’re all set to create the cube. We can instantiate it without passing any arguments to its constructor. Because we didn’t scale the cube in Blender we need to do it here by setting the scaleX, scaleY and scaleZ properties.

After saving the script open Blender again and open the file that we’ve been working on.

Figure 8. Material buttons panel

Figure 13. Changing to the Scene Buttons

Figure 14. Baking the texture

Figure 9. Changing the color

Figure 11. UV Unwrapping

Figure 12. Changing back to the newly created image

Figure 10. Creating a new image

Figure 15. Saving the texture

03/2009 (5)

87

Made with FlippingBook HTML5