/src/away3d/primitives/SkyBox.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 253 lines · 169 code · 37 blank · 47 comment · 0 complexity · 51f54f095e97e63434985779201b5d1c MD5 · raw file

  1. package away3d.primitives
  2. {
  3. import away3d.animators.IAnimator;
  4. import away3d.arcane;
  5. import away3d.bounds.BoundingVolumeBase;
  6. import away3d.bounds.NullBounds;
  7. import away3d.cameras.Camera3D;
  8. import away3d.core.base.IRenderable;
  9. import away3d.core.base.SubGeometry;
  10. import away3d.core.managers.Stage3DProxy;
  11. import away3d.core.partition.EntityNode;
  12. import away3d.core.partition.SkyBoxNode;
  13. import away3d.entities.Entity;
  14. import away3d.errors.AbstractMethodError;
  15. import away3d.library.assets.AssetType;
  16. import away3d.materials.MaterialBase;
  17. import away3d.materials.SkyBoxMaterial;
  18. import away3d.textures.CubeTextureBase;
  19. import flash.display3D.IndexBuffer3D;
  20. import flash.geom.Matrix;
  21. import flash.geom.Matrix3D;
  22. use namespace arcane;
  23. /**
  24. * A SkyBox class is used to render a sky in the scene. It's always considered static and 'at infinity', and as
  25. * such it's always centered at the camera's position and sized to exactly fit within the camera's frustum, ensuring
  26. * the sky box is always as large as possible without being clipped.
  27. */
  28. public class SkyBox extends Entity implements IRenderable
  29. {
  30. // todo: remove SubGeometry, use a simple single buffer with offsets
  31. private var _geometry:SubGeometry;
  32. private var _material:SkyBoxMaterial;
  33. private var _uvTransform:Matrix = new Matrix();
  34. private var _animator:IAnimator;
  35. public function get animator():IAnimator
  36. {
  37. return _animator;
  38. }
  39. override protected function getDefaultBoundingVolume():BoundingVolumeBase
  40. {
  41. return new NullBounds();
  42. }
  43. /**
  44. * Create a new SkyBox object.
  45. * @param cubeMap The CubeMap to use for the sky box's texture.
  46. */
  47. public function SkyBox(cubeMap:CubeTextureBase)
  48. {
  49. super();
  50. _material = new SkyBoxMaterial(cubeMap);
  51. _material.addOwner(this);
  52. _geometry = new SubGeometry();
  53. buildGeometry(_geometry);
  54. }
  55. /**
  56. * @inheritDoc
  57. */
  58. public function activateVertexBuffer(index:int, stage3DProxy:Stage3DProxy):void
  59. {
  60. _geometry.activateVertexBuffer(index, stage3DProxy);
  61. }
  62. /**
  63. * @inheritDoc
  64. */
  65. public function activateUVBuffer(index:int, stage3DProxy:Stage3DProxy):void
  66. {
  67. }
  68. /**
  69. * @inheritDoc
  70. */
  71. public function activateVertexNormalBuffer(index:int, stage3DProxy:Stage3DProxy):void
  72. {
  73. }
  74. /**
  75. * @inheritDoc
  76. */
  77. public function activateVertexTangentBuffer(index:int, stage3DProxy:Stage3DProxy):void
  78. {
  79. }
  80. public function activateSecondaryUVBuffer(index:int, stage3DProxy:Stage3DProxy):void
  81. {
  82. }
  83. /**
  84. * @inheritDoc
  85. */
  86. public function getIndexBuffer(stage3DProxy:Stage3DProxy):IndexBuffer3D
  87. {
  88. return _geometry.getIndexBuffer(stage3DProxy);
  89. }
  90. /**
  91. * The amount of triangles that comprise the SkyBox geometry.
  92. */
  93. public function get numTriangles():uint
  94. {
  95. return _geometry.numTriangles;
  96. }
  97. /**
  98. * The entity that that initially provided the IRenderable to the render pipeline.
  99. */
  100. public function get sourceEntity():Entity
  101. {
  102. return null;
  103. }
  104. /**
  105. * The material with which to render the object.
  106. */
  107. public function get material():MaterialBase
  108. {
  109. return _material;
  110. }
  111. public function set material(value:MaterialBase):void
  112. {
  113. throw new AbstractMethodError("Unsupported method!");
  114. }
  115. public override function get assetType():String
  116. {
  117. return AssetType.SKYBOX;
  118. }
  119. /**
  120. * @inheritDoc
  121. */
  122. override protected function invalidateBounds():void
  123. {
  124. // dead end
  125. }
  126. /**
  127. * @inheritDoc
  128. */
  129. override protected function createEntityPartitionNode():EntityNode
  130. {
  131. return new SkyBoxNode(this);
  132. }
  133. /**
  134. * @inheritDoc
  135. */
  136. override protected function updateBounds():void
  137. {
  138. _boundsInvalid = false;
  139. }
  140. /**
  141. * Builds the geometry that forms the SkyBox
  142. */
  143. private function buildGeometry(target:SubGeometry):void
  144. {
  145. var vertices:Vector.<Number> = new <Number>[
  146. -1, 1, -1, 1, 1, -1,
  147. 1, 1, 1, -1, 1, 1,
  148. -1, -1, -1, 1, -1, -1,
  149. 1, -1, 1, -1, -1, 1
  150. ];
  151. vertices.fixed = true;
  152. var indices:Vector.<uint> = new <uint>[
  153. 0, 1, 2, 2, 3, 0,
  154. 6, 5, 4, 4, 7, 6,
  155. 2, 6, 7, 7, 3, 2,
  156. 4, 5, 1, 1, 0, 4,
  157. 4, 0, 3, 3, 7, 4,
  158. 2, 1, 5, 5, 6, 2
  159. ];
  160. target.updateVertexData(vertices);
  161. target.updateIndexData(indices);
  162. }
  163. public function get castsShadows():Boolean
  164. {
  165. return false;
  166. }
  167. public function get uvTransform():Matrix
  168. {
  169. return _uvTransform;
  170. }
  171. public function get vertexData():Vector.<Number>
  172. {
  173. return _geometry.vertexData;
  174. }
  175. public function get indexData():Vector.<uint>
  176. {
  177. return _geometry.indexData;
  178. }
  179. public function get UVData():Vector.<Number>
  180. {
  181. return _geometry.UVData;
  182. }
  183. public function get numVertices():uint
  184. {
  185. return _geometry.numVertices;
  186. }
  187. public function get vertexStride():uint
  188. {
  189. return _geometry.vertexStride;
  190. }
  191. public function get vertexNormalData():Vector.<Number>
  192. {
  193. return _geometry.vertexNormalData;
  194. }
  195. public function get vertexTangentData():Vector.<Number>
  196. {
  197. return _geometry.vertexTangentData;
  198. }
  199. public function get vertexOffset():int
  200. {
  201. return _geometry.vertexOffset;
  202. }
  203. public function get vertexNormalOffset():int
  204. {
  205. return _geometry.vertexNormalOffset;
  206. }
  207. public function get vertexTangentOffset():int
  208. {
  209. return _geometry.vertexTangentOffset;
  210. }
  211. public function getRenderSceneTransform(camera:Camera3D):Matrix3D
  212. {
  213. return _sceneTransform;
  214. }
  215. }
  216. }