/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

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