<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    backgroundColor="#333333" backgroundAlpha="1"
    pageTitle=" ://fonts.xero.style/ PV3D 2.0 / lighting . demo "
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:xx="com.fontvirus.*" 
    layout="absolute"
    applicationComplete="init3D()"
    viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[/*
           00XXXX                        XXXX00        
           00XXxx                        xxXX00        
           ee0000eeeeRR            RReeee0000ee        
                 xxXX00            00XXxx              
                 XXXX00            00XXXX              
           eexxXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxee        
           00XXXXeeee00XXXXXXXXXXXX00eeeeXXXX00        
       xxXXXXXXXX    00XXXXXXXXXXXX00    XXXXXXXXxx    
       XXXXXXXXXX    00XXXXXXXXXXXX00    XXXXXXXXXX    
   eeeeXXXXXXXXXXeeeeRRXXXXXXXXXXXXRReeeeXXXXXXXXXXeeee
   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   XXXX""""RRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXRR""""XXXX
   XXXX    00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX00    XXXX
   XXXX    00XXXX""""""""""""""""""""""""XXXX00    XXXX
   XXRR    00XXXX                        XXXX00    RRXX
   eeXX    00xxxxRR000000ee    ee000000RRxxxx00    XXee
                 xxXXXXXXxx    xxXXXXXXxx                            
                 XXXXXXXXXX    XXXXXXXXXX                       
    _____             __        .__
  _/ ____\___   _____/  |____  _|__|______  __ __ ______
  \   __/  _ \ /    \   __\  \/ /  \_  __ \|  |  |  ___/
   |  |(  <_> )   |  \  |  \   /|  ||  | \/|  |  |___ \
   |__| \____/|___|  /__|   \_/ |__||__|  /\____/____  >
                   \/                     \/         \/
         .  .  l i g h t i n g  .  d e m o   .  .          */
      
    //_________________________________________
    //                                  importz
    import mx.events.*;
    import flash.display.*;
    //filmed in papervision3D - 2.0a ((codename : great white))
    import org.papervision3d.view.*;
    import org.papervision3d.scenes.*;
    import org.papervision3d.events.*;
    import org.papervision3d.render.*;
    import org.papervision3d.lights.*;
    import org.papervision3d.cameras.*;
    import org.papervision3d.materials.utils.*;
    import org.papervision3d.objects.primitives.*;
    import org.papervision3d.materials.shadematerials.*;
    //custom shiznit
    import com.fontvirus.*;
    //_________________________________________
    //                                     varz    
        private var fps            :FlexFPS;
        private var fs            :FlexFS;
        private var scene        :Scene3D;
        private var cam            :Camera3D;
        private var view        :Viewport3D;
        private var renderer    :BasicRenderEngine;
        private var thelight    :PointLight3D;
        private var thing        :Cube;
        private var rot            :Number = -989;
        private var rotRad        :Number;
    //_________________________________________
    //                              constructor    
    private function init3D():void
    {
        stage.align = StageAlign.TOP_LEFT;
        stage.quality = StageQuality.LOW;
        stage.scaleMode = StageScaleMode.NO_SCALE;

        //create framerate bar
        fps = new FlexFPS(0x006600, 0x33333, 0xffffff, 0, "mb");
        addChild(fps);
        
        //make fullscreen button
        fs = new FlexFS(0x000000, 0xcccccc, "bottomLeft", this.width, this.height);
        addChild(fs);
        
        //setup 3D scene
        scene = new Scene3D();
        cam    = new Camera3D(null, 8, 100);
        view = new Viewport3D(this.width, this.height, true);
        paperCanvas.addChild(view);
        renderer = new BasicRenderEngine();

        //create lighting
        thelight = new PointLight3D(true);
        scene.addChild(thelight);//normally you dont need this, but to make it visible, you do...

        //setup form        
        illuminate();
        
        //create 3D object
        thing = new Cube(new MaterialsList({all:new FlatShadeMaterial(thelight, 0x006600, 0x000000)}), 300, 300, 300);
        scene.addChild(thing);

        //start render loop
        addEventListener(Event.ENTER_FRAME, loop3D);
        //resizer
        addEventListener(ResizeEvent.RESIZE, resize);
    }
    //_________________________________________
    //                              render loop
    private function loop3D(e:Event):void
    {
        //update framerate counter
        fps.update("rendered: " + view.lastRenderList.length + " polys");

        //rotate 3D object
        thing.pitch(1);
        thing.yaw(1);

        //light rotation
        if(willOrbit.selected==true){        
            orbit();
        }

        //render scene
        renderer.renderScene(scene, cam, view);
    }
    private function showPos():void
    {
        display.text = "the light (x:" + thelight.x.toPrecision(4) + ", y:" + thelight.y.toPrecision(4) + ", z:" + thelight.z.toPrecision(4) + ")";
    }
    //_________________________________________
    //                              move lightz
    private function illuminate():void
    {
        //update light position
        thelight.x = theX.value;
        thelight.y = theY.value;
        thelight.z = theZ.value;
        showPos();        
    }
    //_________________________________________
    //                                 rotation
    private function orbit():void
    {
        rot += theSpeed.value;
        rotRad = (rot-90) * (Math.PI/180);
        
        thelight.z = (theRadius.value * Math.cos(rotRad) ) * -1;
        if(dirx.selected==true){
            thelight.x = theRadius.value * Math.sin(rotRad) * -1;
            thelight.y = theY.value;
        } else {
            thelight.y = theRadius.value * Math.sin(rotRad) * -1;
            thelight.x = theX.value;
        }
        showPos();
    }
    //_________________________________________
    //                                formsetup
    private function goOrbit():void
    {
        if(willOrbit.selected==true){
            lblRad.enabled = true;
            lblSpeed.enabled = true;
            theRadius.enabled = true;
            theSpeed.enabled = true;
        } else {
            lblRad.enabled = false;
            lblSpeed.enabled = false;
            theRadius.enabled = false;
            theSpeed.enabled = false;
        }
    }
    //_________________________________________
    //                                  resizer
    private function resize(e:ResizeEvent):void
    {
        fs.setup(this.width, this.height);
    }
]]>
</mx:Script>
<mx:Style>
    Panel {
       shadowDistance: 6;
       shadowDirection: right; 
       backgroundColor:#000000; 
       color:#FFFFFF; 
       cornerRadius:0; 
       headerHeight:22; 
       headerColors:#000000, #666666; 
       width:227; 
       backgroundAlpha:1.0; 
       borderStyle:solid;
    }
    .header {
           letterSpacing: 5;
           color: #ffffff;
           fontWeight: normal;
    }
    RadioButton {
       fillColors: #333333, #ffffff, #333333, #ffffff;
       borderColor: #666666;
       color: #ffffff;
       textSelectedColor: #ffffff;
       textRollOverColor: #cccccc;
       themeColor: #006600;
    }
    CheckBox {
       fillColors: #333333, #ffffff, #333333, #ffffff;
       borderColor: #666666;
       color: #ffffff;
       textSelectedColor: #ffffff;
       textRollOverColor: #cccccc;
       themeColor: #006600;
    }
    HSlider {
       labelOffset: 3;
       thumbOffset: 0;
       showTrackHighlight: true;
       borderColor: #666666;
       trackColors: #999999, #ffffff;
       themeColor: #006600;
       fillColors: #ffffff, #999999, #ffffff, #333333;
    }
</mx:Style>
<xx:Canvas3D id="paperCanvas" top="0" bottom="0" left="0" right="0" backgroundAlpha="0"/>
<mx:Panel title="papervision3D 2.0a - lighting demo" right="10" bottom="13" height="189" layout="absolute" width="252">
    <mx:Label id="display" color="#FFFFFF" width="240" textAlign="center" height="25" x="9" y="38"/>
    <mx:Label text="x" color="#FFFFFF" y="62" x="18"/>
    <mx:HSlider id="theX" minimum="-1000" value="0" maximum="1000" liveDragging="true" change="illuminate()" width="197" x="38" y="60"/>
    <mx:Label text="y" color="#FFFFFF" y="80" x="18"/>
    <mx:HSlider id="theY" minimum="-1000" value="0" maximum="1000" liveDragging="true" change="illuminate()" width="197" x="38" y="80"/>
    <mx:Label text="z" color="#FFFFFF" x="18" y="101"/>
    <mx:HSlider id="theZ" minimum="-1000" value="-989" maximum="1000" liveDragging="true" change="illuminate()" width="197" x="38" y="100"/>
    <mx:CheckBox x="72" y="121" label="orbit" id="willOrbit" selected="false" click="goOrbit()"/>
    <mx:RadioButtonGroup id="dir"/>
    <mx:RadioButton x="162" y="121" label="x" groupName="dir" id="dirx" selected="true"/>
    <mx:RadioButton x="197" y="121" label="y" groupName="dir" id="diry"/>
    <mx:Label x="19" y="146" text="radius" id="lblRad" enabled="false"/>
    <mx:HSlider x="65" y="144" width="170" id="theRadius" minimum="100" value="500" maximum="1500" enabled="false" liveDragging="true"/>
    <mx:Label x="19" y="166" text="speed" id="lblSpeed" enabled="false"/>
    <mx:HSlider x="65" y="164" width="170" id="theSpeed" minimum="0.5" value="5" maximum="15" liveDragging="true" enabled="false"/>
</mx:Panel>
</mx:Application>