Changeset 546

Show
Ignore:
Timestamp:
03/13/08 18:30:26 (10 months ago)
Author:
phill
Message:

o Importing lights.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/common/util-string.h

    r540 r546  
    246246//port of Com_ParseExt 
    247247void ParseExt( const char *&data_p, bool allowLineBreaks, parse_token &tok ); 
     248void ParseVector( float *v, int count, const char *&text, bool parseBrackets ); 
    248249void SkipRestOfLine( const char *&data ); 
    249250 
  • trunk/maya2q3/bsp.cpp

    r544 r546  
    2525{ 
    2626 
     27typedef std::map< std::string, std::string > Entity; 
     28typedef const char *const Literal; 
     29 
     30Literal EkClassName = "classname"; 
     31Literal EkMessage = "message"; 
     32Literal EkDeluxeMapping = "deluxemapping"; 
     33Literal EkOrigin = "origin"; 
     34Literal EkAngle = "angle"; 
     35Literal EkLight = "light"; 
     36Literal EkColor = "_color"; 
     37 
     38Literal EcWorldSpawn = "worldspawn"; 
     39Literal EcLight = "light"; 
     40 
    2741class BspImporter 
    2842{ 
     
    5266        MDagPathArray m_meshPaths; 
    5367 
     68        std::vector< Entity > m_entities; 
     69 
     70        MObjectArray m_lights; 
     71        MDagPathArray m_lightPaths; 
     72 
    5473        std::vector< std::pair< int, int > > m_shaderMap; 
    5574        std::vector< std::vector< int > > m_shaderFaceNums; 
     
    90109        void CreateQuickSelect( const MSelectionList &sel, const MString &name ); 
    91110 
    92         void GroupMeshNodes( const MObject &parentXform ); 
     111        void ParseEntities(); 
     112        void ImportEntityLights(); 
     113        void CreatePointLight( const vec3 &origin, const vec3 &color, float intensity ); 
     114 
     115        void GroupNodes( const MObject &parentXform ); 
    93116}; 
    94117 
     
    524547} 
    525548 
    526 void BspImporter::GroupMeshNodes( const MObject &parentXform ) 
    527 
    528         /* 
     549void BspImporter::GroupNodes( const MObject &parentXform ) 
     550
    529551        MStatus stat; 
    530552 
     
    534556        for( uint i = 0; i < m_meshPaths.length(); i++ ) 
    535557        { 
    536                 MObject obj = m_meshPaths[i].node(); 
    537                 fnParent.addChild( obj ); 
    538         } 
    539         */ 
     558                MDagPath path = m_meshPaths[i]; 
     559 
     560                stat = path.pop(); 
     561                check_status( stat ); 
     562 
     563                MObject obj = path.node( &stat ); 
     564                check_status( stat ); 
     565 
     566                stat = fnParent.addChild( obj ); 
     567                check_status( stat ); 
     568        } 
     569 
     570        for( uint i = 0; i < m_lightPaths.length(); i++ ) 
     571        { 
     572                MDagPath path = m_lightPaths[i]; 
     573 
     574                stat = path.pop(); 
     575                check_status( stat ); 
     576 
     577                MObject obj = path.node( &stat ); 
     578                check_status( stat ); 
     579 
     580                stat = fnParent.addChild( obj ); 
     581                check_status( stat ); 
     582        } 
     583
     584 
     585void BspImporter::ParseEntities() 
     586
     587        const q3::lump_t &lump = m_fileHeader.lumps[q3::LUMP_ENTITIES]; 
     588        boost::scoped_array< char > lump_data( new char[lump.filelen + 1] ); 
     589        m_fileData->seek( lump.fileofs ); 
     590        m_fileData->read( lump_data.get(), lump.filelen ); 
     591        lump_data[lump.filelen] = 0; 
     592 
     593        parse_token tok, val; 
     594        const char *entStr = lump_data.get(); 
     595 
     596        for( ; ; ) 
     597        { 
     598                ParseExt( entStr, true, tok ); 
     599 
     600                if( tok == "" ) 
     601                        break; 
     602 
     603                demand( tok == "{", "Missing { at start of entity block." ); 
     604 
     605                Entity ent; 
     606 
     607                for( ; ; ) 
     608                { 
     609                        ParseExt( entStr, true, tok ); 
     610 
     611                        demand( tok != "", "Missing } in entity block." ); 
     612 
     613                        if( tok == "}" ) 
     614                                break; 
     615 
     616                        ParseExt( entStr, true, val ); 
     617 
     618                        demand( val != "", "Missing value part in entity." ); 
     619 
     620                        ent.insert( Entity::value_type( 
     621                                std::string( tok ), std::string( val ) ) ); 
     622                } 
     623 
     624                m_entities.push_back( ent ); 
     625        } 
     626
     627 
     628void BspImporter::CreatePointLight( const vec3 &origin, const vec3 &color, float intensity ) 
     629
     630        MStatus stat; 
     631 
     632        MFnPointLight light; 
     633         
     634        light.create( true, &stat ); 
     635        check_status( stat ); 
     636 
     637        stat = light.setColor( MColor( color.x, color.y, color.z ) ); 
     638        check_status( stat ); 
     639 
     640        stat = light.setIntensity( intensity / 128 ); 
     641        check_status( stat ); 
     642 
     643        stat = light.setUseRayTraceShadows( true ); 
     644        check_status( stat ); 
     645 
     646        stat = light.setDecayRate( 2 /* quadratic */ ); 
     647        check_status( stat ); 
     648 
     649        MObject lightObj = light.object( &stat ); 
     650        check_status( stat ); 
     651 
     652        stat = m_lights.append( lightObj ); 
     653        check_status( stat ); 
     654 
     655        MDagPath lightPath; 
     656        stat = light.getPath( lightPath ); 
     657        check_status( stat ); 
     658 
     659        stat = m_lightPaths.append( lightPath ); 
     660        check_status( stat ); 
     661 
     662        stat = lightPath.pop(); 
     663        check_status( stat ); 
     664 
     665        MFnTransform lightPos( lightPath, &stat ); 
     666        check_status( stat ); 
     667 
     668        stat = lightPos.setTranslation( MVector( origin.x, origin.y, origin.z ), MSpace::kWorld ); 
     669        check_status( stat ); 
     670
     671 
     672void BspImporter::ImportEntityLights() 
     673
     674        for( size_t i = 0; i < m_entities.size(); i++ ) 
     675        { 
     676                const Entity &ent = m_entities[i]; 
     677 
     678                const char *c; 
     679                Entity::const_iterator iter; 
     680 
     681                iter = ent.find( EkClassName ); 
     682                demand( iter != ent.end(), "Entity without a classname key." ); 
     683                         
     684                if( iter->second != EcLight ) 
     685                        continue; 
     686 
     687                vec3 origin, color; 
     688                float intensity; 
     689 
     690                iter = ent.find( EkOrigin ); 
     691                demand( iter != ent.end(), "Light with no origin." ); 
     692 
     693                c = iter->second.c_str(); 
     694                ParseVector( origin, 3, c, false ); 
     695                origin = q3::Q3VecToMaya( origin ); 
     696 
     697                iter = ent.find( EkColor ); 
     698                if( iter != ent.end() ) 
     699                { 
     700                        c = iter->second.c_str(); 
     701                        ParseVector( color, 3, c, false ); 
     702                } 
     703                else 
     704                        color = vec3c( 1 ); 
     705 
     706                iter = ent.find( EkLight ); 
     707                if( iter != ent.end() ) 
     708                { 
     709                        c = iter->second.c_str(); 
     710                        intensity = (float)atof( c ); 
     711                } 
     712                else 
     713                        intensity = 1; 
     714 
     715                CreatePointLight( origin, color, intensity ); 
     716        } 
    540717} 
    541718 
     
    552729        m_fileData = &in; 
    553730 
     731        ParseEntities(); 
     732 
    554733        ImportSurfaces(); 
    555734        CreateShaderQuickSelects(); 
     735 
     736        ImportEntityLights(); 
     737 
     738        GroupNodes( parentXform ); 
    556739} 
    557740 
  • trunk/maya2q3/common.h

    r540 r546  
    113113#include <maya/MItMeshPolygon.h> 
    114114#include <maya/MFnLambertShader.h> 
     115#include <maya/MFnLight.h> 
     116#include <maya/MFnPointLight.h> 
     117#include <maya/MFnSpotLight.h> 
    115118 
    116119#include <maya/MTime.h> 
  • trunk/maya2q3/q3shader_parse.cpp

    r181 r546  
    4949 
    5050        memset( &m_time, 0, sizeof( m_time ) ); 
    51 } 
    52  
    53 static bool ParseVector( const char *&text, int count, float *v ) 
    54 { 
    55         parse_token tok; 
    56  
    57         // FIXME: spaces are currently required after parens, should change parseext... 
    58         ParseExt( text, false, tok ); 
    59         if( tok != "(" ) 
    60         { 
    61                 warn( "missing ( in shader" ); 
    62                 return false; 
    63         } 
    64  
    65         for( int i = 0; i < count ; i++ ) 
    66         { 
    67                 ParseExt( text, false, tok ); 
    68                 if( tok == "" ) 
    69                         fail( "missing vector element in shader" ); 
    70  
    71                 if( v ) 
    72                         v[i] = (float)atof( tok ); 
    73         } 
    74  
    75         ParseExt( text, false, tok ); 
    76         if( tok != ")" ) 
    77         { 
    78                 warn( "missing ) in shader" ); 
    79                 return false; 
    80         } 
    81  
    82         return true; 
    8351} 
    8452 
     
    589557                        else if( tok == "const" ) 
    590558                        { 
    591                                 ParseVector( text, 3, stage.rgb.c ); 
     559                                ParseVector( stage.rgb.c, 3,  text, true ); 
    592560                                stage.rgb.type = RgbGen::Const; 
    593561                        } 
     
    692660                        else if( tok == "vector" ) 
    693661                        { 
    694                                 ParseVector( text, 3, stage.bundle.texGenVecs[0] ); 
    695                                 ParseVector( text, 3, stage.bundle.texGenVecs[1] ); 
     662                                ParseVector( stage.bundle.texGenVecs[0], 3, text, true ); 
     663                                ParseVector( stage.bundle.texGenVecs[1], 3, text, true ); 
    696664 
    697665                                stage.bundle.texGen = TexGen::Vector; 
     
    1024992                { 
    1025993                        // fogParms 
    1026                         if( !ParseVector( text, 3, null ) ) 
    1027                                 fail( "invalid fog params" ); 
     994                        ParseVector( null, 3, text, true ); 
    1028995 
    1029996                        ParseExt( text, false, tok ); 
  • trunk/maya2q3/util.cpp

    r181 r546  
    3030#endif 
    3131 
    32         throw msg
     32        throw std::exception( msg )
    3333} 
    3434 
     
    211211        data = p; 
    212212} 
     213 
     214void ParseVector( float *v, int count, const char *&text, bool parseBrackets ) 
     215{ 
     216        parse_token tok; 
     217 
     218        if( parseBrackets ) 
     219        { 
     220                ParseExt( text, false, tok ); 
     221                demand( tok == "(", "missing (" ); 
     222        } 
     223 
     224        for( int i = 0; i < count ; i++ ) 
     225        { 
     226                ParseExt( text, false, tok ); 
     227                demand( tok != "", "missing vector element" ); 
     228 
     229                if( v ) 
     230                        v[i] = (float)atof( tok ); 
     231        } 
     232 
     233        if( parseBrackets ) 
     234        { 
     235                ParseExt( text, false, tok ); 
     236                demand( tok == ")", "missing )" ); 
     237        } 
     238}