PageRenderTime 394ms CodeModel.GetById 191ms app.highlight 4ms RepoModel.GetById 198ms app.codeStats 0ms

/src/away3d/materials/ColorMaterial.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 68 lines | 42 code | 9 blank | 17 comment | 6 complexity | 7d52f4c6ee07197d1d77c2d4dbfde907 MD5 | raw file
 1package away3d.materials
 2{
 3	import away3d.arcane;
 4	
 5	import flash.display.BlendMode;
 6	
 7	use namespace arcane;
 8	
 9	/**
10	 * ColorMaterial is a single-pass material that uses a flat color as the surface's diffuse reflection value.
11	 */
12	public class ColorMaterial extends SinglePassMaterialBase
13	{
14		private var _diffuseAlpha:Number = 1;
15		
16		/**
17		 * Creates a new ColorMaterial object.
18		 * @param color The material's diffuse surface color.
19		 * @param alpha The material's surface alpha.
20		 */
21		public function ColorMaterial(color:uint = 0xcccccc, alpha:Number = 1)
22		{
23			super();
24			this.color = color;
25			this.alpha = alpha;
26		}
27		
28		/**
29		 * The alpha of the surface.
30		 */
31		public function get alpha():Number
32		{
33			return _screenPass.diffuseMethod.diffuseAlpha;
34		}
35		
36		public function set alpha(value:Number):void
37		{
38			if (value > 1)
39				value = 1;
40			else if (value < 0)
41				value = 0;
42			_screenPass.diffuseMethod.diffuseAlpha = _diffuseAlpha = value;
43			_screenPass.preserveAlpha = requiresBlending;
44			_screenPass.setBlendMode(blendMode == BlendMode.NORMAL && requiresBlending? BlendMode.LAYER : blendMode);
45		}
46		
47		/**
48		 * The diffuse reflectivity color of the surface.
49		 */
50		public function get color():uint
51		{
52			return _screenPass.diffuseMethod.diffuseColor;
53		}
54		
55		public function set color(value:uint):void
56		{
57			_screenPass.diffuseMethod.diffuseColor = value;
58		}
59		
60		/**
61		 * @inheritDoc
62		 */
63		override public function get requiresBlending():Boolean
64		{
65			return super.requiresBlending || _diffuseAlpha < 1;
66		}
67	}
68}