. .
CREATE OR DIE Special Downloads Shop webinale

Schauplatz

Artikel
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

März 2010

Flash und Geodaten


Fortsetzung, Teil 3

Ich hier – du da

(Link zum Artikel: http://www.createordie.de/cod/artikel/2932)

Der Quellcode steht auch als Download bereit.

Im Grunde haben wir somit unsere Basisanwendung beendet. An dieser Stelle war es mir persönlich jedoch ein wenig zu trist, die Karte bzw. das Kartenmaterial einfach nur anzuzeigen. Warum das gesamte Szenario nicht einfach um ein wenig 3-D erweitern? So eine Karte sieht doch, gemapped auf ein paar konvex gewölbte Planes, einfach viel besser aus.

Ein wenig Papervision3D hier, ein bisschen AS3Mod dort – so ein kleiner 3-D-Geomapper ist nun auch wirklich schnell geschrieben (Listing 3).

  1. package {
  2. ///////////////////////////////////
  3. // import used classes
  4. ///////////////////////////////////
  5. import com.as3dmod.*;
  6. import com.as3dmod.modifiers.*;
  7. import com.as3dmod.plugins.pv3d.*
  8. import flash.display.*;
  9. import flash.events.*;
  10. import flash.filters.*;
  11. import flash.text.*;
  12. import flash.utils.getTimer;
  13. import gs.*;
  14. import gs.easing.*;
  15. import org.papervision3d.cameras.*;
  16. import org.papervision3d.materials.*;
  17. import org.papervision3d.materials.shadematerials.*;
  18. import org.papervision3d.materials.shaders.*;
  19. import org.papervision3d.materials.utils.*;
  20. import org.papervision3d.objects.primitives.*;
  21. import org.papervision3d.render.*;
  22. import org.papervision3d.scenes.*;
  23. import org.papervision3d.view.*;
  24. ///////////////////////////////////
  25. // class
  26. ///////////////////////////////////
  27. public class GeoMapper extends flash.display.Sprite {
  28. public var surface_tp :BitmapData;
  29. public var surface_lm :BitmapData;
  30. public var surface_rm :BitmapData;
  31. public var surface_bm :BitmapData;
  32. private var view :Viewport3D;
  33. private var scene :Scene3D;
  34. private var tp_plane :Plane;
  35. private var lm_plane :Plane;
  36. private var rm_plane :Plane;
  37. private var bm_plane :Plane;
  38. private var camera :Camera3D;
  39. private var renderer :BasicRenderEngine;
  40. private var stack01 :ModifierStack;
  41. private var stack02 :ModifierStack;
  42. private var stack03 :ModifierStack;
  43. private var stack04 :ModifierStack;
  44. private var bend01 :Bend;
  45. private var bend02 :Bend;
  46. private var bend03 :Bend;
  47. private var bend04 :Bend;
  48. private var rumble :Boolean = false;
  49. ///////////////////////////////////
  50. // class constructor
  51. ///////////////////////////////////
  52. public function GeoMapper() {
  53. super();
  54. if ( stage ) {
  55. setup();
  56. } else {
  57. addEventListener( Event.ADDED_TO_STAGE,setup );
  58. }
  59. }
  60. ///////////////////////////////////
  61. // setup
  62. ///////////////////////////////////
  63. private function setup( event:Event = null ):void {
  64. removeEventListener( Event.ADDED_TO_STAGE, setup );
  65. ///////////////////////////////////
  66. // initialize
  67. ///////////////////////////////////
  68. initEngine();
  69. setupMaterials();
  70. initbend01ings();
  71. launch();
  72. }
  73. ///////////////////////////////////
  74. // initialize: 3d.engine
  75. ///////////////////////////////////
  76. private function initEngine():void {
  77. this.view = new Viewport3D( 800, 640 );
  78. this.view.filters = [new DropShadowFilter(40, 90, 0, 0.6, 24, 24)];
  79. this.scene = new Scene3D();
  80. this.renderer = new BasicRenderEngine();
  81. this.camera = new Camera3D();
  82. this.camera.zoom = 13;
  83. this.camera.z = -120;
  84. this.view.mouseEnabled = false;
  85. this.view.mouseChildren = false;
  86. addChild( this.view );
  87. }
  88. ///////////////////////////////////
  89. // setup: material(s)
  90. ///////////////////////////////////
  91. private function setupMaterials():void {
  92. ///////////////////////////////////
  93. // setup: material(s)
  94. ///////////////////////////////////
  95. var bmp01 :BitmapMaterial = new BitmapMaterial( this.surface_tp );
  96. bmp01.smooth = true;
  97. var bmp02 :BitmapMaterial = new BitmapMaterial( this.surface_lm );
  98. bmp02.smooth = true;
  99. var bmp03 :BitmapMaterial = new BitmapMaterial( this.surface_rm );
  100. bmp03.smooth = true;
  101. var bmp04 :BitmapMaterial = new BitmapMaterial( this.surface_bm );
  102. bmp04.smooth = true;
  103. ///////////////////////////////////
  104. // setup: map.plane(s)
  105. ///////////////////////////////////
  106. this.tp_plane = new Plane( bmp01, 800, 213, 10, 10 );
  107. this.tp_plane.y = 213;
  108. this.lm_plane = new Plane( bmp02, 400, 213, 10, 10 );
  109. this.lm_plane.x = -200;
  110. this.rm_plane = new Plane( bmp03, 400, 213, 10, 10 );
  111. this.rm_plane.x = 200;
  112. this.bm_plane = new Plane( bmp04, 800, 213, 10, 10 );
  113. this.bm_plane.y = -213;
  114. ///////////////////////////////////
  115. // add
  116. ///////////////////////////////////
  117. this.scene.addChild( this.tp_plane );
  118. this.scene.addChild( this.lm_plane );
  119. this.scene.addChild( this.rm_plane );
  120. this.scene.addChild( this.bm_plane );
  121. }
  122. ///////////////////////////////////
  123. // initialize: 3d.bend01ing(s)
  124. ///////////////////////////////////
  125. private function initbend01ings():void {
  126. this.stack01 = new ModifierStack( new LibraryPv3d(), this.lm_plane );
  127. this.stack02 = new ModifierStack( new LibraryPv3d(), this.rm_plane );
  128. this.stack03 = new ModifierStack( new LibraryPv3d(), this.tp_plane );
  129. this.stack04 = new ModifierStack( new LibraryPv3d(), this.bm_plane );
  130. this.bend01 = new Bend();
  131. this.bend01.force = -0.1;
  132. this.bend01.offset = 1.0;
  133. this.bend02 = new Bend();
  134. this.bend02.force = -0.1;
  135. this.bend02.offset = 0.0;
  136. this.bend03 = new Bend();
  137. this.bend03.force = -0.2;
  138. this.bend03.offset = 0.5;
  139. this.bend04 = new Bend();
  140. this.bend04.force = -0.2;
  141. this.bend04.offset = 0.5;
  142. ///////////////////////////////////
  143. // add: modifier(s)
  144. ///////////////////////////////////
  145. this.stack01.addModifier( this.bend01 );
  146. this.stack02.addModifier( this.bend02 );
  147. this.stack03.addModifier( this.bend03 );
  148. this.stack04.addModifier( this.bend04 );
  149. }
  150. ///////////////////////////////////
  151. // launch
  152. ///////////////////////////////////
  153. private function launch():void {
  154. addEventListener( Event.ENTER_FRAME, onUpdateFrame );
  155. }
  156. private function onUpdateFrame( event:Event ):void {
  157. ///////////////////////////////////
  158. // handle: modifier.stack
  159. ///////////////////////////////////
  160. this.stack01.apply();
  161. this.stack02.apply();
  162. this.stack03.apply();
  163. this.stack04.apply();
  164. ///////////////////////////////////
  165. // render
  166. ///////////////////////////////////
  167. this.renderer.renderScene( this.scene, this.camera, this.view );
  168. }
  169. ///////////////////////////////////
  170. // process: bend01ing(s)
  171. ///////////////////////////////////
  172. private function deform( event:MouseEvent ):void {
  173. if ( !this.rumble ) {
  174. var p1:Perlin = new Perlin( 0.1 );
  175. var p2:Perlin = new Perlin( 0.1 );
  176. var p3:Perlin = new Perlin( 0.1 );
  177. var p4:Perlin = new Perlin( 0.1 );
  178. this.stack01.clear(); this.stack02.clear();
  179. this.stack03.clear(); this.stack04.clear();
  180. this.stack01.addModifier( this.bend01 ); this.stack01.addModifier( p1 );
  181. this.stack02.addModifier( this.bend02 );
  182. this.stack02.addModifier( p2 );
  183. this.stack03.addModifier( this.bend03 );
  184. this.stack03.addModifier( p3 );
  185. this.stack04.addModifier( this.bend04 );
  186. this.stack04.addModifier( p4 );
  187. this.rumble = true;
  188. } else {
  189. this.stack01.clear(); this.stack02.clear();
  190. this.stack03.clear(); this.stack04.clear();
  191. this.stack01.addModifier( this.bend01 ); this.stack02.addModifier( this.bend02 );
  192. this.stack03.addModifier( this.bend03 ); this.stack04.addModifier( this.bend04 );
  193. this.rumble = false;
  194. }
  195. }
  196. }
  197. }

Der Quellcode steht auch als Download bereit.

 

Kommentare
Bisher keine Kommentare
Neuer Kommentar
  • Gute Kommentare werden belohnt.
  •   (optional)
  •   (Kommentar abonnieren/Gravatar - wird nicht veröffentlicht)
  •    Benachrichtige mich bei nachfolgenden Kommentaren per E-Mail
  • -+
Tags
Werbung
geodaten