In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

PV3Dその5 Planeを球体っぽく並べるのをPV3Dで。

前作ったのをPV3Dで。
画面をクリックするとPlaneが球体に配置されます。
Get Adobe Flash player
by sakef 09 Oct 2010
/**
 * Copyright sakef ( http://wonderfl.net/user/sakef )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jBxZ
 */

/*
    前作ったのをPV3Dで。
    画面をクリックするとPlaneが球体に配置されます。
*/
package
{
    import caurina.transitions.Tweener;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    
    [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="40")]
    public class Main extends Sprite
    {
        private var viewport:Viewport3D;
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var renderer:BasicRenderEngine;
        private var rootNode:DisplayObject3D;
        private var sphereNode:DisplayObject3D;
        private var planeN:int;
        private static const radius:int = 60;
        private static const planeH:int = 15;
        private static const planeW:int = 15;
        
        public function Main()
        {
            viewport=new Viewport3D(0, 0, true, true);
            scene=new Scene3D();
            camera=new Camera3D();
            renderer=new BasicRenderEngine();
            rootNode=scene.addChild(new DisplayObject3D("rootNode"));
            sphereNode=rootNode.addChild(new DisplayObject3D("sphereNode"));
            
            addChild(viewport);
            camera.y=50;
            camera.zoom=50;
            camera.focus=50;
            camera.target=DisplayObject3D.ZERO;
            
            var H:int=(2 * radius * Math.PI) / 2 / planeH;
            var sheeta1:Number;
            var sheeta2:Number=90;
            planeN = 0;
            
            for(var i:int=0; i < H; i++)
            {
                sheeta1=0;
                var pn:int=Math.floor((2 * radius * Math.cos(sheeta2 * Math.PI / 180) * Math.PI) / planeW);
                for(var j:int=0; j < pn; j++)
                {
                    // Planeの作成と座標計算
                    var mat:ColorMaterial=new ColorMaterial(Math.random()*0xFFFFFF, 0.3);
                    var plane:Plane=new Plane(mat, planeW, planeH);
                    plane.material.doubleSided=true;
                    var rx:int=-sheeta2;
                    var ry:int=sheeta1;
                    var xx:int=radius * Math.cos(sheeta2 * Math.PI / 180) * Math.sin(sheeta1 * Math.PI / 180);
                    var yy:int=radius * Math.sin(sheeta2 * Math.PI / 180);
                    var zz:int=radius * Math.cos(sheeta2 * Math.PI / 180) * Math.cos(sheeta1 * Math.PI / 180);
                    plane.extra={x:xx, y:yy, z:zz, rx:rx, ry:ry};
                    sphereNode.addChild(plane, "plane" + planeN.toString());
                    sheeta1+=360 / pn;
                    planeN++;
                    
                    // Planeをランダムに配置
                    plane.x=Math.floor(Math.random() * 600) - 300;
                    plane.y=Math.floor(Math.random() * 600) - 300;
                    plane.z=Math.floor(Math.random() * 600) - 300;
                    plane.rotationX=Math.random() * 360;
                    plane.rotationY=Math.random() * 360;
                    plane.rotationZ=Math.random() * 360;
                }
                sheeta2-=180 / H;
            }
            
            stage.addEventListener(MouseEvent.CLICK, mouseClick);
            renderer.renderScene(scene, camera, viewport);
        }
        
        private function mouseClick(e:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.CLICK, mouseClick);
            addEventListener(Event.ENTER_FRAME, onFrame);
            
            for(var i:int=0; i<planeN; i++)
            {
                var plane:Plane = sphereNode.getChildByName("plane" + i.toString()) as Plane;
                Tweener.addTween(plane, {x:plane.extra.x, y:plane.extra.y, z:plane.extra.z, rotationX:plane.extra.rx, rotationY:plane.extra.ry, rotationZ:0, time:5});
            }
        }
        
        private function onFrame(e:Event):void
        {
            sphereNode.rotationX += 1.5;
            sphereNode.rotationY += 1.5;
            renderer.renderScene(scene, camera, viewport);
        }
    }
}