//------------------------------------------------------------------------ // Build the animation renderable units to render. //------------------------------------------------------------------------ HRESULT FlyAnimation::BuildMaterials(void) { std::string sMatName; // Get the resource Manager. FlyResourceManager* pResMgr = FlyKernel::Instance().GetResourceManager(); // Build the material datas. for( UINT i=0;i<m_sHeader.nNumMaterials;i++ ) { FLYMATERIAL mat; FlyTexture* pTexture; // Create the render material. char cTemp[20]; sprintf( cTemp,"_%d",i ); sMatName = "anim_" + m_sName + cTemp; FlyRenderMaterial* pMaterial = pResMgr->CreateMaterial( sMatName.c_str() ); if( !pMaterial ) return FLY_OUTOFMEMORY; memcpy( &mat,&m_pMaterials[i],sizeof(FLYMATERIAL) ); pMaterial->SetStdMaterial( 0,&mat ); // Load the texture A. if( m_pMaterials[i].sTexture_A != "" ) { pTexture = pResMgr->Load2DTexture( m_pMaterials[i].sTexture_A.c_str(),0 ); if( pTexture ) { pMaterial->SetTexture( 0,0,pTexture ); if( pTexture->HasAlphaChannel() ) { pMaterial->SetSceneAlphaMode( 0,true,false ); pMaterial->SetAlphaBlendMode( 0,SBM_SRCALPHA,SBM_INVSRCALPHA ); } } } // Load the texture B. if( m_pMaterials[i].sTexture_B != "" ) { pTexture = pResMgr->Load2DTexture( m_pMaterials[i].sTexture_B.c_str(),0 ); if( pTexture ) pMaterial->SetTexture( 0,1,pTexture ); } // Add the material to list. m_RMaterials.push_back( pMaterial ); } return FLY_OK; }
//------------------------------------------------------------------------ // Initialize the vegetation object. // ---------------------------------------------------------------------- // Param -> IN: // VEGETATIONTYPE: Vegetation object type. // const char*: Name of the mesh resource. (Mesh vegetation) // float: Width of the polygon. (Polygon vegetation) // float: Height of the polygon. (Polygon vegetation) // const etFloatRect&: Texture coord rect. // const char*: Path to the texture. // UINT: Count of the polygons. //------------------------------------------------------------------------ HRESULT etVegetationObject::Initialize( VEGETATIONTYPE Type,const char* cMeshName, float fWidth,float fHeight,const etFloatRect& texRect, const char* cTexture,UINT nNumPolygons ) { m_Type = Type; FlyResourceManager* pResMgr = etCoreManager::Instance().GetResourceManager(); FlyMeshManager* pMeshMgr = FlyKernel::Instance().GetMeshManager(); if( Type == VGT_POLYGON ) { // Load the texture from file. m_pTexture = pResMgr->Load2DTexture( cTexture,0 ); // Build the renderable object. return BuildPolygonRenderable( fWidth,fHeight,nNumPolygons,texRect ); } else { m_pMesh = pMeshMgr->GetMeshByName( cMeshName ); pMeshMgr->AddResourceRef( cMeshName ); m_nDirtyState = m_pMesh->GetDirtyState(); // Build the mesh object. return BuildMeshRenderable(); } }