/src/away3d/primitives/data/Segment.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 178 lines · 127 code · 32 blank · 19 comment · 5 complexity · 872b16b14b1a7dca28dcb680940aa872 MD5 · raw file

  1. package away3d.primitives.data
  2. {
  3. import away3d.arcane;
  4. import away3d.entities.SegmentSet;
  5. import flash.geom.Vector3D;
  6. use namespace arcane;
  7. public class Segment
  8. {
  9. arcane var _segmentsBase:SegmentSet;
  10. arcane var _thickness:Number;
  11. arcane var _start:Vector3D;
  12. arcane var _end:Vector3D;
  13. arcane var _startR:Number;
  14. arcane var _startG:Number;
  15. arcane var _startB:Number;
  16. arcane var _endR:Number;
  17. arcane var _endG:Number;
  18. arcane var _endB:Number;
  19. private var _index:int = -1;
  20. private var _subSetIndex:int = -1;
  21. private var _startColor:uint;
  22. private var _endColor:uint;
  23. public function Segment(start:Vector3D, end:Vector3D, anchor:Vector3D, colorStart:uint = 0x333333, colorEnd:uint = 0x333333, thickness:Number = 1):void
  24. {
  25. // TODO: not yet used: for CurveSegment support
  26. anchor = null;
  27. _thickness = thickness*.5;
  28. // TODO: add support for curve using anchor v1
  29. // Prefer removing v1 from this, and make Curve a separate class extending Segment? (- David)
  30. _start = start;
  31. _end = end;
  32. startColor = colorStart;
  33. endColor = colorEnd;
  34. }
  35. public function updateSegment(start:Vector3D, end:Vector3D, anchor:Vector3D, colorStart:uint = 0x333333, colorEnd:uint = 0x333333, thickness:Number = 1):void
  36. {
  37. // TODO: not yet used: for CurveSegment support
  38. anchor = null;
  39. _start = start;
  40. _end = end;
  41. if (_startColor != colorStart)
  42. startColor = colorStart;
  43. if (_endColor != colorEnd)
  44. endColor = colorEnd;
  45. _thickness = thickness*.5;
  46. update();
  47. }
  48. /**
  49. * Defines the starting vertex.
  50. */
  51. public function get start():Vector3D
  52. {
  53. return _start;
  54. }
  55. public function set start(value:Vector3D):void
  56. {
  57. _start = value;
  58. update();
  59. }
  60. /**
  61. * Defines the ending vertex.
  62. */
  63. public function get end():Vector3D
  64. {
  65. return _end;
  66. }
  67. public function set end(value:Vector3D):void
  68. {
  69. _end = value;
  70. update();
  71. }
  72. /**
  73. * Defines the ending vertex.
  74. */
  75. public function get thickness():Number
  76. {
  77. return _thickness*2;
  78. }
  79. public function set thickness(value:Number):void
  80. {
  81. _thickness = value*.5;
  82. update();
  83. }
  84. /**
  85. * Defines the startColor
  86. */
  87. public function get startColor():uint
  88. {
  89. return _startColor;
  90. }
  91. public function set startColor(color:uint):void
  92. {
  93. _startR = ( ( color >> 16 ) & 0xff )/255;
  94. _startG = ( ( color >> 8 ) & 0xff )/255;
  95. _startB = ( color & 0xff )/255;
  96. _startColor = color;
  97. update();
  98. }
  99. /**
  100. * Defines the endColor
  101. */
  102. public function get endColor():uint
  103. {
  104. return _endColor;
  105. }
  106. public function set endColor(color:uint):void
  107. {
  108. _endR = ( ( color >> 16 ) & 0xff )/255;
  109. _endG = ( ( color >> 8 ) & 0xff )/255;
  110. _endB = ( color & 0xff )/255;
  111. _endColor = color;
  112. update();
  113. }
  114. public function dispose():void
  115. {
  116. _start = null;
  117. _end = null;
  118. }
  119. arcane function get index():int
  120. {
  121. return _index;
  122. }
  123. arcane function set index(ind:int):void
  124. {
  125. _index = ind;
  126. }
  127. arcane function get subSetIndex():int
  128. {
  129. return _subSetIndex;
  130. }
  131. arcane function set subSetIndex(ind:int):void
  132. {
  133. _subSetIndex = ind;
  134. }
  135. arcane function set segmentsBase(segBase:SegmentSet):void
  136. {
  137. _segmentsBase = segBase;
  138. }
  139. private function update():void
  140. {
  141. if (!_segmentsBase)
  142. return;
  143. _segmentsBase.updateSegment(this);
  144. }
  145. }
  146. }