ViewportLayer
ViewportLayer is a layer and may be sorted by z, index, or origin.
Example
Instructions
- Import
import org.papervision3d.view.layer.ViewportLayer;
- Declare
private var layer :ViewportLayer;
- Initialize
layer = new ViewportLayer(viewport, do3d, isDynamic);
Parameter Default Description viewport NONE viewport do3d NONE object isDynamic false - Add layer
viewport.containerSprite.addLayer(layer);
- Add chlid layer
layer.getChildLayer(object);
Code
package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.cameras.Camera3D; import org.papervision3d.events.InteractiveScene3DEvent; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.objects.primitives.Plane; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import org.papervision3d.view.layer.ViewportLayer; public class Papervision3DViewportLayer extends Sprite { private var scene :Scene3D; private var camera :Camera3D; private var viewport :Viewport3D; private var layer :ViewportLayer; private var renderer :BasicRenderEngine; private var material :ColorMaterial; private var material2 :ColorMaterial; private var object :Plane; private var object2 :Plane; public function Papervision3DViewportLayer() { scene = new Scene3D(); camera = new Camera3D(); viewport = new Viewport3D(); viewport.autoScaleToStage = true; viewport.interactive = true; addChild(viewport); layer = new ViewportLayer(viewport, null); layer.sortMode = "index"; viewport.containerSprite.addLayer(layer); renderer = new BasicRenderEngine(); material = new ColorMaterial(0x000000); material.doubleSided = true; material.interactive = true; material2 = new ColorMaterial(0xff0000); material2.doubleSided = true; material2.interactive = true; object = new Plane(material); object.z = -300; scene.addChild(object); object2 = new Plane(material2); object2.rotationY = 90; object2.z = 300; scene.addChild(object2); layer.getChildLayer(object).layerIndex = 1; layer.getChildLayer(object2).layerIndex = 2; object.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver); object.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut); object.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress); object2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver); object2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut); object2.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress); addEventListener(Event.ENTER_FRAME, handleEnterFrame); } private function handleEnterFrame(e:Event):void { object.yaw(1); object2.yaw(1); renderer.renderScene(scene, camera, viewport); } private function handleObjectOver(e:InteractiveScene3DEvent):void { viewport.containerSprite.buttonMode = true; } private function handleObjectOut(e:InteractiveScene3DEvent):void { viewport.containerSprite.buttonMode = false; } private function handleObjectPress(e:InteractiveScene3DEvent):void { if (layer.getChildLayer(object).layerIndex == 1) { layer.getChildLayer(object).layerIndex = 2; layer.getChildLayer(object2).layerIndex = 1; } else { layer.getChildLayer(object).layerIndex = 1; layer.getChildLayer(object2).layerIndex = 2; } } } }