Flash_and_Flex_03_2009

Sound and Animation

without changing anything. You can see that the UV/Image Editor Window is immediately updated. The unwrapped UV coordinates are connected by lines and are clearly visible on top of the image. Now it is time to bake our texture into a new image. In the UV/Image Editor window we need to change back to our newly created image. Click on the double arrows next to the UV menu, see (Figure 12) and pick the image called Untitled . Then go to the Buttons

window and click on the Scene button, see (Figure 13). In the Scene Buttons view go to the third panel from the left and click on the panel named Bake , see (Figure 14). On the right hand side of this panel there is a vertical row of buttons. The first button with the label Full Render is selected by default. If we leave this selected everything including shades, luminosity, reflection, etc will be baked into the image. Because the shadows are a bit dark

in the texture we will bake an image without shadows. In the same button group there is another button called Textures . Select this button and then hit the big Bake button on the left hand side of the panel. You can see the result in the UV/Image Editor window. Now save the file by going to the Image menu in the UV/Image Editor windowand choosing Save as… , see (Figure 15). Save the file as cube-texture.png to the folder where we will store our Flash files too. Please

Listing 5. Putting it all together

textureErrorHandler );

package {

loader.load( new URLRequest( "cube-

import flash.display.Bitmap; import flash.display.Loader; import flash.display.LoaderInfo; import flash.display.Sprite; import flash.events.Event; import flash.events.IOErrorEvent; import flash.net.URLRequest; import sandy.core.Scene3D; import sandy.core.scenegraph.Camera3D; import sandy.core.scenegraph.Group; import sandy.materials.Appearance; import sandy.materials.BitmapMaterial; public class Main extends Sprite { private var scene : Scene3D;

texture.png" ) );

} private function textureCompleteHandler( event : Event ) : void { var loaderInfo : LoaderInfo = event.currentTarget as LoaderInfo; cubeTexture = Bitmap( loaderInfo.content ); createCube(); } private function textureErrorHandler( event : IOErrorEvent ) : void { trace( "Could not load the texture." ); } 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 );

private var blenderCube : BlenderCube private var cubeTexture : Bitmap; public function Main() { } private function setup3DScene() : void { var camera : Camera3D = new Camera3D( 550, 400 ); setup3DScene(); loadTexture();

camera.x = 0; camera.y = 0; camera.z = 150; camera.lookAt( 0, 0, 0 ); scene = new Scene3D( "scene", this ,

scene.root.addChild( blenderCube );

addEventListener( Event.ENTER_FRAME,

enterFrameHandler );

} protected function enterFrameHandler( event : Event ) : void {

camera, new Group( "rootGroup" ) ); } private function loadTexture() : void {

blenderCube.rotateZ++; blenderCube.rotateY++;

var loader : Loader = new Loader(); loader.contentLoaderInfo.a

scene.render();

ddEventListener( Event.COMPLETE, textureCompleteHandler ); loader.contentLoaderInfo.addEv entListener( IOErrorEvent.IO_ERROR,

}

}

}

03/2009 (5)

86

Made with FlippingBook HTML5