PageRenderTime 202ms CodeModel.GetById 79ms app.highlight 6ms RepoModel.GetById 115ms app.codeStats 0ms

/src/away3d/materials/BitmapMaterial.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 117 lines | 70 code | 17 blank | 30 comment | 5 complexity | dfbe7788abbff77c879cf06d68ae785c MD5 | raw file
  1package away3d.materials
  2{
  3	import away3d.arcane;
  4	import away3d.cameras.Camera3D;
  5
  6	import flash.display.BitmapData;
  7	import flash.display3D.Context3D;
  8	import flash.geom.ColorTransform;
  9
 10	use namespace arcane;
 11
 12	/**
 13	 * BitmapMaterial is a material that uses a BitmapData texture as the surface's diffuse colour.
 14	 */
 15	public class BitmapMaterial extends DefaultMaterialBase
 16	{
 17		private var _alphaBlending : Boolean;
 18
 19		/**
 20		 * Creates a new BitmapMaterial.
 21		 * @param bitmapData The BitmapData object to use as the texture.
 22		 * @param smooth Indicates whether or not the texture should use smoothing.
 23		 * @param repeat Indicates whether or not the texture should be tiled.
 24		 * @param mipmap Indicates whether or not the texture should use mipmapping.
 25		 */
 26		public function BitmapMaterial(bitmapData : BitmapData = null, smooth : Boolean = true, repeat : Boolean = false, mipmap : Boolean = true)
 27		{
 28			super();
 29			this.bitmapData = bitmapData;
 30			this.smooth = smooth;
 31			this.repeat = repeat;
 32			this.mipmap = mipmap;
 33		}
 34
 35		public function get animateUVs() : Boolean
 36		{
 37			return _screenPass.animateUVs;
 38		}
 39
 40		public function set animateUVs(value : Boolean) : void
 41		{
 42			_screenPass.animateUVs = value;
 43		}
 44
 45		/**
 46		 * The alpha of the surface.
 47		 */
 48		public function get alpha() : Number
 49		{
 50			return _screenPass.colorTransform? _screenPass.colorTransform.alphaMultiplier : 1;
 51		}
 52
 53		public function set alpha(value : Number) : void
 54		{
 55			if (value > 1) value = 1;
 56			else if (value < 0) value = 0;
 57
 58			colorTransform ||= new ColorTransform();
 59			colorTransform.alphaMultiplier = value;
 60		}
 61
 62//		arcane override function activatePass(index : uint, context : Context3D, contextIndex : uint, camera : Camera3D) : void
 63//		{
 64//			super.arcane::activatePass(index, context, contextIndex, camera);
 65//		}
 66
 67		/**
 68		 * The BitmapData object to use as the texture.
 69		 */
 70		public function get bitmapData() : BitmapData
 71		{
 72			return _screenPass.diffuseMethod.bitmapData;
 73		}
 74
 75		public function set bitmapData(value : BitmapData) : void
 76		{
 77			_screenPass.diffuseMethod.bitmapData = value;
 78		}
 79
 80		/**
 81		 * Triggers an update of the texture, to be used when the contents of the BitmapData has changed.
 82		 */
 83		public function updateTexture() : void
 84		{
 85			_screenPass.diffuseMethod.invalidateBitmapData();
 86		}
 87
 88		override public function get requiresBlending() : Boolean
 89		{
 90			return super.requiresBlending || _alphaBlending;
 91		}
 92
 93		/**
 94		 * Indicate whether or not the BitmapData contains semi-transparency. If binary transparency is sufficient, for
 95		 * example when using textures of foliage, consider using alphaThreshold instead.
 96		 */
 97		public function get alphaBlending() : Boolean
 98		{
 99			return _alphaBlending;
100		}
101
102		public function set alphaBlending(value : Boolean) : void
103		{
104			_alphaBlending = value;
105		}
106
107		/**
108		 * @inheritDoc
109		 */
110		override public function dispose(deep : Boolean) : void
111		{
112			if (deep)
113				_screenPass.dispose(deep);
114			super.dispose(deep);
115		}
116	}
117}