WEB开发网
开发学院图形图像Flash [Actionscript][Away3D]三维图片展示Demo 阅读

[Actionscript][Away3D]三维图片展示Demo

 2009-03-03 11:58:46 来源:WEB开发网   
核心提示:这个Demo是为了熟悉Away3d和TweenLite而写的,是一个三维图片展示的雏形,[Actionscript][Away3D]三维图片展示Demo,不排除继续写一个完整三维相册的可能,要掌握动画展示的效果,关键在于理解Away3D里物体的运动和摄像头运动,另外写了一个很简单的Loader外壳

这个Demo是为了熟悉Away3d和TweenLite而写的,是一个三维图片展示的雏形,不排除继续写一个完整三维相册的可能。

要掌握动画展示的效果,关键在于理解Away3D里物体的运动和摄像头运动。

另外写了一个很简单的Loader外壳,用来载入外部SWF。

演示:

http://www.kxbd.com/mylab_as/090220TweenAnd3D/

动画文档类:

  1package  {
  2    /**//**
  3     * author: Aken li (http://www.kxbd.com)
  4     * date: 2009-03-02
  5     * dependencies: Away3d 2.3, TweenLite 10
  6     */
  7    import away3d.cameras.*;
  8    import away3d.containers.*;
  9    import away3d.core.base.*;
 10    import away3d.core.math.*;
 11    import away3d.core.utils.*;
 12    import away3d.events.MouseEvent3D;
 13    import away3d.primitives.*;
 14    import away3d.materials.*;
 15    import away3d.core.render.Renderer;
 16   
 17    import gs.TweenLite;
 18    import gs.easing.*
 19    import gs.OverwriteManager;
 20   
 21    import flash.display.*;
 22    import flash.events.*;
 23   
 24    public class Num08 extends MovieClip {
 25        private var view:View3D;
 26        private var objArr:Array = [];
 27        private var objNum:uint = 4;
 28        private var objContainer:ObjectContainer3D;
 29        private var cam:Camera3D;
 30        private var moveContainer:Boolean = true;
 31        private var isLarge:Boolean = false;
 32        private var isLookAt:uint;
 33       
 34        public function Num08() {
 35            init();
 36        }
 37       
 38        private function init() {
 39            OverwriteManager.init(OverwriteManager.AUTO);
 40               
 41            view = new View3D( { x:400, y:300 } );
 42            addChild(view);
 43            view.renderer = Renderer.INTERSECTING_OBJECTS;
 44           
 45            cam = new Camera3D( { x:0, y:0, z:-1000 } );
 46            cam.lookAt(new Number3D(0, 0, 0));
 47            view.camera = cam;
 48           
 49            objContainer = new ObjectContainer3D();
 50            for (var i = 0; i < objNum; i++) {
 51                var obj:Plane = makePlane(i);
 52                obj.useHandCursor = true;
 53                objArr.push(obj);
 54                objContainer.addChild(obj);
 55            }
 56            view.scene.addChild(objContainer);
 57
 58            for (i = 0; i < objNum; i++) {
 59                var _mobj = objArr[i];
 60                TweenLite.to(_mobj, (5 - i) * 0.5,
 61                              { y:150 * i - 225, delay:i * 0.5, ease:Elastic.easeOut,
 62                                onComplete:comFunc, onCompleteParams:[i, _mobj] } );
 63            }
 64            TweenLite.to(objContainer, 3, { rotationX:360, rotationY:360, rotationZ:360, onComplete:addOverFx } );
 65           
 66            addEventListener(Event.ENTER_FRAME, render);
 67            addEventListener(Event.ADDED_TO_STAGE,function(){
 68                stage.addEventListener(MouseEvent.CLICK, clickScene);
 69            });
 70        }
 71       
 72        private function comFunc(i:uint, mObj:Plane) {
 73            moveContainer = false;
 74            mObj.z = 0
 75            mObj.addOnMouseDown(clickObj);
 76        }
 77       
 78        private function addOverFx() {
 79            for (var i = 0; i < objNum; i++) {
 80                objArr[i].addOnMouseOver(moveUpObj);
 81                objArr[i].addOnMouseOut(moveDownObj);
 82            }
 83        }
 84       
 85        private function removeOverFx() {
 86            for (var i = 0; i < objNum; i++) {
 87                objArr[i].removeOnMouseOver(moveUpObj);
 88                objArr[i].removeOnMouseOut(moveDownObj);
 89            }
 90        }
 91       
 92        private function moveUpObj(e:MouseEvent3D) {
 93            TweenLite.to(e.object, 0.5 , { z: -50 } );
 94        }
 95       
 96        private function moveDownObj(e:MouseEvent3D) {
 97            TweenLite.to(e.object, 0.5 , { z: 0 } );
 98        }
 99       
100        private function clickObj(e:MouseEvent3D) {
101            var _obj = e.object;
102            var _clicked = objArr.indexOf(_obj);
103            if(!isLarge){
104                removeOverFx();
105                enlargePic(_obj);
106                isLarge = true;
107            }else if(_clicked==isLookAt) {
108                addOverFx();
109                diminishPic(_obj);
110                isLarge = false;
111            }else {
112                diminishPic(objArr[isLookAt]);
113                enlargePic(_obj);
114                isLarge = true;
115            }
116        }
117       
118        private function clickScene(e:MouseEvent) {
119            if(e.target==stage&&isLarge){
120                addOverFx();
121                diminishPic(objArr[isLookAt]);
122                isLarge = false;
123            }
124        }
125       
126        private function enlargePic(obj) {
127            isLookAt = objArr.indexOf(obj);
128            TweenLite.to(objContainer, 1, {  z: -650 } );
129            TweenLite.to(cam, 1, { y:obj.y } );
130            TweenLite.to(obj, 1, { z: -50 } );
131            obj.material = new BitmapMaterial(Cast.bitmap("imgB0"+(isLookAt+1)));
132        }
133       
134        private function diminishPic(obj) {
135            TweenLite.to(objContainer, 1, { z: 0 } );
136            TweenLite.to(cam, 1, { y:0 } );
137            TweenLite.to(obj, 1, { z:0 } );
138            obj.material = new BitmapMaterial(Cast.bitmap("img0"+(isLookAt+1)));
139        }
140       
141        private function render(e:Event) {
142            view.render();
143            objContainer.rotationX = -view.mouseY * 0.1;
144            objContainer.rotationY = view.mouseX * 0.1;
145        }
146       
147        private function makePlane(i:uint):Plane {
148            var obj = new Plane( { material:"blue#white", width: 200, height: 150, segmentsW:6, segmentsH: 4 } );
149            obj.bothsides = true;
150            obj.material = new BitmapMaterial(Cast.bitmap("img0"+(i+1)));
151            obj.back = new BitmapMaterial(Cast.bitmap("img05"));
152            obj.yUp = false;
153            obj.x = 0;
154            obj.y = 650;
155            obj.z = i;
156            obj.name = i + 1;
157            return obj;
158        }
159       
160    }
161   
162}

1 2  下一页

Tags:Actionscript AwayD 三维

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接