[Resolved]Add lightPicker to a awd model loaded by Loader3D

Software: Away3D 4.x

Avatar
ibsenleo, Newbie
Posted: 14 October 2014 05:04 PM   Total Posts: 8

im loading a model by Loader3D, and this model (is a complete map) has a some subgeometries and some sub textures (im new in this, maybe this is the usual). The problem is everything seems to plain like the lightpicker is not being applied to the materials.

Here i load the map:

_light = new DirectionalLight(-1, -11);
_light.color 0xFFFFFF;
_light.ambient 0
_light
.diffuse 1
_light
.specular 1;
_scene.addChild(_light);
   
_lightPicker = new StaticLightPicker([_light]);

_loader = new Loader3D();
_loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE,onResourceComplete);
_loader.load(new URLRequest('./assets/models/maptest.awd')); 

in the assetEvent, i assign the lightPicker to the textures:

private function onAssetComplete(AssetEvent) : void
{
   
var asset:IAsset e.asset;
   
trace(asset.name+" Cargado!");
 
    if (
asset.assetType == AssetType.MATERIAL)
    
{
        
if(asset is TextureMaterial)
        
{
            
var material:TextureMaterial asset as TextureMaterial
            material
.shadowMethod = new FilteredShadowMapMethod(_light);
            
material.shadowMethod.epsilon 0.1;
            
material.lightPicker _lightPicker;
            
material.specular 0.5;   
        
}
  
        
if (asset is ColorMaterial)
        
{
            
var cmaterial:ColorMaterial asset as ColorMaterial
            cmaterial
.shadowMethod = new FilteredShadowMapMethod(_light);
            
cmaterial.shadowMethod.epsilon 0.1;
            
cmaterial.lightPicker _lightPicker;
            
cmaterial.specular 0.5;
        
}
    trace
("Texture processed");
    
}

and in the Complete event, add the mesh to the scene:

private function onResourceComplete(LoaderEvent) : void
{
    
var mesh:Mesh  _loader.getChildAt(0) as Mesh  
    _scene
.addChild(mesh);

i also tried in this way:

//Loading complete resource
private function onResourceComplete(LoaderEvent) : void
{
    
var mesh:Mesh  _loader.getChildAt(0) as Mesh
  
    
var mat:* = mesh.material;
    
mat.shadowMethod = new FilteredShadowMapMethod(_light);
    
mat.shadowMethod.epsilon 0.1;
    
mat.lightPicker _lightPicker;
    
mat.specular 0.5;
    
_scene.addChild(mesh);
   

The textures are correctly loaded and the lights projects a very weak shadow on the material, but there is no ambient light at all. no light ranges, plain.

I’ve tried changing light values but the same.
Any suggestion?

ps: i’ve tried to what is in this post http://away3d.com/forum/viewthread/3865/ howev,er i couldnt load the map with the AssetManager.

   

Avatar
ibsenleo, Newbie
Posted: 17 October 2014 01:14 PM   Total Posts: 8   [ # 1 ]

Ok, after a long search into the away3D framework and research in away builder i could solve the problem.

Maybe the main reason of this little issue is the way how the plugin in 3DMax exports the materials (maybe im not very skilled with it, because as i said in the previous post i’m new in this) but i could solve doing this:

private function onAssetComplete(AssetEvent) : void
  {
   
var texturaCont:TextureMaterial;
   var 
asset:IAsset e.asset;
   
//trace(asset.name+" Cargado!");
   
   
if (asset.assetType == AssetType.MATERIAL)
   
{
    
if(asset is TextureMaterial)
    
{
     
var material:TextureMaterial asset as TextureMaterial
     material
.ambientTexture null;
     
material.shadowMethod = new FilteredShadowMapMethod(_light);
     
material.ambientMethod = new BasicAmbientMethod();
     
material.diffuseMethod = new BasicDiffuseMethod();
     
material.shadowMethod.epsilon 0.1;
     
material.lightPicker _lightPicker
     material
.specular 0.5;
        
}
    }

The reason as i could see is by default, Away creates the materials with some properties like the ambientMethod, diffuseMethod, etc. but in my case, the exportation from 3DMax for any reason was taking values in the ambientMethod and was overlaying the ambient texture property (material.ambientTexture) in the imported model. So the ambient light was unable to see giving a plain lightning in the whole imported model.

What i did was create a new AmbientMethod and set the ambientTexture to “null” because i could’n reach the way to change the next property with this value:

material.diffuseMethod.useAmbientTexture=false 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X