<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:xx="com.fontvirus.*"
    backgroundGradientColors="[#000000, #4A4A4A]"
    backgroundGradientAlphas="[1.0, 1.0]"
    pageTitle=" ://fonts.xero.style/pv3d-2.0-test "
    applicationComplete="init3D()"
    layout="absolute" 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                       
    _____             __        .__
  _/ ____\___   _____/  |____  _|__|______  __ __ ______
  \   __/  _ \ /    \   __\  \/ /  \_  __ \|  |  |  ___/
   |  |(  <_> )   |  \  |  \   /|  ||  | \/|  |  |___ \
   |__| \____/|___|  /__|   \_/ |__||__|  /\____/____  >
                   \/                     \/         \/
      .  .  p a p e r v i s i o n 3 D - 2 . 0   .  .          */

  //___________________________________________
  //                                    importz
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    import mx.events.*;
    //filmed in papervision3D - v2.0a (the great white)
    import org.papervision3d.view.*;
    import org.papervision3d.scenes.*;
    import org.papervision3d.render.*;
    import org.papervision3d.lights.*;
    import org.papervision3d.cameras.*;
    import org.papervision3d.objects.*;
    import org.papervision3d.materials.*;
    import org.papervision3d.materials.shaders.*;
    import org.papervision3d.materials.shadematerials.*;
    //custom shiznit
    import com.mrdoob.*;
    import com.fontvirus.*;
  //___________________________________________
  //                                       varz
        private var fps             :FlexFPS;
        private var fs              :FlexFS;
        private var scene           :Scene3D;
        private var view            :Viewport3D;
        private var cam             :Camera3D;
        private var renderer        :BasicRenderEngine;
        private var thelight        :PointLight3D;
        private var shadedObject    :DisplayObject3D;
  //___________________________________________
  //                                constructor
    public function init3D():void
    {
        //framerate display
        fps = new FlexFPS(0x333333, 0x000000, 0xffffff);
        addChild(fps);
        
        //fullscreen button
        fs = new FlexFS(0x000000, 0xcccccc, "bottomLeft", this.width, this.height);
        addChild(fs);
        
        //create 3D scene
        scene = new Scene3D();
        cam = new Camera3D(null, 11, 100);
        renderer = new BasicRenderEngine();
        view = new Viewport3D(640, 480, true, false, true, true);
        paperCanvas.addChild(view);
        
        //create lighting
        thelight = new PointLight3D(true);
        thelight.x = paperCanvas.width * 0.5;
        thelight.y = paperCanvas.width * 0.5;
        thelight.moveForward(500);
        
        //3D model by mrdoob.com
        shadedObject = new MrDoobPlanet(new FlatShadeMaterial(thelight, 0x006600, 0x000000));
        scene.addChild(shadedObject, "shadedObject");
        
        //create render loop
        addEventListener(Event.ENTER_FRAME, loop3D);
        addEventListener(ResizeEvent.RESIZE, setup);
    }
  //___________________________________________
  //                                render loop
    private function loop3D(e:Event):void
    {
        //update fps bar
        fps.update("ploys: " + view.lastRenderList.length);

        //rotate
        if(spinit.selected){
            shadedObject.rotationY+=theSpeed.value;
        }
        //influence camera w/ mouse
        cam.x += ((mouseX-paperCanvas.width*.5) - cam.x);
        cam.y += ((mouseY-paperCanvas.height*.5) - cam.y);

        //create dropshadow        
        view.filters = [new DropShadowFilter(50, 45, 0x000000, .35, 18, 18, 1, 1)];

        //render scene
        renderer.renderScene(scene, cam, view);
    }
  //___________________________________________
  //                                swap modelz
    private function changeModel():void
    {
        scene.removeChildByName("shadedObject");
        if(whichModel.selectedItem=="MrDoobPlanet"){
            //model by mrdoob.com
            shadedObject = new MrDoobPlanet();
        } else if(whichModel.selectedItem=="MrDoobSphere"){
            //model by mrdoob.com
            shadedObject = new MrDoobSphere();
        } else if(whichModel.selectedItem=="InvaderAlpha"){
            //model by fontvir.us
            shadedObject = new InvaderAlpha();
            shadedObject.moveDown(150);
        } else if(whichModel.selectedItem=="InvaderBeta"){
            //model by fontvir.us
            shadedObject = new InvaderBeta();
            shadedObject.moveDown(150);
        } else if(whichModel.selectedItem=="InvaderGamma"){
            //model by fontvir.us
            shadedObject = new InvaderGamma();            
            shadedObject.moveDown(150);
            shadedObject.scale = .75;
        } else if(whichModel.selectedItem=="TorusKnot"){
            //model by fontvir.us
            shadedObject = new TorusKnot();
        } else if(whichModel.selectedItem=="TorusKnotTwist"){
            //model by fontvir.us
            shadedObject = new TorusKnotTwist();
        } else if(whichModel.selectedItem=="TorusKnotSpiral"){
            //model by fontvir.us
            shadedObject = new TorusKnotSpiral();
        }
        changeShading();
        scene.addChild(shadedObject, "shadedObject");
    }
  //___________________________________________
  //                             swap materialz
    private function changeShading():void
    {
        if(whichEffect.selectedItem=="cell"){
            shadedObject.material = new CellMaterial(thelight, difColor.selectedColor, ambColor.selectedColor, int(specularLevel.selectedItem));
            specularLevel.enabled = true;
            lbl.enabled = true;
        } else if(whichEffect.selectedItem=="flat") {
            shadedObject.material = new FlatShadeMaterial(thelight, difColor.selectedColor, ambColor.selectedColor);
            specularLevel.enabled = false;
            lbl.enabled = false;
        } else if(whichEffect.selectedItem=="gouraud") {
            shadedObject.material = new GouraudMaterial(thelight, difColor.selectedColor, ambColor.selectedColor);
            specularLevel.enabled = false;
            lbl.enabled = false;
        } else if(whichEffect.selectedItem=="phong") {
            shadedObject.material = new PhongMaterial(thelight, difColor.selectedColor, ambColor.selectedColor, int(specularLevel.selectedItem));
            specularLevel.enabled = true;
            lbl.enabled = true;
        }
    }
  //___________________________________________
  //                                     zoomer
    private function adjustCam():void
    {
        cam.zoom=theZoom.value;
    }
  //___________________________________________
  //                                    resizer
    private function setup(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;
    }

    ComboBox {
       color: #ffffff;
       borderColor: #ffffff;
       fillColors: #000000, #666666, #333333, #000000;
       selectionColor: #006600;
       textSelectedColor: #ffffff;
       rollOverColor: #333333;
       textRollOverColor: #ffffff;
       themeColor: #00ff00;
       alternatingItemColors: #000000, #000000;
       dropDownStyleName: "dropMenu";
    }
    .dropMenu {
       cornerRadius: 14;
       borderThickness: 6;
       borderColor: #000000;
       color: #ffffff;
       textAlign: center;
    }    
</mx:Style>
<xx:Canvas3D id="paperCanvas" top="0" bottom="0" left="0" right="0" backgroundAlpha="0"/>
<mx:Panel title="papervision3D 2.0a - demo" right="10" bottom="10" height="214" layout="absolute" width="233">
    <mx:Label x="10" y="35" text="3D model"/>
    <mx:ComboBox x="77" y="33" width="144" id="whichModel" dataProvider="{['MrDoobPlanet','MrDoobSphere','InvaderAlpha','InvaderBeta','InvaderGamma','TorusKnot','TorusKnotTwist','TorusKnotSpiral']}" change="changeModel()"/>
    <mx:Label x="12" y="64" text="shading effect"/>
    <mx:ComboBox x="106" y="62" width="115" id="whichEffect" change="changeShading()" dataProvider="{['flat','cell','gouraud','phong']}"/>
    <mx:Label x="30" y="94" text="diffuse"/>
    <mx:ColorPicker x="79" y="92" id="difColor" selectedColor="0x006600" change="changeShading()"/>
    <mx:Label x="121" y="94" text="ambiant"/>
    <mx:ColorPicker x="180" y="92" id="ambColor" selectedColor="0x000000" change="changeShading()"/>
    <mx:Label x="13" y="147" text="zoom"/>
    <mx:HSlider x="57" y="144" width="166" id="theZoom" minimum="5" maximum="25" value="11" liveDragging="true" change="adjustCam()"/>
    <mx:CheckBox x="68" y="165" label="auto roation" id="spinit" selected="true"/>
    <mx:Label x="13" y="187" text="speed"/>
    <mx:HSlider x="60" y="185" width="163" id="theSpeed" minimum="-5" value="0.69" maximum="5" liveDragging="true"/>
    <mx:ComboBox x="133" y="122" width="58" dataProvider="{['0','20','50','100','150']}" selectedIndex="2" id="specularLevel" change="changeShading()" enabled="false"/>
    <mx:Label x="41" y="124" text="specular level" enabled="false" id="lbl"/>
</mx:Panel>
</mx:Application>