[AS3 SNIPPET] Papervision 3D 2.0 extendable view with scale 1:1 (3d to 2d)

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package com.rblab.framework.papervision
{
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.cameras.CameraType;
    import org.papervision3d.cameras.DebugCamera3D;
    import org.papervision3d.cameras.SpringCamera3D;
    import org.papervision3d.core.proto.CameraObject3D;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;

    import flash.display.Sprite;

   
    /**
     * @author Riccardo Bartoli
     */

    public class PapervisionView extends Sprite
    {
        //--------------------------------------------------------------------------
        //
        // Private properties
        //
        //--------------------------------------------------------------------------

        private var _viewportWidth : Number;
        private var _viewportHeight : Number;
        private var _scaleToStage : Boolean;
        private var _interactive : Boolean;
        private var _cameraType : String;

        //--------------------------------------------------------------------------
        //
        // Protected properties
        //
        //--------------------------------------------------------------------------

        protected var scene : Scene3D;
        protected var viewport : Viewport3D;
        protected var renderer : BasicRenderEngine;
        protected var camera : CameraObject3D;

        //--------------------------------------------------------------------------
        //
        //  Constructor
        //
        //--------------------------------------------------------------------------

        public function PapervisionView(viewportWidth : Number, viewportHeight : Number, scaleToStage : Boolean, interactive : Boolean, cameraType : String)
        {
            this._viewportWidth = viewportWidth;
            this._viewportHeight = viewportHeight;
            this._scaleToStage = scaleToStage;
            this._interactive = interactive;
            this._cameraType = cameraType;
           
            init();
        }

        //--------------------------------------------------------------------------
        //
        // Private methods
        //
        //--------------------------------------------------------------------------

        private function init() : void
        {
            setupScene();
            setupCamera(_cameraType);
            setupPapervision();
        }

        private function setupScene() : void
        {
            scene = new Scene3D();
           
            viewport = new Viewport3D(_viewportWidth, _viewportHeight, _scaleToStage, _interactive);
            addChild(viewport);
           
            renderer = new BasicRenderEngine();
        }

        private function setupCamera(cameraType : String) : void
        {
            switch(cameraType)
            {
                case CameraType.DEBUG:
                    camera = new DebugCamera3D(viewport);
                    break;
                case CameraType.TARGET:
                    camera = new Camera3D(60);
                    camera.target = DisplayObject3D.ZERO;
                    break;
                case CameraType.SPRING:
                    camera = new SpringCamera3D();
                    camera.target = DisplayObject3D.ZERO;      
                    break;         
                case CameraType.FREE:
                default:
                    camera = new Camera3D(60);
                    break;
            }
           
            camera.focus = 100;
            camera.z = -1000;
            camera.zoom = 10;
        }

        private function setupPapervision() : void
        {
            viewport.buttonMode = _interactive;
            viewport.interactive = _interactive;
        }

        //--------------------------------------------------------------------------
        //
        // Protected methods
        //
        //--------------------------------------------------------------------------

        protected function render() : void
        {
            renderer.renderScene(scene, camera, viewport);
        }
    }
}

London Flash Platform User Group (30/04/2009)

2009_04_header

In a couple of hours I’m going to listen Seb Lee-Delisle and Carlos Ulloa talking about Papervision 3D.

From the London Flash Platform User Group website:

Papervision3D, Simplified (19:00 – 20:00) – Seb Lee-Delisle
Finally! Realtime 3D in Flash is taking off and there has never been more demand for 3D games, apps and websites. And naturally, with such a powerful library comes somewhat of a steep learning curve.

This session will cover how to create 3D objects in code, import them from other 3D apps and even make a simple game.

We Make. You Enjoy (20:15 – 21:15) – Carlos Ulloa

Dive deep into the third dimension with the creator of Papervision3D and discover the secrets behind his latest interactive 3D experience, HelloEnjoy.com.

The session will focus on the techniques, workflow and planning necessary to overcome the creative and technical challenges of real time 3D in Flash, giving an inside view of the entire creation process, from concept and planning, to development and art production.

For more informations click here.