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

Two sided InteractiveScene3DEvent example using BasicView - revision 856 - uses Tweener svn - click the image to rotate to a different image on the reverse side. Images from here and 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.interactivity {
  7. import org.papervision3d.objects.DisplayObject3D;
  8. import org.papervision3d.objects.primitives.Plane;
  9. import org.papervision3d.view.BasicView;
  10. import org.papervision3d.materials.BitmapMaterial;
  11. import org.papervision3d.events.InteractiveScene3DEvent;
  12. import flash.events.Event;
  13. // http://code.google.com/p/tweener/
  14. import caurina.transitions.Tweener;
  15. [SWF(width="800", height="600", backgroundColor="0x000000")]
  16. //
  17. public class InteractiveTwoSided extends BasicView {
  18. private var twoSidedDisplayObject:DisplayObject3D;
  19. private var quality:uint = 8;
  20. private var planeWidth:uint = 800;
  21. private var planeHeight:uint = 600;
  22. [Embed(source = 'assets/3148444287_cd3e90d92d.jpg')]
  23. private var frontPic:Class;
  24. [Embed(source='assets/3148442355_b655ca9d91.jpg')]
  25. private var backPic:Class;
  26. //
  27. public function InteractiveTwoSided(viewportWidth:Number = 800, viewportHeight:Number = 600,
  28. scaleToStage:Boolean=true, interactive:Boolean=true, cameraType:String="CAMERA3D"){
  29. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  30. twoSidedDisplayObject = new DisplayObject3D();
  31. //
  32. // add front plane
  33. var frontBitmapMaterial:BitmapMaterial = new BitmapMaterial(new frontPic().bitmapData);
  34. frontBitmapMaterial.interactive = true;
  35. frontBitmapMaterial.smooth = true;
  36. frontBitmapMaterial.tiled = true;
  37. var frontPlane:Plane = new Plane(frontBitmapMaterial, planeWidth, planeHeight, quality);
  38. frontPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, planeClickedHandler, false, 0, true);
  39. twoSidedDisplayObject.addChild(frontPlane);
  40. //
  41. // add back plane
  42. var backBitmapMaterial:BitmapMaterial = new BitmapMaterial(new backPic().bitmapData);
  43. backBitmapMaterial.interactive = true;
  44. backBitmapMaterial.smooth = true;
  45. backBitmapMaterial.tiled = true;
  46. var backPlane:Plane = new Plane(backBitmapMaterial, planeWidth, planeHeight, quality);
  47. backPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, planeClickedHandler, false, 0, true);
  48. twoSidedDisplayObject.addChild(backPlane);
  49. //
  50. // twoSidedDisplayObject
  51. backPlane.rotationY = 180;
  52. frontPlane.z = 1;
  53. scene.addChild(twoSidedDisplayObject);
  54. camera.target = twoSidedDisplayObject;
  55. camera.zoom = 60;
  56. this.startRendering();
  57. }
  58. //
  59. private function planeClickedHandler(e:InteractiveScene3DEvent):void {
  60. if (!Tweener.isTweening(twoSidedDisplayObject)) {
  61. var targetRotation:Number = (twoSidedDisplayObject.rotationY <180) ? 180 : 0 ;
  62. Tweener.addTween(twoSidedDisplayObject, { time:2, transition:'easeinoutback',
  63. rotationY: targetRotation } );
  64. }
  65. }
  66. //
  67. protected override function onRenderTick(event:Event = null):void {
  68. var rotY: Number = (mouseY-(stage.stageHeight/2))/(stage.height/2)*(1200);
  69. var rotX: Number = (mouseX-(stage.stageWidth/2))/(stage.width/2)*(-1200);
  70. camera.x = camera.x + (rotX - camera.x) / 5;
  71. camera.y = camera.y + (rotY - camera.y) / 5;
  72. renderer.renderScene(scene, camera, viewport)
  73. }
  74. }
  75. }