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: VideoStreamMaterial demo

VideoStreamMaterial demo using BasicView - revision 657 - FLV by bradfitz. Movement based on post 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.video {
  7.  
  8. import org.papervision3d.view.BasicView;
  9. import org.papervision3d.objects.primitives.Plane;
  10. import org.papervision3d.materials.VideoStreamMaterial;
  11. import flash.events.Event;
  12. import flash.media.Video;
  13. import flash.net.NetConnection;
  14. import flash.net.NetStream;
  15.  
  16. [SWF(width="800", height="600", backgroundColor="0xffffff")]
  17.  
  18. public class VideoStreamMaterialDemo extends BasicView {
  19.  
  20. private var plane:Plane;
  21. private var videoStreamMaterial:VideoStreamMaterial;
  22. private var quality:uint = 8;
  23. private var netConnection:NetConnection;
  24. private var video:Video;
  25. private var netStream:NetStream;
  26.  
  27. public function VideoStreamMaterialDemo(viewportWidth:Number=800, viewportHeight:Number=600, scaleToStage:Boolean=false, interactive:Boolean=false, cameraType:String="CAMERA3D") {
  28. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  29.  
  30. var customClient:Object = new Object();
  31. customClient.onMetaData = metaDataHandler;
  32.  
  33. netConnection = new NetConnection();
  34. netConnection.connect(null);
  35.  
  36. netStream = new NetStream(netConnection);
  37. netStream.client = customClient;
  38. netStream.play("drawcat.flv");
  39.  
  40. video = new Video();
  41. video.smoothing = true;
  42. video.attachNetStream(netStream);
  43.  
  44. videoStreamMaterial = new VideoStreamMaterial(video, netStream);
  45.  
  46. plane = new Plane(videoStreamMaterial, 1600, 1200, quality, quality);
  47.  
  48. scene.addChild(plane);
  49.  
  50. camera.target = plane;
  51.  
  52. renderer.renderScene(scene, camera, viewport);
  53. this.startRendering();
  54. }
  55.  
  56. protected override function onRenderTick(event:Event = null):void {
  57. var rotY: Number = (mouseY-(stage.stageHeight/2))/(stage.height/2)*(300);
  58. var rotX: Number = (mouseX-(stage.stageWidth/2))/(stage.width/2)*(-300);
  59. camera.x= camera.x+(rotX-camera.x)/5;
  60. camera.y= camera.y+(rotY-camera.y)/5;
  61. renderer.renderScene(scene, camera, viewport)
  62. }
  63.  
  64. private function metaDataHandler(infoObject:Object):void {
  65. trace('metaDataHandler',infoObject);
  66. }
  67.  
  68. }
  69. }