FTK - getting materials

I'm trying to use the XSI FTK to convert .xsi files to my 3D engine filetype, but I can't afford to read materials. I use this code:

CSLScene XSIScn;
CSLMaterialLibrary *MaterialLibrary;
CSLMaterial **MatList;

if (XSIScn.Open(filename) != SI_SUCCESS)
return false;

XSIScn.Read();

MaterialLibrary = XSIScn.GetMaterialLibrary();
MatList = (CSLMaterial**)MaterialLibrary->GetMaterialList();

for (int m=0; mGetMaterialCount(); m++)
{
// Here I should have to analize each material,
// but if I call MatList[m]->GetDiffuseColor or other
// methods of the class I get an exception and
// the program terminates...
}

Anybody can help me? The FTK help is not clear about this...

Thanks in advance
nICO

Hi nICO,

There are 2 materials type:
* SI_MATERIAL (exported in dotXSI 3.5 format) : with common functions
* XSI_MATERIAL (exported from the dotXSI 3.6 format): with this you have the render tree exported, not the common components.
Both herit from CSLBaseMaterial.

So you have to test which material you read with the function Type();
if (pMaterial->Type() == CSLTemplate::SI_MATERIAL)
{
CSLMaterial mat = (CSLMaterial)pMaterial;
... mat->GetAmbientColor() ...
... mat->GetDiffuseColor() ...
}
else
{
CSLXSIMaterial mat = (CSLXSIMaterial)pMaterial;

//read connections
//read shaders and shaders parameters...

}

Have a look in the SLTest sample from the FTK 3.6.3.
If you just need a common material (ambient, diffuse...), I advise you to use only dotXSI format 3.5.

Gwen