Away3D: Loading & exporting data

Flash, News, Tutorials

Hi All, I’m new to Away3D, what is best way to load models into my project?
I often read messages like this on our Google User Group. Many new features for this have been added in the past few months, so it’s time for a closer look at what possibilities Away3D offers at the moment.

Away3D supports 3 kinds of data files:

  • Models from other (3D) applications
  • Models encoded as pure AS3 classes
  • Away3D AWD format
  •  

    Supported 3D model formats
    The Away3D engine is able to load, parse and display these 3D/exchange formats:

  • Wavefront Obj *
  • Metasequoia MQO *
  • Md2still and Md2 animated
  • Max3DS
  • Kmz
  • Collada
  • Ase
  • Other formats such as LWO, ACD3 will be soon added to this list

    If you work with 3D applications, chances are that you have either used or heard of one of the above formats. They all hold 3D data and you can load them into another 3D application if it supports the given format.

    Away3D also supports some quite unique formats:

  • Swf
  • AWData (.awd)
  • Fonts
  •  

    Swf is not as the name might suggest a loader for swf’s. It is rather a parser allowing you to extract vector information directly from movieclips in a swf and display the extracted vector content in 3D. Here’s an example.

    AWData (away data files .awd) is an entirely new format. This format is the first version of the Away3D native format. It will be a compact, featured and backward compatible format. More on this further down in this post.Transformers: The Last Knight live streaming film

    Away3D  Data only v1
    Same data in various formats. awd data is not compressed yet ?

    Fonts can be used with the Textfield3D class and extrusions derivated from font information, making it possible to embed font outlines in Away3D.

    The exporters
    Getting a model into your project is one thing, but what if you want to go the other way? If you create a tool that creates 3D models – how do you get it back out? Away3D has multiple exporters.

  • 4 different AS3 outputs
  • Wavefront obj
  • Away data (.awd)
  • The AS3 exporters
    Currently you can output to 4 different kinds of AS3 classes. The 2 first ones are the AS3Exporter and the AS3LiteExporter. As the obvious names are suggesting, their output is compatible for Away3D or Away3DLite. These are able to export a whole scene (up to 100k polys whithout having memory issues at compile time). The export is written as a single AS3 class that you can then use directly in your project using standard syntax, for example: new MyExportedClass().

    The third method (a Mesh method) allows you to export a single Mesh description to AS3.  If the source was an animated md2 model, this method will export the mesh animation information as well. This class also features export of single Mesh as xml if you should need that. Note that this methods will probably be removed in futures versions when the AWD format and the other AS3 class exporters get animation support.

    The last is the Elevation2AS3 exporter that exports not only the elevation information, but also creates the bitmap generation data you need for surface tracking.

    Use Wavefront obj to exchange models
    For some projects, it is handy to export the content of your scene to an external 3D editor such as Maya, 3DS MAX, Blender or others. You can use the ObjExporter for this. It allows you to perfectly match your scene in your editor, but also to export dynamically generated objects.

    Away data format
    The new comer into the Away3D arsenal is the AWD file. This format is currently a data only export for static object(s). Like all the other AS3 exporters, you can export a whole scene, but the file doesn’t need to be compiled. It can be embedded, it can be read from remote locations such as databases or simply loaded runtime. Next to a huge size gain compared to standard formats, the format is also compatible with the F9 Away3D (2.4 and higher), F10 Away3D and F10 Away3DLite. It will be extended and developed with this “cross engine” idea for upcoming updates. Mesh animation support for this format is currently under development.

    PreFab3D
    Away3D is open source, this means that all the classes to import and export are available to you in our google code repository. You also can find additional features for these exports such as material embedding in our AwayAIR package. So you can create your own tools in AIR as well.

    In case you choose to go the easy way and just want to improve your workflow, the latest version of PreFab3D is supporting all these with an extra for the awd format: you can drag&drop the awd files on the app to load them back for further editing or viewing. Of course you can embed your prebaked textures from PreFab3D into your AS3 and awd files.

    Best practices
    Many swear by collada, others by 3ds or obj. The point is that most of these formats are ideal for development purposes but most of them are not very suitable for web because of the extra verbose they hold or like the kmz format, even adding extra cpu/ram costs to decompress the zipped files.

    So if your project is not asking for md2 mesh animation or collada bones animation.
    The best way to avoid loading blues and have much smaller project footprint is to export to AS3 or awd format.

    I hope this little post adresses a few of the questions you might have and will help you to make a (better) choice for a format in your next Away3D project.

    If you need technical support or if you have questions, please register on our our dev group or read our documentation/example section on the main Away3D site.

    Away3D RoundedCube primitive

    Flash, Tutorials

    roundedcube

    One of our users asked on our list last week how to build a RoundedCube… mmm…

    The cube is one of the most popular primitives. But none or almost none are rounded cubes, and the very few ones you see around are generated in 3D apps and imported as collada… a waste of bandwidth and ease. The reason for this: no 3D APi for Flash offers one. True until 15 minutes ago.
    There is now a RoundedCube primitive in Away3D.

    How to use it
    First you need to import the class.

    import away3d.primitives.RoundedCube;

    The roundedcube supports single and multiple materials
    like the Cube primitive.

    Single material

    var mat:BitmapMaterial = new BitmapMaterial(someCoolBmd);
    
    var rc: RoundedCube = new RoundedCube(
    		{material:mat, 
    		width:1000,
    		depth: 1000,
    		height: 1000,														  		 		 
    		radius:500,												   
    		subdivision:3 });
    					
    view.scene.addChild(rc);
    

    Multiple materials

    first you need to import the CubeMaterialsData class.

    import away3d.primitives.data.CubeMaterialsData;

    Then just declare a material per side, and pass it to the CubeMaterial instance.

    var matleft:BitmapMaterial = new BitmapMaterial(someNiceBmd);
    var mattop:BitmapMaterial = new BitmapMaterial(someCoolBmd);
    var matbottom:BitmapMaterial = new BitmapMaterial(someWoWBmd);
    var matfront:BitmapMaterial = new BitmapMaterial(someGreenBmd);
    var matright:BitmapMaterial = new BitmapMaterial(someUglyBmd);
    var matback:BitmapMaterial = new BitmapMaterial(someFunnyBmd);
    
    var cubedata:CubeMaterialsData = new CubeMaterialsData(
    			{top:mattop,
    			bottom:matbottom,
    			front:matfront,
    			back:matback,
    			left:matleft, 
    			right:matright})

    now you just need to pass the variable ‘faces’ as cubedata variable.

    var rc: RoundedCube = new RoundedCube(
    		{faces:cubedata,
    		width: 1000,
    		depth: 1000,
    		height: 1000,														  		 		 
    		radius: 500,												   
    		subdivision:3 });
    					
    view.scene.addChild(rc);

    Classic Cube looks soooo passé now… 🙂

    Fabrice

    Away3D PathAnimator Tutorial

    Tutorials

    pathanimator

    This tutorial is an introduction to the PathAnimator classes. Since some features are still under development, this tutorial will introduce the basic way to animate 3d objects using paths. The Away3D 2.2 library or higher is required for this tutorial and we assume you already familiar with Away3D.

    The way it works
    The PathAnimator class is an abstract class working together with the Path class. A Path instance holds path information as a series of CurveSegment objects. Using this system allows you to natively animate one or more 3d objects along a path definition. In this way complex motions can be created at low cost to cpu consumption and development time.

    A PathAnimator instance will automatically update the position and rotation (optional) of the object you assign it based on a series of defined numerical values. No matter how many segments the Path definition holds, 0 will always point to the start of the path data, 1 will refer to the end.

    A native tweener class has been added to Away3D so that basic tweens are possible along a path. The native tweener is NOT there to replace your favourite tweener. Only basic functionality is catered for: linear, standard ease in and standard ease out. If you require more complex tweens, there are plenty of advanced tweening engines to choose from that can be used with the PathAnimator class. The internal tweener is applied by default and is driven by a dedicated handler.

    Events dispatched from the PathAnimator class include: cycle, range and segments (explained later in this article). Note that altering the path definition will update the animation as well, making it suitable for custom motion editors or runtime updates.

    Options available to the PathAnimator class include:

    • Camera or 3d object movement along a path.
    • Camera or 3d object movement along a path while targeting an object.
    • Camera or 3d object movement along a path while aligned to direction of motion.
    • Twisted path support.
    • Object positioning along a path.
    • Can be combined with any other Path enabled class.

    How to implementWatch Full Movie Online Streaming Online and Download

    import away3d.animators.PathAnimator;

    We need to define a Path object as well

    import away3d.animators.data.Path;

    And we need an object. in this case we will use a native primitive, but it can be any object, even an object of type ‘Object’ will do as long as the property x,y,z, and optional rotationX, rotationY, rotationZ are accessible.

    Import all other classes required for materials, view, scene etc…

    Declare an instance of the PathAnimator class. If we want to update the properties of the Path object while the animation is playing we will need to declare it as a variable. The same applies to the object we will animate.

    private var pathanimator:PathAnimator;
    private var cube:Cube;
    code [...]

    First we need to define a Path object. In this case a U shape with some variations along the y axis. The demo shown above displays a much more complicated path, but we will keep it simple for the purposes of this tutorial.

    var aPath:Array = [
    new Number3D(-1000, -1000, -2000),
    new Number3D(-1000, 0, 0),
    new Number3D(1000, 0, 0),
    new Number3D(1000, 1000, -2000),
    ];
    var p:Path = new Path(aPath);

    Now we need to declare an instance of the object we want to animate. An optional “this” is added here just to remind us it is a property of our project class. We use a Cube here to be make the alignment obvious.

    var mat:IMaterial = new BitmapMaterial(new BitmapData(64,64, false, 0xFF0000));
    this.cube = new Cube({material:mat, width:200, height:80, depth:100});
    view.addChild(this.cube);

    The properties
    Now that we have our path information and our object to be animated, we can build our PathAnimator instance. The class has the following properties available:

    • lookat: a Boolean, defines if the object or camera will look at something while moving.
    • aligntopath: a Boolean, defines if the object or camera will be aligned to the path. Note that you cannot have lookat and aligntopath set to true in same PathAnimator. In this case default aligntopath will be used.
    • targetobject: If you have the lookat set to true, you can pass an object here to be used as the target. the object will rotate to point at that target position even if the target is moving.
    • offset: a Number3D, defines an offset to the object position along the path.
    • rotations: an array of Number3Ds, defines twist information along the axis of the path.

    If you are using the internal tweener, further properties are available such as:

    • duration: a Number, defines the duration of the entire animation in milliseconds.
    • fps: an int, defines the framerate of the animation.
    • easein: a Boolean, defines if the tween uses an ease in.
    • easeout: a Boolean, defines if the tween uses an ease out.

    All these properties are set automatically to default values if they are not passed in the init object. They can also be set using getters/settersl once the class in instantiated.

    For demo purposes, we declare here a full init object.

    var init:Object = {	duration:5000,
    lookat:false,
    aligntopath:true,
    targetobject:null,
    offset:new Number3D(0,100,0),
    rotations:null,
    fps:24,
    easein:false ,
    easeout:false,
    };
    this.pathanimator = new PathAnimator(path, this.sphere, init);

    Now we are almost ready to animate. The PathAnimator class has been given it’s path, it’s object, and all it’s properties are set. To set it in motion, lets first construct a little test and place our object half way along the path. we do this just before the render command. Since our target is not a camera, we also tell the camera to look at the object.

    this.pathanimator.update(0.5);
    view.camera.lookAt(this.cube.position);
    view.render();

    Now our cube is placed half way along the path. But its not very obvious, because we cannot see the path curve. Adding a time variable to our code will provide motion, going from 0 to 1 in small increments.

    var time:Number = 0;

    Before our update call, we update the time variable and make sure that it stays lower or equal to 1.

    time = (time +0.001>1)? 0 : time+0.001;
    this.pathanimator.update(time);
    view.camera.lookAt(this.cube.position);
    view.render();

    Now our animation becomes obvious. To increase the speed just use larger increments for the time variable, to decrease the speed use smaller increments. Or you can couple the time variable to an external tweener class to provide more control.

    Lets assume you want to use the native tweener. Instead of using the update() method on the PathAnimator instance, use the animateOnPath() method. The tweener automatically considers a tween starting at 0 and ending at 1. If you want to start the tween from an intermediate point, you can pass the value as an optional argument in the animateOnPath() method. For example, tweening from 0.5 to 1 would require a single animateOnPath(.5) method call. If you want to start a tween from the current position of the PathAnimator, the property “time” can be used from the PathAnimator instance.

    Once an animateOnPath(from) is defined, an animateOnPath() call in the render loop takes care of the rest of the animation. In cases where we want to change the tween settings or jump to another point in the animation, we can use the clearTime() method to reset tween time parameters.

    Runtime update
    While a PathAnimator instance is running, you can change any of it’s properties on the fly such as target, aligntopath or the animating object reference. Here are a few examples.

    pathanimator

    Here the camera is set as the animating object, with aligntopath true. The camera follows the path. No offset here means the camera is between the rails. To give the feeling of traveling in a wagon above the rails, you can pass an offset property such as new Number3D(0,200,0);

    pathanimator

    Here both aligntopath and lookat are set to false. If you move your mouse you can look in front and behind with the camera. It’s like being in a moving wagon while looking around.

    pathanimator

    Here lookat is set to true. The target is set to the object located at 0,0,0.

    pathanimator

    This uses the very same code as our tutorial, except an .obj model is used in place of our cube.

    Before going off to experiment with your own path animations, lets take a quick look at another other handy feature – path events.

    Adding events
    As explained above, the PathAnimator dispatches 3 types of events. The first is the cycle event is which is triggered when the object reaches the end of a path and returns to the start. It will be fired a minimum of one time, even if the object stops at 1.

    pathanimator.addOnCycle(nextRound);
    private function nextRound(e:Event):void
    {
    trace("here we go again");
    }

    The second is the range event which is triggered between 2 numbers in a path – for example 0.35 and 0.40. The event will keep triggering with every update as long as the object position is between this range. An example use would be to trigger fireworks while our object is along the second segment of our path.

    pathanimator.addOnRange(updateFireworks, 0.25, 0.40);
    private function updateFireworks(e:Event):void
    {
    myhandlerThatUpdatesThefireworks();
    }

    The third is the segment event which is triggered when the object enters a new segment along a path. An example use would be a change in sound output.

    pathanimator.addOnChangeSegment(playRailSound);
    private function playRailSound(e:Event):void
    {
    mysound.play(0);
    }

    There are more handlers available for the PathAnimator class beyond the scope of this introduction, but you can read more about them in the 2.2 and higher documentation. More tutorials will be available soon to explain how the PathAnimator can be mixed with other Path related classes. Like the examples displayed above.

    Away3D Animator class tutorial

    Tutorials

    butterflies

    This tutorial shows you how to use the Animator class using the Away3D 1.9.4 library or higher.

    The Animator class allows you to generate one or more series of animation sequences and add them to the internal animation system. It could be described as a runtime md2 generator – a vertex animation format.

    The vertex animations are updated at a given fps (a user defined framerate per second). The object can have one or more logical sequences, and each sequence is defined by a prefix string. Keyframes (the vertex geometry for a single frame of a sequence) in a sequence are identified by the same prefix string and a number; for instance a walk sequence would be defined as prefix: “walk”, each keyframe would then use the naming convention prefix+increment to give ‘walk0’, ‘walk1’, ‘walk2’ etc…

    Once defined you are then able to change the sequences at runtime like you would do for a movieclip. (movieclip.play(“timeline anchor”);) The engine will play the frames within this sequence “timeline” until it reaches the last frame. In our walk sequence it would stop at frame walk2. the sequence can be looped by setting the loop property to true, and the animations can be smoothed (tweened) by setting the smooth property to true, otherwise the sequence plays as individual frames.

    To make your Animator object you need at least two parameters: the base object (used as the starting mesh to be used for all subsequent vertex movements), and the vertices positions for each keyframe. For this reason it is important to pass the same amount of vertex positions for each keyframe. The order of vertex positions must remain coherent throughout each sequence. How to model in a 3D application is beyond the scope of the tutorial. It is possible to tween any two shapes as long as they both have the same amount of vertices.

    How to implement
    You only need to import 1 class using the 1.9.4 library from the animation package and for version 2.1 and higher you’ll also need the AnimationSequence class.

    import away3d.animations.Animator;
    //using 2.0 and higher
    import away3d.core.base.AnimationSequence;

    This example shows 2 meshes exported as still .as files (AS3 export is native in Away3D)
    Both butterflies shapes were modeled in a third party editor.

    butterfly1
    As you can see, each keyframe shows a different state.
    butterfly2

    private function generateButterfly():void
    {
     // the material
     var mat:IMaterial = new BitmapMaterial(new butterfly_texture(), {smooth:false}); 
    
    //instance of the first as3 file (you could create the same using a loader)
     var but1:Butterfly1 = new Butterfly1({scaling:0.6});
    
    //instance of the second as3 file
     var but2:Butterfly2 = new Butterfly2({scaling:0.6});
    
    // instance Animator
     // first parameter, we set the object reference
     // second parameter, a series of objects where we pass the geometry
     // third parameter, the init object
     // fourth parameter, if we want to loop.
     butterfly = new Animator(but1,
                                 [{vertices:but1.vertices, prefix:"fly1"},
                                  {vertices:but2.vertices, prefix:"fly2"}],
                                 {material:mat, y:0, x:0,z:0,bothsides:true},
                                 true);
    
    //using 1.9.4
     //_butterfly.play({prefix:"fly", smooth:true, loop:true, fps:8});
    
    //using 2.0 and higher
     butterfly.play(new AnimationSequence("fly", true, true, 8));
    
    //add object to the scene
     scene.addChild(butterfly);
    }

    In order to update the animation on screen, place the following code in your onEnterFrame listener:

    private function refreshScreen(event:Event):void
    {
     //move the position of the butterfly as it animates if needed
     butterfly.rotationY = -10+Math.random()*20;
     butterfly.moveForward(5);
    
    // update the internal animation
     scene.updateTime();
    
    // showtime
     view.render();
    }

    It is also possible to use the Animator class with any primitive. Here an example using the Cube primitive.
    animation

    var mat:IMaterial = new BitmapMaterial(myBitmadata, {});
    var cube = new Cube({width:350, height:350, depth:350});
    var cube2 = new Cube({width:500, height:50, depth:250});
    var cube3 = new Cube({width:150, height:450, depth:50});
    var cube4 = new Cube({width:650, height:250, depth:550}); 
    
    _anim = new Animator(cube,
                         [{vertices:cube2.vertices, prefix:"cube01"},
                          {vertices:cube3.vertices, prefix:"cube02"},
                          {vertices:cube4.vertices, prefix:"cube03"},
                          {vertices:cube2.vertices, prefix:"cube04"}] ,
                         {material:mat, y:0, x:0, z:0, bothsides:false});
    scene.addChild(_anim);
    
    //using 1.9.4
    //_anim.play({prefix:"cube", smooth:true, loop:true, fps:.5});
    
    //using 2.0 and higher
    _anim.play({new AnimationSequence("cube", true, true, .5));

    Adding more sequences
    You can add other sequences using the following source+increment syntax – shown here for “run”, “jump” and “land” sequences:

    _anim = new Animator(but1,
                         [{vertices:source1.vertices, prefix:"run0"},
                          {vertices:source2.vertices, prefix:"run1"},
                          {vertices:source3.vertices, prefix:"run2"},
                          {vertices:source4.vertices, prefix:"jump0"},
                          {vertices:source5.vertices, prefix:"jump1"},
                          {vertices:source6.vertices, prefix:"land0"},
                          {vertices:source7.vertices, prefix:"land1"}],
                         {material:mat, y:0, x:0, z:0, bothsides:false},
                         true);

    You are now able to toggle the animations at runtime using the following:trailer movie John Wick: Chapter 2 2017

    _anim.play({new AnimationSequence("run", true, true, .5));
    _anim.play({new AnimationSequence("jump", true, true, .5));
    _anim.play({new AnimationSequence("land" true, true, .5));

    More
    The examples shown above are using simple geometry. You can of course do exactly the same with much more complex models.
    Like the md2 format and as3 animated format, you can also access many handlers like play, gotoAndPlay, stop etc., but you can also check which prefix is playing, the actual frame number, add listeners onCycle and onSequence – events fired by the animation engine to ease the programming as the motion complexity increases…

    Another tutorial will cover these events in depth. More information can be found in the BaseMesh class documentation.

    Away3D Surface Tracking tutorial

    Flash, Tutorials

    reader1

    This tutorial shows you how “read” the height of an Elevation mesh in order to place or move objects on it’s surface using the Away3D 2.0 library or higher.

    We assume here you already know how the elevation class works, see the tutorial
    How to create an elevation for more details on the Elevation class.

    A word on the concept and how it works
    The ElevationReader class manages surface tracking using exactly the same parameters as the Elevation class. For obvious reasons it must use the same elevation source BitmapData as well. Both classes share the same principles of color measurement, but this class does not generate any 3d objects. The ElevationReader class generates its own version of the elevation mesh but in a BitmapData form, a smooth shaded interpretation of the mesh based on the source passed to the ElevationReader class. Between each point defined on x – x1 and y – y1, the class draws gradients between the color values along the x and y axes.

    At runtime, you are able to return the height from a given x and y coordinate, allowing an optional offset if you wish your object/camera to be higher than the actual surface level (usually the case). Depending on how your mesh is oriented, the returned number can be used to set the x,y or z properties of your object.

    The reason a separate smoothed gradient BitmapData is used (instead of the original source BitmapData) is simple – say for the purpose of this tutorial you wanted to make an elevation from a source.jpg image containing some noisy pixels in between the resolution you passed to the Elevation class. The color channel values at coordinates between those points will not be an exact reflection of the mesh elevation. ElevationReader saves you the time-consuming task of making the smoothed map yourself.

    Since the surface reading is pixel based, the higher the source resolution the better the reading. Try to have a source size as close as possible to the mesh size. In the case of very rough terrains, the constructor allows you to pass a smoothing integer which averages the current surface calculations with the previous calculation – the higher the integer the slower the reaction time in surface height. This value is useful when an object needs to move slowly across a low resolution terrain.watch full film Brooklyn 2015

    reader2

    The above demo shows you the gradient. Both meshes are the same elevation, but the top one is textured using the smoothed result generated by the ElevationReader. You can see here that the lower the elevation, the darker the color (the internal color channel being used by the class is the red one).

    ElevationReader.generate method properties
    – sourceBmd:BitmapData – This is the same source BitmapData the Elevation class uses.
    – channel:String – Specifies the color channel as: r, g, b or a. The default is r.
    – subdivisionX:int – Specifies the gap between pixels to be read along the x axis, the default is 10.
    – subdivisionY:int – Specifies the gap between pixels to be read along the y axis, the default is 10.
    – factorX:Number – Specifies the scale along the x axis, the default is 1.
    – factorY:Number – Specifies the scale along the y axis, the default is 1.
    – elevate:Number – Specifies the scale along the z axis (the elevation multiplier), the default is 0.5.

    ElevationReader public methods
    – get source():BitmapData – returns the generated smoothed BitmapData object
    – getLevel(x:Number, y:Number offset:Number = 0):Number – the most useful value, returns the height value of the surface at the given coordinates x and y, adding an optional extra offset.

    How to implement
    You’ll need to import 2 classes from the extrusions package

    import away3d.extrusions.Elevation;
    import away3d.extrusions.ElevationReader;

    The code shown below is used by the the demo at top of this tutorial:

    private function prepareWorld():void
    {
    	//the scale along x axis
    	var factorW:Number = 8;
    	
    	//the scale along y axis
    	var factorH:Number = 8;
    	
    	//the elevation scale along z axis
    	var factorD:Number = 3.5;
    	
    	//the precision for the x and y on the source
    	var precisionX:Number = 20;
    	var precisionY:Number = 20;
    	
    	//make a new instance of the reader
    	elevationreader = new ElevationReader(0);
    	
    	//we pass exactly same settings as for the Elevation class
    	elevationreader.traceLevels(elevatesource_bmd,
    	                            "r",
    	                            precisionX,
    	                            precisionY,
    	                            factorW,
    	                            factorH,
    	                            factorD);
    	
    	//make a material
    	var mat:IMaterial = new BitmapMaterial(colorsource_bmd , {smooth:false, debug:false});
    	
    	//you can reuse the smooth data if you want to test
    	var source_elevation:BitmapData = elevationreader.source;
    	var elevate:Elevation = new Elevation();
    	
    	// now we generate the mesh, again using same params
    	var points:Array = elevate.generate(source_elevation,
    	                                    "r",
    	                                    precisionX,
    	                                    precisionY,
    	                                    factorW,
    	                                    factorH,
    	                                    factorD)
    	var extrude:SkinExtrude = new SkinExtrude(points, {material:mat,
    	                                                   recenter:true,
    	                                                   closepath:false,
    	                                                   coverall:true,
    	                                                   subdivision:1,
    	                                                   bothsides:false,
    	                                                   flip:false});
    	extrude.rotationX = 90;
    	extrude.x = extrude.z = 0;
    	extrude.y = 400;
    	(extrude as Mesh).pushback = true;
    	this.scene.addChild(extrude);
    	
    	var matsphere:IMaterial = new BitmapMaterial(generateFromLib("spheretexture"));
    	target = new Sphere ({material:matsphere,
    	                      segmentsH:5,
    	                      segmentsW:5,
    	                      radius:50});
    	target.pushfront = true;
    	scene.addChild(target);
    }

    To update the y of the sphere at runtime, just pass the x and z coordinates of the sphere in the getLevel method to return the surface y. Note that thanks to the orientation of the mesh, the z value is negative in this case.

    private function render(e:Event):void
    {
    	if(target.x > 2400){
    		target.x = -2400;
    		target.z = -1500 + Math.random()*3000;
    	}else{
    		target.x += 50;
    	}
    	target.rotationZ  -= 30;
    	target.y = elevationreader.getLevel(target.x, -target.z, 20);
    	view.render();
    }

    Away3D Fog filter tutorial

    Flash, Tutorials

    fog1Watch Full Movie Online Streaming Online and Download

    This tutorial shows you how to use the fog filter using the Away3D 2.0 library or higher.

    A little word on the fog filter,
    The simulation of a saturated atmosphere created by the fog filter is not only there to enhance the graphical look of a scene, it’s also a very good way of improving the rendering performance of your project. At it’s heart, the fog filtering processes a depth filter as well. In other words, according to your fog filter maxZ property, all faces at a distance greater than this value are not processed by the renderer. The fog filter reaches a 100% alpha value at this given depth value, which equates to a solid 100% color. Note that a ZDepth filter class is also available if you do not wish to use the fog but benefit from the depth filtering.

    FogFilter properties

    – minZ the nearest distance from the camera, this value represents where the fog should start

    – maxZ the furthest distance from the camera, this value represents where the fog should end

    – subdivisions the fog is composed of a series of layers inserted in the view between the rendered triangles – this property sets the number of layers. The alpha values set internally are graduated according to this value.

    – material at this time of development the fog filter supports only solid colors like the ColorMaterial class. This is where you set your color information
    by default the filter has a white color set.

    How to implement the fog filter into your code

    	//create a new material
    	var fogMaterial:ColorMaterial = new ColorMaterial(0xBCC687);
    
    	//create a new fogfilter using the material
    	var fog:FogFilter = new FogFilter({minZ:6500,
    						maxZ:13200,
    						subdivisions:20,
    						material:fogMaterial});
    
    	//create a renderer using the filter
    	var basicrenderer:IRenderer = new BasicRenderer(fog);
    
    	//create a view using the renderer
    	_view = new View3D({scene:new Scene3D(),
    				renderer:basicrenderer});
    
    	_view.x = stage.stageWidth / 2;
    	_view.y = stage.stageHeight / 2;
    	addChild(_view);
    

    The images below should give you an idea of the way it works

    fog2
    In this case if this elevation were to be 1000×1000, minZ would be set at 200, and the maxZ at 900

    fog3
    Here it could be something like minZ 400 and maxZ 550

    fog4
    And here we would have something like minZ 10 and maxZ 500

    this images above are displaying a subdivision of 7. Feel free to experiment with more layers, since the look and feel is highly dependent on the way the layers blend with each other, the amount of faces in between, and their respective sizes on screen.