multiple viewports
Portal
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.BasicView; import org.papervision3d.view.Viewport3D; import org.papervision3d.view.layer.ViewportLayer; import org.papervision3d.view.layer.util.ViewportLayerSortMode; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class Portal extends BasicView { private var portalViewport:Viewport3D = new Viewport3D(); private var portalScene:Scene3D = new Scene3D(); private var portalPlane:Plane; private var exposedViewport:Viewport3D = new Viewport3D(); private var exposedScene:Scene3D = new Scene3D(); private var mainSphere:Sphere; private var exposedSphere:Sphere; public function Portal() { addChild(exposedViewport); addChild(portalViewport); setupExposedViewport(); setupPortalViewport(); setupMainViewport(); startRendering(); stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); } private function setupExposedViewport():void { var bitmapData:BitmapData = new BitmapData(640, 480, false, 0xffffff); var bitmap:Bitmap = new Bitmap(bitmapData); bitmap.x = -320; bitmap.y = -240; var viewportLayer:ViewportLayer = new ViewportLayer(exposedViewport, null); viewportLayer.addChild(bitmap); exposedViewport.containerSprite.addLayer(viewportLayer); var light:PointLight3D = new PointLight3D(); var flatShadeMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000, 0x2b2b2b, 10); exposedSphere = createSpheres(flatShadeMaterial); var viewportLayer2:ViewportLayer = new ViewportLayer(exposedViewport, exposedSphere); for each(var sphere:Sphere in exposedSphere.children) { viewportLayer2.addDisplayObject3D(sphere); } exposedViewport.containerSprite.addLayer(viewportLayer2); viewportLayer.layerIndex = 1; viewportLayer2.layerIndex = 2; exposedViewport.containerSprite.sortMode = ViewportLayerSortMode.INDEX_SORT; exposedScene.addChild(exposedSphere); exposedViewport.containerSprite.mask = portalViewport; } private function setupPortalViewport():void { var whiteMaterial:ColorMaterial = new ColorMaterial(0xffffff); portalPlane = new Plane(whiteMaterial); portalPlane.z = -500; portalScene.addChild(portalPlane); } private function setupMainViewport():void { var wireframeMaterial:WireframeMaterial = new WireframeMaterial(0xffffff); mainSphere = createSpheres(wireframeMaterial); scene.addChild(mainSphere); } private function keyDownHandler(event:KeyboardEvent):void { switch(event.keyCode) { case Keyboard.UP: camera.moveForward(10); break; case Keyboard.DOWN: camera.moveBackward(10); break; } } private function createSpheres(material:MaterialObject3D):Sphere { var parentSphere:Sphere = new Sphere(material); var child1:Sphere = new Sphere(material); child1.x = -500; var child2:Sphere = new Sphere(material); child2.x = 500; var child3:Sphere = new Sphere(material); child3.y = 500; var child4:Sphere = new Sphere(material); child4.y = -500; parentSphere.addChild(child1); parentSphere.addChild(child2); parentSphere.addChild(child3); parentSphere.addChild(child4); return parentSphere; } override protected function onRenderTick(event:Event=null):void { mainSphere.rotationY++; exposedSphere.rotationY++; portalPlane.moveForward(500); portalPlane.rotationY = -viewport.containerSprite.mouseX / 320 * 90; portalPlane.moveBackward(500); renderer.renderScene(portalScene, camera, portalViewport); renderer.renderScene(exposedScene, camera, exposedViewport); renderer.renderScene(scene, camera, viewport); } } }
BitmapViewportMaterial Example
You can easily render one scene into a usable material using BitmapViewportMaterial.
package { import flash.events.Event; import flash.filters.GlowFilter; import org.papervision3d.lights.PointLight3D; import org.papervision3d.materials.BitmapViewportMaterial; import org.papervision3d.materials.shadematerials.FlatShadeMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.objects.primitives.Sphere; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.BasicView; import org.papervision3d.view.BitmapViewport3D; [SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")] public class BitmapViewportMaterialExample extends BasicView { private var viewport2:BitmapViewport3D; private var scene2:Scene3D; private var sphere:Sphere; private var plane:Plane; public function BitmapViewportMaterialExample() { viewport.containerSprite.filters = [new GlowFilter(0xcc0000, 1, 10, 10, 4)]; //adds a red outline to the plane //will be rendered inside of the plane viewport2 = new BitmapViewport3D(); scene2 = new Scene3D(); var light:PointLight3D = new PointLight3D(); var sphereMaterial:FlatShadeMaterial = new FlatShadeMaterial(light, 0xcc0000); sphere = new Sphere(sphereMaterial, 400, 20, 20); scene2.addChild(sphere); //create a material of the above scene^^^ var material:BitmapViewportMaterial = new BitmapViewportMaterial(viewport2, true); material.doubleSided = true; plane = new Plane(material); scene.addChild(plane); startRendering(); } override protected function onRenderTick(event:Event = null):void { plane.localRotationY = viewport.containerSprite.mouseX; sphere.yaw(-1); //render the material scene renderer.renderScene(scene2, camera, viewport2); //render the main scene renderer.renderScene(scene, camera, viewport); } } }
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
- Moving to johnlindquist.com
- AsyncCommand with Robotlegs, Signals, Flight, MinimalComps
- Search Widget – Robotlegs, Signals, Flight, Minimal Comps, Yahoo Astra
- FDT Super Awesome March Deal
- FDT Theme Designer
- 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
Recent Comments
- software akuntansi terbaik on Back in the saddle
- loan rates on Augmented Reality – Recursive Webcam
- loan rates on Looking around the inside of a Sphere
- reverse phone lookup on Looking around the inside of a Sphere
- Oidhreachta on The Spotlight Effect (Dimming the unselected)
- Hosting company on archive
- aanbae on Back in the saddle
- Domain registration on Looking around the inside of a Sphere
- website designing company on Looking around the inside of a Sphere
- Honda Motor on Augmented Reality – Recursive Webcam
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « May | ||||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | ||||
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



