Ejemplo n.º 1
0
int main( int argc, char* argv[] )
{
    if ( argc != 2 )
        goto exit;

    char * root = argv[--argc];

    if ( ! CompileMaterial( root ) )
    {
        printf( "COMPILATION FAILED !\n" );
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;

exit :
    printf( "usage: MaterialCompiler <root>\n\n" );
    printf( "    root    root directory ( required )\n" );
    return 0;
}
Ejemplo n.º 2
0
int MeshCompiler::Compile( const char* InFilename, const char* OutFilename, bool LongIndices )
{
	m_StrippedFilename = FileUtil::StripExtensions( FileUtil::StripLeadingFolders( InFilename ) );

	TiXmlDocument XMLDoc;
	XMLDoc.LoadFile( InFilename );
	TiXmlElement* RootElement = XMLDoc.FirstChildElement();	// "mesh"

	// Sanity check
	if( _stricmp( RootElement->Value(), "mesh" ) )
	{
		PRINTF( "Input file is not a valid XML mesh file.\n" );
		return -1;
	}

	STATICHASH( BakeAOForDynamicMeshes );
	STATICHASH( BakeAOForAnimatedMeshes );
	STATICHASH( TraceTriangleBacks );
	STATICHASH( DynamicAORadius );
	STATICHASH( DynamicAOPushOut );
	MAKEHASH( m_StrippedFilename );

	ConfigManager::Load( FileStream( "tools.cfg", FileStream::EFM_Read ) );
	m_BakeAOForDynamicMeshes = ConfigManager::GetArchetypeBool( sBakeAOForDynamicMeshes, ConfigManager::EmptyContext, false, sm_StrippedFilename );
	m_BakeAOForAnimatedMeshes = ConfigManager::GetArchetypeBool( sBakeAOForAnimatedMeshes, ConfigManager::EmptyContext, false, sm_StrippedFilename );
	m_TraceTriangleBacks = ConfigManager::GetArchetypeBool( sTraceTriangleBacks, ConfigManager::EmptyContext, false, sm_StrippedFilename );
	m_AORadius = ConfigManager::GetArchetypeFloat( sDynamicAORadius, ConfigManager::EmptyContext, 0.1f, sm_StrippedFilename );
	m_AOPushOut = ConfigManager::GetArchetypeFloat( sDynamicAOPushOut, ConfigManager::EmptyContext, 0.01f, sm_StrippedFilename );

	m_Header.m_LongIndices = LongIndices;

	// Get armature first, which will make it easier to handle bone references in verts
	TiXmlElement* Arm = RootElement->FirstChildElement( "armature" );
	CompileArmature( Arm );

	int NumFaces = 0;
	for( TiXmlElement* Face = RootElement->FirstChildElement( "face" ); Face; Face = Face->NextSiblingElement( "face" ) )
	{
		CompileFace( Face );
		NumFaces++;
	}

	for( TiXmlElement* Mat = RootElement->FirstChildElement( "material" ); Mat; Mat = Mat->NextSiblingElement( "material" ) )
	{
		CompileMaterial( Mat );
	}

	m_Header.m_NumVertices = m_Positions.Size();
	m_Header.m_NumIndices = m_Indices.Size();

	NormalizeWeights();

	CalculateAABB();

	if( m_Header.m_HasUVs && m_Header.m_HasNormals )
	{
		m_Header.m_HasTangents = true;
	}
	PRINTF( "Calculating tangents...\n" );
	CalculateTangents();

	CalculateAmbientOcclusion();

	PRINTF( "Compile successful!\n" );
	PRINTF( "Imported %d faces.\n", NumFaces );

	Write( FileStream( OutFilename, FileStream::EFM_Write ) );

	PRINTF( "Exported %d vertices.\n", m_Header.m_NumVertices );
	PRINTF( "Exported %d indices (%d triangles).\n", m_Header.m_NumIndices, m_Header.m_NumIndices / 3 );
	if( m_Header.m_HasSkeleton )
	{
		PRINTF( "Exported %d bones.\n", m_Header.m_NumBones );
		PRINTF( "Exported %d frames.\n", m_Header.m_NumFrames );
		PRINTF( "Exported %d animations.\n", m_Header.m_NumAnims );
	}

	return 0;
}