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: Thunderstorm

Scaling PV3D planes using SoundMixer.computeSpectrum data - revision 856 - sound file from 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 com.dehash.pv3d.examples.noise {
  7. import org.papervision3d.objects.DisplayObject3D;
  8. import org.papervision3d.objects.primitives.*;
  9. import org.papervision3d.materials.BitmapMaterial;
  10. import org.papervision3d.view.BasicView;
  11. import flash.net.URLRequest;
  12. import flash.utils.ByteArray;
  13. import flash.display.Bitmap;
  14. import flash.events.Event;
  15. import flash.filters.*;
  16. import flash.media.*;
  17.  
  18. [SWF(width="800", height="600", backgroundColor="0x000000")]
  19.  
  20. public class SphereOutlineSound extends BasicView {
  21. [Embed(source='../assets/sphere.png')]
  22. private var SphereImage:Class;
  23. private var byteArray:ByteArray;       
  24. private var planes:Array;
  25.  
  26. public function SphereOutlineSound(viewportWidth:Number = 800, viewportHeight:Number = 600,
  27. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D") {
  28. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  29.  
  30. // pv3d
  31. var world:DisplayObject3D = new DisplayObject3D();
  32. world.useOwnContainer = true;
  33. world.filters = [new BlurFilter(24, 12, 2),new GlowFilter()];
  34. scene.addChild(world);
  35. camera.target = world;
  36.  
  37. var bitmapMaterial:BitmapMaterial = new BitmapMaterial(Bitmap(new SphereImage()).bitmapData);
  38. bitmapMaterial.doubleSided = true;
  39.  
  40. var sphere:Sphere = new Sphere(null, 600, 10,10);
  41. planes = [];
  42.  
  43. for ( var i:int = 0; i <sphere.geometry.vertices.length; i++) {
  44. var plane:Plane = new Plane( bitmapMaterial, 50, 50 );
  45. planes.push(plane);
  46. plane.x = sphere.geometry.vertices[i].x;
  47. plane.y = sphere.geometry.vertices[i].y;
  48. plane.z = sphere.geometry.vertices[i].z;
  49. plane.lookAt(camera);
  50. world.addChild(plane);
  51. }
  52.  
  53. // sound
  54. var snd:Sound = new Sound(new URLRequest("assets/storm.mp3"));
  55. var channel:SoundChannel = snd.play(0,100);
  56. byteArray = new ByteArray();
  57.  
  58. startRendering();
  59. }
  60.  
  61. protected override function onRenderTick(event:Event = null):void {
  62.  
  63. try {   
  64. SoundMixer.computeSpectrum(byteArray, true, 2);
  65. for(var i:int = 0; i <planes.length; i++) {
  66. planes[i].scale = (byteArray[i]/100> planes[i].scale )? byteArray[i]/100 : Math.max(planes[i].scale * 0.95, 0.5);
  67. }
  68. }catch (e:Error){
  69. trace("SoundMixer.computeSpectrum Error "+e);
  70. }   
  71.  
  72. camera.x -= (camera.x - Math.sin(mouseX*0.01)*1200) /8;
  73. camera.z -= (camera.z - Math.cos(mouseX*0.01)*1200) /8;
  74. camera.y -= (camera.y - viewport.containerSprite.mouseY * 5) / 8;
  75.  
  76. renderer.renderScene(scene, camera, viewport);
  77. }
  78. }
  79. }