In this tutorial, we will continue to explore simple but useful basic 3D elements. We will also learn how to create a panorama with the basic elements of a rotating lens, sphere, and skybox 3D. We will also learn about a software that can help us create panorama.
In this tutorial, we will first describe two basic 3D elements, and then look at some basic 3D elements that can be used to create a panorama.
Prerequisites
This tutorial is based on other tutorials. If you are a flash 3D cainiao, you may want to take a look at these tutorials first. For example, for some source files, click the attached as file to view how they work. A cover. As file is used in all these examples. This file makes flash films used in the tutorial not work at the same time, or it will drag your computer down. If you are not sure how to use these examples, refer to this tutorial.
"Texture" is used in some examples in this tutorial ". For details about textures and materials, refer to the following tutorial. If you want the code to work in Flash CS3, read this tutorial.
The Trident)
The trigger helps us better understand how 3D objects are presented in 3D spaces. The trigger is a simple 3D basic element with three axes x/y/z. She is very useful for testing complex scenarios. If you want to know that the loaded model is rotating, And you add a trigger to it, everything will be obvious. Click and drag in the following example to see how the trigger sets the position of the three balls in the 3D space.
Video: Click to view the code: triaxe.
The following example uses the default value to create a trigger:
VaR axis: Trident = new Trident ();
View. Scene. addchild (axis );
The trigger has two optional parameters: the length of the axis and whether the axis represents the symbol (x/y/z ).
VaR axis: Trident = new Trident (200, true );
The code above generates a new trigger. The three axes are 200 units long and each axis displays a symbolic symbol. Note that the attributes (lenth/letters) of the trigger are adjusted after it is created, which is different from other basic 3D elements.
Video: Click to view the code: basic02.as basic02_view.as
In the preceding example, the same simple scenario is displayed from four different perspectives. With the help of corner stone, it is easy to know the camera settings for the four view views.
The regularpolygon (Rule polygon)
A rule polygon is also called a disc. Like a plane, it has no thickness. When creating a disk, you can only specify the number of edges and the disc radius.
Polygon = new regularpolygon ({radius: 200, sides: 3 });
View. Scene. addchild (polygon );
The number of edges can be any integer greater than 2. Let's take a look at the following sample settings.
Video: Click to view the code: basic08_regular_polygon.as
If the texture of a polygon is distorted, you can increase the subdivision value:
Polygon. subdivision = 3;
This splits each triangle into three parts. Download the source file and try to add the value of subdivision.
The Sphere)
A cube can be displayed with at least 12 triangles. The ball is more complex. You need more triangles to create a ball. The value is determined by the fidelity of your ball. By default, this value is small. To make the ball more realistic, you need to increase the number of triangles by setting the egmentsw and segmentsh parameters.
Video: Click to view the code: spheretri.
Click the button to increase/decrease the number of triangles that constitute the ball.
Each ball has a radius, so you need these parameters to create a ball:
VaR sphere: sphere = new sphere ({radius: 50, segmentsw: 10, segmentsh: 10 });
You can also set it as follows:
VaR sphere: sphere = new sphere ();
Sphere. radius = 50;
Sphere. segmentsw = 10;
Sphere. segmentsh = 10;
You can set the sphere. Yup attribute to change the tendency of the ball.
Sphere. Yup = false;
In this way, the top of the ball is directed to you. Now you can create a ball. What is the internal content of the ball? Place a "Rotate" camera in the sphere, and we can see the inside of the ball. You can create a panorama in this way. In order to see the ball's interior, we also need to use the invertfaces method.
Sphere. invertfaces ();
This will reverse the texture and be visible only internally. Let's look at the example.
Video: Click to view the code: basic08_sphere.as
Panoramic images used in this example (added by the translator ):
Remember to make 3D objects visible inside and outside, you must set the bothsides attribute:
Sphere. bothsides = true;
Now you know how to create a spherical panorama with sphere. Another popular type of panorama is cube panorama. away3d has two basic 3D elements to achieve cube panorama.
The skybox and skybox6
Skybox and skybox6. The difference between them is that we need to specify 6 images for skybox, while skybox6 only needs a 3 × 2 image. To create a skybox, you must provide materials like this:
VaR mat: bitmapmaterial = new bitmapmaterial (new texture () as Bitmap). bitmapdata );
Largecube = new skybox6 (MAT );
If you use a normal skybox, you need to create six different materials:
Largecube = new skybox (frontmaterial, leftmaterial, backmaterial, rightmaterial, upmaterial, downmaterial );
The following example uses skybox6.
Video: Click to view the code: basic08_skybox6.as
Panoramic images used in this example (added by the translator ):
When you look at the source code, you may notice this sentence:
Largecube. quarterfaces ();
The purpose of this sentence is to subscribe to different aspects of skybox. Only in this way will there be no "prehistoric things" in the rotated texture ". This method is also suitable for other 3D elements and imported models. Compared with the ball, Skybox has the advantage of using X for Panorama. Skybox uses fewer "triangles. Of course, there is a "price", which will make the panorama slightly distorted, but in most cases this twist can be ignored.
So the following work is simple, right? Have you prepared six images for the next step? If you think so, you are too optimistic. Only images used for panorama can be seamlessly integrated after special processing. There is a texture image for skybox6. If not, the skybox6 panorama cannot be displayed as it looks.
So we need to create a 3 × 2 image in this way? There are a lot of software for generating Spherical Panorama images, but few are used to generate 3 × 2 format. In this tutorial, I found a cross-platform (Win/MAC/Linux) software named pano2vr, it is not expensive but can be converted into another panorama format (16 formats are supported ). In the above example, the trial version is used, so the watermark has a watermark. The full version does not contain watermarks.