Flash_and_Flex_03_2009

Sound and Animation

On the ‘Net

Listing 2. Loading the texture image

http://www.blender3d.org/e-shop/

• • • •

private function loadTexture() : void {

http://www.flashsandy.org/

http://away3d.com/

http://blog.papervision3d.org/

var loader : Loader = new Loader(); loader.contentLoaderInfo.addEventListener( Event.COMPLETE, textureCompleteHandler ); loader.contentLoaderInfo.addEventListener( IOErrorEvent.IO_ERROR, textureErrorHandler ); loader.load( new URLRequest( "cube-texture.png" ) );

} private function textureCompleteHandler( event : Event ) : void {

var loaderInfo : LoaderInfo = event.currentTarget as LoaderInfo; cubeTexture = Bitmap( loaderInfo.content ); createCube();

Figure 16. Selecting the ActionScript 3.0 exporter

} private function textureErrorHandler( event : IOErrorEvent ) : void { trace( "Could not load the texture." ); }

Listing 3. Creating the cube

Figure 17. Setting the document class

private function createCube() : void {

blenderCube = new BlenderCube(); blenderCube.scaleX = 30; blenderCube.scaleY = 30; blenderCube.scaleZ = 30; var material : BitmapMaterial = new BitmapMaterial( cubeTexture.bitmapData ); blenderCube.appearance = new Appearance( material );

scene.root.addChild( blenderCube );

Figure 18. The final result

addEventListener( Event.ENTER_FRAME, enterFrameHandler );

Where to go from here This article is a mere introduction to the world of Blender and 3D Flash. If you want to learn more about Blender I highly recommend eatching the books Blender for Dummies and The Essential Blender . To see what amazing things are possible with Blender I recommend the two open movies that were produced by the Blender Foundation, Elephant’s Dream and Big Buck Bunny . Both the books and the movies can be ordered from the Blender Shop.

} Listing 4. The render loop

protected function enterFrameHandler( event : Event ) : void {

blenderCube.rotateZ++; blenderCube.rotateY++; scene.render();

}

In order to apply the texture we first have to create a BitmapMaterial object and pass our Bitmap’s bitmapData object to its constructor. We can now use this BitmapMaterial object to create the cube’s Appearance, see (Listing 3). This creates the object, adds it to the 3D scene and attaches a texture to it. But it

doesn’t show anything on the screen yet. The last step is creating the render loop. We’ll keep it simple by just rotating the cube and calling the Scene3D object’s render() method, see (Listing 4). When we put it all together the listing should look like (listing 5) and our final result looks like this, see (Figure 18).

DENNIS IPPEL Dennis Ippel is a Dutch Senior Creative Developer working for a well-known digital agency in London. He’s an expert in 3D Flash and has extensive

experience with Adobe Flex. http://www.rozengain.com

03/2009 (5)

88

Made with FlippingBook HTML5