Posted By


julespong on 07/13/11

Tagged


Statistics


Viewed 190 times
Favorited by 0 user(s)

SkyboxSwapTest.as


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. package
  2. {
  3. import away3d.containers.ObjectContainer3D;
  4. import away3d.containers.View3D;
  5. import away3d.debug.AwayStats;
  6. import away3d.materials.BitmapMaterial;
  7. import away3d.primitives.SkyBox;
  8.  
  9. import com.greensock.TweenMax;
  10.  
  11. import fl.controls.Button;
  12.  
  13. import flash.display.Sprite;
  14. import flash.events.Event;
  15. import flash.events.MouseEvent;
  16.  
  17. [SWF(frameRate="60", width="1024", height="768")]
  18.  
  19. public class SkyboxSwapTest extends Sprite
  20. {
  21. private var __uiContainer:Sprite;
  22. private var __viewContainer:Sprite;
  23. private var __view:View3D;
  24. private var __objContainer:ObjectContainer3D;
  25.  
  26. private var __skyBox:SkyBox;
  27.  
  28. private var __dragController:HoverDragController;
  29. private var __transitionButton:Button;
  30. private var __cubeMapRenderer:AnimatedCubeMap;
  31.  
  32. private var __haxActive:Boolean = true;
  33.  
  34. public function SkyboxSwapTest()
  35. {
  36. init();
  37. }
  38.  
  39. private function init():void
  40. {
  41. if (stage == null)
  42. {
  43. init();
  44. }
  45. else
  46. {
  47. initDisplay();
  48. init3D();
  49. initCubeMap();
  50. // initSkyBox();
  51. initDragController();
  52. initRender();
  53. }
  54. }
  55.  
  56. private function initDisplay():void
  57. {
  58. __viewContainer = new Sprite();
  59. addChild(__viewContainer);
  60.  
  61. __uiContainer = new Sprite();
  62. __uiContainer.y = 615;
  63. addChild(__uiContainer);
  64.  
  65. __transitionButton = new Button();
  66. __transitionButton.label = "GO";
  67. __transitionButton.addEventListener(MouseEvent.CLICK, transitionClickHandler, false, 0, true);
  68. __uiContainer.addChild(__transitionButton);
  69. }
  70.  
  71. private function initCubeMap():void
  72. {
  73. __cubeMapRenderer = new AnimatedCubeMap();
  74. }
  75.  
  76. private function init3D():void
  77. {
  78. __view = new View3D();
  79. __view.width = 800;
  80. __view.height = 600;
  81. __viewContainer.addChild(__view);
  82.  
  83. __objContainer = new ObjectContainer3D();
  84. __view.scene.addChild(__objContainer);
  85.  
  86. __view.addChild(new AwayStats());
  87. }
  88.  
  89. private function initDragController():void
  90. {
  91. __dragController = new HoverDragController(__view.camera, stage);
  92. }
  93.  
  94. private function initRender():void
  95. {
  96. addEventListener(Event.ENTER_FRAME, enterFrameHandler, false, 0, true);
  97. }
  98.  
  99. protected function enterFrameHandler(event:Event):void
  100. {
  101. prerender();
  102. __view.render();
  103. }
  104.  
  105. private function prerender():void
  106. {
  107. // do
  108. // {
  109. // if (__objContainer.numChildren > 0)
  110. // {
  111. // __objContainer.removeChild(__objContainer.getChildAt(0));
  112. // }
  113. //
  114. // } while(__objContainer.numChildren > 0);
  115.  
  116. if (__skyBox == null)
  117. {
  118. __skyBox = new SkyBox(__cubeMapRenderer.cubeMap);
  119. __view.scene.addChild(__skyBox);
  120. }
  121. else
  122. {
  123. __skyBox = new SkyBox(__cubeMapRenderer.cubeMap);
  124. __view.scene.addChild(__skyBox);
  125.  
  126. // __skyBox.material = BitmapMaterial(__cubeMapRenderer.cubeMap);
  127. // __skyBox.material = __cubeMapRenderer.cubeMap
  128. }
  129.  
  130. }
  131.  
  132. protected function transitionClickHandler(event:MouseEvent):void
  133. {
  134. // TweenMax.to(__skyBox1.material as BitmapMaterial, 1, {autoAlpha:0});
  135. // TweenMax.to(__skyBox1.material as BitmapMaterial, 1, { alpha:0 });
  136. }
  137. }
  138. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.