Sandy engine Study Notes: Preliminary Test of 3D effect

Source: Internet
Author: User
Tags addchild

 

 

 

After one morning's study, I felt that the as3.0 released by Sandy was really powerful. I read some official introductions and made it available.

 

  1. Package
  2. {
  3. Import flash. display. Sprite;
  4. Import flash. Events .*;
  5. Import Sandy. Core. scene3d;
  6. Import Sandy. Core. scenegraph .*;
  7. Import Sandy. Primitive .*;
  8. Import Sandy. Core. Data .*;
  9. Import Sandy. Materials .*;
  10. Import Sandy. Materials. Attributes .*;
  11. Import flash. display. bitmapdata;
  12. Import flash. display. Bitmap;
  13. Import flash. UI. keyboard;
  14. Public class dd extends Sprite
  15. {
  16. Private var scence: scene3d;
  17. Private var camera: camera3d;
  18. Private var box: box;
  19. Private var rot: Int = 45;
  20. Private var IMG: mypic;
  21. Private var bitmap: bitmap;
  22. Private var up: Boolean;
  23. Private var down: Boolean;
  24. Private var left: Boolean;
  25. Private var right: Boolean;
  26. Public Function dd ()
  27. {
  28. IMG = new mypic (0, 0 );
  29. Bitmap = new Bitmap (IMG );
  30. Camera = new camera3d (500,400); // create a camera
  31. Camera. z =-400;
  32. VaR Group: Group = createscence ();
  33. Scence = new scene3d ("scene1", this, camera, group); // create a scenario
  34. Scence. Root. addchild (CAMERA );
  35. Addeventlistener (event. enter_frame, run );
  36. Stage. addeventlistener (keyboardevent. key_down, keydown );
  37. Stage. addeventlistener (keyboardevent. key_up, keyup );
  38. Stage. addeventlistener (event. enter_frame, runing );
  39. }
  40. Private function createscence (): Group
  41. {
  42. // Add Material
  43. // Step 1: Set material attributes
  44. VaR materia: materialattributes = new materialattributes (
  45. New lightattributes (true, 0.3 ),
  46. New lineattributes (1, 0x2111bb, 1)
  47. );
  48. // Step 2: Set material attributes
  49. VaR material: Material = new colormaterial (0xffcc33, 1, materia); // display color material attributes
  50. VaR material: Material = new bitmapmaterial (bitmap. bitmapdata); // display color material attributes
  51. Material. lightingenable = true;
  52. Material. lightingenable = true;
  53. VaR app: appearance = new appearance (material); // specify the material to the visual object.
  54. VaR app2: appearance = new appearance (material); // specifies the texture of a visible object.
  55. VaR G: Group = new group ();
  56. Box = new box ("mybox", 100,100,100 );
  57. Box. Appearance = app;
  58. Box. Appearance = app2;
  59. G. addchild (box );
  60. Return g;
  61. }
  62. Private function run (Event: Event): void
  63. {
  64. Box. rotatex = rot;
  65. Box. rotatey = 45;
  66. Rot + = 1;
  67. Scence. Render (); // Rendering scenario
  68. }
  69. Private function keydown (Event: keyboardevent): void
  70. {
  71. Switch (event. keycode)
  72. {
  73. Case keyboard. Up:
  74. Up = true;
  75. Break;
  76. Case keyboard. down:
  77. Down = true;
  78. Break;
  79. Case keyboard. left:
  80. Left = true;
  81. Break;
  82. Case keyboard. Right:
  83. Right = true;
  84. Break;
  85. }
  86. }
  87. Private function keyup (Event: keyboardevent): void
  88. {
  89. If (event. keycode = keyboard. UP)
  90. {
  91. Up = false;
  92. } Else if (event. keycode = keyboard. down)
  93. {
  94. Down = false;
  95. } Else if (event. keycode = keyboard. Left)
  96. {
  97. Left = false;
  98. } Else if (event. keycode = keyboard. Right)
  99. {
  100. Right = false;
  101. } Else
  102. {
  103. }
  104. }
  105. Private function runing (Event: Event): void
  106. {
  107. If (up)
  108. {
  109. Camera. Z + = 8;
  110. // Camera. scaley + = 4;
  111. } Else if (down)
  112. {
  113. Camera. Z-= 8;
  114. } Else if (left)
  115. {
  116. Camera. Pan + = 2;
  117. } Else if (right)
  118. {
  119. Camera. Pan-= 2;
  120. } Else
  121. {
  122. }
  123. }
  124. }
  125. }

 

I feel pretty good. I have Paster this image, and the 3D effect has come out. With the camera added, the effect is good.

However, I feel that 3D computing is huge. When I scale up this item, the CPU usage is much higher. If you are interested, you can download the class library from the official website and help documentation.

 

This is not a toy, but flash lovers will remember it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.