PageRenderTime 38ms CodeModel.GetById 25ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

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