Flash( ActionScript 3( AS3 ), Papervision3D( PV3D ) )

http://atassyu.tripod.com/Main.swfのソース | http://atassyu.tripod.com/NewProject3.swfのソース | http://atassyu.tripod.com/NewProject4.swfのソース | http://atassyu.tripod.com/NewProject5.swfのソース | http://atassyu.tripod.com/NewProject6.swfのソース

package 
{
    //
    // Copyright (c) 2010, 2011 TESAGEKABAN Atassyu
    //  http://atassyu.tripod.com/
    //
    // 参考 
    //  書籍 池田泰延, Flash 3D コンテンツ制作のための Papervision3D 入門
    //  Web http://wonderfl.net/
    //      http://forum.papervision3d.jp/viewtopic.php?f=8&t=152
    //      http://wonderfl.net/c/fDdO
    //
    // 2011(H23)-02-24 "BBS", "Source" の色をモノトーンに近くした。Heart にグラデかけた。
    // 2011(H23)-02-24 Blur させようとしたが、簡単にはいかないことがわかった。
    // 2011(H23)-02-24 FogMaterial。
    //
    import flash.display.*;
    import flash.filters.*;
    import flash.events.*;
    import org.papervision3d.core.math.Plane3D;
    import org.papervision3d.core.render.filter.FogFilter;
    //import flash.events.MouseEvent;
    import flash.geom.*;
    import flash.utils.*;
    import flash.net.URLRequest;
    import flash.net.navigateToURL; 
    import org.papervision3d.core.render.filter.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.shadematerials.*;
    //import org.papervision3d.materials.special.Letter3DMaterial;
    import org.papervision3d.materials.special.*;
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.lights.*;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.typography.fonts.*;
    import org.papervision3d.typography.Text3D;
    import org.papervision3d.view.*;
    import org.papervision3d.view.stats.*;
    import org.papervision3d.render.*;
    import org.papervision3d.objects.parsers.*;
    import org.papervision3d.materials.BitmapFileMaterial;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.events.*;
    
    /**
     * ...
     * @author TESAGEKABAN Atassyu
     */
    public class Main extends BasicView {
        // objsMenu
        private var objsMenu:DisplayObject3D;
        // Bitmap
        private var wrap:DisplayObject3D;
        private var obj:Plane;
        // Heart
        private const ORBITAL_RADIUS:int = 300;
        //private const CUBE_SIZE:int = 30;
        private const CUBE_SIZE:int = 80;
        private const CUBE_MAX:int  = 30;
        private var wrapHeart:DisplayObject3D;
        private var cube:Cube;
        private var cubes:Vector.<Cube> = new Vector.<Cube>;
        private    var angle:Number;
        // "BBS"
        private var wrapBBS:DisplayObject3D;
        private var textBBS:Text3D;
        // "Source"
        private var wrapSrc:DisplayObject3D;
        private var textSrc:Text3D;
        // Blur
        private static const SIZE:int = 465;
        private var base:BitmapData = new BitmapData( SIZE, SIZE, false, 0 );
        private var rot:BitmapData  = new BitmapData( SIZE, SIZE, false, 0 );
        private var canvas:Bitmap = new Bitmap( base );
        private var blur:BlurFilter = new BlurFilter;

        public function Main():void {    
            super( 0, 0, true, true );

            // stats
            var stats:StatsView = new StatsView( renderer );
            addChild( stats );

            // fog
            var fg:FogMaterial = new FogMaterial( 0xDDDDDD );
            renderer.filter = new FogFilter( fg, 20, 200, 8096 );

            // plane
            var mater:WireframeMaterial = new WireframeMaterial( 0x000000 );
            mater.doubleSided = true;
            var plane:Plane = new Plane( mater, 10000, 10000, 20, 20 );
            plane.y = -1024;
            plane.rotationX = 90;
            scene.addChild( plane );
        
            // objsMenu
            objsMenu = new DisplayObject3D();
            scene.addChild( objsMenu );
            
            // Bitmap
            wrap = new DisplayObject3D();
            scene.addChild( wrap );
            
            var mat:BitmapFileMaterial = new BitmapFileMaterial( "mentroom.jpg", true );
            mat.interactive = true;
            mat.doubleSided = true;
            obj = new Plane( mat, 640, 480 );
            obj.x = 600;
            obj.z = 0;
            obj.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, clickHandler );
            wrap.addChild( obj );
            
            // Heart
            var light:PointLight3D = new PointLight3D( false, false );
            scene.addChild( light );
            
            wrapHeart = new DisplayObject3D();
            scene.addChild( wrapHeart );

            //var color:ColorHSV = new ColorHSV( 0, 0.5, 0.5 );
            //var material:FlatShadeMaterial = new FlatShadeMaterial( light, 0xFFFFFF, 0x111111, 50 );
            var material:GouraudMaterial = new GouraudMaterial( light, 0xFF0000, 0x110000, 50 );
            //var material:GouraudMaterial = new GouraudMaterial( light, color.value32, 0x111111, 50 );
            //var material:PhongMaterial = new PhongMaterial( light, 0xFFFFFF, 0x111111, 50 );
            //var material:CellMaterial = new CellMaterial( light, 0xFFFFFF, 0x111111, 10 );
            cube = new Cube( new MaterialsList( { all:material } ), CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1, 1, 1 );
            wrapHeart.addChild( cube );
            cubes.push( cube );
            //material.destroy();

            for ( var i:int=1; i<CUBE_MAX; i++  ) {
                material = new GouraudMaterial( light, 0xFF0000 + i*8, 0x110000, 50 );
                
                cube = new Cube( new MaterialsList( { all:material } ), CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1, 1, 1 );
                wrapHeart.addChild( cube );
                angle = ( i/CUBE_MAX/2 )*360*Math.PI/180;
                cube.x = Math.sin( angle )*ORBITAL_RADIUS*i/10;
                cube.y = Math.cos( angle )*ORBITAL_RADIUS*i/10;
                cubes.push( cube );

                cube = new Cube( new MaterialsList( { all:material } ), CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1, 1, 1 );
                wrapHeart.addChild( cube );
                angle = ( i/CUBE_MAX/2 )*360*Math.PI/180;
                cube.x = -Math.sin( angle )*ORBITAL_RADIUS*i/10;
                cube.y = Math.cos( angle )*ORBITAL_RADIUS*i/10;
                cubes.push( cube );

                //material.destroy();
            }
            material = new GouraudMaterial( light, 0xFF0000 + CUBE_MAX*8, 0x110000, 50 );
            cube = new Cube( new MaterialsList( { all:material } ), CUBE_SIZE, CUBE_SIZE, CUBE_SIZE, 1, 1, 1 );
            wrapHeart.addChild( cube );
            angle = ( 1/2 )*360*Math.PI/180;
            cube.x = Math.sin( angle )*ORBITAL_RADIUS*i/10;
            cube.y = Math.cos( angle )*ORBITAL_RADIUS*i/10;
            cubes.push( cube );
            //material.destroy();
            
            // BBS
            wrapBBS = new DisplayObject3D();
            scene.addChild( wrapBBS );
            
            var materialBBS:Letter3DMaterial = new Letter3DMaterial( 0x666699 );
            materialBBS.interactive = true;
            materialBBS.doubleSided = true;
            var fontBBS:HelveticaBold = new HelveticaBold();
            textBBS = new Text3D( "BBS", fontBBS, materialBBS );
            textBBS.x = 700;
            textBBS.z = 0;
            textBBS.scale = 5;
            textBBS.lookAt( DisplayObject3D.ZERO );
            //textBBS.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, clickHandlerBBS );
            for ( i = 0; i < textBBS.letters.length; i++) {
                textBBS.letters[i].addEventListener( 
                    InteractiveScene3DEvent.OBJECT_CLICK, clickHandlerBBS
                );
            }
            wrapBBS.addChild( textBBS );
            
            // Source
            wrapSrc = new DisplayObject3D();
            scene.addChild( wrapSrc );
            
            var materialSrc:Letter3DMaterial = new Letter3DMaterial( 0x669966 );
            materialSrc.interactive = true;
            materialSrc.doubleSided = true;
            //var fontSrc:HelveticaBold = new HelveticaBold();
            //var fontSrc:HelveticaLight = new HelveticaLight();
            var fontSrc:HelveticaRoman = new HelveticaRoman();
            textSrc = new Text3D( "Source", fontSrc, materialSrc );
            textSrc.x = 800;
            textSrc.z = 0;
            textSrc.scale = 5;
            textSrc.lookAt( DisplayObject3D.ZERO );
            //textSrc.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, clickHandlerSrc );
            for ( i = 0; i < textSrc.letters.length; i++) {
                textSrc.letters[i].addEventListener( 
                    InteractiveScene3DEvent.OBJECT_CLICK, clickHandlerSrc
                );
            }
            wrapSrc.addChild( textSrc );
            
            // start
            startRendering();
            addEventListener( Event.ENTER_FRAME, loop );
            //addEventListener( MouseEvent.CLICK, clickHandler );
        }
        
        private function loop(e:Event):void {
            var rot:Number = (mouseX / stage.stageWidth ) * 720;
            
            //camera.x = 1000 * Math.sin( rot * Math.PI / 180 ); 
            //camera.z = 1000 * Math.cos( rot * Math.PI / 180 );
            //camera.y = 2000 * ( mouseY / stage.stageHeight );
            
            wrap.rotationY += 0.5;
            
            obj.rotationY += 1;
            obj.rotationX += 0.3;
            obj.rotationZ += 0.07;
            
            wrapHeart.rotationX += 0.03;
            wrapHeart.rotationY += 0.2;

            wrapBBS.rotationY += 0.4;
            
            wrapSrc.rotationY += 0.3;
            
            for ( var i:int = 0; i < cubes.length; i++ ) {
                cubes[ i ].rotationX += 0.3;
                cubes[ i ].rotationZ += 1;
            }
        }

        //private function clickHandler( e:MouseEvent ):void {
        private function clickHandler( e:InteractiveScene3DEvent ):void {
            navigateToURL( new URLRequest( "in9902.htm" ) );
            //navigateToURL( new URLRequest( "http://0bbs.jp/atassyu/" ) );
        }
        
        private function clickHandlerBBS( e:InteractiveScene3DEvent ):void {
            navigateToURL( new URLRequest( "http://0bbs.jp/atassyu/" ) );
        }

        private function clickHandlerSrc( e:InteractiveScene3DEvent ):void {
            navigateToURL( new URLRequest( "flash/NewProject6.htm" ) );
        }
    }
}


// end.

- Rental Orbit Space -