Basic Away 3d Scene Setup


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



Copy this code and paste it in your HTML
  1. import away3d.cameras.*;
  2. import away3d.containers.*;
  3. import away3d.materials.*;
  4. import away3d.primitives.*;
  5.  
  6. // import com.greensock.*;
  7.  
  8. var scene:Scene3D;
  9. var camera:Camera3D;
  10. var view:View3D;
  11. var myCube;
  12.  
  13. init();
  14.  
  15. function init():void
  16. {
  17. initEngine();
  18. initObjects();
  19. stage.addEventListener(Event.RESIZE, stageResize); stageResize();
  20. addEventListener(Event.ENTER_FRAME,loop);
  21. }
  22.  
  23. function loop(e){
  24. // TweenLite.to(myCube,0.5,{rotationX:mouseY-stage.stageHeight/2,rotationY:mouseX-stage.stageWidth/2});
  25. view.render();
  26. }
  27.  
  28. function initEngine():void
  29. {
  30. scene = new Scene3D();
  31. camera = new Camera3D({z:-51});
  32. view = new View3D({scene:scene, camera:camera});
  33. addChild(view);
  34. }
  35.  
  36. function initObjects():void
  37. {
  38. var material = new ColorMaterial("ff0000");
  39. myCube = new Cube({material:material, width:250, height:250, depth:250});
  40. scene.addChild(myCube);
  41. }
  42. function stageResize(event:Event = null):void
  43. {
  44. view.x = stage.stageWidth / 2;
  45. view.y = stage.stageHeight / 2;
  46. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.