PV3D with DAE 模型動畫應用
好久都沒有發一些關於 FLEX 的東西了,不過檢視後台的訪客資訊,程式設計與平面設計的訪客比率大概是 60 比 40 ,前一陣子剛好與 阿默設計 一起合作,寫了一個教學用到個 3D 互動程式,因為我只有負責寫使用 PV3D 的互動區的部分,因此我也不太知道這個東西用在哪裡囉。另外感謝好友 壞蛋 的建模,他也是一位熱心的網友在玩 PV3D 與 FLEX 喔,是一位研究所的研究生呢。
因為這次的東西用到太多因此我就不多做解釋了。各位看官請自便,先看看執行結果吧 ?
這個範例你可以看到 :
- PV3D 如何崁入 FLEX 內
- DAE 如何載入 PV3D 與 FLEX 內
- 多邊形的建立方式
- DAE 的模型動畫載入 PV3D 與 FLEX 內
- 3D 物件的半透明化
差不多是這樣子,文章我就不再多說明了,有放了一些註解在裡面,因為有很多測試碼,所以寫得不是很好,如果有看的朋友可以詢問一下,如果有問題可以再詢問 ^^ , 原始檔我打包在下面,需要的朋友可以下載回去。
CONE4.MXML
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 | <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="14" backgroundColor="#CCCCCC" frameRate="41" creationComplete="init()" width="1000" height="700">
<mx:Script>
<![CDATA[
private var active:Inactive4Cone = new Inactive4Cone();
private function init():void{
this.sub3dArea1.addChild(new CameraControl(1,4,1));
this.sub3dArea2.addChild(new CameraControl(2,4,1));
this.sub3dArea3.addChild(new CameraControl(3,4,1));
this.inactiveArea.addChild(this.active);
}
private function showDobleSide(event:MouseEvent):void{
CameraControl(this.sub3dArea1.getChildAt(0)).showDobbleSide(event.currentTarget.selected);
CameraControl(this.sub3dArea2.getChildAt(0)).showDobbleSide(event.currentTarget.selected);
CameraControl(this.sub3dArea3.getChildAt(0)).showDobbleSide(event.currentTarget.selected);
}
private function modelAction1(event:MouseEvent):void{
if(event.currentTarget.selected){
this.open1.enabled = false;
this.open2.enabled = false;
this.active.openModel1();
setTimeout(activeButton1,2926);
}else{
this.open1.enabled = false;
this.active.closeModel();
setTimeout(activeButton1,2926);
setTimeout(activeButton2,2926);
}
}
private function modelAction2(event:MouseEvent):void{
if(event.currentTarget.selected){
this.open1.enabled = false;
this.open2.enabled = false;
this.active.openModel2();
setTimeout(activeButton2,2926);
}else{
this.open2.enabled = false;
this.active.closeModel();
setTimeout(activeButton1,2926);
setTimeout(activeButton2,2926);
}
}
private function showColor(event:MouseEvent):void{
if(event.currentTarget.selected){
this.active.alphaColor();
}else{
this.active.showColor();
}
}
private function activeButton1():void{
this.open1.enabled = true;
}
private function activeButton2():void{
this.open2.enabled = true;
}
]]>
</mx:Script>
<mx:Panel width="100%" height="100%" layout="vertical" title="四角錐展示">
<mx:HBox width="100%" height="100%">
<mx:VBox width="250" height="100%">
<mx:Panel width="250" height="33%" layout="vertical" title="Y 軸 旋轉視圖">
<mx:UIComponent id="sub3dArea1"/>
</mx:Panel>
<mx:Panel width="250" height="33%" layout="vertical" title="X 軸 旋轉視圖">
<mx:UIComponent id="sub3dArea2"/>
</mx:Panel>
<mx:Panel width="250" height="195" layout="vertical" title="XYZ 旋轉視圖">
<mx:UIComponent id="sub3dArea3"/>
</mx:Panel>
</mx:VBox>
<mx:Panel width="673" height="99%" layout="vertical" title="互動展示區">
<mx:UIComponent id="inactiveArea"/>
<mx:Button label="+" click="this.active.scaleBig();" buttonMode="true"/>
<mx:Button label="-" click="this.active.scaleSmall();" buttonMode="true"/>
<mx:ApplicationControlBar width="100%" horizontalAlign="center">
<mx:Button label="旋轉視圖透明狀態" toggle="true" click="showDobleSide(event)" buttonMode="true"/>
<mx:Button label="互動區物件透明狀態" toggle="true" click="showColor(event)" buttonMode="true"/>
<mx:Button label="展開方式 1 (底部)" id="open1" toggle="true" click="modelAction1(event)" buttonMode="true"/>
<mx:Button label="展開方式 2 (側邊)" id="open2" toggle="true" click="modelAction2(event)" buttonMode="true"/>
</mx:ApplicationControlBar>
</mx:Panel>
</mx:HBox>
</mx:Panel>
</mx:Application> |
CameraControl.as
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 | package { import flash.display.Sprite; import flash.events.Event; import org.papervision3d.cameras.Camera3D; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.objects.primitives.Cylinder; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; public class CameraControl extends Sprite { private var scene:Scene3D; private var viewport:Viewport3D; private var camera:Camera3D; private var renderer:BasicRenderEngine; private var rotationFunction:int = 0; private var show2Sides:Boolean = false; private var coneNumber:int = 3; private var topRidaus:int = 1; private var obj:Cylinder; public function CameraControl(rotationFunc:int = 1,coneNumber:int = 3,topRidaus:int =1) { this.rotationFunction = rotationFunc; this.coneNumber = coneNumber; this.topRidaus = topRidaus; this.init3D(); this.init3DObject(); } private function init3D():void{ this.viewport = new Viewport3D(240,160,false,true); this.addChild(this.viewport); this.renderer = new BasicRenderEngine(); this.camera = new Camera3D(); this.scene = new Scene3D(); this.camera.zoom = 2; this.camera.focus = 150; this.camera.y = 100; this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage); } private function onAddedToStage(event:Event):void{ this.addEventListener(Event.ENTER_FRAME,onEventRender3D); } private function onEventRender3D(event:Event):void{ // 旋轉物體 /* var _targetX:Number = (stage.stageWidth /2 - this.mouseX ) / 40; var _targetY:Number = (stage.stageHeight / 2 - this.mouseY ) / 40; this.obj.rotationY += _targetX; this.obj.rotationX += _targetY; */ //this.obj.rotationY += 1; switch(this.rotationFunction){ case 1: this.obj.rotationY += 0.5; break; case 2: this.obj.rotationX += 0.5; break; case 3: this.obj.rotationX += 0.5; this.obj.rotationY += 0.5; this.obj.rotationZ += 0.5; break; } //旋轉運鏡 /* var _targetX:Number = (stage.mouseX - (stage.stageWidth /2))*2; var _targetY:Number = (stage.mouseY - (stage.stageHeight /2 ))*2; this.camera.x += (_targetX - camera.x ) * 0.05; this.camera.y += (_targetY - camera.y ) * 0.05; */ //算圖 this.renderer.renderScene(this.scene,this.camera,this.viewport); } private function init3DObject():void{ var material:WireframeMaterial = new WireframeMaterial(0x0000FF); material.doubleSided = false; obj = new Cylinder(material, 130, 350, this.coneNumber, 1,this.topRidaus); obj.y = 120; this.scene.addChild(obj); } public function showDobbleSide(show:Boolean):void{ this.obj.material.doubleSided = show; } } } |
Inactive4Cone.as
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | package { import flash.display.Bitmap; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import org.papervision3d.cameras.Camera3D; import org.papervision3d.materials.ColorMaterial; import org.papervision3d.materials.WireframeMaterial; import org.papervision3d.materials.special.CompositeMaterial; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.objects.special.DAEMC; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.render.QuadrantRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; public class Inactive4Cone extends Sprite { private var scene:Scene3D; private var viewport:Viewport3D; private var camera:Camera3D; private var renderer:BasicRenderEngine; private var freeCamera:Boolean = false; private var obj1:DAEMC; private var obj2:DAEMC; //加入 dae [Embed(source = "DAE/4Cone-1.DAE", mimeType = "application/octet-stream")] private var cone3_1:Class; [Embed(source = "DAE/4Cone-2.DAE", mimeType = "application/octet-stream")] private var cone3_2:Class; //載入圖片 [Embed(source = "img/blue.png")] private var Pic1:Class; /* [Embed(source = "img/green.png")] private var Pic2:Class; [Embed(source = "img/red.png")] private var Pic3:Class; [Embed(source = "img/yellow.png")] private var Pic4:Class; */ private var color1:ColorMaterial; private var color2:ColorMaterial; private var color3:ColorMaterial; private var color4:ColorMaterial; private var colorBottom:ColorMaterial; private var cameraTarget:DisplayObject3D = new DisplayObject3D(); public function Inactive4Cone() { this.createMaterial(); this.init3D(); this.init3DObject(); //尚未結案浮水印 var aaa:Bitmap = new Pic1(); aaa.width = 650; aaa.height = 520; this.addChild(aaa); } private function init3D():void{ this.viewport = new Viewport3D(660,570,false,true); this.viewport.buttonMode = true; this.addChild(this.viewport); //this.renderer = new BasicRenderEngine(); this.renderer = new QuadrantRenderEngine(QuadrantRenderEngine.CORRECT_Z_FILTER); this.camera = new Camera3D(); this.scene = new Scene3D(); this.camera.zoom = 2; this.camera.focus = 150; //this.camera.y = 250; this.camera.z = -1500; this.scene.addChild(this.cameraTarget); this.camera.target = this.cameraTarget; this.addEventListener(Event.ADDED_TO_STAGE,onAddedToStage); } private function onAddedToStage(event:Event):void{ this.addEventListener(MouseEvent.MOUSE_DOWN,moveModel); this.stage.addEventListener(MouseEvent.MOUSE_UP,holeModel); this.addEventListener(Event.ENTER_FRAME,onEventRender3D); } private function onEventRender3D(event:Event):void{ // 旋轉物體 /* var _targetX:Number = (stage.stageWidth /2 - this.mouseX ) / 40; var _targetY:Number = (stage.stageHeight / 2 - this.mouseY ) / 40; this.obj.rotationY += _targetX; this.obj.rotationX += _targetY; */ //this.obj.rotationY += 0.5; if(this.freeCamera){ /*if(this.mouseX > this.width/2){ this.obj.rotationY += 1 ; }*/ var _targetX:Number = (this.width /2 - this.mouseX ) / 80; //var _targetY:Number = (this.height / 2 - this.mouseY ) / 80; this.obj1.rotationY += _targetX; //this.obj1.rotationX += _targetY; this.obj2.rotationY += _targetX; //this.obj2.rotationX += _targetY; //var _targetX:Number = (this.mouseX - (this.width /2))*2; var _targetY:Number = (this.mouseY - (this.height /2 ))*6; //this.camera.x += (_targetX - camera.x ) * 0.2; this.camera.y += (_targetY - camera.y ) * 0.05; } //this.obj1.rotationY = 90; //旋轉運鏡 /* var _targetX:Number = (stage.mouseX - (stage.stageWidth /2))*2; var _targetY:Number = (stage.mouseY - (stage.stageHeight /2 ))*2; this.camera.x += (_targetX - camera.x ) * 0.05; this.camera.y += (_targetY - camera.y ) * 0.05; */ //算圖 this.renderer.renderScene(this.scene,this.camera,this.viewport); } private var mList:MaterialsList; private function createMaterial():void{ mList = new MaterialsList(); var mater1:CompositeMaterial = new CompositeMaterial(); var wire1:WireframeMaterial = new WireframeMaterial(0x000000,100,1.3); wire1.doubleSided = true; color1 = new ColorMaterial(0xFF1D25); color1.doubleSided = true; mater1.addMaterial(color1); //mater1.addMaterial(wire1); mater1.doubleSided = true; mater1.interactive = true; mList.addMaterial(mater1,"color_01"); var mater2:CompositeMaterial = new CompositeMaterial(); var wire2:WireframeMaterial = new WireframeMaterial(0x000000,100,1.3); wire2.doubleSided = true; color2 = new ColorMaterial(0xFF931E); color2.doubleSided = true; mater2.addMaterial(color2); //mater2.addMaterial(wire2); mater2.doubleSided = true; mater2.interactive = true; mList.addMaterial(mater2,"color_02"); var mater3:CompositeMaterial = new CompositeMaterial(); var wire3:WireframeMaterial = new WireframeMaterial(0x000000,100,1.3); wire3.doubleSided = true; color3 = new ColorMaterial(0x3FA9F5); color3.doubleSided = true; mater3.addMaterial(color3); //mater3.addMaterial(wire3); mater3.doubleSided = true; mater3.interactive = true; mList.addMaterial(mater3,"color_03"); var mater4:CompositeMaterial = new CompositeMaterial(); var wire4:WireframeMaterial = new WireframeMaterial(0x000000,100,1.3); wire4.doubleSided = true; color4 = new ColorMaterial(0xE06C97); color4.doubleSided = true; mater4.addMaterial(color4); //mater4.addMaterial(wire4); mater4.doubleSided = true; mater4.interactive = true; mList.addMaterial(mater4,"color_04"); var materBottom:CompositeMaterial = new CompositeMaterial(); var wireBottom:WireframeMaterial = new WireframeMaterial(0x000000,100,1.3); wireBottom.doubleSided = true; colorBottom = new ColorMaterial(0x999999); colorBottom.doubleSided = true; materBottom.addMaterial(colorBottom); //materBottom.addMaterial(wireBottom); materBottom.doubleSided = true; materBottom.interactive = true; mList.addMaterial(materBottom,"bottom"); } private function init3DObject():void{ obj1 = new DAEMC(false,null,0); var cone:Object = new cone3_1(); obj1.load(cone,this.mList); obj1.scale = 25; obj1.setFrameLabel(0,"open"); obj1.setFrameLabel(121,"close"); obj1.addFrameScript(120,stopModel1); obj1.addFrameScript(240,stopModel2); this.scene.addChild(obj1); //this.obj1.y = 150; //this.obj1.getChildByName("COLLADA_Scene").getChildByName("blue02").getChildByName("blue02_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj1.getChildByName("COLLADA_Scene").getChildByName("red").getChildByName("red_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj1.getChildByName("COLLADA_Scene").getChildByName("yellow").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj1.getChildByName("COLLADA_Scene").getChildByName("green").getChildByName("green_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); obj2 = new DAEMC(false,null,0); var cone2:Object = new cone3_2(); obj2.load(cone2,this.mList); obj2.scale = 25; obj2.setFrameLabel(0,"open"); obj2.setFrameLabel(121,"close"); obj2.addFrameScript(120,stopModel1); obj2.addFrameScript(240,stopModel2); this.scene.addChild(obj2); //this.obj2.y = 150; this.obj2.visible = false; //this.obj2.getChildByName("COLLADA_Scene").getChildByName("blue02").getChildByName("blue02_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj2.getChildByName("COLLADA_Scene").getChildByName("red").getChildByName("red_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj2.getChildByName("COLLADA_Scene").getChildByName("yellow").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); //this.obj2.getChildByName("COLLADA_Scene").getChildByName("green").getChildByName("green_PIVOT").addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,moveModel); } public function openModel():void{ obj1.gotoAndPlay("open"); obj2.gotoAndPlay("open"); } public function closeModel():void{ obj1.gotoAndPlay("close"); obj2.gotoAndPlay("close"); } private function stopModel1(event:Object):void{ obj1.stop(); obj2.stop(); } private function stopModel2(event:Object):void{ obj1.stop(); obj2.stop(); } private function moveModel(event:Event):void{ this.freeCamera = true; } private function holeModel(event:Event):void{ this.freeCamera = false; } public function scaleBig():void{ this.obj1.scale += 1; this.obj2.scale += 1; } public function scaleSmall():void{ this.obj1.scale -= 1; this.obj2.scale -= 1; } public function showColor():void{ this.color1.fillAlpha = 1; this.color2.fillAlpha = 1; this.color3.fillAlpha = 1; this.color4.fillAlpha = 1; this.colorBottom.fillAlpha = 1; } public function alphaColor():void{ this.color1.fillAlpha = 0.4; this.color2.fillAlpha = 0.4; this.color3.fillAlpha = 0.4; this.color4.fillAlpha = 0.4; this.colorBottom.fillAlpha = 0.4; } public function openModel1():void{ this.obj2.visible = false; this.obj1.visible = true; obj1.gotoAndPlay("open"); } public function openModel2():void{ this.obj1.visible = false; this.obj2.visible = true; obj2.gotoAndPlay("open"); } public function changDAE():void{ this.obj1.visible = false; this.obj2.visible = true; } private function addEvent():void{ } } } |
Random Posts
Loading…
相關文章 :
![showExample[1] showExample[1]](http://files.corausir.org/images/PV3DwithDAE_FA68/showExample1.jpg)











不要再說我在偷懶啦 >”<…
這還蠻酷的耶~
強^^
你終於有新文了~
篇幅這麼短,我還是要替Cora說你偷懶
哇哈哈…..大步逃跑…
@Elvis
似乎是教小朋友認識立體多邊形
現在的教育軟體還是搞剛
@馬諦斯
@@” 我一直都有阿~ 哈
@scorpio
篇幅短可是內容多阿 XD
不一樣的產業不可以比啦 CCC
山羊也太客氣了吧~跟你學了很多呢~~~
(看來這篇也是要狂推了)
這個蠻有意思的!
學海無涯,這個我就跳過好了!:p
@壞蛋
若是沒人建模也搞不出來
@拆組達人
@@” 哈哈~~ 還是感謝支持
這是用DAEMC做的!!!
好嗨喔!!!
什麼時候要講解一下DAEMC呢??
還有另一個問題
就是當我使用camera.moveBackward(10)
模形小的時候感覺不出來
可是當我使用大模型時
他真的像是一格一格慢慢前進
不是很順,請問有什麼辦法可以讓它真的像是拿著攝影機
前後左右的流覽呢(表達有點不清楚)
你好~
我有兩個問題,請教一下
1.請問在你的檔案 Inactive4Cone.as 裡有下列這行:
import org.papervision3d.objects.special.DAEMC;
這是在那一個PV3D的版本?
我找了最近很多版本都沒有 DAEMC 。
2.這個的主要用途?
謝謝^^
@樂
因為效能不彰的關係吧….
線條太多的時候移動起來真的會很頓
@Woods
1. DAEMC 他是一個將 DAE 模型載入後可以像 movieClip 一樣可以播放
是一個非官方元件 你搜尋 DAEMC 就可以找到下載點
2. 主要用途第一點說完了 ^_^
謝謝囉~~
DAEMC還真的很方便^^
@Woods
^_^ OK 的啦~~
您好,最近才摸索flex,看到您這個功能很有趣,載來看一下,可是在CameraControl.as頁面中,會出現錯誤,錯誤的描述是:找不到定義 org.papervision3d,其它行數也有出現找不到定義的問題,請問該怎麼解決呢?還是我在載入檔案過程中有錯誤?我還很菜,如果問的問題很笨,請包涵> <”
@Maybe
那是因為你要先加入path阿
要先去下載PV3D的SWC
建議你先看看其他篇有關PV3D的文章
居然有人幫我回答 ^_^
真開心阿~~