Problem with multiple specular map

Software: Away3D 4.x

lior_hai, Newbie
Posted: 01 August 2013 03:15 PM   Total Posts: 10

I have an issue I am straggling to solve and hoped for some help.

I have build a scene with a loaded 3DS model. I run through all mesh names in loaded model and add specular map & normal map to each based on it’s name.

I also add to all meshs:

FresnelSpecularMethod
EnvMapAmbientMethod
BasicAmbientMethod


The problam is with the spacular map.
All maps works fine but the specular, the specular maps of all meshs is destroyed and replaces by the last specular map added to a mesh in the model.

I have a mesh called “final” in my model. It is the last asset loaded (last asset loaded event to dispatch). All meshs in the scene got “final” specular map even though the normals is correct and each was assigned with uniqe map.

My AsserLoaded function

private function onAsset(event:AssetEvent):void
  {
      
   
if(event.asset.assetType == "mesh")
   
{
    
var mesh:Mesh;
    var 
mat_maps:Array;
    
//create mesh of current part
    
mesh Mesh(event.asset);
    
    
city_container.addChild(mesh);
    
    
//create materials
    
mat_maps materials.getMaps(mesh.name);
    
TextureMaterial(mesh.material).normalMap mat_maps["norm"];
    
TextureMaterial(mesh.material).specularMap mat_maps["spec"];
    
TextureMaterial(mesh.material).gloss mat_maps["gloss"];
    
TextureMaterial(mesh.material).specularMethod mat_maps["spec_method"];
    
TextureMaterial(mesh.material).ambientMethod mat_maps["amb_method"];
    
mesh.material.lightPicker lightPicker;
         
}


My getMaterial function

public function getMaps(obj_name:String):Array
  
{
   
var maps:Array = new Array;
   
   var 
map_norm:Texture2DBase;
   var 
map_spec:Texture2DBase;
   
   
   if(
obj_name.substr(05) == "space")//column
   
{
    maps[
"norm"= new BitmapTexture(new ShipNorm().bitmapData);
    
maps["spec"= new BitmapTexture(new ShipSpec().bitmapData);
    
maps["gloss"50;
    
maps["spec_method"fresnal_specular_method;
    
maps["amb_method"ambient_env_method;
    
maps["cast_shadow"false;
   
}
   
else if(obj_name.substr(05) == "brick")//wall
   
{
    maps[
"norm"= new BitmapTexture(new WallNorm().bitmapData);
    
maps["spec"= new BitmapTexture(new WallSpec().bitmapData);
    
maps["gloss"50;
    
maps["spec_method"fresnal_specular_method;
    
maps["amb_method"ambient_env_method;
    
maps["cast_shadow"false;
   
}
   
   
else if(obj_name == "final")//floor
   
{
    maps[
"norm"= new BitmapTexture(new FinalNorm().bitmapData);
    
maps["spec"= new BitmapTexture(new FinalSpec().bitmapData);
    
maps["gloss"50;
    
maps["spec_method"fresnal_specular_method;
    
maps["amb_method"ambient_env_method;
    
maps["cast_shadow"false;
   
}
   
   
return maps;
  

I have exhausted every option I could think about…
Any help will be great. If any other clerification needed please ask.

   

lior_hai, Newbie
Posted: 02 August 2013 07:05 AM   Total Posts: 10   [ # 1 ]

I don’t understand your reply.

Any help? Anyone? Does anything in the code above looks not right?

   

dtramer2, Newbie
Posted: 02 August 2013 01:19 PM   Total Posts: 16   [ # 2 ]

I’m new here, but looking through the away3d code, it seems that maybe when you set the specular map, that under the covers it is setting the map on the specular method.  Since you are sharing the specular method between meshs it might be overwriting the previous specular map. So, maybe try creating a new specular method for each mesh type.

   

dtramer2, Newbie
Posted: 02 August 2013 03:11 PM   Total Posts: 16   [ # 3 ]

A funny thing that might make what I’m saying seem unlikely is that you’re setting the method after the map.

what’s happening internally is that when you set the specular method, the map gets copied over from the default method to the method passed in.

The away code seems a bit smelly in this area.

   

lior_hai, Newbie
Posted: 03 August 2013 04:52 PM   Total Posts: 10   [ # 4 ]

Thanks for your reply.

I tried changing the order of specular method and specular map creation with no result change.

I suspcted this part of the code…

The thing is i create the specular method befor anything else, when looking at the specular method class i didn’t see anything related to a map so i figuered it can’t be it.

I will keep on digging even though it’s just an experimental game i am working on but when using both specular map and method i got some awsome results and it sucks to let one of them go…

Any farther help will be great.

   

dtramer2, Newbie
Posted: 03 August 2013 05:53 PM   Total Posts: 16   [ # 5 ]

lior_hai, I think maybe you just read my second post, and not my first.

Let me try again and say it more plainly:

Don’t reuse the specular method object.  Create a new one for each specular map.

   

lior_hai, Newbie
Posted: 03 August 2013 07:06 PM   Total Posts: 10   [ # 6 ]

It worked, thank you.

Question though. Does it make a difference in performance? Having a dozen methods instead of 1?

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X