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: BitmapFileMaterial example

BitmapFileMaterial example using BasicView [update improved quality + tiled material] - revision 677 - JPG by //oelia

Actionscript:
  1. /**
  2. * v0.2 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.bitmaps
  7. {
  8. import org.papervision3d.objects.primitives.Plane;
  9. import org.papervision3d.view.BasicView;
  10. import org.papervision3d.materials.BitmapFileMaterial;
  11. import org.papervision3d.events.FileLoadEvent;
  12. import flash.events.Event;
  13.  
  14. [SWF(width="800", height="600", backgroundColor="0xffffff")]
  15.  
  16. public class BitmapFileMaterialDemo extends BasicView
  17. {
  18. private var plane:Plane;
  19. private var bitmapFileMaterial:BitmapFileMaterial;
  20. private var quality:uint = 8;
  21.  
  22. public function BitmapFileMaterialDemo (viewportWidth:Number = 800, viewportHeight:Number = 600,
  23. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D")
  24. {
  25. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  26.  
  27. bitmapFileMaterial = new BitmapFileMaterial();
  28. bitmapFileMaterial.smooth = true;
  29. bitmapFileMaterial.tiled = true;
  30. bitmapFileMaterial.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapLoaded,false, 0, true);
  31. bitmapFileMaterial.addEventListener(FileLoadEvent.LOAD_ERROR, handleFileLoadError,false, 0, true);
  32. bitmapFileMaterial.texture = "2732921665_2979e6f379.jpg";
  33.  
  34. renderer.renderScene(scene, camera, viewport);
  35. this.startRendering();
  36. }
  37.  
  38. protected override function onRenderTick(event:Event = null):void {
  39. camera.x = (stage.mouseX-(stage.stageWidth / 2))/2;
  40. camera.y = (stage.mouseY-(stage.stageHeight / 2))/2;
  41. renderer.renderScene(scene, camera, viewport)
  42. }
  43.  
  44. private function handleBitmapLoaded(e:FileLoadEvent):void {
  45. var w:Number = e.currentTarget.bitmap.width;
  46. var h:Number = e.currentTarget.bitmap.height;
  47. plane = new Plane(bitmapFileMaterial, w*2, h*2, quality, quality);
  48. camera.target = plane;
  49. scene.addChild(plane);
  50. }
  51.  
  52. private function handleFileLoadError(e:FileLoadEvent):void {
  53. trace('handleFileLoadError'+e);
  54. }
  55.  
  56. }
  57. }