/src/away3d/primitives/WireframeCube.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 139 lines · 102 code · 14 blank · 23 comment · 1 complexity · f09da7aa35be5094a2dcd77d4eea8d8c MD5 · raw file

  1. package away3d.primitives
  2. {
  3. import flash.geom.Vector3D;
  4. /**
  5. * A WirefameCube primitive mesh.
  6. */
  7. public class WireframeCube extends WireframePrimitiveBase
  8. {
  9. private var _width:Number;
  10. private var _height:Number;
  11. private var _depth:Number;
  12. /**
  13. * Creates a new WireframeCube object.
  14. * @param width The size of the cube along its X-axis.
  15. * @param height The size of the cube along its Y-axis.
  16. * @param depth The size of the cube along its Z-axis.
  17. * @param color The colour of the wireframe lines
  18. * @param thickness The thickness of the wireframe lines
  19. */
  20. public function WireframeCube(width:Number = 100, height:Number = 100, depth:Number = 100, color:uint = 0xFFFFFF, thickness:Number = 1)
  21. {
  22. super(color, thickness);
  23. _width = width;
  24. _height = height;
  25. _depth = depth;
  26. }
  27. /**
  28. * The size of the cube along its X-axis.
  29. */
  30. public function get width():Number
  31. {
  32. return _width;
  33. }
  34. public function set width(value:Number):void
  35. {
  36. _width = value;
  37. invalidateGeometry();
  38. }
  39. /**
  40. * The size of the cube along its Y-axis.
  41. */
  42. public function get height():Number
  43. {
  44. return _height;
  45. }
  46. public function set height(value:Number):void
  47. {
  48. if (value <= 0)
  49. throw new Error("Value needs to be greater than 0");
  50. _height = value;
  51. invalidateGeometry();
  52. }
  53. /**
  54. * The size of the cube along its Z-axis.
  55. */
  56. public function get depth():Number
  57. {
  58. return _depth;
  59. }
  60. public function set depth(value:Number):void
  61. {
  62. _depth = value;
  63. invalidateGeometry();
  64. }
  65. /**
  66. * @inheritDoc
  67. */
  68. override protected function buildGeometry():void
  69. {
  70. var v0:Vector3D = new Vector3D();
  71. var v1:Vector3D = new Vector3D();
  72. var hw:Number = _width*.5;
  73. var hh:Number = _height*.5;
  74. var hd:Number = _depth*.5;
  75. v0.x = -hw;
  76. v0.y = hh;
  77. v0.z = -hd;
  78. v1.x = -hw;
  79. v1.y = -hh;
  80. v1.z = -hd;
  81. updateOrAddSegment(0, v0, v1);
  82. v0.z = hd;
  83. v1.z = hd;
  84. updateOrAddSegment(1, v0, v1);
  85. v0.x = hw;
  86. v1.x = hw;
  87. updateOrAddSegment(2, v0, v1);
  88. v0.z = -hd;
  89. v1.z = -hd;
  90. updateOrAddSegment(3, v0, v1);
  91. v0.x = -hw;
  92. v0.y = -hh;
  93. v0.z = -hd;
  94. v1.x = hw;
  95. v1.y = -hh;
  96. v1.z = -hd;
  97. updateOrAddSegment(4, v0, v1);
  98. v0.y = hh;
  99. v1.y = hh;
  100. updateOrAddSegment(5, v0, v1);
  101. v0.z = hd;
  102. v1.z = hd;
  103. updateOrAddSegment(6, v0, v1);
  104. v0.y = -hh;
  105. v1.y = -hh;
  106. updateOrAddSegment(7, v0, v1);
  107. v0.x = -hw;
  108. v0.y = -hh;
  109. v0.z = -hd;
  110. v1.x = -hw;
  111. v1.y = -hh;
  112. v1.z = hd;
  113. updateOrAddSegment(8, v0, v1);
  114. v0.y = hh;
  115. v1.y = hh;
  116. updateOrAddSegment(9, v0, v1);
  117. v0.x = hw;
  118. v1.x = hw;
  119. updateOrAddSegment(10, v0, v1);
  120. v0.y = -hh;
  121. v1.y = -hh;
  122. updateOrAddSegment(11, v0, v1);
  123. }
  124. }
  125. }