package { import away3d.containers.View3D; import away3d.core.utils.Cast; import away3d.lights.DirectionalLight3D; import away3d.materials.EnviroBitmapMaterial; import away3d.materials.PhongBitmapMaterial; import away3d.primitives.Torus; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.geom.Vector3D; [SWF(width="500", height="300", frameRate="60", backgroundColor="#FFFFFF")] public class ExTorus extends Sprite { public var view:View3D; private var torus1:Torus; private var torus2:Torus; 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 ExTorus() { // 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(); light.color = 0xffffff; light.specular = 1; light.diffuse = .75; light.direction = new Vector3D(100,300,500); view.scene.addLight(light); this.addEventListener(Event.ENTER_FRAME,update); } public function update(e:Event):void { // Rotate the objects torus1.rotationX += 1; torus1.rotationY += .5; torus2.rotationX -= 1; torus2.rotationY -= .5; // Render the view view.render(); } } }