More Molehill & Away3D Fun

To view the example click the image above – you will need the Flash Player 11 beta for it to run.

So after my last post and initial tests with Away3D 4.0 and the new Molehill APIs, I wanted to dig a bit deeper and get together an example that would test the powers of this great new Flash Player feature a little further and so decided to get a more complete model together. So I downloaded a nice car model to import into blender and played around with it a bit until I had a model that I was happy with, a nice Lamborghini Murcielago.

So exporting my model to use in Away3D was a bit of a pain, it could be because Blender 2.56 is still a beta version and full import / export support for the obj format isn’t in there yet, but due to the fact I had to export each material type into its own obj file and then edit it so that the .mtl file that came with it wasn’t used so that I could create my own materials in Away3D. Hopefully in the future, especially when Unity finally release a version with Flash export support, dealing with models etc should become a lot easier and should simply involve dropping the model into the IDE. So now that I had my obj files ready to import into Away3D, I decided to create a class per obj to load them in individually, these all extended an abstract class as the main functionality is the same for each model, the only part that differed was the materials which was just over-riden per model.

< view plain text >
  1. public function Chrome(view : View3D, lights : Array, name : String, _parent:*)
  2.         {
  3.             super(view, lights, name, _parent);
  4.         }
  6.         override protected function assignMaterial() : void
  7.         {                  
  8.             var _material:ColorMaterial = new ColorMaterial(0xc0c0c0, 1);
  9.             _material.specular = 1;
  10.             _material.ambient = 0.5;
  12.             _material.specularMethod = new FresnelSpecularMethod(true);
  13.             _material.addMethod(new EnviromentMap());
  14.             _material.gloss = 10;
  16.             _material.ambientColor = 0x555555;
  17.             _material.diffuseMethod = new BasicDiffuseMethod();
  18.             _material.lights = _lights;
  20.             mesh.material = _material;
  22.             this.dispatchEvent(new UltraEvent(UltraEvent.OBJ_COMPLETE));
  23.         }

As Away3D stands at the moment, the ResourceManager that is used to load in assets is a singleton class and so can only do one load at a time, looking through the Away3D source code it looks like this is intended to change but that is the way it is at the moment. Anyway again I can’t praise enough the work that has gone into Away 3D to make this great new API available to someone like myself who has no experience working with openGL / DirectX or any type of shaders. The simplicity of Away3D makes creating the materials a breeze and giving materials nice reflections is very simple. For this example as the environment map is used on multiple materials I encapsulated it in a class to re-suse per model. The environment mapping for this is simple and shown clearly on the Away3D examples, in fact the images I used for the mapping I took straight from the Away3D Environment map example.

< view plain text >
  1. public function EnviromentMap(envMap : CubeMap = null, _alpha: Number = 1)
  2.         {          
  3.             _envMap = new CubeMap(  new EnvPosX().bitmapData, new EnvNegX().bitmapData,
  4.                                     new EnvPosY().bitmapData, new EnvNegY().bitmapData,
  5.                                     new EnvPosZ().bitmapData, new EnvNegZ().bitmapData);
  6.             envMap = _envMap;      
  7.             super(envMap, _alpha);
  8.         }

Anyway I am really pleased with not only the visual effects achieved, but also the performance on this as again with a reasonably complex model that would of completely choked in previous versions of flash, I still got a good frame rate on my old laptop. I am also impressed that all in all this example didn’t really add up to a huge amount of work, but of course, with third party tools that will be available in the near future for exporting these kind of models straight to flash, this will become a lot easier.

I think next I would be interested in getting the same model into webGL, not only to test the development pipeline, which I don’t expect to be too dissimilar, but also to see the finished results.

Get the source code for my example here.

This entry was posted in Actionscript 3.0, Away 3D, Molehill and tagged , , . Bookmark the permalink.

6 Responses to More Molehill & Away3D Fun

  1. parizer says:

    add the parameter wmode=direct in html embed code to enable hardware acceleration

  2. happy says:


  3. pete shand says:

    very cool, nice work

  4. demos says:

    i have a question.
    how can i do add a light on a cube in away3d 4?
    code like this.

    var bmd1:BitmapData = new Mr1().bitmapData;
    var bmd2:BitmapData = new Mr2().bitmapData;
    var bmd3:BitmapData = new Mr3().bitmapData;
    var bmd4:BitmapData = new Mr4().bitmapData;
    var bmd5:BitmapData = new Mr5().bitmapData;
    var bmd6:BitmapData = new Mr5().bitmapData;
    var cubeMap:CubeMap = new CubeMap(bmd4, bmd2, bmd5, bmd5, bmd1, bmd3);
    var mat:SkyBoxMaterial = new SkyBoxMaterial(cubeMap);
    mat.lights = [Away3DWorld.pointLight];
    _cube = new Cube(mat, 80, 70, 70, 5,5, 5, false);
    _cube.material.lights = [Away3DWorld.pointLight];

  5. UltraVisual says:

    You would need to add a light to the scene first:

    var pl:PointLight = new PointLight();
    pl.x = 500;
    pl.y = 500;
    pl.z = -500;

    Then you would need to assign this light to the material as you have in your snippet as an array:

    mat.lights = [pl];

    Of course if you have more than one light for that material you just add them to the array assigned to the lights:

    mat.lights = [pl, pl2, pl3, pl4];

    Hope that helps

  6. demos says:

    first. thanks for you reply.
    i have already add a light on the scene.
    and set lights of material.
    oh, i encounter problem is how add a light on the SkyBoxMaterial.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>