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: Earth Globe

Earth image mapped to a sphere to make a simple globe - revision 856 - earthmap2k.jpg originally 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.basic {
  7. import org.papervision3d.materials.BitmapMaterial;
  8. import org.papervision3d.objects.primitives.Sphere;
  9. import org.papervision3d.view.BasicView;
  10. import flash.events.Event;
  11. import flash.display.Bitmap;
  12.  
  13. [SWF(width="800", height="600", backgroundColor="0x000000")]
  14.  
  15. public class EarthDemo extends BasicView {
  16. [Embed(source='earthmap2k.jpg')]
  17. public var EarthImage:Class;
  18.  
  19. public function EarthDemo(viewportWidth:Number = 800, viewportHeight:Number = 600,
  20. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D"){
  21.  
  22. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  23.  
  24. var earthMaterial:BitmapMaterial = new BitmapMaterial( ( ( new EarthImage() ) as Bitmap ).bitmapData );
  25.  
  26. var sphere:Sphere = new Sphere(earthMaterial, 320, 24, 20);
  27. scene.addChild(sphere);
  28. camera.target = sphere;
  29. camera.zoom = 80;
  30. startRendering();
  31. }
  32.  
  33. protected override function onRenderTick(event:Event = null):void {
  34. camera.x -= (camera.x - Math.sin(mouseX*0.01)*1200) /8;
  35. camera.z -= (camera.z - Math.cos(mouseX*0.01)*1200) /8;
  36. camera.y -= (camera.y - viewport.containerSprite.mouseY * 5) / 8;
  37. renderer.renderScene(scene, camera, viewport);
  38. }
  39. }
  40. }