/* =============== Cmd_Cd =============== */ void Cmd_Cd (void) { char temp[256]; FinishModel (); ClearModel (); GetScriptToken (false); // this is a silly mess... sprintf (cdpartial, "models/%s", token); sprintf (cdarchive, "%smodels/%s", gamedir+strlen(qdir), token); sprintf (cddir, "%s%s", gamedir, cdpartial); // Since we also changed directories on the output side (for mirror) make sure the outputdir is set properly too. sprintf(temp, "%s%s", g_outputDir, cdpartial); strcpy(g_outputDir, temp); // if -only was specified and this cd doesn't match, // skip the model (you only need to match leading chars, // so you could regrab all monsters with -only monsters) if (!g_only[0]) return; if (strncmp(token, g_only, strlen(g_only))) { g_skipmodel = true; printf ("skipping %s\n", cdpartial); } }
void CLODConvertApp::FileOpen(CString FileName) { EditList[ModelSelected].Name=""; // Ok... Load the model CFile File; File.Open(FileName, CFile::modeRead, &CFileException(CFileException::generic, NULL)); DWORD FileSize=(DWORD)File.GetLength(); void *FileBuffer=malloc(FileSize); File.Read(FileBuffer, FileSize); FileTitle=File.GetFileTitle(); File.Close(); TheModelPath=FileName; while(RenderPhase) Delay(5); // Eventually clear the model ClearModel(&EditList[ModelSelected]); // Linearize the model and assign to selected item DeIndexModel(FileBuffer, &EditList[ModelSelected]); E_FixModelFeatures(&EditList[ModelSelected]); EditList[ModelSelected].Name=FileTitle; SetupModel(); AddToRecentFileList(FileName); }
void ModelRenderer::LoadModelGL() { Scene::Ptr scene = GetScene(); // Clear out any previously loaded model. ClearModel(); // Load the model as a scene graph resource. Scene::Ptr model = AssetImporter::ImportFile(GetResources(), model_fname_); if (!model) { return; } // Create a node in the main scene graph. node_ = scene->MakeGroup(GetBaseNode()); // Instantiate the model as a child of the newly created node. scene->MakeGroupFromScene(node_, model); // Scale and translate the model so that it fits inside a unit cube // centered at the origin. const AxisAlignedBox& box = model->Root()->WorldBoundingBox(); const QVector3D span = box.Max() - box.Min(); const float max_span = std::max(std::max(span.x(), span.y()), span.z()); const double scale_factor = 1.0 / max_span; node_->SetScale(QVector3D(scale_factor, scale_factor, scale_factor)); node_->SetTranslation(-0.5 * scale_factor * (box.Max() + box.Min())); GetViewport()->ScheduleRedraw(); }
void CMainWindow::LoadModel() { std::string modelPath = QFileDialog::getOpenFileName(this, "Open Model", "", g_GetSupported3DFormats()).toStdString(); if(modelPath.empty()) return; try { CMesh *newModel = new CMesh(); newModel->LoadMesh(modelPath); AskToSaveChanges(); m_openedModel = ""; m_rw2->SetModel(newModel); m_rw3->SetModel(newModel); if(m_model) delete m_model; m_model = newModel; ClearTextures(); m_rw2->ZoomFit(); m_rw3->ZoomFit(); UpdateView(); } catch(std::exception& e) { ClearModel(); QMessageBox::information(this, "Error", e.what()); } }
void ModelRenderer::ParamChanged(const QString& name) { if (name == "Load") { QString fname = QFileDialog::getOpenFileName(params_.get(), "Load File"); if (fname.isEmpty()) { return; } LoadModel(fname); } else if (name == "Clear") { ClearModel(); } }
void CMainWindow::on_actionLoad_Model_triggered() { std::string ivoModelPath = QFileDialog::getOpenFileName(this, "Open Ivo Model", "", "All supported formats (*.ivo *.pdo);;Ivo model (*.ivo);;Pepakura model (*.pdo)").toStdString(); if(ivoModelPath.empty()) return; AskToSaveChanges(); ClearModel(); try { if(ivoModelPath.length() >=4 && ivoModelPath.substr(ivoModelPath.length()-4) == ".ivo") { LoadFromIVO(ivoModelPath.c_str()); } else { switch(GetVersionPDO(ivoModelPath.c_str())) { case 20: LoadFromPDOv2_0(ivoModelPath.c_str()); break; default: QMessageBox::information(this, "Error", "Unsupported PDO format version!"); } } m_rw2->ZoomFit(); m_rw3->ZoomFit(); UpdateView(); } catch(std::exception& e) { ClearModel(); QMessageBox::information(this, "Error", e.what()); } }
/* =============== Cmd_Cd =============== */ void Cmd_Cd (void) { FinishModel (); ClearModel (); GetToken (false); // this is a silly mess... sprintf (cdpartial, "models/%s", token); sprintf (cdarchive, "%smodels/%s", gamedir+strlen(qdir), token); sprintf (cddir, "%s%s", gamedir, cdpartial); // if -only was specified and this cd doesn't match, // skip the model (you only need to match leading chars, // so you could regrab all monsters with -only monsters) if (!g_only[0]) return; if (strncmp(token, g_only, strlen(g_only))) { g_skipmodel = true; printf ("skipping %s\n", cdpartial); } }
void BaseApp::ReloadBundleFile(const char *filename) { #ifndef __DEMO__ /* Count the old number of cameras */ int num_images = GetNumImages(); int old_num_cameras = 0; for (int i = 0; i < num_images; i++) { if (m_image_data[i].m_camera.m_adjusted) old_num_cameras++; } /* Save the previous model */ std::vector<PointData> old_points = m_point_data; std::vector<ImageData> old_images = m_image_data; /* Load the new model */ ClearModel(); ReadBundleFile(filename); if (m_bundle_version < 0.3) FixReflectionBug(); /* Count the new number of cameras */ int num_cameras = 0; for (int i = 0; i < num_images; i++) { if (m_image_data[i].m_camera.m_adjusted) num_cameras++; } int old_num_points = old_points.size(); int new_num_points = m_point_data.size(); std::vector<v3_t> points_old_csp, points_new_csp; /* Find point correspondences */ for (int i = 0; i < old_num_points; i++) { for (int j = i - 5; j < i + 5; j++) { if (j < 0 || j >= new_num_points) continue; float *old_col = old_points[i].m_color; float *col = m_point_data[j].m_color; if (old_col[0] == col[0] && old_col[1] == col[1] && old_col[2] == col[2]) { double *old_pos = old_points[i].m_pos; double *pos = m_point_data[i].m_pos; points_old_csp.push_back(v3_new(old_pos[0], old_pos[1], old_pos[2])); points_new_csp.push_back(v3_new(pos[0], pos[1], pos[2])); goto Next; } } Next: ; } int num_csp_points = points_old_csp.size(); int num_points = old_num_cameras + num_csp_points; v3_t *left_points = new v3_t[num_points]; v3_t *right_points = new v3_t[num_points]; int count = 0; for (int i = 0; i < num_images; i++) { if (old_images[i].m_camera.m_adjusted) { double left_pos[3], right_pos[3]; m_image_data[i].m_camera.GetPosition(left_pos); old_images[i].m_camera.GetPosition(right_pos); left_points[count] = v3_new(left_pos[0], left_pos[1], left_pos[2]); right_points[count] = v3_new(right_pos[0], right_pos[1], right_pos[2]); count++; } } for (int i = 0; i < num_csp_points; i++) { left_points[count] = points_new_csp[i]; right_points[count] = points_old_csp[i]; count++; } /* Do the registration */ double T[16]; align_horn_3D(num_points, right_points, left_points, 1, T); /* Transform the world */ memcpy(m_xform, T, 16 * sizeof(double)); TransformWorldReal(); // TransformWorld(); delete [] left_points; delete [] right_points; #endif /* __DEMO__ */ }
void ModelRenderer::ShutdownGL() { params_->SetEnabled("Load", false); ClearModel(); gl_initialized_ = false; }