package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; import away3d.core.render.Renderer; import away3d.core.utils.Cast; import away3d.lights.DirectionalLight3D; import away3d.materials.PhongBitmapMaterial; import away3d.materials.TransformBitmapMaterial; import away3d.materials.utils.SimpleShadow; import away3d.primitives.Plane; import away3d.primitives.Sphere; import flash.display.Bitmap; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Vector3D; [SWF(width="500", height="300", frameRate="60", backgroundColor="#000000")] public class ExBitmapMaterialExplorer extends Sprite { [Embed(source="spiralgraphics/AlienAlloy3.jpg")] public var texture1:Class; [Embed(source="spiralgraphics/AluminumBrush.jpg")] public var texture2:Class; [Embed(source="spiralgraphics/Amazonia.jpg")] public var texture3:Class; [Embed(source="spiralgraphics/AmethystAlcove.jpg")] private var texture4:Class; [Embed(source="spiralgraphics/AshySandstone.jpg")] private var texture5:Class; [Embed(source="spiralgraphics/BeatenGold.jpg")] private var texture6:Class; [Embed(source="spiralgraphics/BlancoNafin.jpg")] private var texture7:Class; [Embed(source="spiralgraphics/BrecciaPernice.jpg")] private var texture8:Class; [Embed(source="spiralgraphics/FruitJelly.jpg")] private var texture9:Class; [Embed(source="spiralgraphics/MulticolorBricks.jpg")] private var texture10:Class; [Embed(source="spiralgraphics/RawGold.jpg")] private var texture11:Class; [Embed(source="spiralgraphics/SantaFeStucco.jpg")] private var texture12:Class; [Embed(source="spiralgraphics/SteelBottlestamp.jpg")] private var texture13:Class; [Embed(source="spiralgraphics/ChocolateSpread.jpg")] private var texture14:Class; [Embed(source="spiralgraphics/wood1.jpg")] private var texture15:Class; public var view:View3D; private var plane:Plane; private var sphere:Sphere; private var material1:PhongBitmapMaterial; private var material2:TransformBitmapMaterial; private var cam:HoverCamera3D; public function ExBitmapMaterialExplorer() { cam = new HoverCamera3D(); view = new View3D({x:250,y:150,camera:cam}); view.renderer = Renderer.CORRECT_Z_ORDER; addChild(view); plane = new Plane({segmentsW:1, segmentsH:1, y:-120, width:1100, height:1100}); view.scene.addChild(plane); sphere = new Sphere({radius:110,segmentsW:14,segmentsH:8}); sphere.rotationX = 85; view.scene.addChild(sphere); cam.panAngle = 0; cam.tiltAngle = 35; cam.hover(true); cam.zoom = 10; cam.lookAt( sphere.position ); cam.target.z += 10; this.addEventListener(MouseEvent.CLICK,changeMaterial); var light:DirectionalLight3D = new DirectionalLight3D(); // Move the light away from the default 0,0,0 position so we'll see some reflection light.direction = new Vector3D(500,-300,200); light.specular = 0.6; view.scene.addLight(light); var simpleshadow:SimpleShadow = new SimpleShadow(sphere,0x66000000,20,-95); simpleshadow.apply(view.scene); changeMaterial(); this.addEventListener(Event.ENTER_FRAME,update); } public function update(e:Event):void { cam.panAngle += .3; cam.hover(); view.render(); } private function changeMaterial(e:MouseEvent = null):void { var className1:String = "texture"+Math.floor( (Math.random()*15)+1).toString(); var className2:String = "texture"+Math.floor( (Math.random()*15)+1).toString(); material1 = new PhongBitmapMaterial( Cast.bitmap( new this[className1]() as Bitmap ) ); material2 = new TransformBitmapMaterial( Cast.bitmap( new this[className2]() as Bitmap ),{repeat:true, scaleX:.75, scaleY:.75} ); material2.smooth = true; sphere.material = material1; plane.material = material2; view.render(); } } }