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

Interactivity example with pv3d (click on the photo) using BasicView - revision 702 - [update removed onComplete + small improvements + tiled material] - also uses Tweener . JPG by mimiyaw

Actionscript:
  1. /**
  2. * v0.3 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.interactivity {
  7. import org.papervision3d.objects.primitives.Plane;
  8. import org.papervision3d.view.BasicView;
  9. import org.papervision3d.events.FileLoadEvent;
  10. import org.papervision3d.materials.BitmapFileMaterial;
  11. import org.papervision3d.events.InteractiveScene3DEvent;
  12. import flash.events.Event;
  13. // http://code.google.com/p/tweener/
  14. import caurina.transitions.Tweener;
  15.  
  16. [SWF(width="800", height="600", backgroundColor="0xffffff")]
  17.  
  18. public class InteractiveScene3DEventExample extends BasicView
  19. {
  20. private var plane:Plane;
  21. private var quality:uint = 8;
  22. private var planeWidth:uint = 800;
  23. private var planeHeight:uint = 600;
  24. private var bitmapFileMaterial:BitmapFileMaterial;
  25.  
  26. public function InteractiveScene3DEventExample(viewportWidth:Number = 800, viewportHeight:Number = 600,
  27. scaleToStage:Boolean=true, interactive:Boolean=true, cameraType:String="CAMERA3D")
  28. {
  29. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  30.  
  31. bitmapFileMaterial = new BitmapFileMaterial();
  32. bitmapFileMaterial.interactive = true;
  33. bitmapFileMaterial.doubleSided = true;
  34. bitmapFileMaterial.smooth = true;
  35. bitmapFileMaterial.tiled = true;
  36.  
  37. bitmapFileMaterial.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleBitmapFileMaterialLoaded, false, 0, true);
  38. bitmapFileMaterial.addEventListener(FileLoadEvent.LOAD_ERROR, handleBitmapFileMaterialError, false, 0, true);
  39. bitmapFileMaterial.texture = "assets/2782350904_dd8b955fb1_b.jpg";
  40.  
  41. plane = new Plane(null, planeWidth, planeHeight, quality);
  42. plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, planeClickedHandler, false, 0, true);
  43. plane.scaleX = 0;
  44. plane.scaleY = 0;
  45.  
  46. scene.addChild(plane);
  47.  
  48. camera.target = plane;
  49. camera.zoom = 60;
  50.  
  51. this.startRendering();
  52. }
  53.  
  54. private function handleBitmapFileMaterialLoaded(e:FileLoadEvent):void {
  55. plane.material = bitmapFileMaterial;
  56. Tweener.addTween(plane, { time:1, transition:'easeoutquint', scaleX: 1, scaleY: 1} );
  57. }
  58.  
  59. private function handleBitmapFileMaterialError(e:FileLoadEvent):void {
  60. trace('handleBitmapFileMaterialError'+e);
  61. }
  62.  
  63. private function planeClickedHandler(e:InteractiveScene3DEvent):void {
  64. if (!Tweener.isTweening(plane)) {
  65. var targetRotation:Number = (plane.rotationY <360) ? 360 : 0 ;
  66. Tweener.addTween(plane, { time:6, transition:'easeinoutbounce',
  67. rotationY: targetRotation } );
  68. }
  69. }
  70.  
  71. protected override function onRenderTick(event:Event = null):void {
  72. var rotY: Number = (mouseY-(stage.stageHeight/2))/(stage.height/2)*(1200);
  73. var rotX: Number = (mouseX-(stage.stageWidth/2))/(stage.width/2)*(-1200);
  74. camera.x = camera.x + (rotX - camera.x) / 5;
  75. camera.y = camera.y + (rotY - camera.y) / 5;
  76. renderer.renderScene(scene, camera, viewport)
  77. }
  78.  
  79. }
  80. }