Changeset 548
- Timestamp:
- 03/25/08 17:52:58 (10 months ago)
- Files:
-
- trunk/maya2q3/bsp-entities.cpp (added)
- trunk/maya2q3/bsp.cpp (modified) (20 diffs)
- trunk/maya2q3/common.h (modified) (1 diff)
- trunk/maya2q3/maya2q3.vcproj (modified) (4 diffs)
- trunk/maya2q3/q3util.h (modified) (1 diff)
- trunk/maya2q3/shader_node.cpp (modified) (1 diff)
- trunk/x42view.net/x42view.net.csproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/maya2q3/bsp.cpp
r547 r548 25 25 { 26 26 27 typedef std::map< std::string, std::string > Entity;28 27 typedef const char *const Literal; 29 28 … … 39 38 Literal EcLight = "light"; 40 39 40 const int BdSourceVertex = 100; 41 41 42 class BspImporter 42 43 { … … 60 61 MColorArray m_vertexLight; 61 62 MIntArray m_vertexLightIDs; 63 64 MString m_SourceVertDataName; 65 MIntArray m_sourceVertices; 62 66 63 67 std::vector< q3::Patch > m_patchStaging; … … 66 70 MDagPathArray m_meshPaths; 67 71 68 std::vector< Entity > m_entities; 72 bool m_hasDeluxeMaps; 73 std::vector< q3::Entity > m_entities; 69 74 70 75 MObjectArray m_lights; … … 79 84 std::vector< MSelectionList > m_shaderSels; 80 85 86 std::vector< char > m_shaderText; 87 81 88 const char *m_basePath; 82 89 q3::dheader_t m_fileHeader; … … 98 105 } 99 106 107 void InitImporterObjects(); 108 100 109 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 ); 102 111 103 112 void CreateMesh(); 104 113 void ClearStagingArea(); 105 114 115 void ImportShaderText(); 106 116 MObject ImportTexture( const char *shaderName ); 107 117 int GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ); … … 145 155 146 156 BspImporter::BspImporter( void ) 157 : m_SourceVertDataName( "sourceVertexIndex" ) 147 158 { 148 159 m_combineMeshes = false; 160 161 InitImporterObjects(); 162 } 163 164 void 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 179 void BspImporter::ImportShaderText() 180 { 181 149 182 } 150 183 … … 162 195 p2.Append( exts[i] ); 163 196 164 if( GetFileAttributesA( p2 ) != INVALID_FILE_ATTRIBUTES ) 197 struct _stat ss; 198 if( _stat( p2, &ss ) == 0 ) 165 199 { 166 200 basePath = p2; … … 201 235 { 202 236 shaderNum = clamp( shaderNum, 0, (int)shaders.size() - 1 ); 237 238 if( m_hasDeluxeMaps && lightmapNum >= 0 ) 239 lightmapNum /= 2; 203 240 204 241 for( uint i = 0; i < m_shaderMap.size(); i++ ) … … 234 271 check_status( stat ); 235 272 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 236 289 MPlug outColorPlug = fnShader.findPlug( MString( "outColor" ), &stat ); 237 290 check_status( stat ); … … 303 356 304 357 void 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 ) 306 359 { 307 360 if( vertexCount == -1 ) … … 335 388 m_lightmapUVIDs.append( index ); 336 389 m_vertexLightIDs.append( index ); 390 if( generateSourceIDs ) 391 m_sourceVertices.append( index ); 337 392 338 393 index = baseVert + indices[firstIndex + i * 3 + 2]; … … 341 396 m_lightmapUVIDs.append( index ); 342 397 m_vertexLightIDs.append( index ); 398 if( generateSourceIDs ) 399 m_sourceVertices.append( index ); 343 400 344 401 index = baseVert + indices[firstIndex + i * 3 + 1]; … … 347 404 m_lightmapUVIDs.append( index ); 348 405 m_vertexLightIDs.append( index ); 406 if( generateSourceIDs ) 407 m_sourceVertices.append( index ); 349 408 350 409 if( shaderBin != -1 ) … … 492 551 check_status( stat ); 493 552 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 494 576 MDagPath objPath; 495 577 stat = mesh.getPath( objPath ); … … 576 658 m_vertexLightIDs.clear(); 577 659 660 m_sourceVertices.clear(); 661 578 662 for( uint i = 0; i < m_shaderFaceNums.size(); i++ ) 579 663 m_shaderFaceNums[i].clear(); … … 666 750 lump_data[lump.filelen] = 0; 667 751 668 parse_token tok, val;669 752 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 ); 701 761 } 702 762 … … 749 809 for( size_t i = 0; i < m_entities.size(); i++ ) 750 810 { 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 ) 760 814 continue; 761 815 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 ); 791 821 } 792 822 } … … 806 836 807 837 ParseEntities(); 838 ImportShaderText(); 808 839 809 840 ImportSurfaces(); … … 897 928 return MS::kSuccess; 898 929 } 899 900 930 }; 901 931 trunk/maya2q3/common.h
r546 r548 41 41 #include <algorithm> 42 42 #include <string> 43 44 #include <sys/types.h> 45 #include <sys/stat.h> 43 46 44 47 #include "../glew/include/GL/glew.h" trunk/maya2q3/maya2q3.vcproj
r540 r548 572 572 </File> 573 573 <File 574 RelativePath=".\q3shader.h" 575 > 576 </File> 577 <File 574 578 RelativePath=".\q3shader_imageloader.cpp" 575 579 > … … 604 608 </File> 605 609 <File 606 RelativePath=".\q3shader.h"607 >608 </File>609 <File610 RelativePath=".\q3types.h"611 >612 </File>613 <File614 RelativePath=".\q3util.h"615 >616 </File>617 <File618 610 RelativePath=".\util-common.h" 619 611 > … … 648 640 <File 649 641 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" 650 654 > 651 655 </File> … … 849 853 Name="bsp" 850 854 > 855 <File 856 RelativePath=".\bsp-entities.cpp" 857 > 858 </File> 851 859 <File 852 860 RelativePath=".\bsp-patches.cpp" trunk/maya2q3/q3util.h
r535 r548 113 113 void PatchToMesh( const Patch &patch, std::vector< q3::drawVert_t > &out_verts, std::vector< int > &out_indices ); 114 114 115 class KeyNotFound : public std::exception 116 { 117 }; 118 119 struct Entity 120 { 121 public: 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 136 private: 137 typedef std::map< std::string, std::string > EntMap; 138 EntMap pairs; 139 140 friend std::vector< Entity > ParseEntityString( const char *str ); 141 }; 142 115 143 }; 116 144 trunk/maya2q3/shader_node.cpp
r181 r548 364 364 m_shader = null; 365 365 } 366 366 } 367 368 q3::ResourceLoader::FreeData( data ); 369 370 if( m_shader ) 367 371 break; 368 }369 370 q3::ResourceLoader::FreeData( data );371 372 } 372 373 } trunk/x42view.net/x42view.net.csproj
r495 r548 173 173 </Compile> 174 174 <Compile Include="Gui\Options.cs"> 175 <SubType> Component</SubType>175 <SubType>Form</SubType> 176 176 </Compile> 177 177 <Compile Include="Gui\Options.Designer.cs">
