- 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 );
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -157,6 +157,11 @@ void M3Importer::InternReadFile( const std::string& pFile, aiScene* pScene, IOSy
ok = false; ok = false;
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 );

View File

@ -192,7 +192,7 @@ Node& Sweep::NewFrontTriangle(SweepContext& tcx, Point& point, Node& node)
new_node->next = node.next; new_node->next = node.next;
new_node->prev = &node; new_node->prev = &node;
node.next->prev = new_node; node.next->prev = new_node;
node.next = new_node; node.next = new_node;
if (!Legalize(tcx, *triangle)) { if (!Legalize(tcx, *triangle)) {
tcx.MapTriangleToNodes(*triangle); tcx.MapTriangleToNodes(*triangle);
@ -214,7 +214,7 @@ void Sweep::Fill(SweepContext& tcx, Node& node)
// Update the advancing front // Update the advancing front
node.prev->next = node.next; node.prev->next = node.next;
node.next->prev = node.prev; node.next->prev = node.prev;
// If it was legalized the triangle has already been mapped // If it was legalized the triangle has already been mapped
if (!Legalize(tcx, *triangle)) { if (!Legalize(tcx, *triangle)) {
@ -224,7 +224,7 @@ void Sweep::Fill(SweepContext& tcx, Node& node)
} }
void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n) void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n)
{ {
// Fill right holes // Fill right holes
Node* node = n.next; Node* node = n.next;
@ -467,7 +467,7 @@ void Sweep::FillBasinReq(SweepContext& tcx, Node* node)
return; return;
} }
Fill(tcx, *node); Fill(tcx, *node);
if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) { if (node->prev == tcx.basin.left_node && node->next == tcx.basin.right_node) {
return; return;
@ -562,7 +562,7 @@ void Sweep::FillRightConcaveEdgeEvent(SweepContext& tcx, Edge* edge, Node& node)
// Next is convex // Next is convex
} }
} }
} }
} }
@ -749,15 +749,15 @@ void Sweep::FlipScanEdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle&
Point& newP = NextFlipPoint(ep, eq, ot, op); Point& newP = NextFlipPoint(ep, eq, ot, op);
FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP); FlipScanEdgeEvent(tcx, ep, eq, flip_triangle, ot, newP);
} }
} }
Sweep::~Sweep() { Sweep::~Sweep() {
// Clean up memory // Clean up memory
for(int i = 0; i < nodes_.size(); i++) { for(int i = 0; i < nodes_.size(); i++) {
delete nodes_[i]; delete nodes_[i];
} }
} }
} }

Binary file not shown.