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: Sphere outline

Setting position of planes using vertices of a Sphere. Uses BasicView - revision 702

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.positioning {
  7. import org.papervision3d.objects.DisplayObject3D;
  8. import org.papervision3d.objects.primitives.Plane;
  9. import org.papervision3d.objects.primitives.Sphere;
  10. import org.papervision3d.materials.BitmapMaterial;
  11. import org.papervision3d.view.BasicView;
  12. import flash.display.Bitmap;
  13. import flash.events.Event;
  14.  
  15. [SWF(width="800", height="600", backgroundColor="0x000000")]
  16.  
  17. public class SphereOutline extends BasicView {
  18. [Embed(source = 'sphere.png')]
  19. private var SphereImage:Class;
  20.  
  21. private var world:DisplayObject3D;
  22. private var sphere:Sphere;
  23.  
  24.  
  25. public function SphereOutline(viewportWidth:Number = 800, viewportHeight:Number = 600,
  26. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D") {
  27. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  28.  
  29.  
  30. stage.quality = "medium";
  31.  
  32. world = new DisplayObject3D();
  33. camera.target = world;
  34.  
  35. var bitmapMaterial:BitmapMaterial = new BitmapMaterial(Bitmap(new SphereImage()).bitmapData);
  36. bitmapMaterial.doubleSided = true;
  37.  
  38. sphere = new Sphere(null, 500, 15, 15);
  39.  
  40.  
  41. for ( var i:int = 0; i <sphere.geometry.vertices.length; i++) {
  42. var plane:Plane = new Plane( bitmapMaterial, 50, 50 );
  43. plane.x = sphere.geometry.vertices[i].x;
  44. plane.y = sphere.geometry.vertices[i].y;
  45. plane.z = sphere.geometry.vertices[i].z;
  46. plane.lookAt(camera);
  47.  
  48. world.addChild(plane);
  49. }
  50.  
  51.  
  52. scene.addChild(world);
  53.  
  54. startRendering();
  55. }
  56.  
  57.  
  58. protected override function onRenderTick(event:Event = null):void {
  59. camera.x -= (camera.x - Math.sin(mouseX*0.01)*1200) /8;
  60. camera.z -= (camera.z - Math.cos(mouseX*0.01)*1200) /8;
  61. camera.y -= (camera.y - viewport.containerSprite.mouseY * 5) / 8;
  62. renderer.renderScene(scene, camera, viewport);
  63. }
  64.  
  65. }
  66. }