ModelPtr ResourceLoader::getModel(const char *fname, CMap *c) { for (Common::List<Model *>::const_iterator i = _models.begin(); i != _models.end(); ++i) { Model *m = *i; if (strcmp(fname, m->_fname.c_str()) == 0 && *m->_cmap == *c) { return m; } } return loadModel(fname, c); }
void TopazSample::initRendering() { if (!GLEW_ARB_bindless_texture) { LOGI("This sample requires ARB_bindless_texture"); exit(EXIT_FAILURE); } bindlessVboUbo = GLEW_NV_vertex_buffer_unified_memory && requireExtension("GL_NV_uniform_buffer_unified_memory", false); NvAssetLoaderAddSearchPath("Topaz/Topaz"); if(!requireMinAPIVersion(NvGfxAPIVersionGL4_4(), true)) { exit(EXIT_FAILURE); } compileShaders("draw", "shaders/vertex.glsl", "shaders/fragment.glsl"); /* If needed geometry shader: compileShaders("geometry", "shaders/vertex.glsl", "shaders/fragment.glsl", "shaders/geometry.glsl"); */ compileShaders("weightBlended", "shaders/vertex.glsl", "shaders/fragmentBlendOIT.glsl"); compileShaders("weightBlendedFinal", "shaders/vertexOIT.glsl", "shaders/fragmentFinalOIT.glsl"); // like as glClearBufferfv for nv_command_list compileShaders("clear", "shaders/vertexOIT.glsl", "shaders/clear.glsl"); loadModel("models/background.obj", shaderPrograms["draw"]->getProgram()); loadModel("models/way3.obj", shaderPrograms["draw"]->getProgram(), true); loadModel("models/way4.obj", shaderPrograms["draw"]->getProgram(), true); loadModel("models/way5.obj", shaderPrograms["draw"]->getProgram()); loadModel("models/formular.obj", shaderPrograms["draw"]->getProgram()); textures.skybox = NvImage::UploadTextureFromDDSFile("textures/sky_cube.dds"); cmdlist.state.programIncarnation++; CHECK_GL_ERROR(); }
void Cal3dNode::setField(const char *fieldName, const VrmlField &fieldValue) { if TRY_FIELD(core, SFNode) else if TRY_FIELD(materialSet, SFInt) else if TRY_FIELD(animationId, SFInt) else if TRY_FIELD(executeAction, SFInt) else if TRY_FIELD(animationWeight, SFFloat) else if TRY_FIELD(animationOffset, SFFloat) else if TRY_FIELD(animationBlendTime, SFFloat) else if TRY_FIELD(fadeInTime, SFFloat) else if TRY_FIELD(fadeOutTime, SFFloat) else VrmlNodeChild::setField(fieldName, fieldValue); if (strcmp("core", fieldName) == 0) { loadModel((Cal3dCore *)d_core.get()); } /* else if ((strcmp(fieldName, "materialSet") == 0)) { myNode->materialSet = d_materialSet.get(); }*/ else if ((strcmp(fieldName, "executeAction") == 0)) { model->executeAction(d_executeAction.get(), d_fadeInTime.get(), d_fadeOutTime.get()); } else if ((strcmp(fieldName, "animationId") == 0)) { if (currentAnimation != -1) { model->clearCycle(currentAnimation, d_animationBlendTime.get()); // clear in 1sec } currentAnimation = d_animationId.get(); if (currentAnimation == -1) { model->clearCycle(currentAnimation, 0.0); // clear now } model->blendCycle(currentAnimation, d_animationWeight.get(), d_animationBlendTime.get()); } else if ((strcmp(fieldName, "animationOffset") == 0)) { osgCal::ModelData *md = (osgCal::ModelData *)model->getModelData(); md->getCalMixer()->updateAnimation(d_animationOffset.get()); } }
// Create a new 3D Object by loading the data from a .obj file Object3D::Object3D(std::string path) { name = path; loadModel(path); location.x = 1.0; location.y = 1.0; location.z = 0.0; rotation = 0; scale = 40.0f; printStats(); }
Bubble::Bubble(const Aquarium& aquarium, const Eigen::Vector3f& startpos, float radius, bool wiggle) : Object(loadModel("", "icosphere-2"), startpos), wiggleStartX(my_random() * 100), wiggleStartZ(my_random() * 100), wiggle(wiggle), velocity(-3 + my_random() * 6, 10, -3 + my_random() * 6), pop(1 + my_random() * 0.8), aquarium(aquarium) { scale = radius; }
////////////////////////////////////////////////////////////////////////// //@intro 当前控件构造器 //@param model:三维模型 //@param parent:当前控件的父控件 ////////////////////////////////////////////////////////////////////////// GLTextureArea::GLTextureArea(GLModel* model, QWidget *parent) { loadModel(model); setMouseTracking(true); setFocusPolicy(Qt::ClickFocus); mLeftKeyPressed = false; oldX = oldY = 0; mSelectedSliceIndex = -1; mTranslateX = mTranslateY = 0; mControlPointSelected = false; }
void MyGLWidget::initializeGL() { glEnable(GL_DEPTH_TEST); // Activate depth comparisons and update depth buffer glEnable(GL_CULL_FACE); // Draw Front or Back? glDepthFunc(GL_LEQUAL); // Specify the depth buffer //glShadeModel(GL_SMOOTH); // !Deprecated GL_FLAT or GL_SMOOTH (interpolated) glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Are there Interpretations? Set hint! glClearDepth(1.0f); // Clear value for depth buffer (used by glClear) glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear values used by glClear (Color-Buffer)(); loadModel(); initializeTextures(); initalizeBuffer(); initalizeShader(); initializePlanets(); attrVertices = shaderProgram.attributeLocation("vert"); // #version 130 attrTexCoords = shaderProgram.attributeLocation("texCoord"); // #version 130 // Aktiviere die Verwendung der Attribute-Arrays shaderProgram.enableAttributeArray(attrVertices); shaderProgram.enableAttributeArray(attrTexCoords); // Laden der // Ein paar Hilfsvariablen - die 8 steht für // 4 Eckpunktkoordinaten + 4 Texturkoordinaten int offset = 0 ; size_t stride = 8 * sizeof(GLfloat); shaderProgram.setAttributeBuffer(attrVertices,GL_FLOAT,offset,4,stride); offset += 4*sizeof(GLfloat); shaderProgram.setAttributeBuffer(attrTexCoords,GL_FLOAT,offset,4,stride); // Lokalisiere bzw. definierte die Schnittstelle für die Matritzen // Die Matrix kann direkt übergeben werden, da setUniformValue für diesen Typ überladen ist. unifMatrixPerspective = shaderProgram.uniformLocation("perspectiveMatrix"); Q_ASSERT(unifMatrixPerspective >= 0) ; unifMatrixModel = shaderProgram.uniformLocation("modelMatrix"); Q_ASSERT(unifMatrixModel >= 0) ; unifMatrixView = shaderProgram.uniformLocation("viewlMatrix"); Q_ASSERT(unifMatrixView >= 0) ; //qTex->bind(); }
ImportModelDialog::ImportModelDialog(QWidget *parent) : QDialog(parent) { ui.setupUi(this); this->setModal(true); connect(ui.importModel, SIGNAL(clicked()), this, SLOT(loadModel())); connect(ui.importTexture, SIGNAL(clicked()), this, SLOT(loadTextures())); connect(ui.okAction, SIGNAL(clicked()), this, SLOT(ok())); connect(ui.cancelAction, SIGNAL(clicked()), this, SLOT(cancel())); }
void MainWindow::actionImport_Connectors() { if (m_model.meshes() == 0) return; QString conn_path = QFileDialog::getOpenFileName(this, "Locate source file", m_pathImport, "PIE models (*.pie);;Any file (*.*)"); if (conn_path.isEmpty()) return; ModelInfo newinfo; WZM newmodel; if (!loadModel(conn_path, newmodel, newinfo)) return; bool need_ask_about_replacement = true; bool replace_current_ones = false; int maxmeshes = std::max(newmodel.meshes(), m_model.meshes()); for (int i = 0; i < maxmeshes; ++i) { const Mesh& src_mesh = newmodel.getMesh(i); if (!src_mesh.connectors()) continue; Mesh& tgt_mesh = m_model.getMesh(i); if (tgt_mesh.connectors()) { if (need_ask_about_replacement) { need_ask_about_replacement = false; QMessageBox::StandardButton reply; reply = QMessageBox::question(this, "", tr("Do you want to replace any existing connectors?")); if (reply == QMessageBox::Yes) replace_current_ones = true; } if (!replace_current_ones) continue; } tgt_mesh.replaceConnectors(src_mesh); } // Update related view updateConnectorsView(); // And notify model info about new connectors m_modelinfo.m_pieCaps.set(PIE_OPT_DIRECTIVES::podCONNECTORS); }
ModelPtr ResourceLoader::getModel(const Common::String &fname, CMap *c) { Common::String filename = fname; filename.toLowercase(); for (Common::List<Model *>::const_iterator i = _models.begin(); i != _models.end(); ++i) { Model *m = *i; if (filename == m->_fname && *m->_cmap == *c) { return m; } } return loadModel(fname, c); }
Object3DS::Object3DS(Vertex3D startPosition, string modelFileName, Vertex3D startRot) { //start position. mPosition = startPosition; mRotate = startRot; //3ds file to load std::strcpy(filename, modelFileName.c_str()); loadModel(); }
TEST_F(OsgSkeletonRepresentationRenderTests, WithNeutralPoseTest) { auto graphics = std::make_shared<SurgSim::Graphics::OsgSkeletonRepresentation>("Skeleton"); graphics->loadModel("OsgSkeletonRepresentationRenderTests/rigged_cylinder.osgt"); graphics->setSkinningShaderFileName("Shaders/skinning.vert"); graphics->setNeutralBonePose("Bone", makeRigidTransform(makeRotationQuaternion(M_PI_4, Vector3d(1.0, 1.0, 1.0)), Vector3d::Zero())); auto sceneElement = std::make_shared<SurgSim::Framework::BasicSceneElement>("Rigged Cylinder"); sceneElement->addComponent(graphics); scene->addSceneElement(sceneElement); viewElement->setPose(SurgSim::Math::makeRigidTransform( Vector3d(-0.3, 0.3, -0.3), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 0.0, 1.0))); runtime->start(); boost::this_thread::sleep(boost::posix_time::milliseconds(2000)); std::pair<RigidTransform3d, RigidTransform3d> rootTransform; rootTransform.first = makeRigidTransform(makeRotationQuaternion(0.0, Vector3d(1.0, 1.0, 1.0)), Vector3d::Zero()); rootTransform.second = makeRigidTransform(makeRotationQuaternion(0.0, Vector3d(1.0, 1.0, 1.0)), Vector3d::Zero()); std::pair<RigidTransform3d, RigidTransform3d> boneTransform; boneTransform.first = makeRigidTransform(makeRotationQuaternion(0.0, Vector3d(1.0, 0.0, 0.0)), Vector3d::Zero()); boneTransform.second = makeRigidTransform(makeRotationQuaternion(0.0, Vector3d(1.0, 0.0, 0.0)), Vector3d(0.0, 4.0, 0.0)); int numSteps = 1000; for (int i = 0; i < numSteps; ++i) { double t = static_cast<double>(i) / numSteps; RigidTransform3d pose = interpolate(rootTransform, t); sceneElement->setPose(pose); pose = interpolate(boneTransform, t / 3.0); graphics->setBonePose("Bone", RigidTransform3d::Identity()); graphics->setBonePose("Bone_001", pose); graphics->setBonePose("Bone_002", pose); graphics->setBonePose("Bone_003", pose); /// The total number of steps should complete in 5 seconds boost::this_thread::sleep(boost::posix_time::milliseconds(5000 / numSteps)); } runtime->stop(); }
void ObjectDisplay::init(string fileName, string picName, string picAlphaName) {//for the object with alpha value reading from a picture HeadOrNot = false; objName.assign(fileName); textureName.push_back(picName); //we will use alpha value when loading texture transparent = true; loadModel(); loadTexture(picAlphaName); }
// Called every time there is a window event void AppWindow::glutKeyboard ( unsigned char key, int x, int y ) { switch ( key ) { case ' ': camera = !camera; redraw(); break; case 27 : exit(1); // Esc was pressed /*case 's' : std::cout<<"Smoothing normals...\n"; _gsm.smooth ( GS_TORAD(35) ); printInfo(_gsm); _model.build(_gsm); redraw(); break;*/ case 'f' : std::cout<<"Flat normals...\n"; _gsm.flat(); printInfo(_gsm); _model.build(_gsm); redraw(); break; case 'p' : if ( !_model.phong() ) { std::cout<<"Switching to phong shader...\n"; _model.phong(true); } redraw(); break; case 'g' : if ( _model.phong() ) { std::cout<<"Switching to gouraud shader...\n"; _model.phong(false); } redraw(); break; case 'e': rotate += 1; redraw(); break; case 'q': rotate -= 1; redraw(); break; case 'w': _turnud -= 1; redraw(); break; case 's': _turnud += 1; redraw(); break; case 'a': _turnlr += 1; redraw(); break; case 'd': _turnlr -= 1; redraw(); break; case '[': speed -= .001; redraw(); break; case '\'': speed += .001; redraw(); break; case 'n': _wingsflyR++; redraw(); break; case 'm': _wingsflyR--; redraw(); break; case 'b': _wingsflyL++; redraw(); break; case 'v': _wingsflyL--; redraw(); break; case 'l': _backR++; redraw(); break; case 'k': _backR--; redraw(); break; case 'j': _backL++; redraw(); break; case 'h': _backL--; redraw(); break; case 'y': sunanim = !sunanim; redraw(); break; case 't': if (!animate) { animate = true; resetanim = false; } else resetanim = true; redraw(); break; default : loadModel ( int(key-'0') ); break; } }
/*! Re-initialize the model used by the tracker. \param I : The image containing the object to initialize. \param cad_name : Path to the file containing the 3D model description. \param cMo_ : The new vpHomogeneousMatrix between the camera and the new model \param verbose : verbose option to print additional information when loading CAO model files which include other CAO model files. */ void vpMbKltTracker::reInitModel(const vpImage<unsigned char>& I, const char* cad_name, const vpHomogeneousMatrix& cMo_, const bool verbose) { this->cMo.eye(); #if (VISP_HAVE_OPENCV_VERSION < 0x020408) if(cur != NULL){ cvReleaseImage(&cur); cur = NULL; } #endif firstInitialisation = true; // delete the Klt Polygon features vpMbtDistanceKltPoints *kltpoly; for(std::list<vpMbtDistanceKltPoints*>::const_iterator it=kltPolygons.begin(); it!=kltPolygons.end(); ++it){ kltpoly = *it; if (kltpoly!=NULL){ delete kltpoly ; } kltpoly = NULL ; } kltPolygons.clear(); vpMbtDistanceKltCylinder *kltPolyCylinder; for(std::list<vpMbtDistanceKltCylinder*>::const_iterator it=kltCylinders.begin(); it!=kltCylinders.end(); ++it){ kltPolyCylinder = *it; if (kltPolyCylinder!=NULL){ delete kltPolyCylinder ; } kltPolyCylinder = NULL ; } kltCylinders.clear(); // delete the structures used to display circles vpMbtDistanceCircle *ci; for(std::list<vpMbtDistanceCircle*>::const_iterator it=circles_disp.begin(); it!=circles_disp.end(); ++it){ ci = *it; if (ci!=NULL){ delete ci ; } ci = NULL ; } faces.reset(); loadModel(cad_name, verbose); initFromPose(I, cMo_); }
void shot_detector::processImage() { std::cerr << "Processing" << std::endl; std::string file = "/home/niko/projects/apc/catkin/src/apc_ros/apc_object_detection/visual_hull_refined_smoothed.obj"; loadModel(model, file); pcl::io::loadPCDFile("/home/niko/projects/apc/catkin/src/apc_ros/apc_object_detection/niko_file.pcd", *scene); //Downsample the model and the scene so they have rougly the same resolution pcl::PointCloud<PointType>::Ptr scene_filter (new pcl::PointCloud<PointType> ()); pcl_functions::voxelFilter(scene, scene_filter, voxel_sample_); scene = scene_filter; pcl::PointCloud<PointType>::Ptr model_filter (new pcl::PointCloud<PointType> ()); pcl_functions::voxelFilter(model, model_filter, voxel_sample_); model = model_filter; // Randomly select a couple of keypoints so we don't calculte descriptors for everything sampleKeypoints(model, model_keypoints, model_ss_); sampleKeypoints(scene, scene_keypoints, scene_ss_); //Calculate the Normals calcNormals(model, model_normals); calcNormals(scene, scene_normals); pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>); ourcvfh.setInputCloud(scene); ourcvfh.setInputNormals(scene_normals); ourcvfh.setSearchMethod(kdtree); ourcvfh.setEPSAngleThreshold(5.0 / 180.0 * M_PI); // 5 degrees. ourcvfh.setCurvatureThreshold(1.0); ourcvfh.setNormalizeBins(false); // Set the minimum axis ratio between the SGURF axes. At the disambiguation phase, // this will decide if additional Reference Frames need to be created, if ambiguous. ourcvfh.setAxisRatio(0.8); ourcvfh.compute(vfh_scene_descriptors); ourcvfh.setInputCloud(model); ourcvfh.setInputNormals(model_normals); ourcvfh.compute(vfh_model_descriptors); //Calculate the shot descriptors at each keypoint in the scene calcSHOTDescriptors(model, model_keypoints, model_normals, model_descriptors); calcSHOTDescriptors(scene, scene_keypoints, scene_normals, scene_descriptors); // Compare descriptors and try to find correspondences //ransac(rototranslations,model,scene); //refinePose(rototranslations,model,scene); compare(model_descriptors, scene_descriptors); groupCorrespondences(); visualizeCorrespondences(); visualizeICP(); /*Eigen::Matrix4f pose; if(model_scene_corrs->size ()!=0){ groupCorrespondences(); ransac(rototranslations,model,scene); pose=refinePose(rototranslations,model,scene); }*/ }
void T3kSoftlogicDlg::on_BtnSave_clicked() { m_pTabPanelWidget->updateDataFromUI(); T3kCommonData::KeyDataMode eMode = T3kCommonData::instance()->getKeyDataMode(); T3kCommonData::instance()->setKeyDataMode( T3kCommonData::KeyDataModeNormal ); QString strPanelName = T3kCommonData::instance()->getKeys().getPanelName(); T3kCommonData::instance()->setKeyDataMode( eMode ); if( strPanelName.isEmpty() ) { QMessageBox msg( QMessageBox::Critical, "Error", "Panel Name is required.", QMessageBox::Ok, this ); msg.exec(); setFocusPanelName(); return; } QString strModelName( m_strLoadedModelPathName.right( m_strLoadedModelPathName.length() - m_strLoadedModelPathName.lastIndexOf('/') - 1 ) ); int nIdx = strModelName.indexOf( '.' ); strModelName = strModelName.left( nIdx ); if( m_strLoadedModelPathName.isEmpty() || strModelName != strPanelName ) { QString strFileName = strPanelName; strFileName += ".hsk"; QString strDir( QApplication::applicationDirPath() ); if( !m_strLoadedModelPathName.isEmpty() ) { int nBP = m_strLoadedModelPathName.lastIndexOf( '/' ); strDir = m_strLoadedModelPathName.left( nBP+1 ); } QString strSave = QFileDialog::getSaveFileName( this, "Save", strDir, "Files(*.hsk)", &strFileName ); if( strSave.isEmpty() ) return; m_strLoadedModelPathName = strSave; } saveModel( m_strLoadedModelPathName ); QString strLoad = m_strLoadedModelPathName; loadModel( strLoad ); m_pTabPanelWidget->updateUIFromData(); onUpdatePrewview(); T3kCommonData::instance()->resetCalibrationData(); //m_wndTab.ResetNotify(); }
int CFFLD::detector( Mat img, string strModelFile, float threshold, vector<DetectionResult> & result ) { // For xml model; CvLSVMFilterObject** filters = 0; int kFilters = 0; int kComponents = 0; int* kPartFilters = 0; float* b = 0; float scoreThreshold = 0.f; int err_code = 0; Object::Name name = Object::PERSON; string results; string images("."); int nbNegativeScenes = -1; int padding = 12; int interval = 10; //double threshold =-0.50; double overlap = 0.5; // load xml file err_code = loadModel( strModelFile.c_str(), &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold ); if( err_code != 0 ) { cout<<"Invalid xml model file."<<endl; return 0; } Mixture mixture; mixture.importFromOpenCVModel( kFilters, kComponents, kPartFilters, b, filters ); JPEGImage image( img ); HOGPyramid pyramid(image, padding, padding, interval); // Initialize the Patchwork class if ( !Patchwork::Init((pyramid.levels()[0].rows() - padding + 15) & ~15, (pyramid.levels()[0].cols() - padding + 15) & ~15) ) { cerr << "\nCould not initialize the Patchwork class" << endl; return -1; } mixture.cacheFilters(); // Compute the detections vector<Detection> detections; ofstream out; string file; detect(mixture, image.width(), image.height(), pyramid, threshold, overlap, file, out, images, detections, result ); }
Terrain::Terrain() { drawable = true; std::vector<Program::Shader> shaders = { {GL_VERTEX_SHADER, "glsl/terrain.vert.glsl", 0}, {GL_TESS_CONTROL_SHADER, "glsl/terrain.cont.glsl", 0}, {GL_TESS_EVALUATION_SHADER, "glsl/terrain.eval.glsl", 0}, {GL_FRAGMENT_SHADER, "glsl/terrain.frag.glsl", 0}, }; program = Program::newProgram(shaders); vao = std::make_shared<VAO>(); loadModel(); }
void ObjectDisplay::init(string fileName, string picName, int translucent) {//for the object with translucent value (such as glasses lenses) HeadOrNot = false; objName.assign(fileName); textureName.push_back(picName); //we will use alpha value when loading texture transparent = true; alpha = translucent; loadModel(); loadTexture(); }
void IBLWidget::initializeGL() { glcontext->makeCurrent(this); model = new SimpleModel(); loadIBL( (getProbesPath() + "beach.penv").c_str() ); loadModel( (getModelsPath() + "sphere.obj").c_str() ); // load the shaders resultShader = new DGLShader( (getShaderTemplatesPath() + "Quad.vert").c_str(), (getShaderTemplatesPath() + "IBLResult.frag").c_str() ); compShader = new DGLShader( (getShaderTemplatesPath() + "Quad.vert").c_str(), (getShaderTemplatesPath() + "IBLComp.frag").c_str() ); }
void ObjectWorld::initialize(){ ml->addListener(me_eventListener); ml->initialize(); ot = SP<OctTree>(new OctTree(16)); ot_dynamic_model = SP<OctTreeFast>(new OctTreeFast(16)); ot_dynamic_lights = SP<OctTreeFast>(new OctTreeFast(16)); //preload the light model... // maybe in a later version of the engine generate the light mesh.... light_model = SP<Model>(new Model()); light_model->set_path(light_model_path); loadModel(light_model); //preload the unitcube... unitcube_model = SP<Model>(new Model()); unitcube_model->set_path(unitcube_model_path); loadModel(unitcube_model); }
void ObjectDisplay::init(string fileName, string picName) {//for the object without translucent and using one picture as texture HeadOrNot = false; objName.assign(fileName); textureName.push_back(picName); //we will use alpha value when loading texture transparent = false; alpha = 255; loadModel(); loadTexture(); }
PModel MainLoop::loadPrevious(bool erase) { vector<View::ListElem> options; vector<SaveFileInfo> files; getSaveOptions({ {Model::GameType::AUTOSAVE, "Recovered games:"}, {Model::GameType::KEEPER, "Keeper games:"}, {Model::GameType::ADVENTURER, "Adventurer games:"}}, options, files); optional<SaveFileInfo> savedGame = chooseSaveFile(options, files, "No save files found.", view); if (savedGame) return loadModel(savedGame->filename, erase); else return nullptr; }
void loadMD2Models() { loadModel(&skeletor, "skeletor/tris.md2", "skeletor/hueteotl.tga", 1.0f, 5); loadModel(&guy, "Sodf8/Tris.MD2", "Sodf8/Abarlith.pcx", 1.0f, 15); loadModel(&van, "van/tris.md2", "van/van.tga", 0.3f, 0); loadModel(&motor, "motor/motor.md2", "motor/motor.tga", 1.0f, 0); loadModel(&plant, "plant/plant.md2", "plant/plant.tga", 1.0f, 0); loadModel(&plant2, "plant2/plant2.md2", "plant2/plant2.tga", 1.0f, 0); }
Resource *ResourceManager::_load(std::string filename) { Json::Reader reader(Json::Features::strictMode()); Json::Value root; if (not reader.parse(readFile(filename), root)) { std::cout << reader.getFormattedErrorMessages() << std::endl; return NULL; } std::unordered_map<std::string, ResPtr<Resource> > externalResources; if (root.isMember("external resources")) { Json::Value externResVal = root["external resources"]; Json::Value::Members members = externResVal.getMemberNames(); for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it) { std::string name = *it; ResPtr<Resource> resource = load(externResVal[name].asString()); externalResources[name] = resource; } } std::string resourceType = root["type"].asString(); if (resourceType == "texture") { return loadTexture(getMember(root, "texture"), externalResources); } else if (resourceType == "model") { return loadModel(getMember(root, "model"), externalResources); } else if (resourceType == "mesh") { return loadMesh(getMember(root, "mesh"), externalResources); } else if (resourceType == "shader") { return loadShader(getMember(root, "shader"), externalResources); } else if (resourceType == "material") { return loadMaterial(getMember(root, "material"), externalResources); } else { throw std::runtime_error("Unknown resource type."); } }
void vModel::init() { loadModel("../models/trup.obj"); loadTexture("../models/trup.jpg"); glNewList(1, GL_COMPILE); glBegin(GL_TRIANGLES); for(int i=0; i < numVerts; i++) { glTexCoord2d(uvArray[2*i], 1-uvArray[2*i+1]); glNormal3f(normalArray[3*i],normalArray[3*i+1],normalArray[3*i+2]); glVertex3f(vertexArray[3*i],vertexArray[3*i+1],vertexArray[3*i+2]); } glEnd(); glEndList(); }
void CBoard::init( float Width, float Length, float Thickness, float R, float G, float B, string board_texture_image ){ width=Width; length=Length; thickness=Thickness; r = R; g = G; b = B; loadModel( ); // make display display lists out of the board's 3D model board_texture.makeTexture( board_texture_image, PNG ); return; }
// Create scene. Load model from a file void GLWidget::createScene(const QString &filename) { QFileInfo fi(filename); QString ext = fi.suffix(); if(ext == "tsm") { _glc_world = loadTSMFile(filename); isSet = false; } else if(ext == "obj" || ext == "stl" || ext == "off") { _glc_world = loadModel(filename); isSet = false; } }
//------------------------------------------ bool ofxAssimpModelLoader::loadModel(string modelName, bool optimize){ file.open(modelName); if(!file.exists()) { ofLog(OF_LOG_VERBOSE, "%s is not found.", modelName.c_str()); return false; } ofLog(OF_LOG_VERBOSE, "loading model %s", file.getFileName().c_str()); ofLog(OF_LOG_VERBOSE, "loading from folder %s", file.getEnclosingDirectory().c_str()); ofBuffer buffer = file.readToBuffer(); bool bOk = loadModel(buffer, optimize, file.getExtension().c_str()); return bOk; }