Unless real-time lighting is really needed, here's what I would do:

Pre-render two maps in a 3D program; color, and gloss.
Use a regular bitmap material for the car in Away3D.
Depending on user input, composite a color map (plain color), the
color from the 3D program (which contains the texture) and the gloss
into a single BitmapData. The degree of influence from each map is
decided from the user settings.
Use the above BitmapData for the bitmap material (by re-setting
myMaterial.bitmap).


Cheers
/R


On Jan 4, 11:24 am, Jochem Neerhof <[email protected]> wrote:
> Hello Away'ers,
>
> I've got a question. But first I'll explain my problem.
> I have to build a 3d car configurator for a school project. The car's
> paint can be modified by the user on a few different levels: the
> color, brightness and reflection intensity.
>
> My current code:
> package
> {
>         import away3d.cameras.*;
>         import away3d.containers.*;
>         import away3d.core.utils.*;
>         import away3d.lights.PointLight3D;
>         import away3d.materials.*;
>         import away3d.core.render.*;
>
>         import flash.display.*;
>         import flash.events.*;
>
>         import flash3dbook.common.MonkeyMesh;
>
>         [SWF(width="800", height="600")]
>
>         public class AutoConfigurator3d extends Sprite{
>                 [Embed(source="jazz_transparant.png")]
>                 private var AutoTextuur : Class;
>                 [Embed(source="jazz_nm.jpg")]
>                 private var AutoNormals : Class;
>
>                 private var _colorMaterial : ColorMaterial;
>                 private var _autoTexMaterial : BitmapData;
>                 private var _autoNmMaterial : BitmapData;
>                 private var _bitmapMaterial : Dot3BitmapMaterial;
>
>                 protected var _view : View3D = new View3D({camera:_camera,
> renderer:Renderer.CORRECT_Z_ORDER});
>                 protected var _camera : HoverCamera3D;
>                 protected var _auto : HondaMesh;
>                 protected var _auto2 : HondaMesh;
>
>                 protected var _state : int = 0;
>
>                 public function AutoConfigurator3d(){
>                         _createView();
>                         _createScene();
>                         _createMaterials();
>                         _createLight();
>                 }
>
>                 protected function _createView() : void{
>                         _camera = new HoverCamera3D();
>                         _camera.distance = 150;
>                         _camera.tiltAngle = 10;
>
>                         _view.x = 400;
>                         _view.y = 300;
>                         _view.camera = _camera;
>                         addChild(_view);
>
>                         stage.addEventListener(Event.ENTER_FRAME, 
> _onEnterFrame);
>                         stage.addEventListener(MouseEvent.CLICK, _onClick);
>                 }
>
>                 protected function _createScene() : void{
>                         _auto = new HondaMesh();
>                         _auto.scale(0.005);
>                         _auto2 = new HondaMesh();
>                         _auto2.scale(0.004995);
>                         _auto.invertFaces();
>                         _auto2.invertFaces();
>                         _view.scene.addChild(_auto2);
>                         _view.scene.addChild(_auto);
>                 }
>
>                 protected function _createMaterials() : void {
>                         _colorMaterial = new ColorMaterial(0xFFAA00);
>
>                         _autoNmMaterial = Cast.bitmap(AutoNormals);
>                         _autoTexMaterial = Cast.bitmap(AutoTextuur);
>
>                         _bitmapMaterial = new 
> Dot3BitmapMaterial(_autoTexMaterial,
> _autoNmMaterial);
>                         _bitmapMaterial.specular = 0xFFFFFF;
>
>                         _auto.material = _bitmapMaterial;
>                         _auto2.material = _colorMaterial;
>                 }
>
>                 protected function _createLight():void{
>                         var licht : PointLight3D = new PointLight3D();
>                         licht.color = 0xFF0000;
>                         licht.brightness = 2.0;
>                         licht.x = 100;
>                         licht.y = 300;
>                         licht.z = 100;
>                         licht.diffuse = 0.1;
>
>                         _view.scene.addLight(licht);
>                 }
>
>                 protected function _toggle() : void {
>                         switch (_state) {
>                                 case 0:
>                                         _auto.material = _bitmapMaterial;
>                                         _colorMaterial.color = 0xF00F00;
>                                         _state = 1;
>                                         break;
>                                 case 1:
>                                         _auto.material = _bitmapMaterial;
>                                         _colorMaterial.color = 0xFF0000;
>                                         _state = 2;
>                                         break;
>                                 case 2:
>                                         _auto.material = _bitmapMaterial;
>                                         _colorMaterial.color = 0xFFFF00;
>                                         _state = 3;
>                                         break;
>                                 case 3:
>                                         _auto.material = _bitmapMaterial;
>                                         _colorMaterial.color = 0x00FFFF;
>                                         _state = 0;
>                                         break;
>                         }
>                 }
>
>                 protected function _onClick(ev : MouseEvent) : void {
>                         _toggle();
>                 }
>
>                 protected function _onEnterFrame(ev : Event) : void     {
>                         _camera.panAngle -= (stage.mouseX - stage.stageWidth 
> / 2) / 40;
>                         _camera.hover();
>
>                         _view.render();
>                 }
>         }
>
> }
>
> I was hoping that this all could be altered in 1 single material, but
> so far I had no luck finding a good method. (I just stumbled upon
> CompositeMaterial but haven't looked into it yet)
> Right now I switched to 2 models with different materials. 1 model
> with a bitmapdata texture(semi transparant) showing the texture of the
> car and 1 underlying model (slightly smaller scale) with a color
> material. It's possible to change the color of the car now, but the
> car isn't shown right. That's because the cars use ownCanvas.
> So i turned that off and I tried to use the CORRECT_Z_ORDER renderer
> to show the car, but this doesn't work because of the smaller scale of
> the underlying model (it shows through the upper model in certain
> places).
>
> Even if i get this working correctly there is thill the issue of
> applying the reflection correctly.
>
> So here is my question. Is there a better way to solve my problem or
> should I continue and try to fix my current code?

Reply via email to