PageRenderTime 264ms CodeModel.GetById 160ms app.highlight 10ms RepoModel.GetById 91ms app.codeStats 0ms

/src/away3d/primitives/WireframeGrid.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 109 lines | 84 code | 15 blank | 10 comment | 6 complexity | 3cab9cfbe0bcb4140feaac91a14a298c MD5 | raw file
  1package away3d.primitives
  2{
  3	import away3d.entities.*;
  4
  5	import flash.geom.Vector3D;
  6
  7	/**
  8	* Class WireframeGrid generates a grid of lines on a given plane<code>WireframeGrid</code>
  9	* @param	subDivision		[optional] uint . Default is 10;
 10	* @param	gridSize				[optional] uint . Default is 100;
 11	* @param	color					[optional] uint . Default is 0xFFFFFF;
 12	* @param	thickness			[optional] Number . Default is 1;
 13	* @param	plane					[optional] String . Default is PLANE_XZ;
 14	* @param	worldPlanes		[optional] Boolean . Default is false.
 15	* If true, class displays the 3 world planes, at 0,0,0. with subDivision, thickness and gridSize. Overrides color and plane settings.
 16	*/
 17		
 18	public class WireframeGrid extends SegmentSet
 19	{
 20		public static const PLANE_ZY:String = "zy";
 21		public static const PLANE_XY:String = "xy";
 22		public static const PLANE_XZ:String = "xz";
 23		
 24		public function WireframeGrid(subDivision:uint = 10, gridSize:uint = 100, thickness:Number = 1, color:uint = 0xFFFFFF,  plane:String = "xz", worldPlanes:Boolean = false ) {
 25			super();
 26			
 27			if(subDivision == 0) subDivision = 1;
 28			if(thickness <= 0) thickness = 1;
 29			if(gridSize ==  0) gridSize = 1;
 30			 
 31			if(worldPlanes){
 32				build(subDivision, gridSize, 0x0000FF, thickness, PLANE_XY);
 33				build(subDivision, gridSize, 0xFF0000, thickness, PLANE_ZY);
 34				build(subDivision, gridSize, 0x00FF00, thickness, PLANE_XZ);
 35			} else{
 36				build(subDivision, gridSize, color, thickness, plane);
 37			}
 38		}
 39		
 40		private function build(subDivision:uint, gridSize:uint, color:uint, thickness:Number, plane:String):void
 41		{
 42			var bound:Number = gridSize *.5;
 43			var step:Number = gridSize/subDivision;
 44			var v0 : Vector3D = new Vector3D(0, 0, 0) ;
 45			var v1 : Vector3D = new Vector3D(0, 0, 0) ;
 46			var inc:Number = -bound;
 47			
 48			while(inc<=bound){
 49				 
 50				switch(plane){
 51					case PLANE_ZY:
 52						v0.x = 0;
 53						v0.y = inc;
 54						v0.z = bound;
 55						v1.x = 0;
 56						v1.y = inc;
 57						v1.z = -bound;
 58						addSegment( new LineSegment(v0, v1, color, color, thickness));
 59						
 60						v0.z = inc;
 61						v0.x = 0;
 62						v0.y = bound;
 63						v1.x = 0;
 64						v1.y = -bound;
 65						v1.z = inc;
 66						addSegment(new LineSegment(v0, v1, color, color, thickness ));
 67						break;
 68						
 69					case PLANE_XY:
 70						v0.x = bound;
 71						v0.y = inc;
 72						v0.z = 0;
 73						v1.x = -bound;
 74						v1.y = inc;
 75						v1.z = 0;
 76						addSegment( new LineSegment(v0, v1, color, color, thickness));
 77						v0.x = inc;
 78						v0.y = bound;
 79						v0.z = 0;
 80						v1.x = inc;
 81						v1.y = -bound;
 82						v1.z = 0;
 83						addSegment(new LineSegment(v0, v1, color, color, thickness ));
 84						break;
 85						
 86					default:
 87						v0.x = bound;
 88						v0.y = 0;
 89						v0.z = inc;
 90						v1.x = -bound;
 91						v1.y = 0;
 92						v1.z = inc;
 93						addSegment( new LineSegment(v0, v1, color, color, thickness));
 94						
 95						v0.x = inc;
 96						v0.y = 0;
 97						v0.z = bound;
 98						v1.x = inc;
 99						v1.y = 0;
100						v1.z = -bound;
101						addSegment(new LineSegment(v0, v1, color, color, thickness ));
102				}
103				
104				inc += step;
105			}
106		}
107		
108	}
109}