Create the Earth and heavens in less than an hour with Away3D
3D is one of the many cool things made possible with Flash Player 9 and the super fast Virtual Machine. This tutorial will show you how to create a realistic looking interactive earth, complete with a sun and a starlit sky. Scared? Don't be - it's easy with Away3D!
3D is all the rage in the Flash community these days. There are several engines available and each has strengths and weaknesses. Carlos Pinho has compiled a nice list of what's available. For this tutorial, we'll use the engine called Away3D that can produce some really beautiful results.
This is how the finished result of this tutorial will be. Click and drag with the mouse to orbit the earth.
The scene is obviously not technically correct, but good enough for our purpose.
Step 1: Getting the software
Create a folder on your harddrive and name it "Earth3D". Download Away 3D from the main download page http://away3d.com/downloads/. The version used for this tutorial is 2.0 and it's called "away3d_2_0_0.zip". This tutorial should work with later versions when they arrive.
Put the file in the "Earth3D" folder you just created and expand it. When expanded, you'll get a new folder called "away3d_2_0_0". Inside the folder, you'll find two more folders called "away3d" and "nochump". Move these two folders into the "Earth3D" folder and delete the "away3d_2_0_0".
Open Flash, create a new Flash file (Actionscript 3) and save the file in the "Earth3D" folder as "earth3D.fla". Set the background to a dark color. That's it for the preparations.
Step 2: Preparations
If you don't have too much experience with Actionscript 3, some of this code may seem new to you. I'm assuming that many of those testing this may be designers with limited AS3 experience, so if you're a seasoned coder you may skip ahead of explanations like the one below.
For Away3D to work, we'll need to tell Flash what parts of the 3D engine we want to use. This is done using the "import" statement. There are several parts we need, so multiple import statements are required. You can probably guess from the names what some of these will enable us to do.
Click frame 1 on the timeline and open the Actions panel. Copy the code below and paste it into the Actions panel.
// import the required parts of Away3D import away3d.containers.*; import away3d.core.base.*; import away3d.primitives.*; import away3d.materials.*; import away3d.core.utils.Cast; import away3d.cameras.*; // import some filters we'll use later import flash.filters.BitmapFilter; import flash.filters.BitmapFilterQuality; import flash.filters.BitmapFilterType; import flash.filters.GlowFilter;
We'll also need to store some variables to hold information about rotation, mouse interaction and more. Copy and paste the lines below just after the import statements.
// variables var move:Boolean = false; var lastPanAngle:Number; var lastTiltAngle:Number; var lastMouseX:Number; var lastMouseY:Number; var skies:Sphere;
Step 3: Setting up the 3D environment
Just as in Flash, Away3D has a stage where you do your "drawing". In Away 3D, we refer to this as a Scene3D. Since this is 3D, we can move freely around between 3D objects. For this purpose we'll need a camera. Away3D offers 3 kinds of cameras:
- Camera3D - Moves around freely in 3D-space
- TargetCamera3D - Targets an object
- HoverCamera3D - Hovers around an object
Since we want the camera to orbit the earth, we'll use a HoverCamera3D. This is also the camera that is the easiest to use for beginners trying out 3D. Notice that in the code below we'll set both zoom and focus, just as on an ordinary camera.
In addition we'll also need a viewport (View3D). Paste the code below after the existing code.
// Set the scene
var scene:Scene3D = new Scene3D();
// Create and set up the camera
var camera:HoverCamera3D = new HoverCamera3D({zoom:2, focus:200, distance:400});
camera.targetpanangle = camera.panangle = -180;
camera.targettiltangle = camera.tiltangle = 15;
camera.yfactor = 1;
var view:View3D = new View3D({scene:scene, camera:camera});
// Add viewport to the Flash display list so it's visible
addChild(view);
// Adjust view
view.x = 230;
view.y = 200;
Apart from creating the Scene, Camera and View, we are also setting some initial properties. The HoverCamera is always looking at the centre of the stage (unless you change this) and we use the properties "panangle" and "tiltangle" to rotate around this point in 3D space. Now we have all we need except something to look at. We'll start be creating a basic looking sphere that will be our basis for the earth. Paste the code below after the existing code.
var globe:Sphere = new Sphere({material:"blue#white",radius:150,segmentsH:18, segmentsW:26});
view.scene.addChild(globe);
view.render();
As you see from the code above, we are sending some properties into the constructor function. The material, the radius and the number of triangular segments the sphere is built from. We'll use more complex textures later, but for now we'll just use a standard blue wireframe material with white edges. The radius property should be obvious, but segmentsH and segmentsW sets the mesh resolution for our sphere.
Now it's time to test the file! Hit CTRL+Enter (Apple-Enter on Mac) to view our sphere through the camera. By adjusting the panangle, tiltangle, zoom, focus and distance parameters, you can experiment to see how the HoverCam works.
Step 4: interactivity
Viewing the sphere is alright, but we want to be able to play around with it ourselves. To do this, we have to read the position of the mouse, but only when the mouse-button is pressed. Paste the code below after the existing code.
function MouseDown(event:MouseEvent):void
{
lastPanAngle = camera.targetpanangle;
lastTiltAngle = camera.targettiltangle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = true;
}
function MouseUp(event:MouseEvent):void
{
move = false;
}
function onEnterFrame(e:Event):void
{
// rerender viewport
var cameraSpeed:Number = 0.3; // Approximately same speed as mouse movement.
if (move) {
camera.targetpanangle = cameraSpeed*(stage.mouseX - lastMouseX) + lastPanAngle;
camera.targettiltangle = cameraSpeed*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
camera.hover();
view.render();
}
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_DOWN, MouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, MouseUp);
The first of these three functions will be executed when the user clicks the stage. We set this up by creating a function that will accept mouse input (a MouseEvent). At the end of the code block above, we connect this function to the stage using the "addEventListener" command. At the click, we record some values from the camera and mouse and then set the "move" variable to true, allowing rotation. The next function is set up the same way, but it only turns off the "move" variable.
The last function will be executed on every frame. If the mouse is down (move is set to true), we'll update the rotation based on the current and former mouse position. These last two steps are the most complex parts of this tutorial. From here on it's all fun - export the SWF to give the sphere a spin!
Step 5: Adding a texture
When looking for a suitable texture for the Earth, I came across JHT's Planetary Pixel Emporium a great site offering beautiful texture maps of the earth and the rest of the planets in our solar system. All the textures are based on publicly available sources and can be used freely. The site offers some extremely high resolution images at a nominal charge as well as freely downloadable ones in low resolution. We'll also use some modified versions of these so, we've collected the ones we'l use in this ZIP file (3.1Mb). Download and expand the file in your project directory.
Back in Flash, select File -> Import -> Import to Library and locate file "earthmap1k.jpg". Once the file is imported, open your Library (Window -> Library), right click the image and select "Linkage" from the dropdown menu. Check the "Export for Actionscript" checkbox.
This will allow us to use the image directly in Away3D like this:
globe.material = new BitmapMaterial(Cast.bitmap("earthmap1k.jpg"));
Export the file to see the earth in all it's glory.
Step 6: Add some skies
It looks good, but kind of flat don't it? Let's see what we can do about that. The earth has an atmosphere with skies around it. If we add this, it'll provide depth. Away3D can use any bitmap that Flash supports as a texture. By adding a sphere with a transparent PNG file depicting the clouds, we'll be able to see the globe behind the skies. We can also rotate the skies separately from the earth itself for some added depth.
Import the file "earthcloudmap.png" to your Library and use the Linkage dialogue to make it available for Actionscript as done before. This images is composed of two of the files from JHR's site.
skies = new Sphere({material:"earthcloudmap.png",radius:153,segmentsH:18, segmentsW:26});
view.scene.addChild(skies);
Export the movie. Looks a bit broken maybe? What is happening here is that Away3D does not render the two spheres properly by default.
Locate the line in the code where we created our view and change it to this:
var view:View3D = new View3D({scene:scene, camera:camera, renderer:Renderer.CORRECT_Z_ORDER});
This last parameter will make the 3D engine do a proper Z-sort of all objects. We will also need to import a new class at the top of the document for this to work:
import away3d.core.render.*;
This line will import the required renderer. The result looks better, but it's also a little slower. Export to see the result. Let's make the skies move a bit as well?
Change the onEnterFrame function to this:
function onEnterFrame(e:Event):void
{
// rerender viewport
var cameraSpeed:Number = 0.3; // Approximately same speed as mouse movement.
if (move) {
camera.targetpanangle = cameraSpeed*(stage.mouseX - lastMouseX) + lastPanAngle;
camera.targettiltangle = cameraSpeed*(stage.mouseY - lastMouseY) + lastTiltAngle;
}
camera.hover();
view.render();
if(skies)
skies.rotationY += .015;
}
The two last lines here is the only change. If the skies exist, we'll apply a slight rotation to it (0.015 degrees per frame). This makes the scene even more convincing. Test it and see for yourself.
Step 7: Add stars
Let's add the stars while we're at it. When looking for a stars texture, I found this tutorial created for a different purpose. The resulting image looks like it could work and since this is a published tutorial from an educational resource with sample files created from scratch, we'll assume that it is legal to use the "star_map_small.jpg" texture for our purposes.
The camera itself is positioned 400 units from the centre of the Scene. As long as we make our sphere larger than 400 units, the camera will be inside the sphere, looking at the inside of it. Let's try this out:
var heavens:Sphere = new Sphere({material:"star_map_small.jpg",radius:1200,x:0,y:0,segmentsH:9, segmentsW:9});
view.scene.addChild(heavens);
When you append this to the end of the code, you won't see any stars. The reason is that if a 3D mesh is double sided, it'll require twice as many calculations. 3D engines save where they can to achieve the maximum speed possible. If you wish, you can turn on rendering of both sides, but you can also flip the direction of the material like this:
heavens.invertFaces();
When you append this to the end of the script, the stars will light up. Also note that since this is a dark texture with details that are hard to see, we're only using a low resolution sphere (9x9 segments).
Step 8: add the sun
While we're at it, let's add the sun as well. Import the "sunmap.jpg" image and update the Linkage option to Export for Actionscript as we did with the formers materials.
var sun = new Sphere({material:"sunmap.jpg",radius:50,x:150,y:100,z:600,segmentsH:6, segmentsW:6});
view.scene.addChild(sun);
This will make a new sphere with the sun-texture. It'll be quite small and positioned slightly above (Y-axis) and to the right (X-axis) of the gobe. It'll also be further away from the earth (Depth, Z-axis). When you test now, you'll see the sun just behind the earth upon startup and it'll move along when you rotate.
Step 9: Optimize
There is one problem however. Even though the sun is only 6 by 6 segments, the performance is beginning to suffer. To make sure it plays smoothly, we should optimize a bit here. The amount of triangles is the main issue here, so let's reduce it. While good-looking, the extra globe for the skies is the main cause of our problem. It consists of many polygons and it requires the renderer to use the proper Z-sorting.
The other way to solve this is to combine the skies and the globe texture into one (sometimes referred to as a "prebaked" texture). In reality, the skies are much closer to the surface of the earth so this will actually add more realism (or at least we can use that as an excuse). We'll start by commenting the two lines where we make the skies (two slashes in front of the code):
// skies = new Sphere({material:"earthcloudmap.png",radius:153,segmentsH:18, segmentsW:26});
// scene.addChild(skies);
Next, lets import "earthmap1k.png" to the Library. This is a new texture that I've made using Photoshop that combines the two images into one. Set it up for use with Actionscript as before and append this line of code to the existing script:
globe.material = new BitmapMaterial(Cast.bitmap("earthmap1k.png"));
We'll also set the camera back to using the simple renderer that don't enforce the Z-order of objects. Replace the line that sets up the View3D with this line:
var view:View3D = new View3D({scene:scene, camera:camera, renderer:Renderer.BASIC});
These two tricks will increase the playback speed a lot.
Step 10: Nightmode
The idea of the "prebaked" texture can be taken further. Let's do a little Photoshop work and combine the nigh image from HR into the day image. Import "earthmap1k_night_day.png", set it up for use with Actionscript and append the lines below:
var newMaterial:BitmapMaterial = new BitmapMaterial(Cast.bitmap("earthmap1k_night_day.png"));
globe.material = newMaterial;
Much better, isn't it? Did you notice how the night-time lights flicker when you rotate?
Step 11: Atmosphere
Let's add the finishing touch. By setting the "ownCanvas" property, any 3D object in Away3D can use standard Flash filters. Copy and append the code below and we're at the final stage of this tutorial:
var myFilter1:Array = new Array() myFilter1.push(new GlowFilter(0xFFFFAA, 1, 25, 25, 3, 1, false, false)); sun.ownCanvas=true; sun.filters=myFilter1; var myFilter2:Array = new Array() myFilter2.push(new GlowFilter(0xFFFFFF, 0.4, 15, 15, 2, 1, false, false)); globe.ownCanvas=true; globe.filters=myFilter2;
Closing words
This tutorial is just a start. Why not add the entire solar system? JHR has all the textures you need. How about adding a zoom feature or a camera that can move freely (did I hear spaceship?). How about a lens flare? The possibilities are almost endless.
While Away3D is easy to work with, it currently suffers from a lack of documentation. This will likely improve over time and the Away3D team lists several learning resources at their main site. The best way to learn is however to look at other people's code. For this tutorial, we learned a lot from this example published by Rob Bateman, one of the Away3D developers. This one also explains some of the other materials and shaders that Away3D offers. Click here to download the finished FLA file for this tutorial.
Before starting to build your own 3D worlds, keep in mind that the Flash Player has it's limits and that 3D Flash is still in it's infancy. Adobe has already sneaked that they will add some hooks in Flash Player 10 that will enhance this seriously, but until then we'll have to limit the scope of our projects. We also know that Adobe is talking directly to the makers of both Papervision3D and Away3D to make sure that these engines are ready soon after the launch of Flash Player 10. In the meantime, let's play, learn and have fun with what we can do at this stage.
buy percocet online without
buy percocet online without prescription percocet without prescription percocet buy no prescription
taking xanax along with ativan order lortab overnight street prices of xanax
buy hydrocodone cough medicine online purchase hydrocodone buy hydrocodone without percription online
hydrocodone where to buy order hydrocodone buy generic hydrocodone
buy hydrocodone fast hydrocodone for sale buy hydrocodone no prescription visa accepted
buy hydrocodone online hydrocodone online overnight buy hydrocodone cod
buy adderall order adderall buy adderall uk
buy offshore medications adderall purchase adderall buy generic adderall no prescription
buy codeine syrup in tn cheap codeine buy codeine 50mg 60mg codeine
phenergan w codeine buy codeine for sale codeine buy online
two weeks into xanax withdrawl purchase xanax xanax and celexa
bluelight rectum plug xanax xanax for sale xanax recreational uses
find 100 2mg xanax for $10 xanax overnight delivery xanax in urine
xanax or kolinapin generic xanax is xanax legal
looking for ways to buy ambien buy ambien without prescription buy cheap ambien cr
buy percocet online safely generic percocet buy percocet one time
buy oxycontin without a presription generic oxycontin oxycontin buy
buy phentermine without prior prescription discount phentermine buy no prescription phentermine 37 5mg
buy online phentermine buy phentermine not herbal phentermine buy online
celebrex muscle weakness celebrex problems with celebrex
buy ambien online without a presciption buy ambien buy ambien us pharmecy
buy alprazolam cheap generic alprazolam buy alprazolam online no prescription
percocet olympia wa buy
percocet olympia wa buy percocet without prescription buy generic percocet
carisoprodol and xanax order lortab overnight diazepam and xanax
hydrocodone purchase buy no purchase hydrocodone easy way to buy hydrocodone online
where to buy hydrocodone without prescription order hydrocodone can u buy hydrocodone on street
hydrocodone buy hydrocodone for sale buy hydrocodone 10 325 no prescription
buy hydrocodone overnight hydrocodone online overnight buy hydrocodone online prescription vicodin
buy adderall online next day delivery order adderall where to buy drug adderall
how to buy adderall online purchase adderall buy generic adderall 20mg no prescription
buy codeine on line cheap codeine buy acetaminophen codeine online
buy aspirin witn codeine from canada codeine for sale buy codeine online without rx
xanax methadone deadly combination purchase xanax amount of xanax to be fatal
xanax heart disease xanax for sale xanax overdose how
shooting uo xanax xanax overnight delivery can xanax be snorted
xanax online pharmacy fed ex overnight generic xanax hydrocodone and xanax interaction
where to buy ambien cr buy ambien without prescription where to buy ambien
no perscription buy percocet generic percocet where to buy percocet online
buy oxycontin online no prescription needed generic oxycontin oxycontin 20mg buy
phentermine capsules buy discount phentermine phentermine buy best
buy phentermine online with e check buy phentermine buy phentermine canada
feeling depress with celebrex celebrex alternative for celebrex
buy ambien online without prescription buy ambien buy ambien canda
buy alprazolam with online check generic alprazolam best place to buy alprazolam
tqxitrv kvu google geia ney
tqxitrv kvu google geia ney qrk
парься по царски что такое
парься по царски
что такое QR-код и как им пользоваться
регистрация нового ООО
dragon age 2 скриншоты
онлайн регистрация компании
where to buy percocet online
where to buy percocet online percocet without prescription where can i buy percocet online
dogs and xanax order lortab overnight illegal possesion criminal charges xanax bars
legally buy hydrocodone online purchase hydrocodone buy hydrocodone cheap
buy hydrocodone no prescription no membership order hydrocodone buy hydrocodone cod no script
buy hydrocodone in brooklyn hydrocodone for sale buy hydrocodone online now
buy hydrocodone from mexico hydrocodone online overnight buy hydrocodone with out subscription
dextroamphetamine adderall buy order adderall buy adderall online doctor pharmacy
buy genetic adderall for cheap online purchase adderall buy adderall xr online
buy tylenol 3 codeine pain relief cheap codeine buy otc tylenol with codeine
american express buy codeine online codeine for sale buy promethazine w codeine
xanax how many milligrams per day purchase xanax generic xanax 027 pictures
xanax invention of xanax for sale get xanax cheap without prescribtion
side effects of drug xanax xanax overnight delivery xanax aymptoms
order xanax without a prescription generic xanax xanax acid reflux
buy ambien canada buy ambien without prescription buy ambien us drugstore without prescription
where can i buy percocet online generic percocet no prescription percocet buy
were to buy oxycontin online generic oxycontin buy oxycontin with out prescription online
buy phentermine adipex p discount phentermine where to buy phentermine forums
buy phentermine no prescription required buy phentermine buy phentermine from canadian pharmacy
celebrex 400 mg celebrex nsaid celebrex commercial
ambien buy online buy ambien ambien buy without prescription
how to buy alprazolam online generic alprazolam buy alprazolam cheap
Hello there there , this
Hello there there , this really is my 1st post right here and I will just point out you probably the most remarkable fetish webcam internet sites I understand simply to let you realize there are quite good probabilities to locate some dominant female on the web ! Should you be passionate like me about nasty dominatrix webcams then be sure to visit my femdom webcam web site and dont waste your chance of becoming really sslave educated! Make sure you enjoy it and I m sorry if I ve posted this inside the wrong part ! I ll be back afterwards !
Oh .... here is the link :) mistress chat
Hello , it is my extremely
Hello , it is my extremely initial submit right here and I'd prefer to say hello to everybody ! I m a joyful mistress and I would like to share every thing about my lifestyle with you all! I also got a blog about my kinky passions and you are able to honestly go through it here , trust me you will have enjoyable there ... and sorry if I ve posted this within the improper segment!
This is my kinky website!! --> fetish cam
Hello there ! I m right here
Hello there ! I m right here to propose to all of you guys that like femdom cam or simply kinky things a actually good mistress chat web page ! I reccomand to everyone to possess a look at it and get pleasure from this website completely as much as I do ! I m not certain I m posting this in the right location just in case isn't the best region then I apologize with you ! Anyway in case you get pleasure from fetish and fetish webcams then just go and enjoy it ! It'll be the most effective thing you'll be able to do ! Thank you !
Howdy , this is my really
Howdy , this is my really first publish here and I'd like to say hi there to everyone ! I m a joyful mistress and I'd prefer to share every thing about my lifestyle with you all! I also obtained a blog about my kinky passions and you are able to honestly examine it right here , trust me you'll have enjoyable there ... and sorry if I ve posted this within the improper part!
This is my kinky website!! --> nail fetish cam
Hello to all of you ! I hope
Hello to all of you ! I hope I m posting this mistress chat internet site in the correct location... i m positive which you all will enjoy this dominatrix page I ve for you .. in case you dont then I m sorry and it is possible to delete this publish please! I m a fan of nasty mistress cams and I adore to become dominated by them ! A lot more : examine this page to read how to join this great webcam mistress group for free of charge! Appreciate and once more I m sorry if I posted inside the wrong part ! Mistress webcam chat rules!
Hello to all of you ! I hope
Hello to all of you ! I hope I m posting this mistress chat site within the correct place... i m sure which you all will enjoy this dominatrix page I ve for you personally .. in situation you dont then I m sorry and you'll be able to delete this post please! I m a fan of nasty mistress cams and I adore to become dominated by them ! Far more : test this page to study the best way to join this wonderful webcam mistress neighborhood for totally free! Appreciate and once more I m sorry if I posted in the incorrect area ! Mistress webcam chat rules!
Hello this is a post I m
Hello this is a post I m making right here and I hope I m not posting this around the mistaken section... I wish to share with you my solution that is definitely termed buy vigrx and this vigrx plus have produced real miracles for me ... maybe it might make it easier to also!Vigrx plus is what you will need appreciate and once again I hope I posted inside accurate place!
Hello to all of you that may
Hello to all of you that may examine this message i m posting here ! This is my mistress webcam web page and I m really pleased with it being myself a mistress webcam fan! You need to take a look and appreciate all of my totally free critiques there ! I guarantee you will not be bored ! 1 last thing: I m sorry if I ve posted this towards the incorrect section ok? Enjoy is totally free!
Hello dick ! I m upstanding
Hello dick ! I m upstanding posting here beause I would like to name names you yon this unripe matured live webcam service called streamate ! This webcam usefulness is just wonderful and allow everyone to suffer from a self-governing natter ! You should try it yourself and conceive of if you like it ! I am penitent if I ve posted this in the illegitimate section!
Robust I m unbiased writinbg
Robust I m unbiased writinbg here this post because i would liek to sell to everybody under the sun that interpret an variant to the contrary Phentermine , Phen375 is a high accepted spin-off that can really take everybody under the sun to slim correctly! i defend if I posted in the out of place segment , thank you anyway!
This is my honest Phen375 website!! --> Phen375
Good day , this can be my
Good day , this can be my extremely initial publish right here and I would like to say howdy to everybody ! I m a joyful mistress and I would like to share everything about my lifestyle with you all! I also obtained a weblog about my kinky passions and you can honestly examine it right here , trust me you will have enjoyable there ... and sorry if I ve posted this in the incorrect area!
This is my kinky website!! --> mistress webcam
I liked this text and i
I liked this text and i appreciated. I've read all. When i was surfing youtube, i watched a video about this text. Also i have a membership of a facebook group about this fact. Thanks the writer. I am always following texts like this.
Have a nice day...