Away3d Study Notes 2-four basic components of the 3D world

Source: Internet
Author: User
For example, a human being consists of skeleton, muscle, respiratory system, and blood circulation system. away3d is a necessary part of the world: view view, scene, camera, 3D object.

 

Flash 3D, before getting close contact with her, I felt that she was very mysterious and profound. In addition, the flash 3D engine was widely used in foreign countries, and there were very few Chinese materials. For domestic users, flash3d, she is really unapproachable! Until you start learning away3d (there are many mainstream flash3d engines, such as pvd3d, away3d, and Sandy .. However, the away3d architecture is clear and easy to learn. So I chose her ). It turns out that as long as you understand as3, using away3d for 3D stuff is not as complicated as you think. For the purpose of deep learning, I wrote this set of notes and hoped to help beginners of flash3d (this note is based on away3d, but all the engine mechanisms are similar, so it is also suitable for other engine users to read ).

For example, a human being consists of skeleton, muscle, respiratory system, and blood circulation system. away3d is a necessary part of the world:

1. View

2. Scene scenario

3. Camera camera

4. 3D objects

3D objects are what we want to display in the 3D world. When there is content, there must be a "stage" for "content". This "stage" is a scenario. Of course, a camera also needs to "record" the 3D objects in the scene. With these, everything seems to be ready, but it still owes nothing! This Dongfeng is the "viewport ". it is much harder to understand the Front three. Let's think like this: Do we have to watch the recorded "Images" on the TV? Yes, you can think of the TV screen as the viewport.

I call these four elements the four basic components of the 3D world.

The following example describes the basic architecture of away3d. First, let's look at the results of this example:

Click to view

Let's look at the source code:

Package {

// The class to be imported

Import flash. display. Sprite;

Import flash. Events. event;

Import away3d. containers. view3d;

Import away3d. Cameras. camera3d;

Import away3d. containers. scene3d;

Import away3d. primitives. sphere;

// Define the high width and background of the output flash.

[SWF (width = "500", Height = "400", framerate = "60", backgroundcolor = "# ffffff")]

Public class basicobjects extends sprite {

// Declare several variables that will be used later;

Private var view: view3d;

Private var cam: camera3d;

Private var SCE: scene3d;

Private var sphere: sphere;

Public Function basicobjects (): void {

//!!!!! Create four basic components !!!!!!!!!

// Create a camera

Cam = new camera3d ();

// Set the camera position. Do not worry about how to set or set the camera position.

Cam. z =-1000;

// Create a scenario

SCE = new scene3d ();

// Create a new view and specify the camera and scenario used by the view.

View = new view3d ({Camera: cam, Scene: SCE, X: 250, Y: 200 });

// Create a 3D object. Here, a new sphere is created. sphere is a basic 3D element built into away3d.

Sphere = new sphere ();

//!!!!!! The second of the four basic components: the display list must be added to the view and 3D objects !!!!!

// Add the view to the stage and sphere to the scenario.

Addchild (view)

SCE. addchild (sphere );

//!!!! Make sure to "render" it !!!!!!

// Render the viewport

View. Render ();

}

}

}

After reading the source code with comments, you can understand the code as much as you can. The following code is necessary for analysis.

The code can be divided into three steps:

1. create four basic components.

Since it is an indispensable basic component of the 3D world, we certainly need to create it.

2. display view and 3D objects

Like in flash, you must add the object instance to the display list at all levels. Add view to stage and 3D objects (in this example, sphere) to scene.

3. rendering the viewport

The "3D" in the computer is not actually a real 3D. You think, the computer screen is a plane, of course, it cannot be as three-dimensional as the holographic audio and video in the sci-fi film! In the computer, 3D objects are projected to two-dimensional screens by the embedding method. Before using the method (view. Render ();), all the data is 3D data. rendering means to "pivot" the 3D data into two-dimensional data so that it can be displayed on a two-dimensional screen. Remember, the last step -- Rendering! It is the magic of computer 3D.

Source: flb3d.com

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.