Archive for November 21st, 2008
Following line
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;
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; } } }
Waiting for an image to load – BitmapFileMaterial
package { import org.papervision3d.events.FileLoadEvent; import org.papervision3d.materials.BitmapFileMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.view.BasicView; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class WaitForAnImageToLoad extends BasicView { public function WaitForAnImageToLoad() { var url:String = "http://content.screencast.com/media/1676f247-e7f0-4035-a826-06e2d7885731_089125cc-8776-47ed-92d7-280330071c15_static_0_0_00000149.png"; var bitmapFileMaterial:BitmapFileMaterial = new BitmapFileMaterial(url); bitmapFileMaterial.addEventListener(FileLoadEvent.LOAD_COMPLETE, loadCompleteHandler); } private function loadCompleteHandler(event:FileLoadEvent):void { var plane:Plane = new Plane(BitmapFileMaterial(event.target)); scene.addChild(plane); singleRender(); } } }
Camera free vs. target
By default, cameras point forward. If you give them a “target” to look at, they’ll stay focused on the target. In this example, you’ll see two cameras moving in the exact same circular pattern. The left camera keeps looking forward while the right camera keeps looking at the center

source
package { import flash.display.Sprite; import flash.events.Event; import flash.text.TextFormat; import gs.TweenMax; import org.papervision3d.cameras.Camera3D; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; [SWF(width="800", height="300", backgroundColor="#000000", frameRate="60")] public class FreeCameraVSTargetCamera extends Sprite { private var leftViewport:Viewport3D; private var leftCamera:Camera3D; private var rightViewport:Viewport3D; private var rightCamera:Camera3D; private var scene:Scene3D; private var renderer:BasicRenderEngine; public function FreeCameraVSTargetCamera() { leftViewport = new Viewport3D(400, 300); leftCamera = new Camera3D(); leftCamera.y = 100; leftCamera.z = -2000; rightViewport = new Viewport3D(400, 300); rightCamera = new Camera3D(); rightCamera.target = DisplayObject3D.ZERO;//x:0, y:0, z:0 rightCamera.y = 100; rightCamera.z = -2000; addChild(leftViewport); rightViewport.x = 400; rightViewport.opaqueBackground = 0xffffff; addChild(rightViewport); scene= new Scene3D(); renderer = new BasicRenderEngine(); for(var i:int = 0; i < 5; i++) { for(var j:int = 0; j < 5; j++) { var randColor:Number = Math.random() * 0xffffff; var material:WireframeMaterial = new WireframeMaterial(randColor, 1, 2); var sphere:Sphere = new Sphere(material); sphere.x = 1000 * i - 2000; sphere.z = 1000 * j - 2000; scene.addChild(sphere); } } var floor:Plane = new Plane(new WireframeMaterial(0x00cc00, 1, 2), 5000, 5000, 10, 10); floor.pitch(90); floor.y = -100; scene.addChild(floor); //Set both cameras along the same circular motion var bezierThrough:Array = [{x:2000, z:0}, {x:0, z:2000}, {x:-2000, z:0}]; TweenMax.to(leftCamera, 10, {x:0, z:-2000, bezierThrough:bezierThrough, yoyo:true}); TweenMax.to(rightCamera, 10, {x:0, z:-2000, bezierThrough:bezierThrough, yoyo:true}); addEventListener(Event.ENTER_FRAME, enterFrameHandler); addText(); } private function addText():void { var leftHeaderText:headerContainer = new headerContainer(); leftHeaderText.header.text = "No target"; addChild(leftHeaderText); var rightHeaderText:headerContainer = new headerContainer(); rightHeaderText.x = 400; var textFormat:TextFormat = new TextFormat(); textFormat.color = 0x000000; rightHeaderText.header.defaultTextFormat = textFormat; rightHeaderText.header.text = "Target DisplayObject3D.ZERO"; addChild(rightHeaderText); } private function enterFrameHandler(event:Event):void { renderer.renderScene(scene, leftCamera, leftViewport); renderer.renderScene(scene, rightCamera, rightViewport); } } }
Search
Recommended Books
Speaking at FITC Toronto
Recent Posts
- FDT Super Awesome March Deal
- haXe Tutorial
- AS3 Signals Tutorial
- Preferred Video Tutorial Resolution?
- TweenMax – Tweening a timeline (Advanced Tweening)
- Robotlegs + Flight + Union Platform
- Back in the saddle
- Eclipse Theme Designer Preview
- RobotLegs Hello World Video Tutorial
- 10 Things Every Senior Flash Developer Should Know
- Efflex – 3D Effects for Flex
- MorphController – Mighty Morphing Papervision3D
- End dump
- Test if a plane is within the view of the camera (aka testing if culled)
- Materials Reference
Recent Comments
- John Lindquist on ActionScript 3 – Model View Controller (MVC)
- Bruno Fonzi on FDT Super Awesome March Deal
- KD on ActionScript 3 – Model View Controller (MVC)
- BAM5 on haXe Tutorial
- AlexG on Finding 2D Coordinates of a DisplayObject3D
- Josh on ActionScript 3 – Model View Controller (MVC)
- martin everett on requests
- martin everett on requests
- lillacska on Dragging Spheres
- Guy Ritchie on MXML without the Flex framework
Categories
Archives
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


