Explanation needed: applying a light to a loaded mesh/material

Software: Away3D 4.x

Sean72, Newbie
Posted: 10 April 2013 04:58 PM   Total Posts: 28

Hey there,

I have been trying to grasp the process of lighting loaded 3D models.  Are we supposed to apply the light to the model, the material, or both?  There doesn’t e.g. appear to be a way to handle this directly to an instance of Loader3D. 

And if the materials are loaded with the object e.g. in AWD2 format, then we don’t explicitly know what they are so there must be a way to access them.

I have seen some code e.g. from the ant example:

private function onAssetComplete(event:AssetEvent):void
  {
   
if (event.asset.assetType == AssetType.MESH{
    
var mesh:Mesh event.asset as Mesh;
    
mesh.castsShadows true;
   
else if (event.asset.assetType == AssetType.MATERIAL{
    
var material:TextureMaterial event.asset as TextureMaterial;
    
material.shadowMethod = new FilteredShadowMapMethod(_light);
    
material.lightPicker _lightPicker;
    
material.gloss 30;
    
material.specular 1;
    
material.ambientColor 0x303040;
    
material.ambient 1;
   
}
  } 

However, there is some coercion here, and I’m one of those people who need to understand what and why before I can just paste code in and hope it works.

Thanks!

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 11 April 2013 12:31 AM   Total Posts: 166   [ # 1 ]

In your code, ambient parameter is 1.
It means no shade.
Change it lower value.

Cheers.

   

Sean72, Newbie
Posted: 14 April 2013 08:15 PM   Total Posts: 28   [ # 2 ]

Thanks for the help.  With specular on, ambient can be set to 1 and you will still see the light highlights.  However, my problem came from a misunderstanding of ASSET_COMPLETE.  Unlike RESOURCE_COMPLETE, ASSET_COMPLETE happens for every mesh (and a few others namely ‘geometry’ and ‘container’ and ‘texture’ which I don’t know what to do with) in a loaded object.  I was following a code example that disabled ASSET_COMPLETE after only one call, and this was the problem.

   
   
‹‹ Rolling a dice

X

Away3D Forum

Member Login

Username

Password

Remember_me



X