Quantcast
Channel: Not So Stupid » 3D
Viewing all articles
Browse latest Browse all 10

Line experiment in Away3D 4

$
0
0

Hey,
i work on some class to show « line » in away3d 4
this is « line » with always the same tickness on the screen
the final purpose is to generate wireframe , grid, helper and of course cool shit

*update* i add a grid on the floor and axis helper

you need flash player 11 to see this demo

Code source:

package {
	import away3d.arcane;
	import away3d.cameras.lenses.PerspectiveLens;
	import away3d.containers.View3D;
	import away3d.debug.AwayStats;
	import away3d.entities.SegmentSet;
	import away3d.primitives.WireframeAxesGrid;
	import away3d.primitives.LineSegment;
	import away3d.materials.ColorMaterial;

	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.geom.Vector3D;

	use namespace arcane; 

	[SWF(width="700", height="700", frameRate="60")]

	public class MainLine extends Sprite {

		private var _count : Number = 0;
		private var view: View3D;
		private var grid : WireframeAxesGrid;
		private var lines : SegmentSet;

		private var distance : Number;
		private var lastVector : Vector3D;
		private var lastColor : Number;
		private var nextVector : Vector3D;
		private var newColor : Number;
		private var tempColor : Number;

		public function MainLine() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;

			setupView3D();

			lines=new SegmentSet();
			view.scene.addChild(lines);
			grid=new  WireframeAxesGrid(10,500,.25,0x666666,0x666666,0x666666);
			view.scene.addChild(grid);

			lastVector=new Vector3D(Math.sin(_count) *distance,Math.sin(_count * .54) * distance,Math.cos(_count) *distance);
			lastColor=0;

		}

		private function setupView3D() : void {
			view = new View3D();
			view.width=1000;
			view.height=700;
			view.antiAlias = 2;
			view.backgroundColor = 0x333333;
			view.camera.z = -1500;
			view.camera.y = 1000;
			view.camera.x = -1500;
			view.camera.lookAt(new Vector3D(0, 150, 0));
			view.camera.lens.near=.02;
			view.camera.lens.far=500000;
			(view.camera.lens as PerspectiveLens).fieldOfView=45;

			addChild(view);
			/*addChild(new AwayStats(view));
			var sign:SignAway=new SignAway();sign.y=700-280;
			addChild(sign);*/
			addEventListener(Event.ENTER_FRAME, _handleEnterFrame);

		}

		private function _handleEnterFrame(ev : Event) : void {

			_count += .1;
			if(_count<350){
				distance=500*Math.sin(_count/10)-250;
				tempColor=(Math.abs(distance)/250)/3*0xFF;
				nextVector=new Vector3D(Math.sin(_count)*distance,Math.sin(_count*.48 ) * distance,Math.cos(_count) *distance);
				newColor= tempColor << 16 | tempColor*.7 << 8 | 0;
				lines.addSegment(new LineSegment(lastVector, nextVector,lastColor,newColor,2+tempColor/100));
				lastVector=nextVector;
				lastColor=newColor;
			}
			view.camera.x = Math.sin(_count*.05) * 2000;
			view.camera.y = 900;
			view.camera.z = Math.cos(_count*.05 ) * 2000;
			view.camera.lookAt(new Vector3D(0, 0, 0));
			view.render();
		}
	}
}

Viewing all articles
Browse latest Browse all 10

Trending Articles