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.
- public function Chrome(view : View3D, lights : Array, name : String, _parent:*)
- super(view, lights, name, _parent);
- override protected function assignMaterial() : void
- var _material:ColorMaterial = new ColorMaterial(0xc0c0c0, 1);
- _material.specular = 1;
- _material.ambient = 0.5;
- _material.specularMethod = new FresnelSpecularMethod(true);
- _material.addMethod(new EnviromentMap());
- _material.gloss = 10;
- _material.ambientColor = 0x555555;
- _material.diffuseMethod = new BasicDiffuseMethod();
- _material.lights = _lights;
- mesh.material = _material;
- this.dispatchEvent(new UltraEvent(UltraEvent.OBJ_COMPLETE));
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.
- public function EnviromentMap(envMap : CubeMap = null, _alpha: Number = 1)
- _envMap = new CubeMap( new EnvPosX().bitmapData, new EnvNegX().bitmapData,
- new EnvPosY().bitmapData, new EnvNegY().bitmapData,
- new EnvPosZ().bitmapData, new EnvNegZ().bitmapData);
- envMap = _envMap;
- super(envMap, _alpha);
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.