Line experiment in Away3D 4

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();
		}
	}
}
    • drunkcat
    • 8 mars 2011 10:13

    sources?

    • Seraf_NSS
    • 8 mars 2011 10:49

    Hi

    a pleasure to reply a comment like this…
    update the away3d 4 svn for the lines classes

    thx for your interest

  1. Fantastic. I’m picking my way through Away3D 4.0 now. Any chance you could share the code for this? Many thanks.

    • Seraf_NSS
    • 18 mars 2011 3:54

    Hi Polygeek,

    with the lastest version this is how to draw a trident:

    var sgm:SegmentsBase=new SegmentsBase(view);
    view.scene.addChild(sgm);
    sgm.addSegment(new LineSegment(new Vector3D(0, 0, 0), new Vector3D(100, 0, 0),0×000000,0xFFFFFF,1));
    sgm.addSegment(new LineSegment(new Vector3D(0, 0, 0), new Vector3D(0, 100, 0),0×000000,0xFFFFFF,1));
    sgm.addSegment(new LineSegment(new Vector3D(0, 0, 0), new Vector3D(0, 0, 100),0×000000,0xFFFFFF,1));

  2. Thanks. Got it working.

    • woonin
    • 20 mars 2011 12:40

    wow! use vpn and come to here , so,could you share the code source ,thanks very much!

    • Snownova
    • 30 mars 2011 9:47

    Hi Seraph, awesome looking tutorial and thanks for the code to make a trident. I am curious as to how you made your lines curve like that, did you write your own custom linesegment class for it or is there something in away3D 4 that can do it?

    • Seraf_NSS
    • 30 mars 2011 10:15

    Hi,
    it’s really easy to do that

    each frame i add a segment that’s all
    the end position of the segment is defined by a cos sin equation
    and the start position is the last end position

    the tickness and color is also animated

  3. This is an awesome example, thank you for posting the sources.

  1. Aucun trackback pour l'instant