/* =========================================================================== maya2q3 - export .md3 files from maya Copyright (C) 2005 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =========================================================================== */ #include "common.h" namespace cmd { /* This is the main entry point for plugin config & query... */ class Maya2Q3Cmd : MPxCommand { public: static void* CDECL Creator( void ) { return new Maya2Q3Cmd; } static MSyntax CDECL SyntaxCreator( void ) { MSyntax ret; ret.addFlag( "-sl", "-shaderList" ); ret.addFlag( "-f", "-filter", MSyntax::kString ); return ret; } Maya2Q3Cmd( void ) { } virtual /* override */ ~Maya2Q3Cmd( void ) { } virtual MStatus /* override */ doIt( const MArgList &argList ) { MArgDatabase args( syntax(), argList ); if( args.isFlagSet( "-sl" ) ) //shader list time return DoShaderList( args ); displayError( "Invalid command options." ); return MS::kInvalidParameter; } private: void GetImagesInFolders( const char *dir, std::vector< q3::qname > &retList ) { shader::Shader::GetDefaultableTextures( dir + 1, retList ); const char **dirs = q3::ResourceLoader::FindDirectories( dir ); for( const char **cch = dirs; *cch; cch++ ) { if( !strcmp( *cch, ".svn" ) ) //don't go into SCC directories continue; q3::qname path = dir; if( path[path.Length() - 1] != '/' ) path.Append( "/" ); path.Append( *cch ); GetImagesInFolders( path, retList ); } q3::ResourceLoader::FindClose( dirs ); } static bool SortPaths( const q3::qname &n0, const q3::qname &n1 ) { return q3::ComparePaths( n0, n1 ) < 0; } protected: MStatus DoShaderList( const MArgDatabase &args ) { std::vector< q3::qname > retList; //collect all the explicitely defined shader names const char **shaderFiles = q3::ResourceLoader::FindFiles( "scripts", ".shader" ); for( const char **cch = shaderFiles; *cch; cch++ ) { void *data; size_t size; ospath resName = "scripts/"; resName.Append( *cch ); if( q3::ResourceLoader::GetData( resName, data, size ) ) { //as a convenience the ResourceLoader has already appended a null //to the buffer data (note this is not counted in size). shader::Shader::GetShadersInFile( (const char*)data, retList ); q3::ResourceLoader::FreeData( data ); } } q3::ResourceLoader::FindClose( shaderFiles ); GetImagesInFolders( "/", retList ); if( args.isFlagSet( "-f" ) ) { MString filter; args.getFlagArgument( "-f", 0, filter ); filter.toLowerCase(); //apply the filter for( size_t i = retList.size(); i--; ) { q3::qname iLower = retList[i].ToLower(); if( strstr( iLower, filter.asChar() ) == NULL ) retList.erase( retList.begin() + i ); } } std::sort( retList.begin(), retList.end(), SortPaths ); //copy to Maya format MStringArray ret; //eliminate duplicates size_t iLastAdded = (size_t)~0; for( size_t i = 0; i < retList.size(); i++ ) if( iLastAdded == (size_t)~0 || retList[iLastAdded].CompareTo( retList[i] ) != 0 ) { ret.append( MString( (const char*)retList[i] ) ); iLastAdded = i; } setResult( ret ); return MS::kSuccess; } }; const char *g_cmdName = "maya2q3"; void* (CDECL *g_cmdCreator)( void ) = &Maya2Q3Cmd::Creator; MSyntax (CDECL *g_cmdSyntaxCreator)( void ) = &Maya2Q3Cmd::SyntaxCreator; };