Away3D.com
   
 
Quality dvd movies, buy movies online and download movies!!!
rulururu

post Tutorial: How to build an elevation

March 5th, 2008

Filed under: AWAY3D — Fabrice Closier @ 11:14 am

elevate1

This tutorial shows you how to create an elevation using the Away3D 1.9.4 library or higher.

In the extrusion package there is a class called Elevation, which is a companion of the SkinExtrude class. This tutorial will show you how they work together.

A little word on the SkinExtrude, (a dedicated tutorial on this class will be soon available). The SkinExtrude class does only one thing: connect a collection of Number3D, points in 3D space with x, y and z values. It generates a mesh between them and you can define how detailed you want the subdivision of the surface.

Elevation is a class that reads channel information of a BitmapData object, and generates a series of points (Number3D values) based on the color value and the elevation factor passed to the generate method. By itself, the class just returns a multidimensional array containing those points in space.

So what can we do with this data? Well in this case, just pass it to the SkinExtrude class, and like magic, the engine will render those points linked to each other as an elevated mesh, no coding required.

To get started, in order to build the demo shown above you need to spend a few minutes in Photoshop or any other graphical editing package. For the demo, we want to build a piece of a road across some landscape. Begin to build the color information first and then start to build the elevation information afterwards, so that both seamlessly fit, as if they were above each other. In Away3d we need to know which channel (color) will be used for elevation, so if you pass an “r”, the information will be based on the red channel values, similarly for other colour channels (r,g,b,a). In this case, we choose to use the red channel.

In order to build your elevation you need to draw some gradients going from 0, to 255 in that color. Any other color will be ignored, so you can use another color that does not have red in its composition to draw these gradients. How you can do this in Photoshop is beyond the scope of this tutorial.

Here is the color information that will be used for the material of the generated mesh.

elevate3

And here is the gradient, more red means higher elevation.

elevate2

Now that our job is done in Photoshop, it’s time to import these images into Flash. Note that the size of the images is not relevant for this tutorial, but you should try to avoid importing too many kb’s.

Set up your project file as usual, and import the SkinExtrude and the Elevation class.

import away3d.extrusions.Elevation;
import away3d.extrusions.SkinExtrude;

The rest of the code needed to generate the demo shown is below:

//here a little function that generates the bmd from the library, above player 9.0.115 you can directly access the library
//with this one you are fully 9.0 compatible, just add a linkage name to your image in the lib, and pass that id to this function.

private function imageFromLib(source_ID:String):BitmapData
{
var classRef:Class = getDefinitionByName(source_ID) as Class;
return new classRef(classRef.width, classRef.height);
}

private function build():void
{

// instance bitmapdata for elevation info
var source_elevation:BitmapData = imageFromLib(”elevation”);
// your material using the color bitmapdata
var mat:IMaterial = new BitmapMaterial(imageFromLib(”roadcolor”) , {smooth:true});
// instance of the elevation class, you can now call the generate method, multiple times if needed.
var elevate:Elevation = new Elevation();
// we pass to the SkinExtrude class the generated points from the elevation class
extrude = new SkinExtrude(elevate.generate(source_elevation, “r”, 5, 5, 50, 50, 4), {material:mat, recenter:true, closepath:false, coverall:true, subdivision:1, bothsides:false, flip:true});
extrude.rotationX = 90;

// show time!
this.scene.addChild(extrude);
}

A note on the parameters for the Elevation.generate method:
elevate.generate(source_elevation, “r”, 5, 5, 50, 50, 4)

  • the first param: The source bitmapdata, containing our gradients.
  • the second param: Specifies the color channel as a string: r, g, b, a
  • the third param: Specifies an elevation height based on every 5th pixel along the x axis
  • the fourth param: Specifies an elevation height based on every 5th pixel along the y axis
  • the fifth param: Scales the mesh position by 50 along the x axis
  • the sixth param: Scales the mesh position by 50 along the y axis
  • the last param: Scales the mesh position by 4 along the z (elevation) axis
  • That’s it.

    Popularity: 5% [?]

    19 Comments »

    1. how are you saving the images in the library? (I’m using FlashDevelop, so I can’t just drop ‘em in the GUI way so far as I know)

      Comment by rey UNITED STATES — March 5, 2008 @ 3:39 pm

    2. I got it with:
      [Embed(source="elevate2.jpg")]
      public var ElevationJpg:Class;

      var imgObj:Bitmap = new ElevationJpg();
      var source_elevation:BitmapData = imgObj.bitmapData;

      But now I am curious as to whether there is an easy way to set the position to the center of the extrude object like you seem to be doing. Neither view.camera.lookAt(extrude.position) nor view.moveTo(extrude.position) seem to do that for me.

      Comment by rey UNITED STATES — March 5, 2008 @ 5:19 pm

    3. Just pass in the init object of the SkinExtrude the following: recenter:true or use object3d.movePivot(x,y,z); Note that a bug has been fixed for movePivot(), use the latest version from svn repository.

      Comment by Fabrice Closier NETHERLANDS — March 6, 2008 @ 3:35 am

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

      Pingback by trace(myBitmapdata); » Blog Archive » Away3D Surface Tracking tutorial NETHERLANDS — May 28, 2008 @ 3:50 am

    5. I ´m trying the example and i get like 3 FPS ?? and when i dee the online example i see it ok… i´m doing something wrong?

      this is my code:

      [...]
      private function iniciar():void
      {
      scene = new Scene3D();
      camara = new Camera3D( { zoom:10, focus:100, x:500, y:900, z: -1000 } );

      viewport = new View3D( { scene:scene, camera:camara } );
      viewport.x = 250;
      viewport.y = 250;
      addChild(viewport);

      var mat:IMaterial = new BitmapMaterial((new road_class() as Bitmap).bitmapData, { smooth:true } );

      var elevate:Elevation = new Elevation();
      extrude = new SkinExtrude(
      elevate.generate((new road_bump_class() as Bitmap).bitmapData, ‘r’, 5, 5, 6, 6, 2),
      {material:mat, recenter:true, closepath:false, coverall:true, subdivision:0, bothsides:false, flip:false } );
      extrude.rotationX = 90;

      scene.addChild(extrude);
      addEventListener(Event.ENTER_FRAME, render, false, 0, true);

      }

      private function render(e:Event):void
      {
      viewport.render();
      extrude.rotationY ++;
      }
      [...]

      Comment by Pablo ARGENTINA — June 7, 2008 @ 5:21 pm

    6. This is not the place to start a thread, please join the dev group for technical support. Fast answer: the amount of triangles is defined by the (width/Xstep)*(height/Ystep) so exact same code generates more triangles if the bitmapdata you pass has a greater width, greater height or both. Just pass higher steps accordingly.

      Comment by Fabrice Closier NETHERLANDS — June 8, 2008 @ 1:17 pm

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

      Pingback by Flash Tutorials | Away3D tutorials roundup | Lemlinh.com — September 5, 2008 @ 5:59 am

    8. I am trying your tutorial and I am receiving this error message in the output of Flash:
      Scene 1 Layer ‘Layer1′ Frame 1, Line 4 1013: The private attribute may be used only on class property definitions.

      Comment by Carroll Altman UNITED STATES — September 15, 2008 @ 11:21 am

    9. To Carroll: You copied and pasted the code from this page into the flash text editor.
      In there you don’t need to add the word ‘private’ in front of a function. Just delete the private words and it’ll be fine.

      Comment by Escape-Artist NEW ZEALAND — September 16, 2008 @ 5:37 am

    10. hello, im doing several test of this tutorial and i cant make it work,
      i added the code in and deleted the “private” words ,then add the images in library and linkage ass class the elevate2.jpg to elevation and elevate3.jpg as roadcolor, im using flash cs3 with as3 and away3d v2.

      Comment by wicho — February 3, 2009 @ 5:06 pm

    11. For technical support, please join our dev group.

      Comment by Fabrice Closier NETHERLANDS — February 5, 2009 @ 6:41 am

    12. Someone get this to work, really? Why do a tutorial if you do not post all the code and source files? I decompile your swf and there’s a lot more setup that what you try to pass here, just be cool and post the source please, really. And answer the questions posted.

      Comment by mine ITALY — June 11, 2009 @ 10:29 am

    13. Thanks for the tutorial. But I can’t make it all work.
      You should’ve posted the entire source files.
      Cause thousands of noobs will waste several more hours to solve it.

      Comment by Roma UKRAINE — June 23, 2009 @ 5:52 am

    14. You should’ve posted the entire source files.
      No details!Or give more examples!

      Comment by teshu AUSTRALIA — August 25, 2009 @ 8:54 am

    15. I could not get this to work either…

      Comment by Peter McAlenney UNITED STATES — November 25, 2009 @ 10:58 am

    16. That’s why we do have a google group where you can post your questions. Please register if you need technical assistance.

      Comment by Fabrice Closier NETHERLANDS — November 27, 2009 @ 7:44 pm

    17. Does anyone know if there are any videos available to help with this?

      Comment by Camera Flip Bracket THAILAND — March 2, 2010 @ 5:35 am

    18. There are no videos on this, but in case you want to go the easy way, Prefab3D generates them for you. http://www.closier.nl/prefab

      Comment by Fabrice Closier — March 2, 2010 @ 8:36 am

    19. It shows how to create elevation using the Away3D 1.9.4 library or higher. The class which is called the Elevation which is the companion on class SkinExtrute. Great effort by the author for this post. Thanks for this nice post.

      Comment by wheel spin roulette INDIA — March 9, 2010 @ 7:13 am

    RSS feed for comments on this post. TrackBack URI

    Leave a comment

    ruldrurd
       
     
    Hair drug test and herbal detox products. Visit drug detox website for more details on cannabis and marijuana drug detox.
    FireStats iconPowered by FireStats
    Powered by WordPress, Web Design by Laurentiu Piron
    Entries (RSS) and Comments (RSS)




    rmvb player and mkv codec