void Scene::updateVBOs() { QSegMesh * mesh = activeObject(); if(mesh && mesh->isReady) { // Create VBO for each segment if needed for (int i=0;i<(int)mesh->nbSegments();i++) { QSurfaceMesh* seg = mesh->getSegment(i); QString objId = seg->objectName(); if (VBO::isVBOSupported() && !vboCollection.contains(objId)) { Surface_mesh::Vertex_property<Point> points = seg->vertex_property<Point>("v:point"); Surface_mesh::Vertex_property<Point> vnormals = seg->vertex_property<Point>("v:normal"); Surface_mesh::Vertex_property<Color> vcolors = seg->vertex_property<Color>("v:color"); seg->fillTrianglesList(); // Create VBO vboCollection[objId] = VBO( seg->n_vertices(), points.data(), vnormals.data(), vcolors.data(), seg->triangles ); } } } }
QSegMesh * QMeshDoc::importObject(QString fileName) { // Get object name from file path QFileInfo fInfo (fileName); if(!fileName.size() || !fInfo.exists()) { emit(printMessage(QString("Error: invalid file (%1).").arg(fileName))); return NULL; } QString newObjId = fInfo.fileName(); newObjId.chop(4); global_id++; newObjId += QString("-%1").arg(global_id); // Create a new QSegMesh QSegMesh * newMesh = new QSegMesh(); all_objects[ newObjId ] = newMesh; // Reading QSegMesh newMesh->read(fileName); // Set global ID for the mesh and all its segments newMesh->setObjectName(newObjId); // Try to load the controller and groups with the same filename // Setup controller file name fileName.chop(3);fileName += "ctrl"; if(QFileInfo(fileName).exists()) { // Load controller newMesh->ptr["controller"] = new Controller(newMesh, true, fileName); Controller * ctrl = (Controller *)newMesh->ptr["controller"]; fileName.chop(4);fileName += "grp"; if(QFileInfo(fileName).exists()) { std::ifstream inF(qPrintable(fileName), std::ios::in); ctrl->loadGroups(inF); inF.close(); } } else { newMesh->ptr["controller"] = new Controller(newMesh); } return newMesh; }
void QMeshDoc::importObject() { Workspace * workspace = (Workspace *) parent(); if(workspace->activeScene == NULL) return; // The dialog QString fileName = QFileDialog::getOpenFileName(0, "Import Mesh", DEFAULT_FILE_PATH, "Mesh Files (*.obj *.off *.stl)"); // Read the file QSegMesh * newMesh = importObject(fileName); if (newMesh) { // Save the default path DEFAULT_FILE_PATH = QFileInfo(fileName).absolutePath(); // Emit signals emit(printMessage(newMesh->objectName() + " has been imported.")); emit(objectImported(newMesh)); } }
void QMeshDoc::importObject(QString fileName) { Workspace * workspace = (Workspace *) parent(); if(workspace->activeScene == NULL) return; // Get object name from file path QFileInfo fInfo (fileName); if(!fileName.size() || !fInfo.exists()) { emit(printMessage(QString("Error: invalid file (%1).").arg(fileName))); return; } QString newObjId = fInfo.fileName(); newObjId.chop(4); global_id++; newObjId += QString("-%1").arg(global_id); // Create a new QSegMesh QSegMesh * newMesh = new QSegMesh(); all_objects[ newObjId ] = newMesh; // Reading QSegMesh newMesh->read(fileName); // Set global ID for the mesh and all its segments newMesh->setObjectName(newObjId); // Focus active scene workspace->activeScene->setFocus(); workspace->activeScene->print(newObjId + " has been imported."); workspace->activeScene->setActiveObject(newMesh); DEFAULT_FILE_PATH = QFileInfo(fileName).absolutePath(); }