Alternativa 8 for Dummies Part III

From AlternativaPlatform Wiki

Jump to: navigation, search

Contents

[edit] Three-dimensional objects.

All three-dimensional objects extend the Alternativa Object3D class. This includes invisible objects like Camera3D or Light3D and real objects like Mesh or Wireframe. This class contains basic properties of three-dimensional objects; properties such as x, y, z, scaleX, scaleY, scaleZ and visible etc.

[edit] Mesh

Mesh is a collection of polygons of any object. It is the base class for primitive classes like Box, Decal, GeoSphere, Skin and SkyBox. Describing it makes no sense. However, in the last two lessons we have worked effectively with it. Just remember that almost any object in three-dimensional polygonal space in Alternativa is a Mesh.

[edit] Surface

Class surface. Any polygon object can be split into multiple surfaces, each of which can be assigned their own material. The surface consists of a sequence of triangles.

To create a surface, the method of addSurface polygonal object.

The method parameters:

public function addSurface(material:Material, indexBegin:uint, numTriangles:uint):Surface
material:Material — surface material
indexBegin:uint — Start index in IndexBuffer.
numTriangles:uint — number of triangles

Let's see the class in action:

box = new Box(200, 200, 200); //create box
rootContainer.addChild(box);
 
for (var i:int = 0; i < 6; i++) { //box to add 6 surfaces
     var texture:BitmapTextureResource = new BitmapTextureResource(new aLogo[i]().bitmapData); 
     box.addSurface(new TextureMaterial(texture), i*6, 2); //each impose its texture
}

3-11eng.jpg


[edit] SkyBox

Skybox - this is in fact an ordinary cube. The difference is that the textures do not stretch to the outer surface of the cube, and the internal. He also does not depend on the parameters of the viewport. Camera at any distance from him, its geometry will not be cut. Used to create the sky.

var textureScyD:BitmapTextureResource = new BitmapTextureResource(new SkyD().bitmapData); //Create 6 textures for our SkyBox
var textureScyU:BitmapTextureResource = new BitmapTextureResource(new SkyU().bitmapData);
var textureScyR:BitmapTextureResource = new BitmapTextureResource(new SkyR().bitmapData);
var textureScyL:BitmapTextureResource = new BitmapTextureResource(new SkyL().bitmapData);
var textureScyF:BitmapTextureResource = new BitmapTextureResource(new SkyF().bitmapData);
var textureScyB:BitmapTextureResource = new BitmapTextureResource(new SkyB().bitmapData);
 
skybox = new SkyBox (3000, new TextureMaterial(textureScyL),
                           new TextureMaterial(textureScyR),
                           new TextureMaterial(textureScyB),
                           new TextureMaterial(textureScyF),
                           new TextureMaterial(textureScyD),
                           new TextureMaterial(textureScyU), 
                                                     0.001); //create a Skybox
rootContainer.addChild(skybox);//Add to the container

Consider the constructor parameters:

public function SkyBox(size:Number, left:Material = null, 
                                    right:Material = null, 
                                    back:Material = null, 
                                    front:Material = null, 
                                    bottom:Material = null, 
                                    top:Material = null, 
                                    uvPadding:Number = 0);
size:Number — Size of skybox.
left:Material (default = null) — Material for left side.
right:Material (default = null) — Material for right side.
back:Material (default = null) — Material for back side.
front:Material (default = null) — Material for front side.
bottom:Material (default = null) — Material for bottom side.
top:Material (default = null) — Material for top side.
uvPadding:Number (default = 0) — Padding from the edges in texture coordinates.

3-12eng.jpg


[edit] WireFrame

WireFrame - class of three-dimensional lines. Contains several static methods for working with him. What he gives us the functional:

1) We can convert any mesh into an object composed of lines instead of polygons.

var parser:ParserA3D = new ParserA3D(); 
    parser.parse(new A3dModel());
    car =  parser.objects[1] as Mesh;
 
    carWireFrame = WireFrame.createEdges(car, 0xFFFFFFFF, 1, 1); //transform the mesh into three-dimensional line.
    rootContainer.addChild(carWireFrame);//add to a container

The method parameters createEdges():

mesh:Mesh - Mesh which will be converted into three-dimensional line
color:uint (default = 0) - Line color.
alpha:Number (default = 1) - transparency lines
thickness:Number (default = 1) - Line thickness.

Compare the two pictures:

1) just Mesh

3-13eng.jpg

2) Wireframe

3-14eng.jpg

We also have the opportunity to draw a 3D-line. For this there are still two static methods: createLinesList () and createLineStrip (). In both of them, we pass the vector of the points through which lines are drawn. The difference is that the method of drawing the line createLinesList pairs between two points, that is, a line is drawn between two points, then to continue drawing from the last point must again indicate it to the next line. CreateLineStrip method draws a continuous line through all the points mentioned in the vector.

Look at the method createLinesList:

var pointsVector:Vector.<Vector3D> = Vector.<Vector3D>([new Vector3D(  70, -70,  70), new Vector3D(  70,  70,  70), 
                                                        new Vector3D(  70,  70,  70), new Vector3D( -70,  70,  70), 
                                                        new Vector3D( -70,  70,  70), new Vector3D( -70, -70,  70), 
                                                        new Vector3D( -70, -70,  70), new Vector3D(  70, -70,  70),
                                                        new Vector3D(  70, -70, -70), new Vector3D(  70,  70, -70), 
                                                        new Vector3D(  70,  70, -70), new Vector3D( -70,  70, -70),
                                                        new Vector3D( -70,  70, -70), new Vector3D( -70, -70, -70), 
                                                        new Vector3D( -70, -70, -70), new Vector3D(  70, -70, -70),
                                                        new Vector3D(  70, -70,  70), new Vector3D(  70, -70, -70), 
                                                        new Vector3D(  70,  70,  70), new Vector3D(  70,  70, -70), 
                                                        new Vector3D( -70,  70,  70), new Vector3D( -70,  70, -70),
                                                        new Vector3D( -70, -70,  70), new Vector3D( -70, -70, -70)]);
wireFrame = WireFrame.createLinesList(pointsVector, 0xFF00FF00, 1, 3); //pass the vector points, color, alpha and size of lines
rootContainer.addChild(wireFrame);

3-15eng.jpg


[edit] Decal

Class decals. Decals - these are special textures that can be applied over conventional textures. For example, blood, traces of bullets, a grenade trail, logos, etc. However, they are stable to the z-fighting game. That is, at any distance from the camera they will not be blinking, due to the fact that the camera can not understand anyone who overrides.

Here's a sample of blood decals:

Decal.jpg

An experiment.

Let's create here a code and compile it:

package {
	import alternativa.engine3d.controllers.SimpleObjectController;
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.core.Object3D;
	import alternativa.engine3d.core.Resource;
	import alternativa.engine3d.core.View;
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.engine3d.objects.Decal;
	import alternativa.engine3d.primitives.Box;
	import alternativa.engine3d.resources.BitmapTextureResource;
	import flash.display.Sprite;
	import flash.display.Stage3D;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
 
	/**
	 * ...
	 * @author redefy
	 */
	public class TestDecal extends Sprite {
		[Embed(source="resources/Smoke Kick.png")]
		private static const Smoke:Class;
		[Embed(source="resources/crumple.jpg")]
		private static const Crumple:Class;
		private var rootContainer:Object3D = new Object3D();
 
		private var camera:Camera3D;
		private var stage3D:Stage3D;
		private var simpleController:SimpleObjectController;
 
		private var boxOut:Box;
		private var boxIn:Box;
 
		private var decalOut:Decal;
		private var decalIn:Decal;
 
		public function TestDecal(){
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
 
			camera = new Camera3D(0.1, 200000);
			camera.view = new View(800, 500);
			camera.rotationX = -90 * Math.PI / 180;
			camera.z = 100
			camera.y = -1200;
			addChild(camera.diagram);
			addChild(camera.view);
 
			boxOut = new Box(400, 400, 400);
			var boxOutMaterial:TextureMaterial = new TextureMaterial(new BitmapTextureResource(new Crumple().bitmapData));
			boxOut.addSurface(boxOutMaterial, 12, 2);
			boxOut.x = 400;
			rootContainer.addChild(boxOut);
 
			boxIn = new Box(200, 200, 200);
			var boxInMaterial:TextureMaterial = new TextureMaterial(new BitmapTextureResource(new Smoke().bitmapData));
			boxInMaterial.useDiffuseAlphaChannel = true;
			boxIn.addSurface(boxInMaterial, 12, 2);
			boxIn.x = 400;
			boxIn.y = -101;
			rootContainer.addChild(boxIn);
 
			decalIn = new Decal(); 
			decalIn.geometry = boxIn.geometry;
			decalIn.addSurface(boxInMaterial, 12, 2);
			decalIn.x = -400;
			decalIn.y = -101;
			rootContainer.addChild(decalIn);
 
			decalOut = new Decal(); 
			decalOut.geometry = boxOut.geometry;
			decalOut.addSurface(boxOutMaterial, 12, 2);
			decalOut.x = -400;
			rootContainer.addChild(decalOut);
 
			rootContainer.addChild(camera);
 
			simpleController = new SimpleObjectController(stage, camera, 400);
 
			stage3D = stage.stage3Ds[0];
			stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
			stage3D.requestContext3D();
		}
 
		private function onContextCreate(e:Event):void {
			for each (var resource:Resource in rootContainer.getResources(true)){
				resource.upload(stage3D.context3D);
			}
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
 
		private function onEnterFrame(e:Event):void {
			camera.render(stage3D);
			simpleController.update();
		}
	}
}

At a short distance from the camera of these objects the difference is not noticeable ...

3-16eng.jpg

But it is necessary to push the camera away from the objects box starts z-fighting, while the decals are in order.

3-17eng.jpg

In order to avoid z-fighting game and was created by the developers of this class ...


[edit] Sprite3D

Continue. Sprite3D - a flat three-dimensional object, which is always turned to the camera. So you are not about what conditions may not be able to see it reversed.

Let us create and see it in action:

var texture:BitmapTextureResource = new BitmapTextureResource(new TextureSprite().bitmapData);
    sprite = new Sprite3D(500, 500, new TextureMaterial(texture)); //create a sprite.
    sprite.rotation = 0.8; //turn
    rootContainer.addChild(sprite);

How do we can influence its initial parameters:

1. We can use properties to set the initial rotation of the object rotation (in radians)

2. The same can shift the point of attachment sprite3D to the camera, this is done by using the properties and originX originY. Properties can range from 0 to 1. The default value is 0.5 (in the middle of the object).

3. Well, the standard properties Object3D -> x, y, z, scaleX etc.

Constructor parameters:

public function Sprite3D(width:Number, height:Number, material:Material = null)
width:Number — Sprite width. 
height:Number — Sprite height. 
material:Material (default = null) — Sprite material.

3-18eng.jpg


[edit] AxisAlignedSprite

AxisAlignedSprite - Flat, always deployed to the camera, oriented along the axis of three-dimensional object. We also like the Sprite3D, can displace an anchor point, scale, and it also always AxisAlignedSprite turned to the camera. What is different from AxisAlignedSprite Sprite3D? Well, let's investigate. First, unlike Sprite3D, we can only rotate along the axis Y, AxisAlignedSprite class allows us, as it follows from its name, specify the rotation along all three axes, X | | Y | | Z. Second, we can choose what will be regarded AxisAlignedSprite, the alignment relative to the camera. If the property alignToView set to true (the default) then the sprite is aligned with the rotation axis of the camera, if false then the sprite is aligned with the camera position in 3D-space. I think the show AxisAlignedSprite no sense, it looks like the Sprite3D.


[edit] AnimSprite

AnimSprite Sprite3D class extends possible to assign more than one material, and the vector of the material. And do not get normal Sprite3D and animated sprite. Look at the picture:

AnimSprite.png

From it we will animate the explosion. Create a AnimSprite:

var textureMaterial:TextureMaterial;
var phases:BitmapData = new TextureSprite().bitmapData; //Get bitmapdata image
var materials:Vector.<Material> = new Vector.<Material>(); //Create vector material
    for (var i:int = 0; i < phases.width; i += 128){ //in the loop cut image
	 var bmp:BitmapData = new BitmapData(128, 128, true, 0); //image in the size of 128x128
	 bmp.copyPixels(phases, new Rectangle(i, 0, 128, 128), new Point());
	 textureMaterial = new TextureMaterial(new BitmapTextureResource(bmp));
	 textureMaterial.alphaThreshold = 1;
	 materials.push(textureMaterial); //add to the texture vector
    }
 
animSprite = new AnimSprite(128, 128, materials, true); //create animated sprite
rootContainer.addChild(animSprite); //add to a container
 
............
 
private function onEnterFrame(e:Event):void {
	animSprite.frame++; //that animation played out, we need to change the current material is a sprite to the next
	camera.render(stage3D);
	simpleController.update();
}

Constructor parameters:

public function AnimSprite(width:Number, height:Number, materials:Vector = null, loop:Boolean = false, frame:int = 0);
width:Number — Sprite width. 
height:Number — Sprite height.
materials:Vector (default = null) — Material list.
loop:Boolean (default = false) — Loop option.
frame:int (default = 0) — Current frame.

3-19eng.jpg

Sources: TestObjectsAlternativa.zip

[edit] The light sources

We first discuss the general features for all light sources. First of all benefit from the lights on the stage will only be used if 3D objects are superimposed material class VertexLightTextureMaterial or StandartMaterial, so as soon as they support dynamic lighting. All light sources extend the class Light3D, which in turn extends the class Object3D. From this it follows that all light sources have properties and methods as in any other three-dimensional objects (x, y, z, rotationX, scaleY, etc.). Light3D class extends the functionality by adding two class Object3D properties: color - The color of the light source and intensity - intensity of light. Let me not to be repeated just remember that any light source, we can customize the color and intensity. All the lights Let's consider the example of one scene. Let's start ...


[edit] AmbientLight

This is the simplest source of light. It covers all the 3D objects evenly on all sides. That is, no matter where it is located, and the objects are close to him and away from it will be covered equally.

ambientLight = new AmbientLight(0xFFFFFF); //Create AmbientLight. The constructor takes one argument - the color of the light
ambientLight.intensity = 0.8; //set up the intensity of light
ambientLight.z = 200;
rootContainer.addChild(ambientLight);

As you can see not on what the shadows, blackouts objects can not be considered.

3-21eng.jpg


[edit] DirectionalLight

Directional light. To specify the direction of light using the method lookAt ().

directionalLight = new DirectionalLight(0xC9D231); //Create DirectionalLight. The constructor takes one argument - the color of the light
directionalLight.z = 200;
directionalLight.intensity = 4;//set up the intensity of light
rootContainer.addChild(directionalLight); 
....
private function onEnterFrame(e:Event):void {
   directionalLight.lookAt(lion.x, lion.y, lion.z);  //send the object lion (insect)
 
   simpleController.update();
   camera.render(stage3D);
}

What we have. DirectionalLight shines in the direction in which we have indicated. Those surfaces of 3D-objects that do not fall within the scope will not be covered.

3-22eng.jpg


[edit] OmniLight

A point source of light attenuation. Lighting is directed to all sides evenly.

omniLight = new OmniLight(0xFF0000, 2000 ,5000); //Создаем OmniLight. 
//Constructor parameters OmniLight(color:uint, attenuationBegin:Number, attenuationEnd:Number)
//color:uint - Light source color.
//attenuationBegin:Number - Light source attenuation start radius.
//attenuationEnd:Number - Light source attenuation end radius.
 
omniLight.intensity = 3; //set up the intensity of light
omniLight.z= - 6500;
rootContainer.addChild(omniLight);

So, as we see OmniLight covers a circular area with a radius specified in the parameter attenuationEnd (radius of the end of the attenuation of light). At the same time from its initial position and to the area with a radius specified in the parameter attenuationBegin (radius of the start of attenuation of light) the light shines evenly. And then begins to slowly fade to a region with a radius of attenuationEnd (radius of the end of the attenuation of light) and at its edge intensity OmniLight will be equal to 0.

3-23eng.jpg


[edit] SpotLightt

Conical light. This light source, the area coverage is limited to a cone. To set the direction to rotate the light source or use the lookAt (). Looks like OmniLight, as well as to specify the radius of the attenuation of light. But besides that we also ask the direction of light, so unlike OmniLight, SpotLight not shine in all directions from itself, and to some one.

spotLight = new SpotLight(0xB5DCF5, 0 ,15000, 0.3, 2.0); //Создаем SpotLight. 
//Constructor parameters SpotLightt(color:uint, attenuationBegin:Number, attenuationEnd:Number, hotspot:Number, falloff:Number)
//color:uint - Light source color.
//attenuationBegin:Number - Light source attenuation start radius.
//attenuationEnd:Number - Light source attenuation end radius.
//hotspot:Number — Cone start attenuation angle. Is in radians.
//falloff:Number — Cone end attenuation angle. Is in radians.
 
spotLight.y = -6000
spotLight.z= - 7500;
spotLight.intensity = 6;  //set up the intensity of light
rootContainer.addChild(spotLight);
....
private function onEnterFrame(e:Event):void {
   spotLight.lookAt(dog.x,dog.y+2000,dog.z);  //send an object dog
 
   simpleController.update();
   camera.render(stage3D);
}

3-24eng.jpg

Sources: testScene.rar


[edit] 3.3 Mouse events in 3D

Working with mouse events in the Alternativa with three-dimensional objects is similar to working with the DisplayObject in Flash. We also initially assign a listener to the type of event, and the function to be executed when that event occurs. Let's consider an example. I have created a three-dimensional model of the earth with three 3D-objects on it.

3-31eng.jpg

Do not be afraid, they do not bite. They are really soft and fluffy.

3-32eng.jpg

3-33eng.jpg

3-34eng.jpg

Let's say I want to mouse click on any of the objects of their scale has increased in two, and when you release the mouse decreased to normal. Nothing could be easier. Look the code:

package {
 
	import com.greensock.*; //I use the library "greensock" for twinning the size of the object.
	import com.greensock.easing.*;
 
////////////////////////////classes of Alternativa////////////////////////////
	import alternativa.engine3d.controllers.SimpleObjectController;
	import alternativa.engine3d.core.Camera3D;
	import alternativa.engine3d.core.Object3D;
	import alternativa.engine3d.core.Resource;
	import alternativa.engine3d.core.View;
	import alternativa.engine3d.core.events.MouseEvent3D;
	import alternativa.engine3d.lights.AmbientLight;
	import alternativa.engine3d.loaders.ParserA3D;
	import alternativa.engine3d.materials.TextureMaterial;
	import alternativa.engine3d.materials.VertexLightTextureMaterial;
	import alternativa.engine3d.objects.Mesh;
	import alternativa.engine3d.objects.Sprite3D;
	import alternativa.engine3d.primitives.GeoSphere;
	import alternativa.engine3d.resources.BitmapTextureResource;
	import alternativa.engine3d.resources.Geometry;
////////////////////////////Flash classes////////////////////////////
	import flash.display.Sprite;
	import flash.display.Stage3D;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
 
	public class Main extends Sprite {
 
		//////////////////////import textures/////////////////////////////////////
		[Embed(source="resources/textures/boomer.jpg")]     static private const BoomerTexture:Class;
		[Embed(source="resources/textures/hulk_01.jpg")]    static private const HulkTexture:Class;
		[Embed(source="resources/textures/hunter_01.jpg")]  static private const HunterTexture:Class;
		[Embed(source="resources/textures/earth.jpg")]      static private const EarthTexture:Class;
		[Embed(source="resources/textures/background.jpg")] static private const BackTexture:Class;
		///////////////////////models//////////////////////////////////////////
		[Embed("resources/models/boomer.a3d",mimeType="application/octet-stream")]  static private const BoomerMesh:Class;
		[Embed("resources/models/hulk.a3d",mimeType="application/octet-stream")]    static private const HulkMesh:Class;
		[Embed("resources/models/hunter.a3d",mimeType="application/octet-stream")]  static private const HunterMesh:Class;
		//////////////////////////////////////////////////////////////////////////
 
		private var rootContainer:Object3D = new Object3D();
		private var camera:Camera3D;
		private var stage3D:Stage3D;
		private var world:Object3D;
		private var simpleController:SimpleObjectController;
 
		private var back:Sprite3D; //background
		private var parser:ParserA3D; //parser
 
		private var earth:GeoSphere; //our earth
 
		private var boomer:Mesh; //three models that I add to the surface
		private var hulk:Mesh;
		private var hunter:Mesh;
 
		public function Main(){
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
 
			init(); //function initializes all the necessary parameters
			createMesh(); //function creates all objects, meshes
 
			stage3D = stage.stage3Ds[0];
			stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
			stage3D.requestContext3D();
		}
 
		private function init():void {
 
			camera = new Camera3D(0.1, 50000); //here everything is must be clear without explanation
			camera.view = new View(1280, 1024); //No? Then carefully read the two previous lessons
			camera.view.antiAlias = 2;
			camera.rotationX = -90 * Math.PI / 180;
			camera.y = -1000;
			camera.z = -100;
			addChild(camera.view);
			addChild(camera.diagram);
			rootContainer.addChild(camera);
 
			world = new Object3D(); //container for all objects components of earth
			rootContainer.addChild(world);
 
			var backMaterial:BitmapTextureResource = new BitmapTextureResource(new BackTexture().bitmapData);
			back = new Sprite3D(2060, 1430, new TextureMaterial(backMaterial)); //Create a background
			back.perspectiveScale = false; //Sprite does not alter its scale with distance <-> approaching the camera
			back.y = 250;
			rootContainer.addChild(back);
 
			var ambientLight:AmbientLight = new AmbientLight(0xFFFFFF); //Ambient light
			ambientLight.intensity = 1;
			ambientLight.z = 200;
			rootContainer.addChild(ambientLight);
 
			simpleController = new SimpleObjectController(stage, world, 150); //controller for the container world
 
			simpleController.unbindKey(37); //reset of the controller
			simpleController.unbindKey(38); //are assigned to the key
			simpleController.unbindKey(39); //I canceled the management of the object world
			simpleController.unbindKey(40); //with the arrows
			simpleController.unbindKey(65); //and WASD
			simpleController.unbindKey(68);
			simpleController.unbindKey(83);
			simpleController.unbindKey(87);
		}
 
		private function createMesh():void { //parse and add all the needed 3D-objects in the scene
			var earthMaterial:BitmapTextureResource = new BitmapTextureResource(new EarthTexture().bitmapData);
			earth = new GeoSphere(300, 20); //create a earth
			earth.setMaterialToAllSurfaces(new VertexLightTextureMaterial(earthMaterial));
			world.addChild(earth);
 
			parser = new ParserA3D(); //create a parser
			parser.parse(new BoomerMesh()); //parse the first 3D object
			boomer = parser.objects[0] as Mesh; //find the mesh
			boomer.x = 0; //position the on stage
			boomer.y = 0;
			boomer.z = 295;
			boomer.scaleX = 2; //and scale the to the size you want
			boomer.scaleY = 2;
			boomer.scaleZ = 2;
 
			var boomerTexture:BitmapTextureResource = new BitmapTextureResource(new BoomerTexture().bitmapData);
			boomer.setMaterialToAllSurfaces(new VertexLightTextureMaterial(boomerTexture)); //apply a texture
			boomer.addEventListener(MouseEvent3D.MOUSE_DOWN, boomerMouseDown); //event listener "key pressed"
			boomer.addEventListener(MouseEvent3D.MOUSE_UP, boomerMouseUp); //event listener "key is released"
			world.addChild(boomer); //add to a container
 
			parser.parse(new HulkMesh()); //Other objects are parsed the same
			hulk = parser.objects[0] as Mesh;
 
			hulk.x = 345;
			hulk.y = 111;
			hulk.z = 90;
			hulk.rotationX = -90 * Math.PI / 180;
			hulk.rotationY = 180 * Math.PI / 180;
			hulk.rotationZ = -70 * Math.PI / 180;
			hulk.scaleX = 2;
			hulk.scaleY = 2;
			hulk.scaleZ = 2;
 
			var hulkTexture:BitmapTextureResource = new BitmapTextureResource(new HulkTexture().bitmapData);
			hulk.setMaterialToAllSurfaces(new VertexLightTextureMaterial(hulkTexture));
			hulk.addEventListener(MouseEvent3D.MOUSE_DOWN, hulkMouseDown);
			hulk.addEventListener(MouseEvent3D.MOUSE_UP, hulkMouseUp);
			world.addChild(hulk);
 
			parser.parse(new HunterMesh());
			hunter = parser.objects[0] as Mesh;
 
			hunter.x = -198;
			hunter.y = 189;
			hunter.z = -119;
			hunter.rotationX = -70 * Math.PI / 180;
			hunter.rotationY = 180 * Math.PI / 180;
			hunter.rotationZ = 45 * Math.PI / 180;
			hunter.scaleX = 2;
			hunter.scaleY = 2;
			hunter.scaleZ = 2;
 
			var hunterTexture:BitmapTextureResource = new BitmapTextureResource(new HunterTexture().bitmapData);
			hunter.setMaterialToAllSurfaces(new VertexLightTextureMaterial(hunterTexture));
			hunter.addEventListener(MouseEvent3D.MOUSE_DOWN, hunterMouseDown);
			hunter.addEventListener(MouseEvent3D.MOUSE_UP, hunterMouseUp);
			world.addChild(hunter);
 
		}
 
		private function hulkMouseDown(e:MouseEvent3D):void { //when you press on the object
			TweenLite.to(e.target, 0.7, {scaleX: 3, scaleY: 3, scaleZ: 3, x: 375, ease: Elastic.easeOut}); //increase its size
		}
 
		private function hulkMouseUp(e:MouseEvent3D):void { //when you release the button on the object
			TweenLite.to(e.target, 0.7, {scaleX: 2, scaleY: 2, scaleZ: 2, x: 345, ease: Elastic.easeOut}); //restore the original
		}
 
		private function boomerMouseDown(e:MouseEvent3D):void { //similarly
			TweenLite.to(e.target, 0.7, {scaleX: 3, scaleY: 3, scaleZ: 3, ease: Elastic.easeOut});
		}
 
		private function boomerMouseUp(e:MouseEvent3D):void {
			TweenLite.to(e.target, 0.7, {scaleX: 2, scaleY: 2, scaleZ: 2, ease: Elastic.easeOut});
		}
 
		private function hunterMouseDown(e:MouseEvent3D):void {
			TweenLite.to(e.target, 0.7, {scaleX: 3, scaleY: 3, scaleZ: 3, ease: Elastic.easeOut});
		}
 
		private function hunterMouseUp(e:MouseEvent3D):void {
			TweenLite.to(e.target, 0.7, {scaleX: 2, scaleY: 2, scaleZ: 2, ease: Elastic.easeOut});
		}
 
		private function onContextCreate(e:Event):void { //standard operation to add all the resources in Context3D
			stage3D.removeEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
 
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			for each (var resource:Resource in rootContainer.getResources(true)){
				resource.upload(stage3D.context3D);
			}
		}
 
		private function onEnterFrame(e:Event):void {
			simpleController.update();
			camera.render(stage3D);
		}
	}
}

Try clicking on any of the three objects. You will get about this:

3-35eng.jpg

Of course, we could also make the transition to any web-page by clicking on them, and any other action.

Enumerate all types of events that we can hear:

CLICK 
DOUBLE_CLICK
MOUSE_DOWN
MOUSE_MOVE
MOUSE_OUT
MOUSE_OVER
MOUSE_UP 
MOUSE_WHEEL
ROLL_OUT
ROLL_OVER

Since they are all identical to the events of a class flash MouseEvent, not describe them see sense.

Sources: Earth.zip


Author #redefy

Personal tools
Namespaces
Variants
Actions
Navigation
Category
Toolbox
In other languages