Example #1
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 );
}
Example #2
0
void CShaderCfgLoader::FinalizeRes( TResource * pRes )
{
	pRes->eState = TResource::FAILED;

	//--------------------------------------------------------------------------
	// Tip: Check XMLWrapper
	//--------------------------------------------------------------------------
	IXMLWrapper * pWrapper = (IXMLWrapper *)g_pSystem->GetInterface( IT_UTIL );

	if ( !pWrapper )
		return;

	CXMLElement * pRoot = NULL;
	pWrapper->LoadXMLFromMem( (char *)pRes->pBuffer, pRes->nSize, &pRoot );
	DEL_ARRAY( pRes->pBuffer );
	//pRes->pResource = pRoot;

	//--------------------------------------------------------------------------
	// Tip: Check root element name
	//--------------------------------------------------------------------------
	CStr sName( pRoot->GetName() );

	if ( !sName.Compare( "Shaders" ) )
	{
		DEL( pRoot );
		return;
	}

	//--------------------------------------------------------------------------
	// Tip: Parsing shaders
	//--------------------------------------------------------------------------
	for ( size_t i = 0; i < pRoot->GetNumChilds(); ++i )
	{
		//----------------------------------------------------------------------
		// Tip: New shader
		//----------------------------------------------------------------------
		CXMLElement * pShaderBranch = pRoot->GetChild( i );
		CStr sPath( "Shaders/" );
		sPath.Add( pShaderBranch->GetName() );

//		const CStr		sShader( pShaderBranch->GetName() );
//		CBaseShader	*	pShader	= NEW CBaseShader( sShader.GetString() );
//		CXMLAttr *		pProgPath = pShaderBranch->GetAttr( "ProgramPath" );
//		CStr			sProgPath( pProgPath->GetValue() );

		SysWrite( Va( "\tshader %s", pShaderBranch->GetName() ) );

		IVertexDecl *	pDecl = NULL;
		TUniform	*	pUniforms = NULL;
		uint			nUnfmCount = 0;

		//----------------------------------------------------------------------
		// Tip: Parse shader data
		//----------------------------------------------------------------------
		for ( size_t j = 0; j < pShaderBranch->GetNumChilds(); ++j )
		{
			CXMLElement *	pStruct = pShaderBranch->GetChild( j );
			const CStr		sStruct( pStruct->GetName() );

			if ( sStruct.Compare( "VertexFormat" ) )
			{
				pDecl = ParseVertexFormat( pStruct );
			}
			else if ( sStruct.Compare( "Constants" ) )
			{
/*
				pShader->m_nUniformCount	= 1;
				pShader->m_pUniforms		= NEW CBaseShader::TUniform [ pShader->m_nUniformCount ];

				pShader->m_pUniforms[ 0 ].sName	= "vColorMod";
				pShader->m_pUniforms[ 0 ].eType	= TYPE_VEC4;
				pShader->m_pUniforms[ 0 ].nLoc	= pShader->GetUniformLoc( pShader->m_pUniforms[ 0 ].sName );
				pShader->m_pUniforms[ 0 ].nCount	= 1;

				m_ppShaders[ UI_SHADER ] = pShader;
*/
				nUnfmCount = ParseConstants( pStruct, &pUniforms );
				//pShader->ParseMaps( pStruct );
			}
		}

		g_pRenderer->CreateShader( sPath.GetString(), pDecl, pUniforms, nUnfmCount );
	}

	DEL( pRoot );

	pRes->eState = TResource::LOADED;
}