package { import flash.display.*; import flash.events.*; import org.papervision3d.scenes.*; import org.papervision3d.objects.*; import org.papervision3d.cameras.*; import org.papervision3d.materials.*; public class MovieTxtCube extends Sprite { private var container : Sprite; private var scene : MovieScene3D; private var camera : Camera3D; private var rootNode : DisplayObject3D; private var cubeObj : Cube; private var material : BitmapFileMaterial; //---------------------------------------------Constructor public function MovieTxtCube():void { stage.frameRate = 60; stage.quality = "MEDIUM"; stage.scaleMode = "noScale"; stage.align = StageAlign.TOP_LEFT; //コンテナ生成 container = new Sprite(); container.x = stage.stageWidth / 2; container.y = stage.stageHeight / 2; stage.addChild( container ); //シーン生成 scene = new MovieScene3D( container ); //rootNode生成 rootNode = new DisplayObject3D(); scene.addChild( rootNode ); //マテリアル設定 material = new BitmapFileMaterial( "wizard.jpg" ); material.doubleSided = true material.smooth = true; //Cubeオブジェクト生成 cubeObj = new Cube(material, 800, 800, 800, 2, 2, 2); rootNode.addChild(cubeObj); //camera設定 camera = new Camera3D(); camera.zoom = 2; stage.addEventListener(Event.ENTER_FRAME, loop); stage.addEventListener(Event.RESIZE, onStageResize); } //---------------------------------------------loop private function loop(e:Event):void{ cubeObj.rotationY=container.mouseX; cubeObj.rotationX=container.mouseY; material.updateBitmap(); scene.renderCamera( camera ); } //---------------------------------------------onStageResize private function onStageResize(e:Event):void{ container.x = this.stage.stageWidth / 2; container.y = this.stage.stageHeight / 2; } } }