Following line

Friday, November 21st, 2008 | examples, requests

Line3Ds have a starting Vertex3D and an ending Vertex3D. You can simply update those vertices using the following properties to move the line around:

//starting
line.v0.x = 0;
line.v0.x = 0;
line.v0.x = 0;
//ending
line.v1.x = 100;
line.v1.x = 100;
line.v1.x = 100;


source

package
{
	import gs.TweenMax;
 
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.materials.WireframeMaterial;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.stats.StatsView;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class LinesBetweenTwo3DPoints extends BasicView
	{
		private var sphere1:Sphere;
		private var sphere2:Sphere;
		private var line:Line3D;
		private var startVertex3D:Vertex3D;
		private var endVertex3D:Vertex3D;
 
		public function LinesBetweenTwo3DPoints()
		{
			var stats:StatsView = new StatsView(renderer);
			stats.x = 440;
			addChild(stats);
 
			var material:WireframeMaterial = new WireframeMaterial(0xcc0000);
			sphere1 = new Sphere(material, 50);
			sphere2 = new Sphere(material, 50);
			sphere2.x = 500;
			sphere2.y = 500;
 
			var lines:Lines3D = new Lines3D();
 
			startVertex3D = new Vertex3D(sphere1.x, sphere1.y, sphere1.z);
			endVertex3D = new Vertex3D(sphere2.x, sphere2.y, sphere2.z);
			var lineMaterial:LineMaterial = new LineMaterial(0x00cc00);
			line = new Line3D(lines, lineMaterial, 4, startVertex3D, endVertex3D);
 
			lines.addLine(line);
 
			scene.addChild(sphere1);
			scene.addChild(sphere2);
			scene.addChild(lines);
 
			startRendering();
 
			//Tween stuff
			var bezierThrough:Array = []; 
			for(var i:int = 0; i < 10; i++)
			{
				var bezierPoint:Object = {};
				bezierPoint.x = Math.random() * 1000 - 500;
				bezierPoint.y = Math.random() * 1000 - 500;
				bezierPoint.z = Math.random() * 500;
				bezierThrough.push(bezierPoint);
			}
 
			TweenMax.to(sphere2, 10, {x:500, y:500, z:0, bezierThrough:bezierThrough, loop:true, onUpdate:tweenUpdate});
		}
 
		private function tweenUpdate():void
		{
			sphere1.lookAt(sphere2); //just for added efffect :)
			//v1 is the end point, so have it follow sphere2
			line.v1.x = sphere2.x;
			line.v1.y = sphere2.y;
			line.v1.z = sphere2.z;
		}
	}
}

Tags:

  • Soorry!
    I confuse Line3D with Lines3D.
  • var lines:Lines3D = new Lines3D();

    But:
    public function Line3D(instance:Lines3D, material:LineMaterial, size:Number, vertex0:Vertex3D, vertex1:Vertex3D)

    it seems lack five parameters
  • John Lindquist
    I understand why you would do that. In the standard flash graphics package, you have to draw, clear, then redraw each frame. In pv3d, line3ds are renderable items that can easily be moved around without reissuing draw commands (all the drawing/redrawing is handled internally).
  • You are offically my hero. my original try at this was to remove and then addchild per update causing a pretty nasty memory leak.

    thanks again!
blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

Recent Comments

 

November 2008
M T W T F S S
    Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...