Limdor - 2013-12-09

Hi,

I'm trying to get material properties but with some of them it doesn't work. I get a AI_FAILURE.
I've checked the materials web page and because I'm using C++ I use the system explained.

if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_NAME, name) )

But in the file types.h it said that I shouldn't use the AI_SUCCESS constant.

// just for backwards compatibility, don't use these constants anymore
#define AI_SUCCESS     aiReturn_SUCCESS
#define AI_FAILURE     aiReturn_FAILURE
#define AI_OUTOFMEMORY aiReturn_OUTOFMEMORY

Can you explain me what I'm doing wrong? I attach a code to show how I get the material properties.

Thanks

void SceneLoader::ShowMaterialInformation(const aiMaterial* pMaterial)
{
    aiString name;
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_NAME, name) )
    {
        Debug::Log( QString("   Name: %1").arg(name.data) );
    }
    aiColor3D color;
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_AMBIENT, color) )
    {
        Debug::Log( QString("   Ambient color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_DIFFUSE, color) )
    {
        Debug::Log( QString("   Diffuse color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_EMISSIVE, color) )
    {
        Debug::Log( QString("   Emissive color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_REFLECTIVE, color) )
    {
        Debug::Log( QString("   Reflective color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_SPECULAR, color) )
    {
        Debug::Log( QString("   Specular color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    float value;
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_SHININESS, value) )
    {
        Debug::Log( QString("   Shininess: %1").arg(value) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_SHININESS_STRENGTH, value) )
    {
        Debug::Log( QString("   Shininess strength: %1").arg(value) );
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_COLOR_TRANSPARENT, color) )
    {
        Debug::Log( QString("   Transparent color: (%1, %2, %3)").arg(color.r).arg(color.g).arg(color.b) );
    }
    int intValue;
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_ENABLE_WIREFRAME, intValue) )
    {
        if( intValue == 0 )
        {
            Debug::Log( QString("   Wireframe: Disabled") );
        }
        else if( intValue == 1 )
        {
            Debug::Log( QString("   Wireframe: Enabled") );
        }
        else
        {
            Debug::Warning( QString("   Wireframe: Unexpected value") );
        }
    }
    if( AI_SUCCESS == pMaterial->Get(AI_MATKEY_SHADING_MODEL, intValue) )
    {
        Debug::Log( QString("   Shading model: %1").arg(intValue) );
    }
    unsigned int aux = pMaterial->GetTextureCount(aiTextureType_AMBIENT);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of ambient textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_AMBIENT, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_DIFFUSE);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of diffuse textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_DIFFUSE, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_DISPLACEMENT);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of displacement textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_DISPLACEMENT, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_EMISSIVE);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of emissive textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_EMISSIVE, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_HEIGHT);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of height textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_HEIGHT, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_LIGHTMAP);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of lightmap textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_LIGHTMAP, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_NORMALS);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of normals textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_NORMALS, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_OPACITY);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of opacity textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_OPACITY, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_REFLECTION);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of reflection textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_REFLECTION, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_SHININESS);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of shininess textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_SHININESS, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_SPECULAR);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of specular textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_SPECULAR, i);
        }
    }
    aux = pMaterial->GetTextureCount(aiTextureType_UNKNOWN);
    if( aux > 0 )
    {
        Debug::Log( QString("   Number of unknown textures: %1").arg( aux ) );
        for( unsigned int i = 0; i < aux; i++ )
        {
            ShowTextureInformation(pMaterial, aiTextureType_UNKNOWN, i);
        }
    }
}

void SceneLoader::ShowTextureInformation(const aiMaterial* pMaterial, aiTextureType pType, unsigned int pTextureNumber)
{
    aiString path;
    aiTextureMapping mapping;
    unsigned int uvindex;
    float blend;
    aiTextureOp op;
    aiTextureMapMode mapmode;
    Debug::Log( QString("      Information of texture %1").arg(pTextureNumber) );
    if( AI_SUCCESS == pMaterial->GetTexture( pType, pTextureNumber, &path, &mapping, &uvindex, &blend, &op, &mapmode ) )
    {
        Debug::Log( QString("         Path: %1").arg(path.data) );
        Debug::Log( QString("         UV index: %1").arg(uvindex) );
        Debug::Log( QString("         Blend: %1").arg(blend) );
    }
    else
    {
        Debug::Log( QString("         Impossible to get the texture") );
    }
}