📜 ⬆️ ⬇️

Away3d Universe - Episode 2: In the beginning it was .... # 000000

Mastering Away3d we will continue creating the first project with three-dimensional space and an object inside.

Open the Flex Builder, in which the Away3dFP10 library should already be open, and create a new ActionScript Project away3d_prj01_world.


We will set up a project for compilation for the 10th flash player, as it was described in the previous article (in the following articles I will not return to setting up projects) and remove the check mark from the Generate HTML wraper file (launch in the player faster than in the browser).
Now let's add the Away3dFP10 library to the Library path:

We will slightly correct the code by adding the metadata for swf compilation, setting the dimensions to 600 by 400, frame-rate 31, and the background color is black, the main class will now look like this:
 package {
  import flash.display.Sprite;
 
  [SWF (width = "600", height = "400", frameRate = "31", backgroundColor = "0x000000")]
  public class away3d_prj01_world extends Sprite
  {
   public function away3d_prj01_world ()
   {
   }
  }
 }


After all the preparations we can finally launch, and if everything was correct, see a black window in the flash player that opens.
Improve the situation by adding a sphere. Any construction of a three-dimensional world in Away3d begins with the creation of a View3D object and adding (addChild) to the Display list - this is essentially the window through which you are looking into the world you have built. We expose the view in the middle of the screen. Next, a Scene3D object is created and defined as a property of an object of the View3D class - this is actually the foundation of the three-dimensional world of Away3d. Finally, a Sphere object is created and added (addChild) to an object of the Scene3D class. Then we commanded the view to visualize (render) the world. As a result, we will see the sphere in the middle of the window with a randomly specified color.

Final Code:
 package {
  import away3d.containers.Scene3D;
  import away3d.containers.View3D;
  import away3d.primitives.Sphere;
 
  import flash.display.Sprite;
 
  [SWF (width = "600", height = "400", frameRate = "31", backgroundColor = "0x000000")]
  public class away3d_prj01_world extends Sprite
  {
   private var view: View3D;
   private var sphere: Sphere;
  
   public function away3d_prj01_world ()
   {
    view = new View3D;
    addChild (view);
   
    // set view postion
    view.x = 300;
    view.y = 200;
   
    var scene: Scene3D = new Scene3D;
    view.scene = scene;
   
    sphere = new Sphere;
    scene.addChild (sphere);
   
    // lets visualyze
    view.render ();
   }
  }
 }

Working example
Sources

')

Source: https://habr.com/ru/post/69604/


All Articles