Create a 3D scene, such as outdoor is the sky, the earth has a distant background. This can be easily achieved by Skybox.
The use of 1,skybox
Skybox is actually a cube, just a different skin on each surface of the interior. Then the camera in the cube inside, feel like an indoor environment affixed to the blue sky and white clouds, let people feel that is on the scene.
2, reflection on the surface of the object
By simply giving the object the same skin texture as the skybox, the surface of the object will feel a specular effect reflecting the ambient image. (as in this case the ball)
3, the effect chart is as follows
package{
Import Flash.display.Sprite;
Import flash.display.StageAlign;
Import Flash.display.StageScaleMode;
Import flash.events.Event;
Import flash.events.MouseEvent;
Import Flash.geom.Vector3D;
Import Away3d.containers.View3D;
Import Away3d.controllers.HoverController;
Import Away3d.entities.Mesh;
Import away3d.materials.ColorMaterial;
Import away3d.materials.TextureMaterial;
Import Away3d.materials.methods.EnvMapMethod;
Import Away3d.primitives.CubeGeometry;
Import Away3d.primitives.SkyBox;
Import Away3d.primitives.SphereGeometry;
Import Away3d.textures.BitmapCubeTexture;
Import Away3d.utils.Cast;
[SWF (Framerate=, backgroundcolor= "#FFFFFF")]
public class S3 extends Sprite {
private Var _view3d:view3d;
Private var cameracontroller:hovercontroller;//360 panoramic display camera controller
Floor picture (used as a texture for the floor)
[Embed (source= "assets/road.jpg")]
private Var Floorclass:class;
Floor Material
private Var floormaterial:texturematerial;
Environment picture
[Embed (source= "assets/skybox/snow_positive_x.jpg")]
private Var Envposx:class;
[Embed (source= "assets/skybox/snow_positive_y.jpg")]
private Var Envposy:class;
[Embed (source= "assets/skybox/snow_positive_z.jpg")]
private Var Envposz:class;
[Embed (source= "assets/skybox/snow_negative_x.jpg")]
private Var Envnegx:class;
[Embed (source= "assets/skybox/snow_negative_y.jpg")]
private Var Envnegy:class;
[Embed (source= "assets/skybox/snow_negative_z.jpg")]
private Var Envnegz:class;
Environmental material
private Var environmenttexture:bitmapcubetexture;
private Var environmentmaterial:colormaterial;
Sky
private Var _skybox:skybox;
private Var Lastpanangle:number;
private Var Lasttiltangle:number;
private Var Lastmousex:number;
private Var Lastmousey:number;
private Var Move:boolean;
Public Function S3 () {
Initengine ();
Initmaterials ();
Initobjects ();
Initlisteners ();
}
/**
* Initialize engine
*/
Private Function Initengine (): void
{
Stage.scalemode = Stagescalemode.no_scale;
Stage.align = Stagealign.top_left;
Create a viewport
_view3d = new View3D ();
_view3d.antialias = 4; Set anti-aliasing level
Initializing the camera
Cameracontroller = new Hovercontroller (_view3d.camera);
/*cameracontroller.distance = 1000;
Cameracontroller.mintiltangle = 0;
Cameracontroller.maxtiltangle = 90;
Cameracontroller.panangle = 45;*/
Cameracontroller.tiltangle = 15;
AddChild (_VIEW3D);
}
/**
* Initialization of the material
*/
Private Function Initmaterials (): void
{
The texture of the floor
floormaterial = new Texturematerial (Cast.bitmaptexture (Floorclass));
Environment texture
Environmenttexture = new Bitmapcubetexture (
Cast.bitmapdata (ENVPOSX), Cast.bitmapdata (ENVNEGX),
Cast.bitmapdata (Envposy), Cast.bitmapdata (Envnegy),
Cast.bitmapdata (Envposz), Cast.bitmapdata (Envnegz));
environmentmaterial = new Colormaterial ();
Environmentmaterial.addmethod (New Envmapmethod (Environmenttexture, 1));
}
/**
* Initialize Object
*/
Private Function initobjects (): void
{
Create a square (floor) in a three-dimensional stage
var Cube1:mesh = new Mesh (new Cubegeometry (M, m), floormaterial);
_view3d.scene.addchild (CUBE1);
Add Sky Box (environment)
_skybox = new Skybox (environmenttexture);
_view3d.scene.addchild (_skybox);
Add Sphere
var Ball:mesh = new Mesh (new Spheregeometry), environmentmaterial);
Ball.position = new Vector3D (0,200,0);
_view3d.scene.addchild (ball);
}
/**
* Initialization Monitoring
*/
Private Function Initlisteners (): void
{
AddEventListener (Event.enter_frame, _onenterframe);
Mouse Event Monitoring
Stage.addeventlistener (Mouseevent.mouse_down, OnMouseDown);
Stage.addeventlistener (mouseevent.mouse_up, onMouseUp);
Stage.addeventlistener (Mouseevent.mouse_wheel,onwheel);
Stage.addeventlistener (Event.resize, onResize);
OnResize ();
}
/**
* Render View
*/
Private Function _onenterframe (e:event): void
{
Moving perspective
if (move) {
Cameracontroller.panangle = 0.3 * (stage.mousex-lastmousex) + lastpanangle;
Cameracontroller.tiltangle = 0.3 * (Stage.mousey-lastmousey) + lasttiltangle;
}
Render View
_view3d.render ();
}
/**
* Use stage size always full screen
*/
Private Function onResize (event:event = null): void
{
_view3d.width = Stage.stagewidth;
_view3d.height = Stage.stageheight;
}
/**
* Mouse Wheel Event
*/
Private Function Onwheel (e:mouseevent): void
{
if (E.delta > 0) {
if (Cameracontroller.distance < 1000)
Cameracontroller.distance + 100;
}else{
if (Cameracontroller.distance > 600)
Cameracontroller.distance-= 100;
}
}
/**
* Mouse Down Event
*/
Private Function OnMouseDown (event:mouseevent): void
{
Lastpanangle = Cameracontroller.panangle;
Lasttiltangle = Cameracontroller.tiltangle;
Lastmousex = Stage.mousex;
Lastmousey = Stage.mousey;
move = true;
}
/**
* Mouse Bounce Event
*/
Private Function OnMouseUp (event:mouseevent): void
{
move = false;
}
}
}