示例#1
0
IVertexDecl * ParseVertexFormat( CXMLElement * pBranch )
{
	IVertexDecl * pDecl = g_pRenderer->CreateVertexDecl();

	if ( !pDecl )
		return NULL;

	uint nOffset = 0;

	// Перебираем все дочерние элементы ----------------------------------------

	for ( size_t n = 0; n < pBranch->GetNumChilds(); ++n )
	{
		CXMLElement * pInputElem = pBranch->GetChild( n );
		CXMLAttr * pType = pInputElem->GetAttr( "Type" );
		CXMLAttr * pSem = pInputElem->GetAttr( "D3D_Semantic" );

		ETypeID eType = g_pSystem->GetType( pType->GetValue() );

		pDecl->AddAttr(
			pInputElem->GetName(),
			( NULL != pSem ) ? pSem->GetValue() : NULL,
			eType, nOffset );

		nOffset += g_pSystem->GetSizeOf( eType );
	}

	pDecl->SetStride( nOffset ); // Записывам шаг (размер) вершины в байтах 

	return pDecl;
}
示例#2
0
void CModel::Load( const char * szFile )
{
    CXMLElement * pModelXML = NULL;
    g_pXMLWrapper->LoadXML( szFile, &pModelXML );

    if ( !pModelXML )
        return;

    CXMLElement * pMeshXML = pModelXML->GetChild( "Mesh" );

    if ( pMeshXML )
    {
        CXMLAttr * pMeshAttr = pMeshXML->GetAttr( "File" );

        if ( pMeshAttr )
        {
            LoadObjects( pMeshAttr->GetValue() );
        }

        //----------------------------------------------------------------------
        // Tip: Читаем материалы
        //----------------------------------------------------------------------
        for ( uint n = 0; n < pMeshXML->GetNumChilds(); ++n )
        {
            LoadMaterial( pMeshXML->GetChild( n ) );
        }
    }

    //--------------------------------------------------------------------------
    //
    //--------------------------------------------------------------------------
    CXMLElement * pAnimXML = pModelXML->GetChild( "Animations" );

    if ( pAnimXML )
    {
        for ( uint n = 0; n < pAnimXML->GetNumChilds(); ++n )
        {
            CXMLElement * pCurAnimXML = pAnimXML->GetChild( n );

            CXMLAttr * pFileAttr = pCurAnimXML->GetAttr( "File" );
            CXMLAttr * pNameAttr = pCurAnimXML->GetAttr( "Name" );

            CAnim * pAnim = NEW CAnim;

            if ( pAnim->Load( pFileAttr->GetValue() ) )
            {
                pAnim->SetName( pNameAttr->GetValue() );
                AddAnim( pAnim );
                PlayAnim( "test_anim" );
                continue;
            }

            DEL( pAnim );
        }
    }

    DEL( pModelXML );
}