Changeset 546
- Timestamp:
- 03/13/08 18:30:26 (10 months ago)
- Files:
-
- trunk/common/util-string.h (modified) (1 diff)
- trunk/maya2q3/bsp.cpp (modified) (6 diffs)
- trunk/maya2q3/common.h (modified) (1 diff)
- trunk/maya2q3/q3shader_parse.cpp (modified) (4 diffs)
- trunk/maya2q3/util.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/common/util-string.h
r540 r546 246 246 //port of Com_ParseExt 247 247 void ParseExt( const char *&data_p, bool allowLineBreaks, parse_token &tok ); 248 void ParseVector( float *v, int count, const char *&text, bool parseBrackets ); 248 249 void SkipRestOfLine( const char *&data ); 249 250 trunk/maya2q3/bsp.cpp
r544 r546 25 25 { 26 26 27 typedef std::map< std::string, std::string > Entity; 28 typedef const char *const Literal; 29 30 Literal EkClassName = "classname"; 31 Literal EkMessage = "message"; 32 Literal EkDeluxeMapping = "deluxemapping"; 33 Literal EkOrigin = "origin"; 34 Literal EkAngle = "angle"; 35 Literal EkLight = "light"; 36 Literal EkColor = "_color"; 37 38 Literal EcWorldSpawn = "worldspawn"; 39 Literal EcLight = "light"; 40 27 41 class BspImporter 28 42 { … … 52 66 MDagPathArray m_meshPaths; 53 67 68 std::vector< Entity > m_entities; 69 70 MObjectArray m_lights; 71 MDagPathArray m_lightPaths; 72 54 73 std::vector< std::pair< int, int > > m_shaderMap; 55 74 std::vector< std::vector< int > > m_shaderFaceNums; … … 90 109 void CreateQuickSelect( const MSelectionList &sel, const MString &name ); 91 110 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 ); 93 116 }; 94 117 … … 524 547 } 525 548 526 void BspImporter::GroupMeshNodes( const MObject &parentXform ) 527 { 528 /* 549 void BspImporter::GroupNodes( const MObject &parentXform ) 550 { 529 551 MStatus stat; 530 552 … … 534 556 for( uint i = 0; i < m_meshPaths.length(); i++ ) 535 557 { 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 585 void 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 628 void 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 672 void 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 } 540 717 } 541 718 … … 552 729 m_fileData = ∈ 553 730 731 ParseEntities(); 732 554 733 ImportSurfaces(); 555 734 CreateShaderQuickSelects(); 735 736 ImportEntityLights(); 737 738 GroupNodes( parentXform ); 556 739 } 557 740 trunk/maya2q3/common.h
r540 r546 113 113 #include <maya/MItMeshPolygon.h> 114 114 #include <maya/MFnLambertShader.h> 115 #include <maya/MFnLight.h> 116 #include <maya/MFnPointLight.h> 117 #include <maya/MFnSpotLight.h> 115 118 116 119 #include <maya/MTime.h> trunk/maya2q3/q3shader_parse.cpp
r181 r546 49 49 50 50 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;83 51 } 84 52 … … 589 557 else if( tok == "const" ) 590 558 { 591 ParseVector( text, 3, stage.rgb.c);559 ParseVector( stage.rgb.c, 3, text, true ); 592 560 stage.rgb.type = RgbGen::Const; 593 561 } … … 692 660 else if( tok == "vector" ) 693 661 { 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 ); 696 664 697 665 stage.bundle.texGen = TexGen::Vector; … … 1024 992 { 1025 993 // fogParms 1026 if( !ParseVector( text, 3, null ) ) 1027 fail( "invalid fog params" ); 994 ParseVector( null, 3, text, true ); 1028 995 1029 996 ParseExt( text, false, tok ); trunk/maya2q3/util.cpp
r181 r546 30 30 #endif 31 31 32 throw msg;32 throw std::exception( msg ); 33 33 } 34 34 … … 211 211 data = p; 212 212 } 213 214 void 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 }
