PageRenderTime 63ms CodeModel.GetById 20ms app.highlight 12ms RepoModel.GetById 18ms app.codeStats 1ms

/src/away3d/primitives/WireframePlane.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 189 lines | 130 code | 28 blank | 31 comment | 15 complexity | 0e2fc3c9893b5fadce49d55b3eb0dbf3 MD5 | raw file
  1package away3d.primitives
  2{
  3	import flash.geom.Vector3D;
  4	
  5	/**
  6	 * A WireframePlane primitive mesh.
  7	 */
  8	public class WireframePlane extends WireframePrimitiveBase
  9	{
 10		public static const ORIENTATION_YZ:String = "yz";
 11		public static const ORIENTATION_XY:String = "xy";
 12		public static const ORIENTATION_XZ:String = "xz";
 13		
 14		private var _width:Number;
 15		private var _height:Number;
 16		private var _segmentsW:int;
 17		private var _segmentsH:int;
 18		private var _orientation:String;
 19		
 20		/**
 21		 * Creates a new WireframePlane object.
 22		 * @param width The size of the cube along its X-axis.
 23		 * @param height The size of the cube along its Y-axis.
 24		 * @param segmentsW The number of segments that make up the cube along the X-axis.
 25		 * @param segmentsH The number of segments that make up the cube along the Y-axis.
 26		 * @param color The colour of the wireframe lines
 27		 * @param thickness The thickness of the wireframe lines
 28		 * @param orientation The orientaion in which the plane lies.
 29		 */
 30		public function WireframePlane(width:Number, height:Number, segmentsW:int = 10, segmentsH:int = 10, color:uint = 0xFFFFFF, thickness:Number = 1, orientation:String = "yz")
 31		{
 32			super(color, thickness);
 33			
 34			_width = width;
 35			_height = height;
 36			_segmentsW = segmentsW;
 37			_segmentsH = segmentsH;
 38			_orientation = orientation;
 39		}
 40		
 41		/**
 42		 * The orientaion in which the plane lies.
 43		 */
 44		public function get orientation():String
 45		{
 46			return _orientation;
 47		}
 48		
 49		public function set orientation(value:String):void
 50		{
 51			_orientation = value;
 52			invalidateGeometry();
 53		}
 54		
 55		/**
 56		 * The size of the cube along its X-axis.
 57		 */
 58		public function get width():Number
 59		{
 60			return _width;
 61		}
 62		
 63		public function set width(value:Number):void
 64		{
 65			_width = value;
 66			invalidateGeometry();
 67		}
 68		
 69		/**
 70		 * The size of the cube along its Y-axis.
 71		 */
 72		public function get height():Number
 73		{
 74			return _height;
 75		}
 76		
 77		public function set height(value:Number):void
 78		{
 79			if (value <= 0)
 80				throw new Error("Value needs to be greater than 0");
 81			_height = value;
 82			invalidateGeometry();
 83		}
 84		
 85		/**
 86		 * The number of segments that make up the plane along the X-axis.
 87		 */
 88		public function get segmentsW():int
 89		{
 90			return _segmentsW;
 91		}
 92		
 93		public function set segmentsW(value:int):void
 94		{
 95			_segmentsW = value;
 96			removeAllSegments();
 97			invalidateGeometry();
 98		}
 99		
100		/**
101		 * The number of segments that make up the plane along the Y-axis.
102		 */
103		public function get segmentsH():int
104		{
105			return _segmentsH;
106		}
107		
108		public function set segmentsH(value:int):void
109		{
110			_segmentsH = value;
111			removeAllSegments();
112			invalidateGeometry();
113		}
114		
115		/**
116		 * @inheritDoc
117		 */
118		override protected function buildGeometry():void
119		{
120			var v0:Vector3D = new Vector3D();
121			var v1:Vector3D = new Vector3D();
122			var hw:Number = _width*.5;
123			var hh:Number = _height*.5;
124			var index:int;
125			var ws:int, hs:int;
126			
127			if (_orientation == ORIENTATION_XY) {
128				v0.y = hh;
129				v0.z = 0;
130				v1.y = -hh;
131				v1.z = 0;
132				
133				for (ws = 0; ws <= _segmentsW; ++ws) {
134					v0.x = v1.x = (ws/_segmentsW - .5)*_width;
135					updateOrAddSegment(index++, v0, v1);
136				}
137				
138				v0.x = -hw;
139				v1.x = hw;
140				
141				for (hs = 0; hs <= _segmentsH; ++hs) {
142					v0.y = v1.y = (hs/_segmentsH - .5)*_height;
143					updateOrAddSegment(index++, v0, v1);
144				}
145			}
146			
147			else if (_orientation == ORIENTATION_XZ) {
148				v0.z = hh;
149				v0.y = 0;
150				v1.z = -hh;
151				v1.y = 0;
152				
153				for (ws = 0; ws <= _segmentsW; ++ws) {
154					v0.x = v1.x = (ws/_segmentsW - .5)*_width;
155					updateOrAddSegment(index++, v0, v1);
156				}
157				
158				v0.x = -hw;
159				v1.x = hw;
160				
161				for (hs = 0; hs <= _segmentsH; ++hs) {
162					v0.z = v1.z = (hs/_segmentsH - .5)*_height;
163					updateOrAddSegment(index++, v0, v1);
164				}
165			}
166			
167			else if (_orientation == ORIENTATION_YZ) {
168				v0.y = hh;
169				v0.x = 0;
170				v1.y = -hh;
171				v1.x = 0;
172				
173				for (ws = 0; ws <= _segmentsW; ++ws) {
174					v0.z = v1.z = (ws/_segmentsW - .5)*_width;
175					updateOrAddSegment(index++, v0, v1);
176				}
177				
178				v0.z = hw;
179				v1.z = -hw;
180				
181				for (hs = 0; hs <= _segmentsH; ++hs) {
182					v0.y = v1.y = (hs/_segmentsH - .5)*_height;
183					updateOrAddSegment(index++, v0, v1);
184				}
185			}
186		}
187	
188	}
189}