package materials { import away3d.materials.BitmapMaterial; import away3d.materials.methods.OutlineMethod; import away3d.primitives.Cube; import away3d.primitives.Sphere; import flash.display.BitmapData; import flash.display.BlendMode; import triga.render.MaterialHelper; import triga.render.ViewHelper; /** * @author Nicolas Barradeau * http://en.nicoptere.net */ public class D_GradientMaterials extends BaseScene { [Embed(source="../../lib/res/textures/cubemap_512.png")] private var source:Class; private var cubemap:BitmapData = new source().bitmapData; public function D_GradientMaterials() { setup(); } override protected function initObjects():void { var distance:Number = 2500; for (var i:int = 0; i < 36; i++) { var mat:BitmapMaterial; if ( i % 2 == 0 ) { var color:uint = getColor(); mat = MaterialHelper.horizontalGradient( 64, [ color, getColor(), getColor(), color ] ); } else { mat = MaterialHelper.verticalGradient( 64, [ getColor(), getColor(), getColor(), getColor() ] ); } mat.lights = lights; mat.blendMode = BlendMode.ADD; MaterialHelper.createEnvrionmentMap( mat, cubemap, .9, .35 ); var sp:Sphere = new Sphere( mat, 50 + Math.random() * 200, 32, 32 ); sp.x = ( Math.random() - .5 ) * distance; sp.y = ( Math.random() - .5 ) * distance; sp.z = ( Math.random() - .5 ) * distance; addMesh( sp ); } } private function getColor():uint { var alpha:uint = 0x80 + 0x80 * Math.random(); var color:uint = 0x808080 + Math.random() * 0x808080; return alpha << 24 | color; } } }