package { import away3d.containers.View3D; import away3d.lights.DirectionalLight3D; import away3d.materials.Dot3BitmapMaterial; import away3d.materials.EnviroBitmapMaterial; import away3d.materials.PhongBitmapMaterial; import away3d.primitives.Torus; import away3d.core.utils.Cast; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; [SWF(width="500", height="300", frameRate="60", backgroundColor="#FFFFFF")] public class Basic08_torus extends Sprite { private var view:View3D; private var torus1:Torus; private var torus2:Torus; private var cover:Cover; private var light:DirectionalLight3D; /** * The following 6 lines are how graphics are embedded using Flex. * If you are using the Flash IDE, simply remove these * lines of code, import the image to your library and set it to * export with the class same name as the variable used below. **/ [Embed(source="resources/mandelbrot.jpg")] private var enviroTexture:Class; [Embed(source="resources/doughnut.jpg")] private var doughTexture:Class; [Embed(source="resources/marble.jpg")] private var grassTexture:Class; public function Basic08_torus() { // create a viewport view = new View3D({x:250,y:150}); addChild(view); // Create Torus and apply fancy material var enviro:BitmapData = Cast.bitmap(enviroTexture); var grass:BitmapData = Cast.bitmap(grassTexture); var mat:EnviroBitmapMaterial = new EnviroBitmapMaterial(enviro,grass); mat.reflectiveness = 0.3; torus1 = new Torus({material:mat,x:-140,radius:80}); torus1.segmentsR = 20; torus1.segmentsT = 10; view.scene.addChild(torus1); // Create another torus with delicious texture var doughTexture:BitmapData = Cast.bitmap(doughTexture); var mat2:PhongBitmapMaterial = new PhongBitmapMaterial(doughTexture); //mat2.specular = 0.5; torus2 = new Torus({material:mat2,radius:80,x:140,rotationX:90}); torus2.segmentsR = 20; torus2.segmentsT = 10; view.scene.addChild(torus2); // Add a light to make the Phong material visible light = new DirectionalLight3D({x:100,y:300,z:-500}); light.color = 0xffffff; light.specular = 1; light.diffuse = .75; view.scene.addChild(light); // add the cover that prevents the problem with too many SWF files running at once view.render(); cover = new Cover(this,500,300); addChild(cover); // render on enterframe this.addEventListener(Event.ENTER_FRAME,render); } private function render(e:Event):void { if(!cover.visible) { // Rotate the objects torus1.rotationX += 1; torus1.rotationY += .5; torus2.rotationX -= 1; torus2.rotationY -= .5; // Render the view view.render(); } } } }