コード例 #1
0
ファイル: SkeletonMeshBuilder.cpp プロジェクト: abc00/adrian
// ------------------------------------------------------------------------------------------------
// Creates a dummy material and returns it.
aiMaterial* SkeletonMeshBuilder::CreateMaterial()
{
	Assimp::MaterialHelper* matHelper = new Assimp::MaterialHelper;

	// Name
	aiString matName( std::string( "SkeletonMaterial"));
	matHelper->AddProperty( &matName, AI_MATKEY_NAME);

	// Prevent backface culling
	const int no_cull = 1;
	matHelper->AddProperty(&no_cull,1,AI_MATKEY_TWOSIDED);

	return matHelper;
}
コード例 #2
0
ファイル: Q3BSPFileImporter.cpp プロジェクト: niavok/spring
// ------------------------------------------------------------------------------------------------
//	Creates all referenced materials.
void Q3BSPFileImporter::createMaterials( const Q3BSP::Q3BSPModel *pModel, aiScene* pScene,
										Q3BSPZipArchive *pArchive )
{
	if ( m_MaterialLookupMap.empty() )
	{
		return;
	}

	pScene->mMaterials = new aiMaterial*[ m_MaterialLookupMap.size() ];
	aiString aiMatName;
	int textureId( -1 ), lightmapId( -1 );
	for ( FaceMapIt it = m_MaterialLookupMap.begin(); it != m_MaterialLookupMap.end();
		++it )
	{
		const std::string matName = (*it).first;
		if ( matName.empty() )
		{
			continue;
		}

		aiMatName.Set( matName );
		Assimp::MaterialHelper *pMatHelper = new Assimp::MaterialHelper;
		pMatHelper->AddProperty( &aiMatName, AI_MATKEY_NAME );

		extractIds( matName, textureId, lightmapId );
		
		// Adding the texture
		if ( -1 != textureId )
		{
			sQ3BSPTexture *pTexture = pModel->m_Textures[ textureId ];
			if ( NULL != pTexture )
			{
				std::string tmp( "*" ), texName( "" );
				tmp += pTexture->strName;
				tmp += ".jpg";
				normalizePathName( tmp, texName );
				
				if ( !importTextureFromArchive( pModel, pArchive, pScene, pMatHelper, textureId ) )
				{
				}
			}

		}
		if ( -1 != lightmapId )
		{
			importLightmap( pModel, pScene, pMatHelper, lightmapId );
		}
		pScene->mMaterials[ pScene->mNumMaterials ] = pMatHelper;
		pScene->mNumMaterials++;
	}
	pScene->mNumTextures = mTextures.size();
	pScene->mTextures = new aiTexture*[ pScene->mNumTextures ];
	std::copy( mTextures.begin(), mTextures.end(), pScene->mTextures );
}
コード例 #3
0
ファイル: ObjFileImporter.cpp プロジェクト: Distrotech/qt3d
// ------------------------------------------------------------------------------------------------
//    Creates the material
void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pScene )
{
    ai_assert( NULL != pScene );
    if ( NULL == pScene )
        return;

    const unsigned int numMaterials = (unsigned int) pModel->m_MaterialLib.size();
    pScene->mNumMaterials = 0;
    if ( pModel->m_MaterialLib.empty() )
    {
        DefaultLogger::get()->debug("OBJ: no materials specified");
        return;
    }
    pScene->mMaterials = new aiMaterial*[ numMaterials ];
    for ( unsigned int matIndex = 0; matIndex < numMaterials; matIndex++ )
    {
        Assimp::MaterialHelper* mat = new Assimp::MaterialHelper;

        // Store material name
        std::map<std::string, ObjFile::Material*>::const_iterator it;
        it = pModel->m_MaterialMap.find( pModel->m_MaterialLib[ matIndex ] );

        // No material found, use the default material
        if ( pModel->m_MaterialMap.end() == it )
            continue;

        ObjFile::Material *pCurrentMaterial = (*it).second;
        mat->AddProperty( &pCurrentMaterial->MaterialName, AI_MATKEY_NAME );

        // convert illumination model
        int sm = 0;
        switch (pCurrentMaterial->illumination_model)
        {
        case 0:
            sm = aiShadingMode_NoShading;
            break;
        case 1:
            sm = aiShadingMode_Gouraud;
            break;
        case 2:
            sm = aiShadingMode_Phong;
            break;
        default:
            sm = aiShadingMode_Gouraud;
            DefaultLogger::get()->error("OBJ/MTL: Unexpected illumination model (0-2 recognized)");
        }
        mat->AddProperty<int>( &sm, 1, AI_MATKEY_SHADING_MODEL);

        // multiplying the specular exponent with 2 seems to yield better results
        pCurrentMaterial->shineness *= 4.f;

        // Adding material colors
        mat->AddProperty( &pCurrentMaterial->ambient, 1, AI_MATKEY_COLOR_AMBIENT );
        mat->AddProperty( &pCurrentMaterial->diffuse, 1, AI_MATKEY_COLOR_DIFFUSE );
        mat->AddProperty( &pCurrentMaterial->specular, 1, AI_MATKEY_COLOR_SPECULAR );
        mat->AddProperty( &pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS );
        mat->AddProperty( &pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY );

        // Adding refraction index
        mat->AddProperty( &pCurrentMaterial->ior, 1, AI_MATKEY_REFRACTI );

        // Adding textures
        if ( 0 != pCurrentMaterial->texture.length )
            mat->AddProperty( &pCurrentMaterial->texture, AI_MATKEY_TEXTURE_DIFFUSE(0));

        if ( 0 != pCurrentMaterial->textureAmbient.length )
            mat->AddProperty( &pCurrentMaterial->textureAmbient, AI_MATKEY_TEXTURE_AMBIENT(0));

        if ( 0 != pCurrentMaterial->textureSpecular.length )
            mat->AddProperty( &pCurrentMaterial->textureSpecular, AI_MATKEY_TEXTURE_SPECULAR(0));

        if ( 0 != pCurrentMaterial->textureBump.length )
            mat->AddProperty( &pCurrentMaterial->textureBump, AI_MATKEY_TEXTURE_HEIGHT(0));

        if ( 0 != pCurrentMaterial->textureOpacity.length )
            mat->AddProperty( &pCurrentMaterial->textureOpacity, AI_MATKEY_TEXTURE_OPACITY(0));

        if ( 0 != pCurrentMaterial->textureSpecularity.length )
            mat->AddProperty( &pCurrentMaterial->textureSpecularity, AI_MATKEY_TEXTURE_SHININESS(0));

        // Store material property info in material array in scene
        pScene->mMaterials[ pScene->mNumMaterials ] = mat;
        pScene->mNumMaterials++;
    }

    // Test number of created materials.
    ai_assert( pScene->mNumMaterials == numMaterials );
}