Changeset 548

Show
Ignore:
Timestamp:
03/25/08 17:52:58 (10 months ago)
Author:
phill
Message:

o Source vertex blind data hell.

Files:

Legend:

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

    r547 r548  
    2525{ 
    2626 
    27 typedef std::map< std::string, std::string > Entity; 
    2827typedef const char *const Literal; 
    2928 
     
    3938Literal EcLight = "light"; 
    4039 
     40const int BdSourceVertex = 100; 
     41 
    4142class BspImporter 
    4243{ 
     
    6061        MColorArray m_vertexLight; 
    6162        MIntArray m_vertexLightIDs; 
     63         
     64        MString m_SourceVertDataName; 
     65        MIntArray m_sourceVertices; 
    6266 
    6367        std::vector< q3::Patch > m_patchStaging; 
     
    6670        MDagPathArray m_meshPaths; 
    6771 
    68         std::vector< Entity > m_entities; 
     72        bool m_hasDeluxeMaps; 
     73        std::vector< q3::Entity > m_entities; 
    6974 
    7075        MObjectArray m_lights; 
     
    7984        std::vector< MSelectionList > m_shaderSels; 
    8085 
     86        std::vector< char > m_shaderText; 
     87 
    8188        const char *m_basePath; 
    8289        q3::dheader_t m_fileHeader; 
     
    98105        } 
    99106 
     107        void InitImporterObjects(); 
     108 
    100109        void ParseTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, int shaderBin, 
    101                 int firstVert = 0, int vertexCount = -1, int firstIndex = 0, int indexCount = -1 ); 
     110                int firstVert = 0, int vertexCount = -1, int firstIndex = 0, int indexCount = -1, bool generateSourceIDs = true ); 
    102111 
    103112        void CreateMesh(); 
    104113        void ClearStagingArea(); 
    105114 
     115        void ImportShaderText(); 
    106116        MObject ImportTexture( const char *shaderName ); 
    107117        int GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ); 
     
    145155 
    146156BspImporter::BspImporter( void ) 
     157        : m_SourceVertDataName( "sourceVertexIndex" ) 
    147158{ 
    148159        m_combineMeshes = false; 
     160 
     161        InitImporterObjects(); 
     162} 
     163 
     164void BspImporter::InitImporterObjects() 
     165{ 
     166        MStatus stat; 
     167        MFnMesh mesh; 
     168 
     169        MStringArray longNames, shortNames, formatNames; 
     170 
     171        longNames.append( m_SourceVertDataName ); 
     172        shortNames.append( "svi" ); 
     173        formatNames.append( "int" ); 
     174 
     175        stat = mesh.createBlindDataType( BdSourceVertex, longNames, shortNames, formatNames ); 
     176        check_status( stat ); 
     177} 
     178 
     179void BspImporter::ImportShaderText() 
     180{ 
     181         
    149182} 
    150183 
     
    162195                p2.Append( exts[i] ); 
    163196 
    164                 if( GetFileAttributesA( p2 ) != INVALID_FILE_ATTRIBUTES ) 
     197                struct _stat ss; 
     198                if( _stat( p2, &ss ) == 0 ) 
    165199                { 
    166200                        basePath = p2; 
     
    201235{ 
    202236        shaderNum = clamp( shaderNum, 0, (int)shaders.size() - 1 ); 
     237 
     238        if( m_hasDeluxeMaps && lightmapNum >= 0 ) 
     239                lightmapNum /= 2; 
    203240 
    204241        for( uint i = 0; i < m_shaderMap.size(); i++ ) 
     
    234271        check_status( stat ); 
    235272 
     273        { 
     274                MFnTypedAttribute attr; 
     275                MObject attrObj = attr.create( "originalShaderName", 
     276                        "osn", MFnData::kString, MObject::kNullObj, &stat ); 
     277                check_status( stat ); 
     278 
     279                stat = fnShader.addAttribute( attrObj ); 
     280                check_status( stat ); 
     281 
     282                MPlug attrPlug = fnShader.findPlug( attrObj, &stat ); 
     283                check_status( stat ); 
     284 
     285                stat = attrPlug.setString( MString( shader.shader ) ); 
     286                check_status( stat ); 
     287        } 
     288 
    236289        MPlug outColorPlug = fnShader.findPlug( MString( "outColor" ), &stat ); 
    237290        check_status( stat ); 
     
    303356 
    304357void BspImporter::ParseTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, 
    305                 int shaderBin, int firstVert, int vertexCount, int firstIndex, int indexCount
     358                int shaderBin, int firstVert, int vertexCount, int firstIndex, int indexCount, bool generateSourceIDs
    306359{ 
    307360        if( vertexCount == -1 ) 
     
    335388                m_lightmapUVIDs.append( index ); 
    336389                m_vertexLightIDs.append( index ); 
     390                if( generateSourceIDs ) 
     391                        m_sourceVertices.append( index ); 
    337392                 
    338393                index = baseVert + indices[firstIndex + i * 3 + 2]; 
     
    341396                m_lightmapUVIDs.append( index ); 
    342397                m_vertexLightIDs.append( index ); 
     398                if( generateSourceIDs ) 
     399                        m_sourceVertices.append( index ); 
    343400 
    344401                index = baseVert + indices[firstIndex + i * 3 + 1]; 
     
    347404                m_lightmapUVIDs.append( index ); 
    348405                m_vertexLightIDs.append( index ); 
     406                if( generateSourceIDs ) 
     407                        m_sourceVertices.append( index ); 
    349408 
    350409                if( shaderBin != -1 ) 
     
    492551        check_status( stat ); 
    493552 
     553        if( m_sourceVertices.length() ) 
     554        { 
     555                int iVert = 0; 
     556                for( int iFace = 0; iFace < (int)m_faceCounts.length(); iFace++ ) 
     557                { 
     558                        for( int iFaceVert = 0; iFaceVert < m_faceCounts[iFace]; iFaceVert++ ) 
     559                        { 
     560                                int blindIndex; 
     561                                stat = mesh.getFaceVertexBlindDataIndex( iFace, m_faceVertIndices[iVert], blindIndex ); 
     562                                check_status( stat ); 
     563 
     564                                stat = mesh.setIntBlindData( blindIndex, MFn::kMeshFaceVertComponent, 
     565                                        BdSourceVertex, m_SourceVertDataName, m_sourceVertices[iVert] ); 
     566                                check_status( stat ); 
     567 
     568                                iVert++; 
     569                        } 
     570                } 
     571        } 
     572 
     573        stat = mesh.updateSurface(); 
     574        check_status( stat ); 
     575 
    494576        MDagPath objPath; 
    495577        stat = mesh.getPath( objPath ); 
     
    576658        m_vertexLightIDs.clear(); 
    577659 
     660        m_sourceVertices.clear(); 
     661 
    578662        for( uint i = 0; i < m_shaderFaceNums.size(); i++ ) 
    579663                m_shaderFaceNums[i].clear(); 
     
    666750        lump_data[lump.filelen] = 0; 
    667751 
    668         parse_token tok, val; 
    669752        const char *entStr = lump_data.get(); 
    670  
    671         for( ; ; ) 
    672         { 
    673                 ParseExt( entStr, true, tok ); 
    674  
    675                 if( tok == "" ) 
    676                         break; 
    677  
    678                 demand( tok == "{", "Missing { at start of entity block." ); 
    679  
    680                 Entity ent; 
    681  
    682                 for( ; ; ) 
    683                 { 
    684                         ParseExt( entStr, true, tok ); 
    685  
    686                         demand( tok != "", "Missing } in entity block." ); 
    687  
    688                         if( tok == "}" ) 
    689                                 break; 
    690  
    691                         ParseExt( entStr, true, val ); 
    692  
    693                         demand( val != "", "Missing value part in entity." ); 
    694  
    695                         ent.insert( Entity::value_type( 
    696                                 std::string( tok ), std::string( val ) ) ); 
    697                 } 
    698  
    699                 m_entities.push_back( ent ); 
    700         } 
     753         
     754        m_entities = q3::Entity::ParseEntities( entStr ); 
     755 
     756        if( m_entities.size() == 0 || 
     757                m_entities[0].AsString( EkClassName ) != EcWorldSpawn ) 
     758                throw std::exception( "Missing world spawn." ); 
     759 
     760        m_hasDeluxeMaps = m_entities[0].AsBool( EkDeluxeMapping, false ); 
    701761} 
    702762 
     
    749809        for( size_t i = 0; i < m_entities.size(); i++ ) 
    750810        { 
    751                 const Entity &ent = m_entities[i]; 
    752  
    753                 const char *c; 
    754                 Entity::const_iterator iter; 
    755  
    756                 iter = ent.find( EkClassName ); 
    757                 demand( iter != ent.end(), "Entity without a classname key." ); 
    758                          
    759                 if( iter->second != EcLight ) 
     811                const q3::Entity &ent = m_entities[i]; 
     812 
     813                if( ent.AsString( EkClassName ) != EcLight ) 
    760814                        continue; 
    761815 
    762                 vec3 origin, color; 
    763                 float intensity; 
    764  
    765                 iter = ent.find( EkOrigin ); 
    766                 demand( iter != ent.end(), "Light with no origin." ); 
    767  
    768                 c = iter->second.c_str(); 
    769                 ParseVector( origin, 3, c, false ); 
    770                 origin = q3::Q3VecToMaya( origin ); 
    771  
    772                 iter = ent.find( EkColor ); 
    773                 if( iter != ent.end() ) 
    774                 { 
    775                         c = iter->second.c_str(); 
    776                         ParseVector( color, 3, c, false ); 
    777                 } 
    778                 else 
    779                         color = vec3c( 1 ); 
    780  
    781                 iter = ent.find( EkLight ); 
    782                 if( iter != ent.end() ) 
    783                 { 
    784                         c = iter->second.c_str(); 
    785                         intensity = (float)atof( c ); 
    786                 } 
    787                 else 
    788                         intensity = 1; 
    789  
    790                 CreatePointLight( origin, color, intensity ); 
     816                vec3 origin = ent.AsVec3( EkOrigin ); 
     817                vec3 color = ent.AsVec3( EkColor, vec3c( 1 ) ); 
     818                float intensity = ent.AsFloat( EkLight, 1 ); 
     819 
     820                CreatePointLight( q3::Q3VecToMaya( origin ), color, intensity ); 
    791821        } 
    792822} 
     
    806836 
    807837        ParseEntities(); 
     838        ImportShaderText(); 
    808839 
    809840        ImportSurfaces(); 
     
    897928                return MS::kSuccess; 
    898929        } 
    899  
    900930}; 
    901931 
  • trunk/maya2q3/common.h

    r546 r548  
    4141#include <algorithm> 
    4242#include <string> 
     43 
     44#include <sys/types.h> 
     45#include <sys/stat.h> 
    4346 
    4447#include "../glew/include/GL/glew.h" 
  • trunk/maya2q3/maya2q3.vcproj

    r540 r548  
    572572                        </File> 
    573573                        <File 
     574                                RelativePath=".\q3shader.h" 
     575                                > 
     576                        </File> 
     577                        <File 
    574578                                RelativePath=".\q3shader_imageloader.cpp" 
    575579                                > 
     
    604608                        </File> 
    605609                        <File 
    606                                 RelativePath=".\q3shader.h" 
    607                                 > 
    608                         </File> 
    609                         <File 
    610                                 RelativePath=".\q3types.h" 
    611                                 > 
    612                         </File> 
    613                         <File 
    614                                 RelativePath=".\q3util.h" 
    615                                 > 
    616                         </File> 
    617                         <File 
    618610                                RelativePath=".\util-common.h" 
    619611                                > 
     
    648640                                <File 
    649641                                        RelativePath=".\DXVec.h" 
     642                                        > 
     643                                </File> 
     644                        </Filter> 
     645                        <Filter 
     646                                Name="q3" 
     647                                > 
     648                                <File 
     649                                        RelativePath=".\q3types.h" 
     650                                        > 
     651                                </File> 
     652                                <File 
     653                                        RelativePath=".\q3util.h" 
    650654                                        > 
    651655                                </File> 
     
    849853                        Name="bsp" 
    850854                        > 
     855                        <File 
     856                                RelativePath=".\bsp-entities.cpp" 
     857                                > 
     858                        </File> 
    851859                        <File 
    852860                                RelativePath=".\bsp-patches.cpp" 
  • trunk/maya2q3/q3util.h

    r535 r548  
    113113void PatchToMesh( const Patch &patch, std::vector< q3::drawVert_t > &out_verts, std::vector< int > &out_indices ); 
    114114 
     115class KeyNotFound : public std::exception 
     116{ 
     117}; 
     118 
     119struct Entity 
     120{ 
     121public: 
     122        const std::string& AsString( const std::string &key ) const; 
     123        const std::string& AsString( const std::string &key, const std::string &def ) const; 
     124 
     125        bool AsBool( const std::string &key ) const; 
     126        bool AsBool( const std::string &key, bool def ) const; 
     127 
     128        float AsFloat( const std::string &key ) const; 
     129        float AsFloat( const std::string &key, float def ) const; 
     130 
     131        vec3 AsVec3( const std::string &key ) const; 
     132        vec3 AsVec3( const std::string &key, const vec3 &def ) const; 
     133 
     134        static std::vector< Entity > ParseEntities( const char *str ); 
     135 
     136private: 
     137        typedef std::map< std::string, std::string > EntMap; 
     138        EntMap          pairs; 
     139 
     140        friend std::vector< Entity > ParseEntityString( const char *str ); 
     141}; 
     142 
    115143}; 
    116144 
  • trunk/maya2q3/shader_node.cpp

    r181 r548  
    364364                                                                m_shader = null; 
    365365                                                        } 
    366  
     366                                                } 
     367 
     368                                                q3::ResourceLoader::FreeData( data ); 
     369 
     370                                                if( m_shader ) 
    367371                                                        break; 
    368                                                 } 
    369  
    370                                                 q3::ResourceLoader::FreeData( data ); 
    371372                                        } 
    372373                                } 
  • trunk/x42view.net/x42view.net.csproj

    r495 r548  
    173173    </Compile> 
    174174    <Compile Include="Gui\Options.cs"> 
    175       <SubType>Component</SubType> 
     175      <SubType>Form</SubType> 
    176176    </Compile> 
    177177    <Compile Include="Gui\Options.Designer.cs">