Quantcast
Channel: RIA wolf
Viewing all articles
Browse latest Browse all 10

Minko 3D basic Apache flex setup

$
0
0

MXML component class

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
package {
    import aerys.minko.render.Viewport;
    import aerys.minko.scene.controller.camera.ArcBallController;
    import aerys.minko.scene.node.Scene;
    import aerys.minko.scene.node.camera.Camera;

    import flash.events.Event;
    import flash.geom.Point;

    import mx.core.UIComponent;
    [Event(name="minkoReady", type="Stage3DEvent")]
    public class MinkoFlexContainer extends UIComponent {
        private var _viewport:Viewport = new Viewport();
        private var _camera:Camera = null;
        private var _cameraController:ArcBallController = null;
        private var _scene:Scene = new Scene();
        private var _cursor:Point = new Point();
        private var _added:Boolean = false;
        public function MinkoFlexContainer() {
            this.addEventListener(Event.ADDED_TO_STAGE, handleAdded);
        }
        private function handleAdded(event:Event):void {
            this.removeEventListener(Event.ADDED_TO_STAGE, handleAdded);
            invalidateProperties();
        }
        public function get viewport():Viewport {
            return _viewport;
        }
        public function get camera():Camera {
            return _camera;
        }
        public function get cameraController():ArcBallController {
            return _cameraController;
        }
        public function get scene():Scene {
            return _scene;
        }

        override public function initialize():void {
            super.initialize();
            invalidateProperties();
        }
        override protected function createChildren():void {
            super.createChildren();
            invalidateProperties();
        }
        override protected function commitProperties():void {
            super.commitProperties();
            if (stage) {
                if (!_added) {
                    _added = true;
                    stage.addChildAt(_viewport, 0);
                    _viewport.backgroundColor = 0x666666ff;
                    initializeScene();
                    initializeUI();
                    stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
                    dispatchEvent(new Stage3DEvent(Stage3DEvent.MINKO_READY, true, true));
                }
            }
        }
        protected function initializeScene():void {
            _camera = new Camera();
            _cameraController = new ArcBallController();
            _cameraController.bindDefaultControls(_viewport);
            _cameraController.minDistance = 1;
            _cameraController.yaw = Math.PI * -.5;
            _cameraController.pitch = Math.PI / 2;
            _cameraController.distance = 5;
            camera.addController(_cameraController);
            _scene.addChild(camera);
        }
        protected function initializeUI():void {
        }
        protected function enterFrameHandler(event:Event):void {
            _scene.render(_viewport);
        }
    }
}

Event notifying about engine being initialized

1
2
3
4
5
6
7
8
9
package {
    import flash.events.Event;
    public class Stage3DEvent extends Event{
        public static const MINKO_READY:String="minkoReady";
        public function Stage3DEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false) {
            super(type, bubbles, cancelable);
        }
    }
}

Implementation of the component

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
<code lang="mxml">
<?xml version="1.0"?>
<!--
  How to see Stage3D with flex on top of it.
 
  Set the application to blendMode="layer"
 
  And have another container with filled content to blendMode="erase"
 
  combination of these two actions will erase the background of flex application
  and it wont be covering Stage3D view
-->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:local="*"
               addedToStage="handleAdded()" blendMode="layer">
    <fx:Declarations></fx:Declarations>
    <fx:Script>
        <![CDATA[
        private function handleAdded():void {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
        }
        private function handleMinkoReady():void {
           
        }
        ]]>
    </fx:Script>
    <s:Group blendMode="erase" height="100%" width="100%">
        <s:Rect height="100%" width="100%">
            <s:fill>
                <s:SolidColor alpha="1" color="#00FF00"/>
            </s:fill>
        </s:Rect>
    </s:Group>
<local:MinkoFlexContainer id="flexContainer" minkoReady="handleMinkoReady()"/>
</s:Application>


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images