PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/away3d/materials/utils/CubeMap.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 157 lines | 94 code | 20 blank | 43 comment | 4 complexity | 4d579c0c7bc5f5c5a6d81827c5525380 MD5 | raw file
  1package away3d.materials.utils
  2{
  3	import away3d.arcane;
  4	import away3d.materials.utils.MipmapGenerator;
  5
  6	import flash.display.BitmapData;
  7	import flash.display3D.textures.CubeTexture;
  8
  9	use namespace arcane;
 10
 11	/**
 12	 * CubeMap represents a cube map texture, consisting out of 6 BitmapData objects. All BitmapData objects should be
 13	 * of the same size.
 14	 *
 15	 * todo: provide abstract form for render to texture cubemaps, dds, etc
 16	 */
 17	public class CubeMap
 18	{
 19		private var _bitmapDatas : Vector.<BitmapData>;
 20		private var _size : int;
 21
 22		/**
 23		 * Creates a new CubeMap object.
 24		 * @param posX The texture on the cube's right face.
 25		 * @param negX The texture on the cube's left face.
 26		 * @param posY The texture on the cube's top face.
 27		 * @param negY The texture on the cube's bottom face.
 28		 * @param posZ The texture on the cube's far face.
 29		 * @param negZ The texture on the cube's near face.
 30		 */
 31		public function CubeMap(posX : BitmapData = null, negX : BitmapData = null,
 32								posY : BitmapData = null, negY : BitmapData = null,
 33								posZ : BitmapData = null, negZ : BitmapData = null)
 34		{
 35			_bitmapDatas = new Vector.<BitmapData>(6, true);
 36			_bitmapDatas[0] = posX;
 37			_bitmapDatas[1] = negX;
 38			_bitmapDatas[2] = posY;
 39			_bitmapDatas[3] = negY;
 40			_bitmapDatas[4] = posZ;
 41			_bitmapDatas[5] = negZ;
 42			if (positiveX) {
 43				_size = positiveX.width;
 44				_size = positiveY.width;
 45			}
 46		}
 47
 48		/**
 49		 * The size of the cube map texture.
 50		 */
 51		public function get size() : int
 52		{
 53			return _size;
 54		}
 55
 56		/**
 57		 * The texture on the cube's right face.
 58		 */
 59		public function get positiveX() : BitmapData
 60		{
 61			return _bitmapDatas[0];
 62		}
 63
 64		public function set positiveX(value : BitmapData) : void
 65		{
 66			_size = value.width;
 67			_bitmapDatas[0] = value;
 68		}
 69
 70		/**
 71		 * The texture on the cube's left face.
 72		 */
 73		public function get negativeX() : BitmapData
 74		{
 75			return _bitmapDatas[1];
 76		}
 77
 78		public function set negativeX(value : BitmapData) : void
 79		{
 80			_bitmapDatas[1] = value;
 81		}
 82
 83		/**
 84		 * The texture on the cube's top face.
 85		 */
 86		public function get positiveY() : BitmapData
 87		{
 88			return _bitmapDatas[2];
 89		}
 90
 91		public function set positiveY(value : BitmapData) : void
 92		{
 93			_bitmapDatas[2] = value;
 94		}
 95
 96		/**
 97		 * The texture on the cube's bottom face.
 98		 */
 99		public function get negativeY() : BitmapData
100		{
101			return _bitmapDatas[3];
102		}
103
104		public function set negativeY(value : BitmapData) : void
105		{
106			_bitmapDatas[3] = value;
107		}
108
109		/**
110		 * The texture on the cube's far face.
111		 */
112		public function get positiveZ() : BitmapData
113		{
114			return _bitmapDatas[4];
115		}
116
117		public function set positiveZ(value : BitmapData) : void
118		{
119			_bitmapDatas[4] = value;
120		}
121
122		/**
123		 * The texture on the cube's near face.
124		 */
125		public function get negativeZ() : BitmapData
126		{
127			return _bitmapDatas[5];
128		}
129
130		public function set negativeZ(value : BitmapData) : void
131		{
132			_bitmapDatas[5] = value;
133		}
134
135		/**
136		 * Disposes of all BitmapData objects used by this CubeMap.
137		 */
138		public function dispose() : void
139		{
140			if (_bitmapDatas)
141				for (var i : int = 0; i < 6; ++i)
142					_bitmapDatas[i].dispose();
143
144			_bitmapDatas = null;
145		}
146
147		/**
148		 * Uploads the BitmapData objects to the CubeTexture.
149		 * @param cubeTexture The CubeTexture to upload to.
150		 */
151		arcane function upload(cubeTexture : CubeTexture) : void
152		{
153			for (var i : int = 0; i < 6; ++i)
154				MipmapGenerator.generateMipMaps(_bitmapDatas[i], cubeTexture, null, false, i);
155		}
156	}
157}