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: AS3DMod Sandbox

AS3DMod sandbox using BasicView - revision 702 - source code below is for a simplified pv3d usage example in a similar style to the other files here.

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 {
  7. // pv3d
  8. import org.papervision3d.materials.WireframeMaterial;
  9. import org.papervision3d.materials.ColorMaterial;
  10. import org.papervision3d.materials.special.CompositeMaterial;
  11. import org.papervision3d.objects.primitives.Plane;
  12. import org.papervision3d.view.BasicView;
  13. import org.papervision3d.view.stats.StatsView;
  14. // as3dmod from http://www.everydayflash.com/blog/index.php/2008/09/03/as3dmod/
  15. import com.as3dmod.modifiers.Bend;
  16. import com.as3dmod.modifiers.Noise;
  17. import com.as3dmod.modifiers.Perlin;
  18. import com.as3dmod.ModifierStack;
  19. import com.as3dmod.plugins.pv3d.LibraryPv3d;
  20. import com.as3dmod.util.ModConstant;
  21. import com.as3dmod.util.Phase;
  22. // flash
  23. import flash.events.Event;
  24.  
  25. [SWF(width="800", height="600", backgroundColor="0x000000")]
  26.  
  27. public class As3dmodExample extends BasicView {
  28.  
  29. private var modifierStack:ModifierStack;
  30. private var bend:Bend;
  31. private var bendPhase:Phase;
  32.  
  33. public function As3dmodExample(viewportWidth:Number = 800, viewportHeight:Number = 600,
  34. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D")
  35. {
  36. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  37. addChild(new StatsView(renderer));
  38.  
  39. stage.quality = "low";
  40.  
  41. // do pv3d stuff
  42. var compositeMaterial:CompositeMaterial = new CompositeMaterial();
  43. compositeMaterial.addMaterial( new ColorMaterial(0x270e59) );
  44. compositeMaterial.addMaterial( new WireframeMaterial(0x491ca5) );
  45. compositeMaterial.doubleSided = true;
  46.  
  47. var plane:Plane = new Plane(compositeMaterial, 800, 800, 16, 16);
  48.  
  49. scene.addChild(plane);
  50. camera.target = plane;
  51.  
  52. // do as3dmod stuff
  53. modifierStack = new ModifierStack(new LibraryPv3d(), plane);
  54.  
  55. var noise:Noise = new Noise(10);
  56. noise.constraintAxes(ModConstant.X | ModConstant.Y);
  57. modifierStack.addModifier(noise);
  58. modifierStack.collapse();
  59.  
  60. var perlin:Perlin = new Perlin(3);
  61. perlin.setFalloff(1, 0);
  62. modifierStack.addModifier(perlin);
  63.  
  64. bend = new Bend(0, 0.7);
  65. bend.constraint = ModConstant.LEFT;
  66. bendPhase = new Phase();
  67. modifierStack.addModifier(bend);
  68.  
  69. renderer.renderScene(scene, camera, viewport)
  70. this.startRendering();
  71. }
  72.  
  73. protected override function onRenderTick(event:Event = null):void {
  74. // as3dmod enterframe calls
  75. bendPhase.value += 0.05;
  76. bend.force = bendPhase.phasedValue * 2;
  77. modifierStack.apply();
  78.  
  79. // some hovering
  80. camera.x -= (camera.x - Math.sin(mouseX*0.01)*1000) /8;
  81. camera.z -= (camera.z - Math.cos(mouseX*0.01)*1000) /8;
  82. camera.y -= (camera.y - viewport.containerSprite.mouseY * 5) /8;
  83.  
  84. renderer.renderScene(scene, camera, viewport);
  85. }
  86.  
  87. }
  88. }