Changeset 547

Show
Ignore:
Timestamp:
03/25/08 04:24:06 (10 months ago)
Author:
phill
Message:

o Texture import madness. Ish.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/maya2q3/bsp.cpp

    r546 r547  
    4343public: 
    4444        BspImporter( void ); 
    45         void Import( std::istream &stm, const MObject &parentTransform ); 
     45        void Import( std::istream &stm, const MObject &parentTransform, const char *basePath ); 
    4646 
    4747private: 
     
    7979        std::vector< MSelectionList > m_shaderSels; 
    8080 
     81        const char *m_basePath; 
    8182        q3::dheader_t m_fileHeader; 
    8283        BinaryReader *m_fileData; 
     
    103104        void ClearStagingArea(); 
    104105 
     106        MObject ImportTexture( const char *shaderName ); 
    105107        int GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ); 
    106108 
     
    147149} 
    148150 
     151MObject BspImporter::ImportTexture( const char *shaderName ) 
     152{ 
     153        ospath basePath( m_basePath ); 
     154        basePath.Append( shaderName ); 
     155 
     156        const char *path = 0; 
     157 
     158        static const char *const exts[] = { ".tga", ".jpg" }; 
     159        for( size_t i = 0; i < lengthof( exts ); i++ ) 
     160        { 
     161                ospath p2( basePath ); 
     162                p2.Append( exts[i] ); 
     163 
     164                if( GetFileAttributesA( p2 ) != INVALID_FILE_ATTRIBUTES ) 
     165                { 
     166                        basePath = p2; 
     167                        path = basePath; 
     168                        break; 
     169                } 
     170        } 
     171 
     172        if( !path ) 
     173                return MObject::kNullObj; 
     174 
     175        MStatus stat; 
     176 
     177        MFnDependencyNode fnTex; 
     178        fnTex.create( MString( "file" ), &stat ); 
     179        check_status( stat ); 
     180 
     181        sstr< 1024 > nameBuf; 
     182        MangleShaderName( nameBuf, shaderName ); 
     183        nameBuf.Append( "_tex" ); 
     184 
     185        fnTex.setName( MString( nameBuf ), &stat ); 
     186        check_status( stat ); 
     187 
     188        MPlug filePlug = fnTex.findPlug( MString( "fileTextureName" ), &stat ); 
     189        check_status( stat ); 
     190 
     191        stat = filePlug.setString( MString( path ) ); 
     192        check_status( stat ); 
     193 
     194        MObject ret = fnTex.object( &stat ); 
     195        check_status( stat ); 
     196 
     197        return ret; 
     198} 
     199 
    149200int BspImporter::GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ) 
    150201{ 
     
    172223 
    173224        MStatus stat; 
     225 
     226        MDGModifier dgMod; 
     227 
    174228        MFnLambertShader fnShader; 
    175229 
     
    185239        MObject shaderObj = fnShader.object( &stat ); 
    186240        check_status( stat ); 
     241 
     242        MObject texObj = ImportTexture( shader.shader ); 
     243        if( texObj != MObject::kNullObj ) 
     244        { 
     245                MFnDependencyNode fnTex( texObj, &stat ); 
     246                check_status( stat ); 
     247 
     248                MPlug texColorPlug = fnTex.findPlug( MString( "outColor" ), &stat ); 
     249                check_status( stat ); 
     250                //MPlug texTransPlug = fnTex.findPlug( MString( "outTransparency" ), &stat ); 
     251                //check_status( stat ); 
     252 
     253                MPlug shaderColorPlug = fnShader.findPlug( MString( "color" ), &stat ); 
     254                check_status( stat ); 
     255                //MPlug shaderTransPlug = fnShader.findPlug( MString( "transparency" ), &stat ); 
     256                //check_status( stat ); 
     257 
     258 
     259                stat = dgMod.connect( texColorPlug, shaderColorPlug ); 
     260                check_status( stat ); 
     261                //stat = dgMod.connect( texTransPlug, shaderTransPlug ); 
     262                //check_status( stat ); 
     263        } 
    187264 
    188265        MFnSet fnGroup; 
     
    200277        MObject groupObj = fnGroup.object( &stat ); 
    201278        check_status( stat ); 
    202  
    203         MDGModifier dgMod; 
    204279 
    205280        MPlugArray connections; 
     
    717792} 
    718793 
    719 void BspImporter::Import( std::istream &stm, const MObject &parentXform
     794void BspImporter::Import( std::istream &stm, const MObject &parentXform, const char *basePath
    720795{ 
    721796        size_t base_pos = stm.tellg(); 
     
    728803 
    729804        m_fileData = &in; 
     805        m_basePath = basePath; 
    730806 
    731807        ParseEntities(); 
     
    773849                file.open( filename.resolvedFullName().asChar(), std::ios::in | std::ios::binary ); 
    774850 
     851                MString basePath = filename.resolvedPath(); 
     852 
     853                basePath = basePath.substring( 0, basePath.length() - 2 ); 
     854 
     855                int idx = basePath.rindex( '/' ); 
     856                if( idx > 0 ) 
     857                        basePath = basePath.substring( 0, idx ); 
     858 
    775859                try 
    776860                { 
     
    789873 
    790874                        BspImporter imp; 
    791                         imp.Import( file, xformObj ); 
     875                        imp.Import( file, xformObj, basePath.asChar() ); 
    792876                } 
    793877                catch( std::exception &ex ) 
  • trunk/maya2q3/maya_entry.cpp

    r543 r547  
    2626 
    2727static const char *g_vendor = "HermitWorks"; 
    28 static const char *g_version = "3.3.2"; 
     28static const char *g_version = "3.3.3"; 
    2929static const char *g_reqVer = "Any"; 
    3030