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 MultCubeObj2 extends Sprite
    {
        private var container : Sprite;
        private var scene     : MovieScene3D;
        private var camera    : Camera3D;
        private var rootNode  : DisplayObject3D;
        private var cubeObj1  : Cube;
        private var cubeObj2  : Cube;
        private var material1 : BitmapFileMaterial;
        private var material2 : BitmapFileMaterial;

        //---------------------------------------------Constructor
        public function MultCubeObj2():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 );
 
            //マテリアル1設定
            material1 = new BitmapFileMaterial( "zaku.jpg" );
            material1.doubleSided = true
            material1.smooth = true;
            //Cubeオブジェクト1生成
            cubeObj1 = new Cube(material1, 800, 800, 800, 2, 2, 2);
            //cubeObj1.x = -800;
            rootNode.addChild(cubeObj1);
 
            //マテリアル2設定
            material2 = new BitmapFileMaterial( "sla.jpg" );
            material2.doubleSided = true
            material2.smooth = true;
            //Cubeオブジェクト2生成
            cubeObj2 = new Cube(material2, 800, 800, 800, 2, 2, 2);
            cubeObj2.x = 800;
            cubeObj1.addChild(cubeObj2);

            //camera設定
            camera = new Camera3D();
            camera.zoom = 1;
 
            stage.addEventListener(Event.ENTER_FRAME, loop);
            stage.addEventListener(Event.RESIZE, onStageResize);
        }

        //---------------------------------------------loop
        private function loop(e:Event):void{
            cubeObj1.rotationY=container.mouseX;
            cubeObj1.rotationX=container.mouseY;
            material1.updateBitmap();

            cubeObj2.rotationY=-container.mouseX;
            cubeObj2.rotationX=-container.mouseY;
            material2.updateBitmap();

            scene.renderCamera( camera );
        }

        //---------------------------------------------onStageResize
        private function onStageResize(e:Event):void{
             container.x = this.stage.stageWidth  / 2;
             container.y = this.stage.stageHeight / 2;
        }
    }
}