package materials { import away3d.cameras.lenses.FreeMatrixLens; import away3d.lights.PointLight; import away3d.materials.ColorMaterial; import away3d.materials.methods.BasicDiffuseMethod; import away3d.materials.methods.BasicSpecularMethod; import away3d.materials.methods.CelDiffuseMethod; import away3d.materials.methods.CelSpecularMethod; import away3d.materials.methods.FresnelSpecularMethod; import away3d.materials.methods.OutlineMethod; import away3d.materials.methods.RimLightMethod; import away3d.primitives.Sphere; import com.bit101.components.ColorChooser; import com.bit101.components.HUISlider; import com.bit101.components.Label; import flash.events.Event; import flash.geom.Vector3D; /** * @author Nicolas Barradeau * http://en.nicoptere.net */ public class A_Colormaterial extends BaseScene { private var colorMaterial:ColorMaterial; private var sphere:Sphere; /***************** UI *****************/ private var diffuseColor:ColorChooser; private var glossiness:HUISlider; private var specularity:HUISlider; private var specularColor:ColorChooser; private var ambient:HUISlider; private var ambientColor:ColorChooser; private var light:PointLight; private var lightX:HUISlider; private var lightY:HUISlider; public function A_Colormaterial() { //prépare la scène setup(); //crée un materiau couleur aplat colorMaterial = new ColorMaterial( 0 ); //crée un volume pour voir ce qu'on fait... sphere = new Sphere( colorMaterial, 200,32,24 ); addMesh( sphere ); //si on a une lumière, le matériau va renvoyer une partie de la lumière //associe un tableau d'objets lumière light = new PointLight(); light.color = 0xFFFFFF; light.position = new Vector3D( 250, 250, -250 ); addMesh( light ); colorMaterial.lights = [ light ]; /* gloss ( 1 - 100 ): force avec laquelle la lumière est renvoyée par le matériau */ colorMaterial.gloss = 1; //peut varier selon un map //colorMat.glossMap = bitmapdata; /* shininess ( 0 - 1 ): quantité de lumière renvoyée par le matériau */ colorMaterial.specular = .5; //teinte de la lumière spéculaire colorMaterial.specularColor = 0xFFFFFF; //peut varier selon un map //colorMaterial.specularMap = bitmapdata; //methodes additionnelles //cell shading ///* //colorMaterial.diffuseMethod = new CelDiffuseMethod( 3 ); //colorMaterial.specularMethod = new CelSpecularMethod( .25 ); //*/ //outline (halo solide) //colorMaterial.addMethod( new OutlineMethod( 0xFFFFFF, 10 ) ) ; //rayonnement interne //colorMaterial.addMethod( new RimLightMethod( 0xFFFFFF ) ); //joli mais bypass tous les réglages //colorMaterial.specularMethod = new FresnelSpecularMethod( true ); /******************************************************************************** UI ********************************************************************************/ var ox:int = 10; var oy:int = -10; var diffuseColorLabel:Label = new Label( this, ox, oy += 20, 'difuse color' ); diffuseColor = new ColorChooser( this, ox + diffuseColorLabel.width + 10, oy, colorMaterial.color, onChange ); specularity = new HUISlider( this, ox, oy += 20, 'specularity', onChange ); specularity.value = colorMaterial.specular * 100; glossiness = new HUISlider( this, ox, oy += 20, 'glossiness', onChange ); glossiness.minimum = 1; glossiness.value = colorMaterial.gloss; var specularColorLabel:Label = new Label( this, ox, oy += 20, 'specular color' ); specularColor = new ColorChooser( this, ox + specularColorLabel.width +10, oy, 0xFFFFFF, onChange ); ambient = new HUISlider( this, ox, oy += 20, 'ambient', onChange ); ambient.value = 0; var ambientColorLabel:Label = new Label( this, ox, oy += 20, 'ambient color' ); ambientColor = new ColorChooser( this, ox + specularColorLabel.width +10, oy, 0, onChange ); oy += 40; lightX = new HUISlider( this, ox, oy += 20, 'light X', onChange ); lightY = new HUISlider( this, ox, oy += 20, 'light Y', onChange ); lightX.minimum = lightY.minimum = -300; lightX.maximum = lightY.maximum = 300; } private function onChange( e:Event = null ):void { colorMaterial.color = diffuseColor.value; colorMaterial.gloss = glossiness.value; colorMaterial.specular = specularity.value * .01; colorMaterial.specularColor = specularColor.value; colorMaterial.ambientColor = ambientColor.value; colorMaterial.ambient = ambient.value * .01; } override protected function onEnterFrame(event:Event):void { light.x = lightX.value; light.y = lightY.value; view.render(); } } }