/src/away3d/primitives/WireframePrimitiveBase.as

http://github.com/away3d/away3d-core-fp11 · ActionScript · 109 lines · 91 code · 18 blank · 0 comment · 6 complexity · 952df017be0d976ec8f7d0d0f13c9439 MD5 · raw file

  1. package away3d.primitives
  2. {
  3. import away3d.arcane;
  4. import away3d.bounds.BoundingVolumeBase;
  5. import away3d.entities.SegmentSet;
  6. import away3d.errors.AbstractMethodError;
  7. import away3d.primitives.data.Segment;
  8. import flash.geom.Vector3D;
  9. use namespace arcane;
  10. public class WireframePrimitiveBase extends SegmentSet
  11. {
  12. private var _geomDirty:Boolean = true;
  13. private var _color:uint;
  14. private var _thickness:Number;
  15. public function WireframePrimitiveBase(color:uint = 0xffffff, thickness:Number = 1)
  16. {
  17. if (thickness <= 0)
  18. thickness = 1;
  19. _color = color;
  20. _thickness = thickness;
  21. mouseEnabled = mouseChildren = false;
  22. }
  23. public function get color():uint
  24. {
  25. return _color;
  26. }
  27. public function set color(value:uint):void
  28. {
  29. _color = value;
  30. for each (var segRef:Object in _segments) {
  31. segRef.segment.startColor = segRef.segment.endColor = value;
  32. }
  33. }
  34. public function get thickness():Number
  35. {
  36. return _thickness;
  37. }
  38. public function set thickness(value:Number):void
  39. {
  40. _thickness = value;
  41. for each (var segRef:Object in _segments) {
  42. segRef.segment.thickness = segRef.segment.thickness = value;
  43. }
  44. }
  45. override public function removeAllSegments():void
  46. {
  47. super.removeAllSegments();
  48. }
  49. override public function get bounds():BoundingVolumeBase
  50. {
  51. if (_geomDirty)
  52. updateGeometry();
  53. return super.bounds;
  54. }
  55. protected function buildGeometry():void
  56. {
  57. throw new AbstractMethodError();
  58. }
  59. protected function invalidateGeometry():void
  60. {
  61. _geomDirty = true;
  62. invalidateBounds();
  63. }
  64. private function updateGeometry():void
  65. {
  66. buildGeometry();
  67. _geomDirty = false;
  68. }
  69. protected function updateOrAddSegment(index:uint, v0:Vector3D, v1:Vector3D):void
  70. {
  71. var segment:Segment;
  72. var s:Vector3D, e:Vector3D;
  73. if ((segment = getSegment(index)) != null) {
  74. s = segment.start;
  75. e = segment.end;
  76. s.x = v0.x;
  77. s.y = v0.y;
  78. s.z = v0.z;
  79. e.x = v1.x;
  80. e.y = v1.y;
  81. e.z = v1.z;
  82. segment.updateSegment(s, e, null, _color, _color, _thickness);
  83. } else
  84. addSegment(new LineSegment(v0.clone(), v1.clone(), _color, _color, _thickness));
  85. }
  86. override protected function updateMouseChildren():void
  87. {
  88. _ancestorsAllowMouseEnabled = false;
  89. }
  90. }
  91. }