- Update : Fix the M3-Importer: geometry import works.

- Update : Add a non-bsp example model for the m3-loader.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1176 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/head
kimmi 2012-02-19 09:10:04 +00:00
parent 946b2f0354
commit 37fb338c1f
4 changed files with 33 additions and 30 deletions

View File

@ -81,7 +81,7 @@ bool M3Importer::CanRead( const std::string &rFile, IOSystem* /*pIOHandler*/, bo
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void M3Importer::GetExtensionList(std::set<std::string>& extensions) void M3Importer::GetExtensionList(std::set<std::string>& extensions)
{ {
extensions.insert( "m3" ); extensions.insert( M3Extension );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -158,6 +158,11 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy
break; break;
} }
// Everything ok, if not throw an exception
if ( !ok ) {
throw DeadlyImportError( "Failed to open file " + pFile + ".");
}
// Get all region data // Get all region data
regions = GetEntries<Region>( pViews->regions ); regions = GetEntries<Region>( pViews->regions );
@ -165,11 +170,6 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy
faces = GetEntries<uint16>( pViews->faces ); faces = GetEntries<uint16>( pViews->faces );
nFaces = pViews->faces.nEntries; nFaces = pViews->faces.nEntries;
// Everything ok, if not throw an exception
if ( !ok ) {
throw DeadlyImportError( "Failed to open file " + pFile + ".");
}
// Convert the vertices // Convert the vertices
std::vector<aiVector3D> vertices; std::vector<aiVector3D> vertices;
vertices.resize( nVertices ); vertices.resize( nVertices );
@ -186,21 +186,21 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy
} }
} }
// Write UV coords // Write the UV coordinates
offset = 0; offset = 0;
std::vector<aiVector3D> uvCoords; std::vector<aiVector3D> uvCoords;
uvCoords.resize( nVertices ); uvCoords.resize( nVertices );
for( unsigned int i = 0; i < nVertices; ++i ) { for( unsigned int i = 0; i < nVertices; ++i ) {
if( pVerts1 ) { if( pVerts1 ) {
float u = (float) pVerts1[i].uv[0] / 2048; float u = (float) pVerts1[ i ].uv[ 0 ] / 2048;
float v = (float) pVerts1[i].uv[1] / 2048; float v = (float) pVerts1[ i ].uv[ 1 ] / 2048;
uvCoords[ offset ].Set( u, v, 0.0f ); uvCoords[ offset ].Set( u, v, 0.0f );
++offset; ++offset;
} }
if( pVerts2 ) { if( pVerts2 ) {
float u = (float) pVerts2[i].uv[0] / 2048; float u = (float) pVerts2[ i ].uv[ 0 ] / 2048;
float v = (float) pVerts2[i].uv[1] / 2048; float v = (float) pVerts2[ i ].uv[ 1 ] / 2048;
uvCoords[ offset ].Set( u, v, 0.0f ); uvCoords[ offset ].Set( u, v, 0.0f );
++offset; ++offset;
} }
@ -267,7 +267,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
pRootNode->mChildren = new aiNode*[ pRootNode->mNumChildren ]; pRootNode->mChildren = new aiNode*[ pRootNode->mNumChildren ];
} }
for ( unsigned int i=0; i<pViews->regions.nEntries; ++i ) { for ( unsigned int i=0; i<pRootNode->mNumChildren; ++i ) {
// Create a new node // Create a new node
pCurrentNode = createNode( pRootNode ); pCurrentNode = createNode( pRootNode );
std::stringstream stream; std::stringstream stream;
@ -276,10 +276,10 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
pRootNode->mChildren[ i ] = pCurrentNode; pRootNode->mChildren[ i ] = pCurrentNode;
// Loop over the faces of the nodes // Loop over the faces of the nodes
unsigned int numFaces = ( pRegions[ i ].ofsIndices + pRegions[ i ].nIndices ) - pRegions[ i ].ofsIndices; unsigned int numFaces = ( ( pRegions[ i ].ofsIndices + pRegions[ i ].nIndices ) - pRegions[ i ].ofsIndices ) / 3;
aiMesh *pMesh = new aiMesh; aiMesh *pMesh = new aiMesh;
MeshArray.push_back( pMesh ); MeshArray.push_back( pMesh );
//pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
pMesh->mNumFaces = numFaces; pMesh->mNumFaces = numFaces;
pMesh->mFaces = new aiFace[ pMesh->mNumFaces ]; pMesh->mFaces = new aiFace[ pMesh->mNumFaces ];
@ -303,7 +303,7 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
pCurrentNode->mMeshes = new unsigned int[ 1 ]; pCurrentNode->mMeshes = new unsigned int[ 1 ];
const unsigned int meshIdx = MeshArray.size() - 1; const unsigned int meshIdx = MeshArray.size() - 1;
pCurrentNode->mMeshes[ 0 ] = meshIdx; pCurrentNode->mMeshes[ 0 ] = meshIdx;
createVertexData( pMesh, vertices, normals ); createVertexData( pMesh, vertices, uvCoords, normals );
} }
// Copy the meshes into the scene // Copy the meshes into the scene
@ -319,12 +319,14 @@ void M3Importer::convertToAssimp( const std::string& pFile, aiScene* pScene, DIV
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// //
void M3Importer::createVertexData( aiMesh *pMesh, const std::vector<aiVector3D> &vertices, void M3Importer::createVertexData( aiMesh *pMesh, const std::vector<aiVector3D> &vertices,
const std::vector<aiVector3D> &uvCoords,
const std::vector<aiVector3D> &normals ) const std::vector<aiVector3D> &normals )
{ {
unsigned int numIndices = 0; unsigned int numIndices = 0;
pMesh->mNumVertices = pMesh->mNumFaces * 3; pMesh->mNumVertices = pMesh->mNumFaces * 3;
pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ]; pMesh->mVertices = new aiVector3D[ pMesh->mNumVertices ];
// pMesh->mNumUVComponents
pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ]; pMesh->mNormals = new aiVector3D[ pMesh->mNumVertices ];
unsigned int pos = 0; unsigned int pos = 0;
for ( unsigned int currentFace = 0; currentFace < pMesh->mNumFaces; currentFace++ ) { for ( unsigned int currentFace = 0; currentFace < pMesh->mNumFaces; currentFace++ ) {

View File

@ -698,7 +698,8 @@ private:
void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler ); void InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler );
void convertToAssimp( const std::string& pFile, aiScene* pScene, DIV *pViews, Region *pRegions, uint16 *pFaces, void convertToAssimp( const std::string& pFile, aiScene* pScene, DIV *pViews, Region *pRegions, uint16 *pFaces,
const std::vector<aiVector3D> &vertices, const std::vector<aiVector3D> &uvCoords, const std::vector<aiVector3D> &normals ); const std::vector<aiVector3D> &vertices, const std::vector<aiVector3D> &uvCoords, const std::vector<aiVector3D> &normals );
void createVertexData( aiMesh *pMesh, const std::vector<aiVector3D> &vertices, const std::vector<aiVector3D> &normals ); void createVertexData( aiMesh *pMesh, const std::vector<aiVector3D> &vertices, const std::vector<aiVector3D> &uvCoords,
const std::vector<aiVector3D> &normals );
aiNode *createNode( aiNode *pParent ); aiNode *createNode( aiNode *pParent );
template<typename T> template<typename T>
T* GetEntries( Reference ref ); T* GetEntries( Reference ref );

Binary file not shown.