Creating Material with only a light source possible?

Software: Away3D 4.x

Yashin, Newbie
Posted: 30 January 2013 01:53 PM   Total Posts: 11

Hello all.
I have loaded an .obj object in my project. The loaded objects gets all its material information through the accompanied mtl file. But what is only missing is that i need to apply a light source to the mesh.

My question is, how do i create a material without any color information or texture information but with only a source of light?

If i apply the code below, “myTexture” will be applied to all the meshes as well as a light source. If i comment “mesh.material = _aMaterial ;”, the correct texture information will be retrieved from the mtl file but no light. So I need to create a material giving only a light source.

Anyone can help me please?

private function onModelParseComplete(e:AssetEvent):void
{
    
var mesh Mesh;

   
_aMaterial = new TextureMaterial(Cast.bitmapTexture(myTexture));
   
_aMaterial.shadowMethod = new FilteredShadowMapMethod(_light);
   
_aMaterial.lightPicker _lightPicker;
   
_aMaterial.specular 0;

    for (var 
int 0loader.numChildren; ++i{

 mesh 
Mesh(loader.getChildAt(i));
 
mesh.material _aMaterial ;
    

 

 

   

Avatar
Fabrice Closier, Administrator
Posted: 30 January 2013 02:11 PM   Total Posts: 1265   [ # 1 ]

if you replace mesh.material = sameMaterialWithLightForEveryMesh; that you have with:

if(!mesh.material.lightPicker && mesh.material.lightPicker != _lightPicker)
  mesh.material.lightPicker = _lightPicker;

The extra check is there to check if the picker was already assigned, as the material may be shared.

 

   

Yashin, Newbie
Posted: 30 January 2013 02:50 PM   Total Posts: 11   [ # 2 ]

Hello,
Thanks it works! smile

However I still need to fix two things :

- Only meshes having texture information in the MTL file has a light source. Other meshes with only color information are rendered plain with no light information.

- The object does not cast its own shadow within itself.

 

   

Avatar
Fabrice Closier, Administrator
Posted: 30 January 2013 03:18 PM   Total Posts: 1265   [ # 3 ]

to your first question: That’s a possible outcome because you do parse only the first container. You could achieve what you want doing this way using a recursive method that would “visit” all the elements of the scenegraph.
A much easy way to proceed is to add an AssetEvent listener, and check on assetComplete if its a material. Instead of checking meshes. Where the proposed check from past reply would be of course unnecessary, as Material are finalized and dispatched only once.

For the second point, you need to set castShadow to true, and you will probably have to measure your model size in case you do not know it, in order to set your camera.lens near and far accordingly.

 

   

Yashin, Newbie
Posted: 31 January 2013 08:27 AM   Total Posts: 11   [ # 4 ]

Well, for the lights, castShadows is set to true.

_mainLight = new PointLight();
   
_mainLight.castsShadows true;
   
_mainLight.800;
   
_mainLight.color 0xaaaaff;
   
_mainLight.diffuse 1;
   
_mainLight.specular 1;
   
_mainLight.radius 400;
   
_mainLight.fallOff 500;
   
_mainLight.ambient 0xa0a0c0;
   
_mainLight.ambient .5;
   
away3DScene.scene.addChild(_mainLight);
   
    
_light2  = new DirectionalLight(0, -11);
    
_light2.castsShadows true;
    
_lightPicker  = new StaticLightPicker([_light2_mainLight]);
  
   
away3DScene.scene.addChild(_light2);
   
   
_aMaterial = new TextureMaterial(Cast.bitmapTexture(SandTexture));
   
_aMaterial.shadowMethod = new FilteredShadowMapMethod(_light2);
   
_aMaterial.lightPicker _lightPicker;
   
_aMaterial.specular 0;
   
_ground = new Mesh(new PlaneGeometry(60006000), _aMaterial);
   
away3DScene.scene.addChild(_ground); 

Don’t you think it has something to do with shadowMethod of the material assigned to the object? Because if I use a material declared in the codes and
assign

_aMaterial.shadowMethod = new FilteredShadowMapMethod(_light2); 

It works perfectly. But when I use the material from the MTL file, the shadow for the object ( Its own shadow within itself ) is not present. Check the preview to understand what I mean.

 

 

   

Yashin, Newbie
Posted: 31 January 2013 08:37 AM   Total Posts: 11   [ # 5 ]

Well I managed to do it. It was quite easy.

var mesh Mesh;
   var 
myMaterial TextureMaterial = new TextureMaterial();

   
   for (var 
int 0loader.numChildren; ++i{
    
//trace("i : " + i);
     
mesh Mesh(loader.getChildAt(i));
     if(!
mesh.material.lightPicker && mesh.material.lightPicker != _lightPicker)
      
mesh.material.lightPicker _lightPicker;
      
     
myMaterial mesh.material as TextureMaterial ;
     
myMaterial.shadowMethod = new FilteredShadowMapMethod(_light2);
     
   

 

 

   

Avatar
Fabrice Closier, Administrator
Posted: 31 January 2013 08:56 AM   Total Posts: 1265   [ # 6 ]

The very same case as your lights issue… Glad you found out wink

 

   

Yashin, Newbie
Posted: 31 January 2013 09:09 AM   Total Posts: 11   [ # 7 ]

:D

What about getting softer shadows?
I’ve tried SoftShadowMapMethod instead of FilteredShadowMapMethod but it is not making a difference.

 

   

relgycandy, Newbie
Posted: 04 March 2013 06:37 AM   Total Posts: 3   [ # 8 ]

A much easy way to proceed is to add an AssetEvent listener, and check on assetComplete if its a material. Instead of checking meshes. Where the proposed check from past reply would be of course unnecessary, as Material are finalized and dispatched only once.

 


_____________________________________
wow gold|diablo 3 gold|wow gold kaufen|GW2 Gold

 

 

   

kingston250, Newbie
Posted: 16 March 2013 12:08 PM   Total Posts: 11   [ # 9 ]

Yes it think SoftShadowMapMethod is better then it and also easy to use. i am also use this SoftShadowMapMethod mostly and satisfied with the services of it.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X