dehash »  AS3 Papervision3D GreatWhite example code «

Some AS3 code examples that use Papervision3D GreatWhite from SVN. Made with FlashDevelop and Flex3 SDK but as they are pure AS3 examples they should work mostly the same in Flash 9 too. Some examples are clean and basic but others are less so and some are just ideas for things to explore later when more examples are added. Will try to put build/revision number in each post but note when using SVN it is inevitable that if some time has passed parts of these they may not work without tweaking in later builds. The source code text is released as open source under the BSD License which is a very open license with few restrictions. Any external media used however (bitmaps, flv, sound etc) is not covered by this license. If you notice mistakes please email dehash_at_gmail_dot_com.

 

Title: Lines3D

Line3D demo using BasicView - revision 652 - note: setting the controlVertex in Line3D seems to have no effect

Actionscript:
  1. /**
  2. * v0.1 code by dehash.com 2008
  3. * Released as open source under the BSD License
  4. * http://www.opensource.org/licenses/bsd-license.php
  5. */
  6. package com.dehash.pv3d.examples.basic
  7. {
  8.  
  9. import org.papervision3d.core.geom.renderables.Line3D;
  10. import org.papervision3d.core.geom.renderables.Vertex3D;
  11. import org.papervision3d.materials.special.LineMaterial;
  12. import org.papervision3d.view.BasicView;
  13. import org.papervision3d.core.geom.Lines3D;
  14. import flash.events.Event;
  15.  
  16. [SWF(width="800", height="600", backgroundColor="0x000000")]
  17.  
  18. public class Lines3DDemo extends BasicView
  19. {
  20.  
  21. private var lines3D:Lines3D;
  22.  
  23. public function Lines3DDemo(viewportWidth:Number = 800, viewportHeight:Number = 600,
  24. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D")
  25. {
  26.  
  27. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  28.  
  29. lines3D = new Lines3D(randLineMaterial());
  30.  
  31. var v1:Vertex3D = new Vertex3D(0,0,0);
  32.  
  33. for(var i:uint = 1; i <20; i++){
  34. var line:Line3D = new Line3D(lines3D, randLineMaterial() , 2, v1, randVertex(), randVertex());
  35. lines3D.addLine(line);
  36. }
  37. scene.addChild(lines3D);
  38.  
  39. renderer.renderScene(scene, camera, viewport);
  40.  
  41. this.startRendering();
  42. }
  43.  
  44. protected override function onRenderTick(event:Event = null):void {
  45.  
  46. lines3D.yaw((mouseY-(stage.stageHeight/2))/(stage.height/2)*5);
  47. lines3D.roll((mouseX-(stage.stageWidth/2))/(stage.width/2)*-5);
  48.  
  49. renderer.renderScene(scene, camera, viewport)
  50. }
  51.  
  52. private function randVertex():Vertex3D {
  53. return new Vertex3D(randNum(),randNum(),randNum());
  54. }
  55.  
  56. private function randLineMaterial():LineMaterial {
  57. return new LineMaterial(randColor());
  58. }
  59.  
  60. private function randColor():Number {
  61. return Math.floor((Math.random() * 0xFFFFFF));
  62. }
  63.  
  64. private function randNum():Number {
  65. return 800 - (Math.random() * 1600);
  66. }
  67. }
  68. }