/src/away3d/primitives/WireframePlane.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 189 lines · 130 code · 28 blank · 31 comment · 15 complexity · 0e2fc3c9893b5fadce49d55b3eb0dbf3 MD5 · raw file

  1. package away3d.primitives
  2. {
  3. import flash.geom.Vector3D;
  4. /**
  5. * A WireframePlane primitive mesh.
  6. */
  7. public class WireframePlane extends WireframePrimitiveBase
  8. {
  9. public static const ORIENTATION_YZ:String = "yz";
  10. public static const ORIENTATION_XY:String = "xy";
  11. public static const ORIENTATION_XZ:String = "xz";
  12. private var _width:Number;
  13. private var _height:Number;
  14. private var _segmentsW:int;
  15. private var _segmentsH:int;
  16. private var _orientation:String;
  17. /**
  18. * Creates a new WireframePlane object.
  19. * @param width The size of the cube along its X-axis.
  20. * @param height The size of the cube along its Y-axis.
  21. * @param segmentsW The number of segments that make up the cube along the X-axis.
  22. * @param segmentsH The number of segments that make up the cube along the Y-axis.
  23. * @param color The colour of the wireframe lines
  24. * @param thickness The thickness of the wireframe lines
  25. * @param orientation The orientaion in which the plane lies.
  26. */
  27. public function WireframePlane(width:Number, height:Number, segmentsW:int = 10, segmentsH:int = 10, color:uint = 0xFFFFFF, thickness:Number = 1, orientation:String = "yz")
  28. {
  29. super(color, thickness);
  30. _width = width;
  31. _height = height;
  32. _segmentsW = segmentsW;
  33. _segmentsH = segmentsH;
  34. _orientation = orientation;
  35. }
  36. /**
  37. * The orientaion in which the plane lies.
  38. */
  39. public function get orientation():String
  40. {
  41. return _orientation;
  42. }
  43. public function set orientation(value:String):void
  44. {
  45. _orientation = value;
  46. invalidateGeometry();
  47. }
  48. /**
  49. * The size of the cube along its X-axis.
  50. */
  51. public function get width():Number
  52. {
  53. return _width;
  54. }
  55. public function set width(value:Number):void
  56. {
  57. _width = value;
  58. invalidateGeometry();
  59. }
  60. /**
  61. * The size of the cube along its Y-axis.
  62. */
  63. public function get height():Number
  64. {
  65. return _height;
  66. }
  67. public function set height(value:Number):void
  68. {
  69. if (value <= 0)
  70. throw new Error("Value needs to be greater than 0");
  71. _height = value;
  72. invalidateGeometry();
  73. }
  74. /**
  75. * The number of segments that make up the plane along the X-axis.
  76. */
  77. public function get segmentsW():int
  78. {
  79. return _segmentsW;
  80. }
  81. public function set segmentsW(value:int):void
  82. {
  83. _segmentsW = value;
  84. removeAllSegments();
  85. invalidateGeometry();
  86. }
  87. /**
  88. * The number of segments that make up the plane along the Y-axis.
  89. */
  90. public function get segmentsH():int
  91. {
  92. return _segmentsH;
  93. }
  94. public function set segmentsH(value:int):void
  95. {
  96. _segmentsH = value;
  97. removeAllSegments();
  98. invalidateGeometry();
  99. }
  100. /**
  101. * @inheritDoc
  102. */
  103. override protected function buildGeometry():void
  104. {
  105. var v0:Vector3D = new Vector3D();
  106. var v1:Vector3D = new Vector3D();
  107. var hw:Number = _width*.5;
  108. var hh:Number = _height*.5;
  109. var index:int;
  110. var ws:int, hs:int;
  111. if (_orientation == ORIENTATION_XY) {
  112. v0.y = hh;
  113. v0.z = 0;
  114. v1.y = -hh;
  115. v1.z = 0;
  116. for (ws = 0; ws <= _segmentsW; ++ws) {
  117. v0.x = v1.x = (ws/_segmentsW - .5)*_width;
  118. updateOrAddSegment(index++, v0, v1);
  119. }
  120. v0.x = -hw;
  121. v1.x = hw;
  122. for (hs = 0; hs <= _segmentsH; ++hs) {
  123. v0.y = v1.y = (hs/_segmentsH - .5)*_height;
  124. updateOrAddSegment(index++, v0, v1);
  125. }
  126. }
  127. else if (_orientation == ORIENTATION_XZ) {
  128. v0.z = hh;
  129. v0.y = 0;
  130. v1.z = -hh;
  131. v1.y = 0;
  132. for (ws = 0; ws <= _segmentsW; ++ws) {
  133. v0.x = v1.x = (ws/_segmentsW - .5)*_width;
  134. updateOrAddSegment(index++, v0, v1);
  135. }
  136. v0.x = -hw;
  137. v1.x = hw;
  138. for (hs = 0; hs <= _segmentsH; ++hs) {
  139. v0.z = v1.z = (hs/_segmentsH - .5)*_height;
  140. updateOrAddSegment(index++, v0, v1);
  141. }
  142. }
  143. else if (_orientation == ORIENTATION_YZ) {
  144. v0.y = hh;
  145. v0.x = 0;
  146. v1.y = -hh;
  147. v1.x = 0;
  148. for (ws = 0; ws <= _segmentsW; ++ws) {
  149. v0.z = v1.z = (ws/_segmentsW - .5)*_width;
  150. updateOrAddSegment(index++, v0, v1);
  151. }
  152. v0.z = hw;
  153. v1.z = -hw;
  154. for (hs = 0; hs <= _segmentsH; ++hs) {
  155. v0.y = v1.y = (hs/_segmentsH - .5)*_height;
  156. updateOrAddSegment(index++, v0, v1);
  157. }
  158. }
  159. }
  160. }
  161. }