PageRenderTime 244ms CodeModel.GetById 121ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

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