package {
    import flash.display.*;
    import flash.events.*;
 
    import org.papervision3d.scenes.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.cameras.*;
    import org.papervision3d.materials.*;
 
    [SWF(backgroundColor=0x000000)]
 
    public class MyPlane extends Sprite
    {
        private var container : Sprite;
        private var scene     : Scene3D;
        private var camera    : Camera3D;
        private var rootNode  : DisplayObject3D;
 
        private var planeObj  : DisplayObject3D;
        private var planeSize : int = 300;//Planeオブジェクト1辺の長さ
        private var segment   : int = 1;  //面の分割数
        private var material  : ColorMaterial;
 
        private var valx      : Number = 0;
        private var valy      : Number = 0;
 
        //---------------------------------------------Constructor
        public function MyPlane():void
        {
            stage.frameRate = 60;
            stage.quality   = "MEDIUM";
            stage.scaleMode = "noScale";
            stage.align = StageAlign.TOP_LEFT;
 
            //コンテナ生成
            container = new Sprite();
            container.x = 200;
            container.y = 200;
            stage.addChild( container );
 
            //シーン生成
            scene = new Scene3D( container );
 
            //rootNode生成
            rootNode = new DisplayObject3D();
            scene.addChild( rootNode );
 
            //マテリアル設定
            material = new ColorMaterial( 0xffffff, 1 );
            material.oneSide = false;
 
            //Planeオブジェクト生成
            planeObj = new Plane( material, planeSize, planeSize, segment, segment );
            rootNode.addChild( planeObj );
 
            //camera設定
            camera = new Camera3D();
            camera.z = -planeSize;
            camera.focus = 50;
            camera.zoom = 1;
 
            stage.addEventListener(Event.ENTER_FRAME, loop);
        }
 
        //---------------------------------------------loop                                                                     
        private function loop( event:Event ):void
        {
            // Y軸回転
            planeObj.rotationY += 5;
 
            //再レンダリング
            scene.renderCamera( camera );
        }
    }
}