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: Simple Wow Engine Demo

Very simple Wow Demo example using BasicView [update: added cube + fps] - revision 694 - uses Wow Physics Engine SVN and also some ideas from here

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.physics {
  7. import org.papervision3d.materials.WireframeMaterial;
  8. import org.papervision3d.materials.utils.MaterialsList;
  9. import org.papervision3d.objects.DisplayObject3D;
  10. import org.papervision3d.objects.primitives.Sphere;
  11. import org.papervision3d.objects.primitives.Cube;
  12. import org.papervision3d.view.BasicView;
  13.  
  14. import fr.seraf.wow.primitive.WSphere;
  15. import fr.seraf.wow.core.WOWEngine;
  16. import fr.seraf.wow.primitive.WBoundArea;
  17. import fr.seraf.wow.core.data.WVector;
  18.  
  19. import org.papervision3d.view.stats.StatsView;
  20.  
  21. import flash.events.Event;
  22.  
  23. [SWF(width="800", height="600", backgroundColor="0x000000")]
  24.  
  25. public class WowDemo extends BasicView {
  26. private var wow:WOWEngine;
  27. private var wowObjects:Array;
  28. private var pv3DObjects:Array;
  29. private var world:DisplayObject3D;
  30.  
  31. public function WowDemo(viewportWidth:Number = 800, viewportHeight:Number = 600,
  32. scaleToStage:Boolean=true, interactive:Boolean=false, cameraType:String="CAMERA3D")
  33. {
  34. super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
  35.  
  36. var stats:StatsView = new StatsView(renderer);
  37. stage.addChild(stats);
  38.  
  39.  
  40. world = new DisplayObject3D();
  41.  
  42. pv3DObjects = new Array();
  43.  
  44. for(var i:uint = 0; i <5; i++){
  45. var sphere:Sphere = new Sphere();
  46. world.addChild(sphere);
  47. pv3DObjects.push(sphere);
  48. }
  49. scene.addChild(world);
  50. camera.target = world;
  51. camera.zoom = 50;
  52.  
  53. wow= new WOWEngine(0.5);
  54. wow.collisionResponseMode = wow.STANDARD;
  55. var bound:WBoundArea = new WBoundArea(800,600,600);
  56. bound.setPosition(0, 0, 0);
  57. wow.setBoundArea(bound);
  58.  
  59. wowObjects = new Array();
  60.  
  61. for (var i:uint = 0; i <5; i++){
  62. var wSphere:WSphere = new WSphere(0, 0, 0, 5, false, 0.005, 0.9, 0.01);
  63. wSphere.px = rand(100, 50);
  64. wSphere.py = rand(100, 50);
  65. wSphere.pz = rand(100, 50);
  66. wow.addParticle(wSphere);
  67. wSphere.addForce( new WVector( rand(1,4), rand(1,4), rand(1,4) ) ) ;
  68. wowObjects.push(wSphere);
  69. }
  70.  
  71. var materialsList:MaterialsList = new MaterialsList();
  72. materialsList.addMaterial(new WireframeMaterial(0x333333), "all");
  73. scene.addChild(new Cube(materialsList, 1000, 800, 800));
  74.  
  75. startRendering();
  76. }
  77.  
  78. protected override function onRenderTick(event:Event = null):void {
  79. var rotY: Number = (mouseY-(stage.stageHeight/2))/(stage.height/2)*(1600);
  80. var rotX: Number = (mouseX-(stage.stageWidth/2))/(stage.width/2)*(-1600);
  81. camera.x= camera.x+(rotX-camera.x)/5;
  82. camera.y = camera.y + (rotY - camera.y) / 5;
  83.  
  84. wow.step();
  85. for(var i:uint = 0; i <pv3DObjects.length; i++) {
  86. pv3DObjects[i].x = wowObjects[i].px
  87. pv3DObjects[i].y = wowObjects[i].py
  88. pv3DObjects[i].z = wowObjects[i].pz
  89. }
  90. renderer.renderScene(scene, camera, viewport)
  91. }
  92.  
  93. private function rand(max:Number, min:Number):Number {
  94. return Math.random()*(max-min) + min;
  95. }
  96.  
  97. }
  98. }