package { import flash.display.*; import flash.events.*; import org.papervision3d.cameras.*; import org.papervision3d.view.*; import org.papervision3d.materials.*; import org.papervision3d.objects.*; import org.papervision3d.objects.primitives.* import org.papervision3d.materials.utils.*; [SWF(width = "720", height = "480", frameRate = "60", backgroundColor = "#FFFFFF")] public class Main extends BasicView { // 3Dオブジェクト private var cube:Cube; private var wire:Cube; /** * コンストラクタ */ public function Main() { // BasicViewの初期化 super(720, 480, true, false, CameraType.FREE); // init swf //stage.quality = StageQuality.LOW; // カメラ camera.x = camera.y = camera.z = 0; camera.focus = 200; camera.zoom = 1; // マテリアル(立方体の面を作成) var materials:MaterialsList = new MaterialsList( { front : new BitmapFileMaterial( "imgs/pano_cube_cubefront.jpg", true ), back : new BitmapFileMaterial( "imgs/pano_cube_cubeback.jpg", true ), right : new BitmapFileMaterial( "imgs/pano_cube_cuberight.jpg", true ), left : new BitmapFileMaterial( "imgs/pano_cube_cubeleft.jpg", true ), top : new BitmapFileMaterial( "imgs/pano_cube_cubetop.jpg", true ), bottom: new BitmapFileMaterial( "imgs/pano_cube_cubebottom.jpg", true ) } ); // 立方体の面を設定 // You can add or sustract faces to your selection. For examples: Cube.FRONT+Cube.BACK or Cube.ALL-Cube.Top. // On single sided materials, all faces will be visible from the inside. var insideFaces :int = Cube.ALL; // Front and back cube faces will not be created. var excludeFaces :int = Cube.NONE; // 定数 var size :Number = 5000; var quality :Number = 10; // キューブを作成 cube = new Cube( materials, size, size, size, quality, quality, quality, insideFaces, excludeFaces ); wire = new Cube( new MaterialsList( { all:new WireframeMaterial() } ), size, size, size, quality, quality, quality, insideFaces, excludeFaces ); wire.visible = false; // シーンに追加 scene.addChild(cube); scene.addChild(wire); // マウスのインタラクティブを設定しています addEventListener(Event.ENTER_FRAME, enterFrameHandler); addEventListener(MouseEvent.MOUSE_DOWN, downHandler); addEventListener(MouseEvent.MOUSE_UP, upHandler); addEventListener(MouseEvent.MOUSE_WHEEL, wheelHandler); // レンダリングを開始します startRendering(); } /** * マウスの位置に応じてインタラクティブを設定しています * @param event */ private function enterFrameHandler(event:Event):void { // Pan camera.rotationY += (480 * mouseX/(stage.stageWidth) - camera.rotationY) * .1; camera.rotationX += (180 * mouseY/(stage.stageHeight) - 90 - camera.rotationX) * .1; } /** * マウスを押したときにワイヤーフレームが表示されるように設定しています * @param event */ private function downHandler(event:MouseEvent):void { wire.visible = true; } /** * マウスを話したときにワイヤーフレームが非表示になるように設定しています * @param event */ private function upHandler(event:MouseEvent):void { wire.visible = false; } /** * マウスホイールでカメラ焦点を調整します * @param event */ private function wheelHandler(event:MouseEvent):void { camera.zoom += event.delta / 10; if (camera.zoom < 1) camera.zoom = 1; } } }