首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

怎么把Papervision3d物体加到 flex中(附 立方体例子)

2012-11-22 
如何把Papervision3d物体加到 flex中(附 立方体例子)本文介绍怎么在mx:Application ??? width640??? h

如何把Papervision3d物体加到 flex中(附 立方体例子)

本文介绍怎么在<mx:Application
??? width="640"
??? height="480"
??? xmlns:mx="http://www.adobe.com/2006/mxml"
??? layout="absolute"
??? applicationComplete="applicationComplete()">
??? <mx:Script>
??? ??? <![CDATA[
?
??? ??? ??? import org.papervision3d.objects.primitives.Cube;
??? ??? ??? import org.papervision3d.view.BasicView;
??? ??? ??? import org.papervision3d.lights.PointLight3D;
??? ??? ??? import org.papervision3d.materials.BitmapMaterial;
??? ??? ??? import org.papervision3d.materials.shaders.PhongShader;
??? ??? ??? import org.papervision3d.materials.shaders.ShadedMaterial;
??? ??? ??? import org.papervision3d.materials.shaders.Shader;
??? ??? ??? import org.papervision3d.materials.utils.MaterialsList;
??? ??? ???
??? ??? ???
??? ??? ??? import org.papervision3d.core.utils.Mouse3D;
??? ??? ??? import org.papervision3d.cameras.Camera3D;
??? ??? ??? import org.papervision3d.view.layer.ViewportLayer;
??? ??? ??? import org.papervision3d.objects.DisplayObject3D;
??? ??? ???
??? ??? ?private var myMouse3D:Mouse3D;

??? ??? ???
??? ??? [Embed(source="../assets/1.jpg")]
??? ??? private var frontAsset:Class;
??? ???
??? ??? [Embed(source="../assets/2.jpg")]
??? ??? private var backAsset:Class;
??? ???
??? ??? [Embed(source="../assets/4.jpg")]
??? ??? private var bottomAsset:Class;

??? ??? [Embed(source="../assets/5.jpg")]
??? ??? private var leftAsset:Class;

??? ??? [@Embed(source='../assets/6.jpg')]
??? ??? private var rightAsset:Class;

??? ??? [Embed(source="../assets/3.jpg")]
??? ??? private var topAsset:Class;
??? ???
??? ??? private var light:PointLight3D;
??? ??? private var cube:MyCube;
??? ??? private var basicView:BasicView = new BasicView();
??? ??? ??? ???
??? ??? private var materialsList:MaterialsList = new MaterialsList();
??? ???
??? ??? private function applicationComplete():void
??? ??? {
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new frontAsset(),true ), "front");???
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new backAsset() ), "back");
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new bottomAsset() ), "bottom");??? ??? ???
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new leftAsset() ), "left");
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new rightAsset() ), "right");
??? ??? ??? materialsList.addMaterial(createShadedMaterial( new topAsset() ), "top");
??????????? //定义立方体
??? ??? ??? cube = new MyCube(materialsList, 500, 500, 500, 5, 5, 5);
??? ??? ??? basicView.scene.addChild(cube);
??? ??? ???
??? ??? ??? Mouse3D.enabled = true;
??? ??? ?? ??? basicView.viewport.interactive=true;
??? ?????? ??? myMouse3D =this.basicView.viewport.interactiveSceneManager.mouse3D;
??? ?????? ???
??? ??????? this.stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheels);
??? ??? ??? this.stage.addEventListener(MouseEvent.MOUSE_MOVE,onRenderTick);
??? ??? ??
??? ??? ??? basicView.startRendering();
??? ??? ??? pv3dPanel.rawChildren.addChild(basicView); //method #1
??? ??? }
??? ??? ???
??? ??? protected function onRenderTick(event:Event=null):void
??? ??? {
??? ??? ???
??? ??? ??? cube.rotationY += (basicView.viewport.containerSprite.mouseX - cube.rotationY) * .1;
??? ??? ??? cube.rotationX += (basicView.viewport.containerSprite.mouseY - cube.rotationX) * .1;
??? ??? ??? basicView.renderer.renderScene(basicView.scene,basicView.camera, basicView.viewport);
??? ??? }
??? ??? ???
??? ??? ???
??? ??? private function createShadedMaterial(bitmap:Bitmap,precise:Boolean=false):ShadedMaterial
??? ??? {
??? ??? ??? var bitmapMaterial:BitmapMaterial = new BitmapMaterial(bitmap.bitmapData,precise);
??? ??? ??? bitmapMaterial.smooth=true;
??? ??? ??? bitmapMaterial.interactive=true;
??? ??? ??? var shader:Shader = new PhongShader(light, 0xffffff, 0x333333, 10, bitmap.bitmapData, bitmap.bitmapData);
??? ??? ??? var shadedMaterial:ShadedMaterial = new ShadedMaterial(bitmapMaterial, shader);
??? ??? ???
??? ??? ??? return shadedMaterial;
??? ??? }
??? ???
??? ?? //滚动鼠标中间轮,进行缩放
??? ?? private function onWheels(event:MouseEvent):void
??? ?? {
??? ?? ??? ??? basicView.camera.moveForward(10*event.delta);
??? ?? }
???? ]]>
??? </mx:Script>

??? <mx:Panel id="pv3dPanel" width="100%" height="100%">
??? ??? <mx:Label text="Label" id="testLabel"/>
??? </mx:Panel>
</mx:Application>

?

4。运行效果如下:怎么把Papervision3d物体加到 flex中(附 立方体例子)

?

?

?

方法2:使用自定义控件,把3d窗体封装到自定义控件中, 在主应用中引入这个自定义控件。

根据方法1进行自定义,源程序略。

?

?

?

1 楼 frogfool 2010-03-26   header.swc

MyCube是啥?

热点排行