void My3DViewer::startLoader(){ loader=new myFileDialog(this); QString openfile=QFileDialog::getOpenFileName(this, tr("Open File"),"\CIS277",tr("OBJ files (*.obj)")); if(openfile.compare("")!=0){ string opens=openfile.toStdString(); c=new char[opens.length()+1]; for(int i=0; i<opens.length(); i++){ c[i]=opens[i]; cout<<c[i]; } //null terminated string c[opens.length()]='\0'; emit objFileName(c); } }
bool SceneParser::addTriangleMesh(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addTriangleMesh: empty node \n"; return false; } if (std::string(elementNode->tag) != "TriangleMesh") { return false; } // read filename char * cobjFileName; if (!(cobjFileName = getattributevaluebyname(elementNode, "OBJFileName"))) { std::cerr << "SceneParser::addTriangleMesh: no file specified!" << "\n"; return false; } // build obj object std::string objFileName(cobjFileName); char * attributeValue; Vector3 translate; translate[0]=0.0;translate[1]=0.0;translate[2]=0.0; if (attributeValue = getattributevaluebyname(elementNode, "translateFromOrigin")) { if (!stringToVector3<double>(translate, attributeValue)) { return false; } } double newRadius=1.0; if (attributeValue = getattributevaluebyname(elementNode, "radius")) { if (!stringToNumber<double>(newRadius, attributeValue)) { return false; } } Material* material; struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); if(materialNode) { material = getMaterialReference(materialNode, scene); } // set Texture struct basicxmlnode * textureNode = getchildnodebyname(elementNode, "Texture"); ITexture* textureImage = getTextureReference(textureNode, scene); // set Bumpmap struct basicxmlnode * bumpmapNode = getchildnodebyname(elementNode, "Bumpmap"); ITexture* bumpmap = getTextureReference(bumpmapNode, scene); Vector4 color = Vector4(1,0,0,1); double reflectionPercentage = 0; if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { return false; } } double refractionPercentage = 0; double refractionIndex = 1; if (attributeValue = getattributevaluebyname(elementNode, "refractionPercentage")) { if (!stringToNumber<double>(refractionPercentage, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "refractionIndex")) { if (!stringToNumber<double>(refractionIndex, attributeValue)) { return false; } } Mesh *m = new Mesh(scene,0,0); scene->addMesh(m); bool readSuccess = Mesh3DReader::read(objFileName,*m); if (!readSuccess) { std::cerr << "SceneParser::addTriangleMesh: Error while importing from Obj file: "<< objFileName << "\n"; return false; } /* bool readVertexNormals = false; bool readTexture = false; readOBJFile(objFileName,m,scene,readVertexNormals,readTexture); if(!readVertexNormals) { calcVertexNormals(m); } */ preprocessing(m,newRadius,translate); for(unsigned int i=0;i<m->numberOfFaces();i++) { m->getFace(i)->setTexture(textureImage); m->getFace(i)->setBumpmap(bumpmap); m->getFace(i)->setColor(color); m->getFace(i)->setMaterial(material); m->getFace(i)->setReflectionPercentage(reflectionPercentage); m->getFace(i)->setRefractionPercentage(refractionPercentage); m->getFace(i)->setRefractionIndex(refractionIndex); } return true; }