Home

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

PV3D Torus


Below is an example using Papervision3D AS3 engine using Flex2 SDK and FlashDevelop3 Beta 2. Look here for a fantastic Shark Demo

Actionscript:
  1. package {
  2. import flash.display.*;
  3. import flash.events.*;
  4. import org.papervision3d.scenes.*;
  5. import org.papervision3d.objects.*;
  6. import org.papervision3d.cameras.*;
  7. import org.papervision3d.materials.*;
  8.  
  9. import com.suite75.papervision3d.objects.*;
  10.  
  11. [SWF(backgroundColor="#000000", frameRate="30")]
  12.  
  13. public class TestTorus extends Sprite {
  14. private var container : Sprite;
  15. private var scene     : Scene3D;
  16. private var camera    : Camera3D;
  17. private var rootNode  : DisplayObject3D;
  18.  
  19. private var torusObj  : DisplayObject3D;
  20. private var torusSize : int = 300;
  21. private var segment   : int = 3;
  22. private var material  : ColorMaterial;
  23.  
  24. private var valx      : Number = 0;
  25. private var valy      : Number = 0;
  26.  
  27. public function TestTorus():void {
  28. stage.frameRate = 60;
  29. stage.quality   = "MEDIUM";
  30. stage.scaleMode = "noScale";
  31. stage.align = StageAlign.TOP_LEFT;
  32. this.addEventListener(Event.ENTER_FRAME, loop3D);
  33. this.stage.addEventListener(Event.RESIZE, onStageResize);
  34.  
  35. init3D();
  36. }
  37.  
  38. private function init3D():void {
  39. this.container = new Sprite();
  40. addChild(this.container);
  41. this.container.x = this.stage.stageWidth  / 2;
  42. this.container.y = this.stage.stageHeight / 2;
  43.  
  44. scene = new Scene3D( container );
  45.  
  46. camera = new Camera3D();
  47. camera.z = -torusSize;
  48. camera.focus = 500;
  49. camera.zoom = 1;
  50.  
  51. rootNode = scene.addChild( new DisplayObject3D( "rootNode" ) );
  52.  
  53. material = new ColorMaterial( 0x0099cc, 0.3);
  54. material.oneSide = false;
  55.  
  56. torusObj = rootNode.addChild( new Torus( material,100,50) );
  57. torusObj.material.lineColor = 0x00ccff;
  58. torusObj.material.lineAlpha = 0.3;
  59. }
  60.  
  61. private function loop3D( event:Event ):void {
  62.  
  63. valx += this.container.mouseX / 50;
  64. valy += this.container.mouseY / 50;
  65. torusObj.rotationY = valx;
  66. torusObj.rotationX = valy;
  67.  
  68. this.scene.renderCamera( camera );
  69. }
  70.  
  71. private function onStageResize(event:Event):void {
  72. this.container.x = this.stage.stageWidth  / 2;
  73. this.container.y = this.stage.stageHeight / 2;
  74. }
  75.  
  76. }
  77. }

Some code here was useful to use

Tags »

 | Comments Feed: RSS 2.0
Category: Code Examples, Flash, Papervision 3D

You can leave a response.

Leave a Reply

CAPTCHA Image CAPTCHA Audio
Refresh Image