Changeset 540
- Timestamp:
- 03/06/08 05:59:35 (10 months ago)
- Files:
-
- trunk/bin/win32/release (8.5)/bin/maya2q3.mll (modified) (previous)
- trunk/bin/win32/release (8.5)/bin/maya2q3.pdb (modified) (previous)
- trunk/common/util-string.h (modified) (1 diff)
- trunk/common/util.h (modified) (3 diffs)
- trunk/glew/build/vc2005/glew_static.vcproj (modified) (1 diff)
- trunk/libx42pp/include/x42util.h (modified) (1 diff)
- trunk/maya2q3/bsp.cpp (modified) (8 diffs)
- trunk/maya2q3/common.h (modified) (2 diffs)
- trunk/maya2q3/maya2q3.vcproj (modified) (15 diffs)
- trunk/maya2q3/maya_entry.cpp (modified) (1 diff)
- trunk/maya2q3/util-ext.cpp (modified) (1 diff)
- trunk/maya2q3/util-maya2q3.h (modified) (1 diff)
- trunk/physfs/physfs_static.vcproj (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/common/util-string.h
r211 r540 122 122 } 123 123 124 size_t Length() 124 size_t Length() const 125 125 { 126 126 return strlen( val ); trunk/common/util.h
r211 r540 27 27 void demand( bool cond, const char *msg ); 28 28 29 #ifdef assert 30 #undef assert 31 #endif 32 29 33 #ifdef _DEBUG 30 34 #define assert demand … … 142 146 END_ENUM_WITH_TYPE_OPEN( E, T ) \ 143 147 END_OPEN_ENUM( E ) 148 149 class bad_int_cast : public std::exception 150 { 151 public: 152 bad_int_cast( void ) : std::exception( "Integer conversion caused loss of data." ) { } 153 virtual ~bad_int_cast( void ) { } 154 }; 155 156 template< typename T, size_t num_bits = sizeof( T ) * CHAR_BIT > 157 struct integer_traits 158 { 159 private: 160 template< size_t num_bits > 161 struct signed_max 162 { 163 static const T val = (T)(signed_max< num_bits - 1 >::val << 1) | 0x1; 164 }; 165 166 template< > 167 struct signed_max< 2 > 168 { 169 static const T val = (T)0x1; 170 }; 171 172 template< > 173 struct signed_max< 1 > 174 { 175 //can't have a 1-bit signed value 176 }; 177 178 template< > 179 struct signed_max< 0 > 180 { 181 //can't have a 0-bit signed value 182 }; 183 184 template< size_t num_bits > 185 struct signed_min 186 { 187 static const T val = (T)((signed_min< num_bits - 1 >::val) << 1); 188 }; 189 190 template< > 191 struct signed_min< 2 > 192 { 193 static const T val = (T)0x2; 194 }; 195 196 template< > 197 struct signed_min< 1 > 198 { 199 //can't have a 1-bit signed value 200 }; 201 202 template< > 203 struct signed_min< 0 > 204 { 205 //can't have a 0-bit signed value 206 }; 207 208 template< size_t num_bits > 209 struct unsigned_max 210 { 211 static const T val = (T)(unsigned_max< num_bits - 1 >::val << 1) | 0x1; 212 }; 213 214 template< > 215 struct unsigned_max< 1 > 216 { 217 static const T val = (T)0x1; 218 }; 219 220 template< > 221 struct unsigned_max< 0 > 222 { 223 //can'g have a 0-bit unsigned value 224 }; 225 226 public: 227 static const bool is_signed = (((T)-1) < 0); 228 static const T max_val = is_signed ? signed_max< num_bits >::val : unsigned_max< num_bits >::val; 229 static const T min_val = is_signed ? signed_min< num_bits >::val : (T)0; 230 231 static const T bit_width = num_bits; 232 }; 233 234 #pragma warning( push ) 235 #pragma warning( disable : 4127 ) //constant conditional --by design 236 237 template< typename O, typename I > 238 inline O checked_int_cast( const I &in ) 239 { 240 typedef integer_traits<O> ot; 241 242 if( in < ot::min_val || in > ot::max_val ) 243 throw bad_int_cast(); 244 245 return static_cast< O >( in ); 246 } 247 248 #pragma warning( pop ) 249 250 #define lengthof( a ) (sizeof( a ) / sizeof( (a)[0] )) 251 252 template< typename T > 253 inline T align( T p, T a ) 254 { 255 return ((p + a - (T)1) / a) * a; 256 } 257 258 template< typename T > 259 inline T* align( T *p, intptr_t a ) 260 { 261 return (T*)align( (intptr_t)p, a ); 262 } 263 264 template< typename T > 265 inline bool is_pow_2( T i ) 266 { 267 return (i & (i - 1)) == 0; 268 } 269 270 template< typename T > 271 inline int log2_fast( T i ) 272 { 273 for( int log = 0; log < integer_traits< T >::bit_width; log++ ) 274 if( (T)1 << log == i ) 275 return log; 276 277 return -1; 278 } 144 279 145 280 typedef unsigned char byte; … … 162 297 #endif 163 298 164 #define __decl_minmax_s( T ) const T min_##T = ~(((T)~(T)0) >> 1); const T max_##T = ((T)~(T)0) >> 1; //min val is only high bit, max is all but high bit165 #define __decl_minmax_u( T ) const T min_##T = 0; const T max_##T = (T)~(T)0;166 167 __decl_minmax_u( byte ) __decl_minmax_s( sbyte )168 __decl_minmax_u( ushort ) __decl_minmax_s( short )169 __decl_minmax_u( uint ) __decl_minmax_s( int )170 __decl_minmax_u( uintptr ) __decl_minmax_s( intptr )171 __decl_minmax_u( uhuge ) __decl_minmax_s( huge )172 173 #undef __decl_minmax_s174 #undef __decl_minmax_u175 176 299 struct argb 177 300 { trunk/glew/build/vc2005/glew_static.vcproj
r207 r540 46 46 Name="VCCLCompilerTool" 47 47 Optimization="2" 48 InlineFunctionExpansion=" 1"48 InlineFunctionExpansion="2" 49 49 AdditionalIncludeDirectories="../../include" 50 50 PreprocessorDefinitions="WIN32;NDEBUG;_LIB;WIN32_LEAN_AND_MEAN;VC_EXTRALEAN;GLEW_STATIC" 51 51 StringPooling="true" 52 RuntimeLibrary=" 0"52 RuntimeLibrary="2" 53 53 EnableFunctionLevelLinking="true" 54 54 PrecompiledHeaderFile=".\static/release/glew_static.pch" trunk/libx42pp/include/x42util.h
r462 r540 28 28 namespace util 29 29 { 30 31 #pragma once32 30 33 31 class bad_int_cast trunk/maya2q3/bsp.cpp
r535 r540 25 25 { 26 26 27 class Bsp MeshData27 class BspImporter 28 28 { 29 29 public: 30 BspImporter( void ); 31 void Import( std::istream &stm ); 32 33 private: 30 34 float m_unitScale; 35 bool m_combineMeshes; 31 36 32 37 MPointArray m_verts; 38 33 39 MIntArray m_faceCounts; 34 40 MIntArray m_faceVertIndices; 35 41 42 MIntArray m_textureUVIDs; 43 MFloatArray m_textureU, m_textureV; 44 MIntArray m_lightmapUVIDs; 45 MFloatArray m_lightmapU, m_lightmapV; 46 47 MColorArray m_vertexLight; 48 MIntArray m_vertexLightIDs; 49 36 50 std::vector< q3::Patch > m_patchStaging; 37 51 38 BspMeshData( void ); 39 40 void AppendBSP( std::istream &stm ); 41 42 MObject CreateMesh( void ); 43 44 private: 45 void AppendTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, 52 MObjectArray m_meshes; 53 54 std::vector< std::pair< int, int > > m_shaderMap; 55 std::vector< std::vector< int > > m_shaderFaceNums; 56 MObjectArray m_shaders; 57 58 q3::dheader_t m_fileHeader; 59 BinaryReader *m_fileData; 60 61 template< typename T > 62 std::vector< T > ReadLump( int lumpIndex ) 63 { 64 const q3::lump_t &lump = m_fileHeader.lumps[lumpIndex]; 65 66 if( lump.filelen % sizeof( T ) != 0 ) 67 throw std::exception( "Funny lump size." ); 68 69 std::vector< T > ret( lump.filelen / sizeof( T ) ); 70 m_fileData->seek( lump.fileofs ); 71 m_fileData->read( &ret[0], lump.filelen ); 72 73 return ret; 74 } 75 76 void ParseTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, int shaderBin, 46 77 int firstVert = 0, int vertexCount = -1, int firstIndex = 0, int indexCount = -1 ); 47 void AppendFace( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ); 48 void AppendMesh( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ); 49 void AppendPatch( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ); 50 51 void BakePatches(); 78 79 MObject CreateMesh(); 80 void ClearStagingArea(); 81 82 int GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ); 83 84 void ImportSurfaces(); 52 85 }; 53 86 54 87 #pragma warning( disable : 4100 ) //shut up unreferenced parameter warnings until dev of this file is done 55 88 56 BspMeshData::BspMeshData( void ) 57 { 58 m_unitScale = 1.0F; 59 } 60 61 void BspMeshData::AppendTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, 62 int firstVert, int vertexCount, int firstIndex, int indexCount ) 89 BspImporter::BspImporter( void ) 90 { 91 m_unitScale = 0.01F; 92 m_combineMeshes = true; //augh! 93 } 94 95 int BspImporter::GetShaderIndex( const std::vector< q3::dshader_t > &shaders, int shaderNum, int lightmapNum ) 96 { 97 shaderNum = clamp( shaderNum, 0, (int)shaders.size() - 1 ); 98 99 for( uint i = 0; i < m_shaderMap.size(); i++ ) 100 { 101 if( m_shaderMap[i].first == shaderNum && 102 m_shaderMap[i].second == lightmapNum ) 103 return (int)i; 104 } 105 106 const q3::dshader_t &shader = shaders[shaderNum]; 107 sstr< 1024 > buf; 108 109 size_t srcLen = shader.shader.Length(); 110 for( size_t i = 0; i < srcLen; i++ ) 111 { 112 char c = shader.shader[i]; 113 switch( c ) 114 { 115 case '_': 116 buf.Append( "__" ); 117 break; 118 119 case '/': 120 case '\\': 121 buf.Append( "_" ); 122 break; 123 124 default: 125 buf.Append( "%c", c ); 126 break; 127 } 128 } 129 130 if( lightmapNum > 0 ) 131 buf.Append( "_lmap_%i", lightmapNum ); 132 133 MStatus stat; 134 MFnLambertShader fnShader; 135 136 fnShader.create( true, &stat ); 137 check_status( stat ); 138 139 fnShader.setName( MString( buf ), &stat ); 140 check_status( stat ); 141 142 MPlug outColorPlug = fnShader.findPlug( MString( "outColor" ), &stat ); 143 check_status( stat ); 144 145 MObject shaderObj = fnShader.object( &stat ); 146 check_status( stat ); 147 148 MFnSet fnGroup; 149 MSelectionList empty; 150 fnGroup.create( empty, MFnSet::kRenderableOnly, false, &stat ); 151 check_status( stat ); 152 153 buf.Append( "SG" ); 154 fnGroup.setName( MString( buf ), &stat ); 155 check_status( stat ); 156 157 MPlug surfaceShaderPlug = fnGroup.findPlug( MString( "surfaceShader" ), &stat ); 158 check_status( stat ); 159 160 MObject groupObj = fnGroup.object( &stat ); 161 check_status( stat ); 162 163 MDGModifier dgMod; 164 165 MPlugArray connections; 166 surfaceShaderPlug.connectedTo( connections, true, false, &stat ); 167 check_status( stat ); 168 169 for( uint i = 0; i < connections.length(); i++ ) 170 { 171 stat = dgMod.disconnect( connections[i], surfaceShaderPlug ); 172 check_status( stat ); 173 } 174 175 stat = dgMod.connect( outColorPlug, surfaceShaderPlug ); 176 check_status( stat ); 177 178 stat = dgMod.doIt(); 179 check_status( stat ); 180 181 m_shaders.append( groupObj ); 182 183 m_shaderMap.push_back( std::pair< int, int >( shaderNum, lightmapNum ) ); 184 m_shaderFaceNums.push_back( std::vector< int >() ); 185 186 return (int)(m_shaderFaceNums.size() - 1); 187 } 188 189 void BspImporter::ParseTriangles( const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices, 190 int shaderBin, int firstVert, int vertexCount, int firstIndex, int indexCount ) 63 191 { 64 192 if( vertexCount == -1 ) … … 69 197 int baseVert = (int)m_verts.length(); 70 198 for( int i = 0; i < vertexCount; i++ ) 71 m_verts.append( MPoint( verts[firstVert + i].xyz ) ); 199 { 200 const q3::drawVert_t &v = verts[firstVert + i]; 201 202 m_verts.append( MPoint( q3::Q3VecToMaya( v.xyz ) * m_unitScale ) ); 203 m_textureU.append( v.st.x ); 204 m_textureV.append( v.st.y ); 205 m_lightmapU.append( v.lightmap.x ); 206 m_lightmapV.append( v.lightmap.y ); 207 m_vertexLight.append( MColor( MColor::kRGB, v.color[0], v.color[1], v.color[2] ) ); 208 } 72 209 73 210 //ToDo: collapse out coplanar edges (?) … … 76 213 for( int i = 0; i < numTris; i++ ) 77 214 { 78 m_faceVertIndices.append( baseVert + indices[firstIndex + i * 3 + 0] ); 79 m_faceVertIndices.append( baseVert + indices[firstIndex + i * 3 + 2] ); 80 m_faceVertIndices.append( baseVert + indices[firstIndex + i * 3 + 1] ); 215 int index; 216 217 index = baseVert + indices[firstIndex + i * 3 + 0]; 218 m_faceVertIndices.append( index ); 219 m_textureUVIDs.append( index ); 220 m_lightmapUVIDs.append( index ); 221 m_vertexLightIDs.append( index ); 222 223 index = baseVert + indices[firstIndex + i * 3 + 2]; 224 m_faceVertIndices.append( index ); 225 m_textureUVIDs.append( index ); 226 m_lightmapUVIDs.append( index ); 227 m_vertexLightIDs.append( index ); 228 229 index = baseVert + indices[firstIndex + i * 3 + 1]; 230 m_faceVertIndices.append( index ); 231 m_textureUVIDs.append( index ); 232 m_lightmapUVIDs.append( index ); 233 m_vertexLightIDs.append( index ); 234 235 if( shaderBin != -1 ) 236 m_shaderFaceNums[shaderBin].push_back( m_faceCounts.length() ); 81 237 82 238 m_faceCounts.append( 3 ); … … 84 240 } 85 241 86 void BspMeshData::AppendFace( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ) 87 { 88 AppendTriangles( verts, indices, surf.firstVert, surf.numVerts, surf.firstIndex, surf.numIndexes ); 89 } 90 91 void BspMeshData::AppendMesh( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ) 92 { 93 AppendTriangles( verts, indices, surf.firstVert, surf.numVerts, surf.firstIndex, surf.numIndexes ); 94 } 95 96 void BspMeshData::AppendPatch( const q3::dsurface_t &surf, const std::vector< q3::drawVert_t > &verts, const std::vector< int > &indices ) 97 { 98 q3::Patch p = q3::SubdividePatchToGrid( surf.patchWidth, surf.patchHeight, &verts[surf.firstVert] ); 99 m_patchStaging.push_back( p ); 100 } 101 102 void BspMeshData::BakePatches() 103 { 242 void BspImporter::ImportSurfaces() 243 { 244 std::vector< q3::dsurface_t > surfs = ReadLump< q3::dsurface_t >( q3::LUMP_SURFACES ); 245 std::vector< q3::drawVert_t > verts = ReadLump< q3::drawVert_t >( q3::LUMP_DRAWVERTS ); 246 std::vector< int > indices = ReadLump< int >( q3::LUMP_DRAWINDEXES ); 247 248 std::vector< q3::dshader_t > shaders = ReadLump< q3::dshader_t >( q3::LUMP_SHADERS ); 249 250 m_meshes.setLength( (uint)surfs.size() ); 251 for( uint i = 0; i < surfs.size(); i++ ) 252 { 253 const q3::dsurface_t &surf = surfs[i]; 254 255 switch( surf.surfaceType ) 256 { 257 case q3::MST_PLANAR: 258 case q3::MST_TRIANGLE_SOUP: 259 { 260 int shader = GetShaderIndex( shaders, surf.shaderNum, surf.lightmapNum ); 261 ParseTriangles( verts, indices, shader, surf.firstVert, surf.numVerts, surf.firstIndex, surf.numIndexes ); 262 } 263 break; 264 265 case q3::MST_PATCH: 266 { 267 q3::Patch p = q3::SubdividePatchToGrid( surf.patchWidth, surf.patchHeight, &verts[surf.firstVert] ); 268 p.meshIdx = i; 269 m_patchStaging.push_back( p ); 270 } 271 break; 272 273 default: 274 warn( "Ignoring surface." ); 275 } 276 277 if( m_verts.length() && !m_combineMeshes ) 278 { 279 m_meshes[i] = CreateMesh(); 280 ClearStagingArea(); 281 } 282 } 283 104 284 q3::StitchAllPatches( m_patchStaging ); 105 285 q3::FixSharedVertexLodError( m_patchStaging ); 106 286 107 std::vector< int > indices; 108 std::vector< q3::drawVert_t > verts; 109 110 for( uint i = 0; i < m_patchStaging.size(); i++ ) 111 { 112 q3::PatchToMesh( m_patchStaging[i], verts, indices ); 113 AppendTriangles( verts, indices ); 287 { 288 std::vector< int > indices; 289 std::vector< q3::drawVert_t > verts; 290 291 for( uint i = 0; i < m_patchStaging.size(); i++ ) 292 { 293 q3::Patch &p = m_patchStaging[i]; 294 const q3::dsurface_t &srcSurf = surfs[p.meshIdx]; 295 296 int shader = GetShaderIndex( shaders, srcSurf.shaderNum, srcSurf.lightmapNum ); 297 298 q3::PatchToMesh( p, verts, indices ); 299 ParseTriangles( verts, indices, shader ); 300 301 if( m_verts.length() && !m_combineMeshes ) 302 { 303 m_meshes[p.meshIdx] = CreateMesh(); 304 ClearStagingArea(); 305 } 306 } 307 } 308 309 if( m_verts.length() ) 310 { 311 m_meshes.append( CreateMesh() ); 312 ClearStagingArea(); 114 313 } 115 314 … … 117 316 } 118 317 119 void Bsp MeshData::AppendBSP( std::istream &stm )318 void BspImporter::Import( std::istream &stm ) 120 319 { 121 320 size_t base_pos = stm.tellg(); … … 123 322 BinaryReader in( stm ); 124 323 125 q3::dheader_t head; 126 in >> head; 127 128 const q3::lump_t &lumpSurfs = head.lumps[q3::LUMP_SURFACES]; 129 const q3::lump_t &lumpVerts = head.lumps[q3::LUMP_DRAWVERTS]; 130 const q3::lump_t &lumpIndices = head.lumps[q3::LUMP_DRAWINDEXES]; 131 132 demand( lumpSurfs.filelen % sizeof( q3::dsurface_t ) == 0, "Funny lump size." ); 133 demand( lumpVerts.filelen % sizeof( q3::drawVert_t ) == 0, "Funny lump size." ); 134 demand( lumpIndices.filelen % sizeof( int ) == 0, "Funny lump size." ); 135 136 size_t numSurfaces = lumpSurfs.filelen / sizeof( q3::dsurface_t ); 137 138 std::vector< q3::dsurface_t > surfs( numSurfaces ); 139 in.seek( base_pos + lumpSurfs.fileofs ); 140 in.read( &surfs[0], lumpSurfs.filelen ); 141 142 std::vector< q3::drawVert_t > verts( lumpVerts.filelen / sizeof( q3::drawVert_t ) ); 143 in.seek( base_pos + lumpVerts.fileofs ); 144 in.read( &verts[0], lumpVerts.filelen ); 145 146 for( uint i = 0; i < verts.size(); i++ ) 147 //do the position conversion once 148 verts[i].xyz = q3::Q3VecToMaya( verts[i].xyz ) * m_unitScale; 149 150 std::vector< int > indices( lumpIndices.filelen / sizeof( int ) ); 151 in.seek( base_pos + lumpIndices.fileofs ); 152 in.read( &indices[0], lumpIndices.filelen ); 153 154 for( uint i = 0; i < numSurfaces; i++ ) 155 { 156 switch( surfs[i].surfaceType ) 157 { 158 case q3::MST_PLANAR: 159 AppendFace( surfs[i], verts, indices ); 160 break; 161 162 case q3::MST_TRIANGLE_SOUP: 163 AppendMesh( surfs[i], verts, indices ); 164 break; 165 166 case q3::MST_PATCH: 167 AppendPatch( surfs[i], verts, indices ); 168 break; 169 170 default: 171 warn( "Ignoring surface." ); 172 } 173 } 174 } 175 176 MObject BspMeshData::CreateMesh( void ) 177 { 178 BakePatches(); 179 324 in >> m_fileHeader; 325 for( int i = 0; i < q3::HEADER_LUMPS; i++ ) 326 m_fileHeader.lumps[i].fileofs += base_pos; 327 328 m_fileData = ∈ 329 330 ImportSurfaces(); 331 } 332 333 MObject BspImporter::CreateMesh( void ) 334 { 180 335 MStatus stat; 181 336 … … 183 338 MObject ret = mesh.create( m_verts.length(), m_faceCounts.length(), m_verts, 184 339 m_faceCounts, m_faceVertIndices, MObject::kNullObj, &stat ); 185 186 if( !stat ) 187 return MObject::kNullObj; 188 189 //ToDo: stuff to the mesh? 190 191 mesh.updateSurface(); 192 193 MString cmd = MString( "sets -e -fe initialShadingGroup " ) + mesh.name(); 194 MGlobal::executeCommand( cmd ); 340 check_status( stat ); 341 342 MString texCoordSetName( "TexCoords" ); 343 stat = mesh.createUVSet( texCoordSetName ); 344 check_status( stat ); 345 stat = mesh.setUVs( m_textureU, m_textureV, &texCoordSetName ); 346 check_status( stat ); 347 stat = mesh.assignUVs( m_faceCounts, m_textureUVIDs, &texCoordSetName ); 348 check_status( stat ); 349 350 MString lightmapSetName( "LightmapCoords" ); 351 stat = mesh.createUVSet( lightmapSetName ); 352 check_status( stat ); 353 stat = mesh.setUVs( m_lightmapU, m_lightmapV, &lightmapSetName ); 354 check_status( stat ); 355 stat = mesh.assignUVs( m_faceCounts, m_lightmapUVIDs, &lightmapSetName ); 356 check_status( stat ); 357 358 stat = mesh.setCurrentUVSetName( texCoordSetName ); 359 check_status( stat ); 360 361 mesh.deleteUVSet( "map1" ); 362 363 MString vertexLightName( "VertexLight" ); 364 stat = mesh.createColorSet( vertexLightName ); 365 check_status( stat ); 366 stat = mesh.setColors( m_vertexLight, &vertexLightName ); 367 check_status( stat ); 368 stat = mesh.assignColors( m_vertexLightIDs, &vertexLightName ); 369 check_status( stat ); 370 371 stat = mesh.updateSurface(); 372 check_status( stat ); 373 374 MDagPath objPath; 375 stat = mesh.getPath( objPath ); 376 check_status( stat ); 377 378 for( uint i = 0; i < m_shaderFaceNums.size(); i++ ) 379 { 380 const std::vector< int > &map = m_shaderFaceNums[i]; 381 382 if( !map.size() ) 383 continue; 384 385 MFnSet fnSg( m_shaders[i], &stat ); 386 check_status( stat ); 387 388 MItMeshPolygon polyIt( objPath, MObject::kNullObj, &stat ); 389 check_status( stat ); 390 391 MSelectionList sel; 392 393 for( uint j = 0; j < map.size(); j++ ) 394 { 395 int prevIndex; 396 stat = polyIt.setIndex( map[j], prevIndex ); 397 check_status( stat ); 398 399 MObject comp = polyIt.polygon( &stat ); 400 check_status( stat ); 401 402 stat = sel.add( objPath, comp ); 403 check_status( stat ); 404 } 405 406 stat = fnSg.addMembers( sel ); 407 check_status( stat ); 408 } 409 410 //MString cmd = MString( "sets -e -fe initialShadingGroup " ) + mesh.name(); 411 //stat = MGlobal::executeCommand( cmd ); 412 //check_status( stat ); 195 413 196 414 return ret; 197 415 } 198 416 199 void ImportBspFile( std::ifstream &file ) 200 { 201 BspMeshData mesh; 202 mesh.AppendBSP( file ); 203 204 MObject meshObj = mesh.CreateMesh(); 205 206 demand( !meshObj.isNull(), "Failed to create mesh." ); 417 void BspImporter::ClearStagingArea() 418 { 419 m_verts.clear(); 420 421 m_faceCounts.clear(); 422 m_faceVertIndices.clear(); 423 424 m_textureUVIDs.clear(); 425 m_textureU.clear(); 426 m_textureV.clear(); 427 m_lightmapUVIDs.clear(); 428 m_lightmapU.clear(); 429 m_lightmapV.clear(); 430 431 m_vertexLight.clear(); 432 m_vertexLightIDs.clear(); 433 434 for( uint i = 0; i < m_shaderFaceNums.size(); i++ ) 435 m_shaderFaceNums[i].clear(); 207 436 } 208 437 … … 243 472 try 244 473 { 245 ImportBspFile( file ); 474 BspImporter imp; 475 imp.Import( file ); 476 } 477 catch( std::exception &ex ) 478 { 479 MGlobal::displayError( MString( ex.what() ) ); 246 480 } 247 481 catch( ... ) trunk/maya2q3/common.h
r495 r540 112 112 #include <maya/MFnTransform.h> 113 113 #include <maya/MItMeshPolygon.h> 114 #include <maya/MFnLambertShader.h> 114 115 115 116 #include <maya/MTime.h> … … 165 166 #endif 166 167 168 #include <boost/smart_ptr.hpp> 169 167 170 #include "../common/math.h" 168 171 #include "../common/math-vector.h" trunk/maya2q3/maya2q3.vcproj
r535 r540 46 46 MinimalRebuild="true" 47 47 BasicRuntimeChecks="3" 48 RuntimeLibrary=" 1"48 RuntimeLibrary="2" 49 49 DefaultCharIsUnsigned="true" 50 50 TreatWChar_tAsBuiltInType="true" … … 134 134 AdditionalIncludeDirectories="$(ProgramFiles)\Alias\Maya6.0\include" 135 135 PreprocessorDefinitions="NT_PLUGIN;GLEW_STATIC" 136 RuntimeLibrary=" 0"136 RuntimeLibrary="2" 137 137 DefaultCharIsUnsigned="true" 138 138 TreatWChar_tAsBuiltInType="true" … … 226 226 MinimalRebuild="true" 227 227 BasicRuntimeChecks="3" 228 RuntimeLibrary=" 0"228 RuntimeLibrary="2" 229 229 DefaultCharIsUnsigned="true" 230 230 TreatWChar_tAsBuiltInType="true" … … 314 314 AdditionalIncludeDirectories="$(ProgramFiles)\Alias\Maya7.0\include" 315 315 PreprocessorDefinitions="NT_PLUGIN;GLEW_STATIC" 316 RuntimeLibrary=" 0"316 RuntimeLibrary="2" 317 317 DefaultCharIsUnsigned="true" 318 318 TreatWChar_tAsBuiltInType="true" … … 406 406 MinimalRebuild="true" 407 407 BasicRuntimeChecks="3" 408 RuntimeLibrary=" 0"408 RuntimeLibrary="2" 409 409 DefaultCharIsUnsigned="true" 410 410 TreatWChar_tAsBuiltInType="true" … … 464 464 Name="VCPostBuildEventTool" 465 465 Description="Copying to Maya plugins directory." 466 CommandLine="copy "$(OutDir)\$(ProjectName).mll" "$(ProgramFiles)\Alias\Maya7.0\bin\plug-ins"
copy "$(ProjectDir)\AEQ3ShaderTemplate.mel" "$(ProgramFiles)\Alias\Maya7.0\scripts\AETemplates"
copy "$(ProjectDir)\maya2q3.mel" "$(ProgramFiles)\Alias\Maya7.0\scripts\others"
" 467 ExcludedFromBuild="true" 466 CommandLine="copy "$(OutDir)\$(ProjectName).mll" "C:\Program Files (x86)\Autodesk\Maya8.5\bin\plug-ins"
copy "$(ProjectDir)\AEQ3ShaderTemplate.mel" "C:\Program Files (x86)\Autodesk\Maya8.5\scripts\AETemplates"
copy "$(ProjectDir)\maya2q3.mel" "C:\Program Files (x86)\Autodesk\Maya8.5\scripts\others"
" 468 467 /> 469 468 </Configuration> … … 495 494 AdditionalIncludeDirectories=""C:\Program Files (x86)\Autodesk\Maya8.5\include"" 496 495 PreprocessorDefinitions="NT_PLUGIN;GLEW_STATIC" 497 RuntimeLibrary=" 0"496 RuntimeLibrary="2" 498 497 DefaultCharIsUnsigned="true" 499 498 TreatWChar_tAsBuiltInType="true" … … 562 561 <Files> 563 562 <Filter 564 Name="Source Files" 565 Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" 566 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" 567 > 568 <File 569 RelativePath=".\bsp-patches.cpp" 570 > 571 </File> 572 <File 573 RelativePath=".\bsp.cpp" 574 > 575 </File> 576 <File 577 RelativePath=".\math.cpp" 578 > 579 </File> 563 Name="q3shader" 564 > 580 565 <File 581 566 RelativePath=".\maya2q3_cmd.cpp" … … 583 568 </File> 584 569 <File 585 RelativePath=".\maya_entry.cpp"586 >587 </File>588 <File589 RelativePath=".\md3.cpp"590 >591 </File>592 <File593 570 RelativePath=".\q3shader.cpp" 594 571 > … … 608 585 <File 609 586 RelativePath=".\shader_node.cpp" 610 >611 </File>612 <File613 RelativePath=".\util-ext.cpp"614 >615 </File>616 <File617 RelativePath=".\util.cpp"618 587 > 619 588 </File> 620 589 </Filter> 621 590 <Filter 622 Name="Header Files" 623 Filter="h;hpp;hxx;hm;inl;inc;xsd" 624 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" 625 > 626 <File 627 RelativePath=".\common.h" 628 > 629 </File> 630 <File 631 RelativePath=".\common.pch.cpp" 632 > 633 <FileConfiguration 634 Name="Debug (6.0)|Win32" 635 > 636 <Tool 637 Name="VCCLCompilerTool" 638 UsePrecompiledHeader="1" 639 /> 640 </FileConfiguration> 641 <FileConfiguration 642 Name="Release (6.0)|Win32" 643 > 644 <Tool 645 Name="VCCLCompilerTool" 646 UsePrecompiledHeader="1" 647 /> 648 </FileConfiguration> 649 <FileConfiguration 650 Name="Debug (7.0)|Win32" 651 > 652 <Tool 653 Name="VCCLCompilerTool" 654 UsePrecompiledHeader="1" 655 /> 656 </FileConfiguration> 657 <FileConfiguration 658
