<?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[
import mx.events.*;
import flash.display.*;
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.*;
import com.fontvirus.*;
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;
private function init3D():void
{
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.LOW;
stage.scaleMode = StageScaleMode.NO_SCALE;
fps = new FlexFPS(0x006600, 0x33333, 0xffffff, 0, "mb");
addChild(fps);
fs = new FlexFS(0x000000, 0xcccccc, "bottomLeft", this.width, this.height);
addChild(fs);
scene = new Scene3D();
cam = new Camera3D(null, 8, 100);
view = new Viewport3D(this.width, this.height, true);
paperCanvas.addChild(view);
renderer = new BasicRenderEngine();
thelight = new PointLight3D(true);
scene.addChild(thelight);
illuminate();
thing = new Cube(new MaterialsList({all:new FlatShadeMaterial(thelight, 0x006600, 0x000000)}), 300, 300, 300);
scene.addChild(thing);
addEventListener(Event.ENTER_FRAME, loop3D);
addEventListener(ResizeEvent.RESIZE, resize);
}
private function loop3D(e:Event):void
{
fps.update("rendered: " + view.lastRenderList.length + " polys");
thing.pitch(1);
thing.yaw(1);
if(willOrbit.selected==true){
orbit();
}
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) + ")";
}
private function illuminate():void
{
thelight.x = theX.value;
thelight.y = theY.value;
thelight.z = theZ.value;
showPos();
}
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();
}
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;
}
}
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>