<?xml version="1.0" encoding="utf-8"?>
<mx:Application
backgroundColor="#000000" backgroundAlpha="1"
pageTitle=" ...let me touch yer vertices... "
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:xx="com.fontvirus.*"
layout="absolute"
viewSourceURL="srcview/index.html"
applicationComplete="init3D()">
<mx:Script>
<![CDATA[
import flash.display.*;
import mx.controls.*;
import org.papervision3d.view.*;
import org.papervision3d.render.*;
import org.papervision3d.events.*;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.materials.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.core.geom.renderables.*;
import com.fontvirus.*;
private var fps :FlexFPS;
private var cam :Camera3D;
private var scene :Scene3D;
private var view :Viewport3D;
private var renderer :BasicRenderEngine;
private var skin :CompositeMaterial;
private var terrian :Plane;
private var intro :Boolean = true;
private var thisface :Triangle3D = null;
private var lastface :Triangle3D = null;
public function init3D():void
{
fps = new FlexFPS(0x006600, 0x000000, 0xffffff, 0);
addChild(fps);
cam = new Camera3D();
scene = new Scene3D();
view = new Viewport3D(paperCanvas.width, paperCanvas.height, true, true, false, false);
paperCanvas.addChild(view);
renderer = new BasicRenderEngine();
skin = new CompositeMaterial();
skin.interactive = true;
skin.doubleSided = true;
skin.addMaterial(new WireframeMaterial(0xcccccc, 1, 2));
skin.addMaterial(new ColorMaterial(0x006600));
terrian = new Plane(skin, 500, 700, 10, 10);
terrian.y += 50;
terrian.name = "plane";
scene.addChild(terrian);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, extrude);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_MOVE, highlight);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, highlight);
addEventListener(Event.ENTER_FRAME, loop3D);
}
private function loop3D(e:Event):void
{
fps.update("rendered: " + view.lastRenderList.length + " polys");
if(intro==true){
if(cam.z<-300){
cam.z+=4;
}
if(terrian.rotationX<185){
terrian.rotationX+=1.1;
lblx.text = "rotation x: " + terrian.rotationX.toPrecision(3);
} else {
lblx.filters = [new GlowFilter(0xFFFFFF, 1, 5, 5, 5, 1, true, false)];
thex.enabled = true;
}
if(terrian.rotationY<125){
terrian.rotationY+=.73;
lbly.text = "rotation y: " + terrian.rotationY.toPrecision(3);
} else {
lbly.filters = [new GlowFilter(0xFFFFFF, 1, 5, 5, 5, 1, true, false)];
they.enabled = true;
intro = false;
}
if(terrian.rotationZ<85){
terrian.rotationZ+=.5;
lblz.text = "rotation z: " + terrian.rotationZ.toPrecision(3);
} else {
lblz.filters = [new GlowFilter(0xFFFFFF, 1, 5, 5, 5, 1, true, false)];
thez.enabled = true;
}
}
renderer.renderScene(scene, cam, view);
}
private function extrude(e:InteractiveScene3DEvent):void
{
if(direction.selectedIndex==0){
e.face3d.v0.z-=ammount.value;
} else {
e.face3d.v0.z+=ammount.value;
}
var mat:CompositeMaterial = new CompositeMaterial();
mat.interactive = true;
mat.doubleSided = true;
mat.addMaterial(new WireframeMaterial(0xffffff, 1, 2));
if(e.face3d._materialName=="dark"){
mat.addMaterial(new ColorMaterial(0x006600, 1 , true));
e.face3d.material = mat;
e.face3d._materialName = "light";
} else {
mat.addMaterial(new ColorMaterial(0x003300, 1 , true));
e.face3d.material = mat;
e.face3d._materialName = "dark";
}
}
private function highlight(e:InteractiveScene3DEvent):void
{
lastface = thisface;
thisface = e.face3d;
var mat:CompositeMaterial = new CompositeMaterial();
mat.interactive = true;
mat.doubleSided = true;
mat.addMaterial(new WireframeMaterial(0xffffff, 1, 2));
if(thisface!=null){
mat.addMaterial(new ColorMaterial(0x00FF00, 1, true));
thisface.material = mat;
if(e.face3d._materialName=="dark"){
thisface._materialName = "dark";
} else {
thisface._materialName = "light";
}
lbldebug.text = "face3D: " + thisface.id;
} else {
lbldebug.text = "face3D: null";
}
if(lastface!=null){
if(lastface!=thisface){
if(lastface._materialName=="light"){
mat.addMaterial(new ColorMaterial(0x006600, 1, true));
lastface.material = mat;
lastface._materialName = "light";
} else {
mat.addMaterial(new ColorMaterial(0x003300, 1, true));
lastface.material = mat;
lastface._materialName = "dark";
}
}
}
}
private function moveit():void
{
terrian.rotationX = thex.value;
lblx.text = "rotation x: " + thex.value.toPrecision(3);
terrian.rotationY = they.value;
lbly.text = "rotation y: " + they.value.toPrecision(3);
terrian.rotationZ = thez.value;
lblz.text = "rotation z: " + thez.value.toPrecision(3);
}
private function reset():void
{
intro = true;
cam.z = -1000;
scene.removeChildByName("plane");
terrian = new Plane(skin, 500, 700, 10, 10);
terrian.y += 50;
terrian.name = "plane";
scene.addChild(terrian);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, extrude);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_MOVE, highlight);
terrian.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, highlight);
thex.value = 185;
thex.enabled = false;
they.value = 125;
they.enabled = false;
thez.value = 85;
thez.enabled = false;
lblx.filters = [new GlowFilter(0x666666, 1, 5, 5, 5, 1, true, false)];
lbly.filters = [new GlowFilter(0x666666, 1, 5, 5, 5, 1, true, false)];
lblz.filters = [new GlowFilter(0x666666, 1, 5, 5, 5, 1, true, false)];
}
]]>
</mx:Script>
<mx:Style>
Panel {
borderStyle: solid;
borderColor: #ffffff;
borderAlpha: 1;
borderThickness: 1;
roundedBottomCorners: false;
cornerRadius: 0;
headerHeight: 23;
headerColors: #999999, #000000;
backgroundColor: #000000;
titleStyleName: "header";
}
.header {
borderStyle: solid;
borderColor: #ffffff;
borderAlpha: 1;
borderThickness: 1;
letterSpacing: 2;
color: #ffffff;
textAlign: center;
fontWeight: bold;
}
ComboBox {
cornerRadius: 2;
color: #ffffff;
borderColor: #ffffff;
fillColors: #333333, #000000, #000000, #333333;
selectionColor: #000000;
textSelectedColor: #ffffff;
rollOverColor: #00ff00;
textRollOverColor: #000000;
themeColor: #00ff00;
alternatingItemColors: #000000, #000000;
textAlign: center;
}
Button {
cornerRadius: 0;
fillColors: #333333, #000000, #000000, #333333;
color: #ffffff;
textRollOverColor: #ffffff;
textSelectedColor: #cccccc;
themeColor: #00ff00;
}
</mx:Style>
<xx:Canvas3D id="paperCanvas" top="0" bottom="0" left="0" right="0" backgroundAlpha="0"/>
<mx:Panel width="321" height="123" layout="absolute" right="0" bottom="0" title="face3D terrain gen">
<mx:Label width="85" color="#FFFFFF" height="27" id="lbldebug" x="7" y="26"/>
<mx:ComboBox x="100" y="47" width="93" dataProvider="['convex','concave']" id="direction"></mx:ComboBox>
<mx:Label x="100" y="77" text="ammount" color="#FFFFFF"/>
<mx:HSlider value="10" x="100" y="89" width="94" id="ammount" minimum="1" maximum="50"/>
<mx:VRule x="90" y="28" strokeColor="#5F5656" height="78"/>
<mx:VRule x="201" y="28" strokeColor="#5F5656" height="78"/>
<mx:Label id="lblx" text="rotation x:" color="#666666" width="106" x="211" y="26"/>
<mx:HSlider value="185" width="110" id="thex" minimum="0" maximum="360" liveDragging="true" change="moveit()" x="207" y="35" enabled="false"/>
<mx:Label id="lbly" text="rotation y:" color="#666666" width="106" x="211" y="52"/>
<mx:HSlider value="125" width="112" id="they" minimum="0" maximum="360" liveDragging="true" change="moveit()" x="205" y="61" enabled="false"/>
<mx:Label id="lblz" text="rotation z:" color="#666666" width="105" x="212" y="78"/>
<mx:HSlider value="85" width="112" id="thez" minimum="0" maximum="360" liveDragging="true" change="moveit()" x="205" y="88" enabled="false"/>
<mx:Button x="7" y="79" label="reset" width="62" click="reset()"/>
<mx:Label x="100" y="26" text="on click:" color="#FFFFFF"/>
</mx:Panel>
</mx:Application>