//data loading bool ModelData::LoadIn(QString filepath) { bool loaderReady; bool abort; STLTri* pLoadedTri = NULL; Triangle3D newtri; this->filepath = filepath; if(filepath.isEmpty()) return false; //extract filename from path! filename = QFileInfo(filepath).fileName(); B9ModelLoader mLoader(filepath,loaderReady,NULL); if(loaderReady == false)//error opening model data { //display Loader Error QMessageBox msgBox; msgBox.setText(mLoader.GetError()); msgBox.exec(); return false; } //make a progress bar and connect it to LoadingBar loadbar(0,100); loadbar.useCancelButton(false); loadbar.setDescription("Importing: " + filename); QObject::connect(&mLoader,SIGNAL(PercentCompletedUpdate(qint64,qint64)), &loadbar,SLOT(setProgress(qint64,qint64))); //now we are ready to walk the loader through reading each triangle //and copying it into the this model data. while(mLoader.LoadNextTri(pLoadedTri,abort)) { if(abort) { //display Loader abort error QMessageBox msgBox; msgBox.setText(mLoader.GetError()); msgBox.exec(); return false; } else { //newtri.normal.setX(pLoadedTri->nx); //newtri.normal.setY(pLoadedTri->ny); //newtri.normal.setZ(pLoadedTri->nz); newtri.vertex[0].setX(pLoadedTri->x0); newtri.vertex[0].setY(pLoadedTri->y0); newtri.vertex[0].setZ(pLoadedTri->z0); newtri.vertex[1].setX(pLoadedTri->x1); newtri.vertex[1].setY(pLoadedTri->y1); newtri.vertex[1].setZ(pLoadedTri->z1); newtri.vertex[2].setX(pLoadedTri->x2); newtri.vertex[2].setY(pLoadedTri->y2); newtri.vertex[2].setZ(pLoadedTri->z2); //use right hand rule for importing normals - ignore file normals.. newtri.UpdateNormalFromGeom(); delete pLoadedTri; newtri.UpdateBounds(); triList.push_back(newtri); } } qDebug() << "Loaded triangles: " << triList.size(); //now center it! CenterModel(); //generate a normal display lists. int displaySuccess = FormNormalDisplayLists(); if(displaySuccess) return true; else return false; }
//data loading bool ModelData::LoadIn(QString filepath) { unsigned int m; unsigned int t; unsigned int i; Triangle3D newtri; const struct aiFace* face; this->filepath = filepath; if(filepath.isEmpty()) return false; //extract filename from path! filename = QFileInfo(filepath).baseName(); //AI_CONFIG_PP_FD_REMOVE = aiPrimitiveType_POINTS | aiPrimitiveType_LINES; pScene = aiImportFile(filepath.toAscii(), aiProcess_Triangulate);// | aiProcess_JoinIdenticalVertices); //trian if(pScene == NULL)//assimp cant handle the file - lets try our own reader. { //display Assimp Error QMessageBox msgBox; msgBox.setText("Assimp Error: " + QString().fromAscii(aiGetErrorString())); msgBox.exec(); aiReleaseImport(pScene); return false; } qDebug() << "Model imported with " << pScene->mMeshes[0]->mNumFaces << " faces."; for (m = 0; m < pScene->mNumMeshes; m++) { const aiMesh* mesh = pScene->mMeshes[m]; for (t = 0; t < mesh->mNumFaces; t++) { face = &mesh->mFaces[t]; if(face->mNumIndices == 3) { for(i = 0; i < face->mNumIndices; i++) { int index = face->mIndices[i]; newtri.normal.setX(mesh->mNormals[index].x); newtri.normal.setY(mesh->mNormals[index].y); newtri.normal.setZ(mesh->mNormals[index].z); newtri.vertex[i].setX(mesh->mVertices[index].x); newtri.vertex[i].setY(mesh->mVertices[index].y); newtri.vertex[i].setZ(mesh->mVertices[index].z); } newtri.UpdateBounds(); triList.push_back(newtri); } } } aiReleaseImport(pScene); qDebug() << "Loaded triangles: " << triList.size(); //now center it! CenterModel(); //generate a displaylist int displayerror = FormDisplayList(); //check for errors in display list creation (if its a large model the card may run out of memory. if(displayerror){ while(displayerror)//loop and see if there are additional errors as well. { //display Assimp Error qDebug() << "Display List Error: " << displayerror; //write to log as well. QMessageBox msgBox; switch(displayerror) { case GL_OUT_OF_MEMORY: msgBox.setText("OpenGL Error: GL_OUT_OF_MEMORY\nModel is too large to render on your graphics card."); break; case GL_INVALID_ENUM: msgBox.setText("OpenGL Error: GL_INVALID_ENUM"); break; case GL_INVALID_VALUE: msgBox.setText("OpenGL Error: GL_INVALID_VALUE"); break; case GL_INVALID_FRAMEBUFFER_OPERATION: msgBox.setText("OpenGL Error: GL_INVALID_FRAMEBUFFER_OPERATION"); break; case GL_STACK_UNDERFLOW: msgBox.setText("OpenGL Error: GL_STACK_UNDERFLOW"); break; case GL_STACK_OVERFLOW: msgBox.setText("OpenGL Error: GL_STACK_OVERFLOW"); break; default: break; } msgBox.exec(); displayerror = glGetError(); } return false; } return true; }