Using Papervision3D with FlashDevelop 3
Sunday, June 24th, 2007 | Author: dehash
[EDIT] For a more up to date post click here http://www.dehash.com/?p=152
![]()
Below is an example using Papervision3D AS3 engine using Flex2 SDK and FlashDevelop3 Beta 2. Look here for a fantastic Shark Demo
Actionscript:
-
package {
-
import flash.display.*;
-
import flash.events.*;
-
import org.papervision3d.scenes.*;
-
import org.papervision3d.objects.*;
-
import org.papervision3d.cameras.*;
-
import org.papervision3d.materials.*;
-
-
import com.suite75.papervision3d.objects.*;
-
-
[SWF(backgroundColor="#000000", frameRate="30")]
-
-
public class TestTorus extends Sprite {
-
private var container : Sprite;
-
private var scene : Scene3D;
-
private var camera : Camera3D;
-
private var rootNode : DisplayObject3D;
-
-
private var torusObj : DisplayObject3D;
-
private var torusSize : int = 300;
-
private var segment : int = 3;
-
private var material : ColorMaterial;
-
-
private var valx : Number = 0;
-
private var valy : Number = 0;
-
-
public function TestTorus():void {
-
stage.frameRate = 60;
-
stage.quality = "MEDIUM";
-
stage.scaleMode = "noScale";
-
stage.align = StageAlign.TOP_LEFT;
-
this.addEventListener(Event.ENTER_FRAME, loop3D);
-
this.stage.addEventListener(Event.RESIZE, onStageResize);
-
-
init3D();
-
}
-
-
private function init3D():void {
-
this.container = new Sprite();
-
addChild(this.container);
-
this.container.x = this.stage.stageWidth / 2;
-
this.container.y = this.stage.stageHeight / 2;
-
-
scene = new Scene3D( container );
-
-
camera = new Camera3D();
-
camera.z = -torusSize;
-
camera.focus = 500;
-
camera.zoom = 1;
-
-
rootNode = scene.addChild( new DisplayObject3D( "rootNode" ) );
-
-
material = new ColorMaterial( 0x0099cc, 0.3);
-
material.oneSide = false;
-
-
torusObj = rootNode.addChild( new Torus( material,100,50) );
-
torusObj.material.lineColor = 0x00ccff;
-
torusObj.material.lineAlpha = 0.3;
-
}
-
-
private function loop3D( event:Event ):void {
-
-
valx += this.container.mouseX / 50;
-
valy += this.container.mouseY / 50;
-
torusObj.rotationY = valx;
-
torusObj.rotationX = valy;
-
-
this.scene.renderCamera( camera );
-
}
-
-
private function onStageResize(event:Event):void {
-
this.container.x = this.stage.stageWidth / 2;
-
this.container.y = this.stage.stageHeight / 2;
-
}
-
-
}
-
}
Some code here was useful to use


