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: An idea for a Fish

Just a first try at a fish using BasicView - revision 702 - uses as3dmod svn

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.as3dmod {
  7. // pv3d
  8. import org.papervision3d.view.BasicView;
  9. import org.papervision3d.objects.primitives.Plane;
  10. import org.papervision3d.materials.BitmapMaterial;
  11. // as3dmod svn from http://code.google.com/p/as3dmod/
  12. import com.as3dmod.plugins.pv3d.LibraryPv3d;
  13. import com.as3dmod.ModifierStack;
  14. import com.as3dmod.modifiers.Noise;
  15. import com.as3dmod.modifiers.Perlin;
  16. import com.as3dmod.modifiers.Bend;
  17. import com.as3dmod.util.Phase;
  18. import com.as3dmod.util.ModConstant;
  19. // flash
  20. import flash.events.Event;
  21. import flash.display.Bitmap;
  22. import flash.ui.Mouse;
  23.  
  24. [SWF(width = "800", height = "600", backgroundColor = "0x00FFFF")]
  25.  
  26. public class AS3DModFish extends BasicView {
  27.  
  28. [Embed(source = 'fish.png')]
  29. private var fishImage:Class;
  30. private var fish:Plane;
  31. private var modifierStack:ModifierStack;
  32. private var bend:Bend;
  33. private var bendPhase:Phase;
  34.  
  35. public function AS3DModFish(viewportWidth:Number = 800, viewportHeight:Number = 600,
  36. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D")
  37. {
  38. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  39.  
  40. // global
  41. stage.quality = "low";
  42. Mouse.hide();
  43.  
  44. // pv3d
  45. var fishMaterial:BitmapMaterial = new BitmapMaterial(Bitmap(new fishImage()).bitmapData);
  46. fishMaterial.doubleSided = true;
  47. fish = new Plane(fishMaterial, 700, 500, 16, 16);
  48. fish.yaw(70); fish.z = 1600;
  49. scene.addChild(fish);
  50.  
  51. // as3dmod
  52. modifierStack = new ModifierStack(new LibraryPv3d(), fish);
  53. bend = new Bend();
  54. bendPhase = new Phase();
  55. bend.bendAxis = ModConstant.X;
  56. bend.pointAxis = ModConstant.NONE;
  57. bend.offset = ModConstant.RIGHT;
  58. modifierStack.addModifier(bend);
  59. modifierStack.addModifier(new Perlin(1));
  60. var noise:Noise = new Noise(7);
  61. noise.constraintAxes(ModConstant.X);
  62. modifierStack.addModifier(noise);   
  63.  
  64. startRendering();
  65. }
  66.  
  67. protected override function onRenderTick(event:Event = null):void {
  68. // as3dmod
  69. bendPhase.value += 0.04;
  70. bend.force = bendPhase.phasedValue/3;
  71. modifierStack.apply()
  72. // pv3d
  73. fish.rotationY++;
  74. // hover
  75. camera.x -= (camera.x - Math.sin(mouseX*0.01)*800) /8;
  76. camera.z -= (camera.z - Math.cos(mouseX*0.01)*400) /8;
  77. camera.y -= (camera.y - viewport.containerSprite.mouseY * 5) / 8;
  78. // render
  79. renderer.renderScene(scene, camera, viewport);
  80. }
  81.  
  82. }
  83. }