AbstractModel* WavefrontLoader::load(const char* str) { WavefrontModel* m = new WavefrontModel(); m->setName(str); #ifndef SERVER std::ifstream file; file.open(str); std::stringstream ss(std::stringstream::in | std::stringstream::out); std::string line; std::string value; if (file.is_open()) { //std::cout << "file is open" << std::endl; while (!file.eof()) { getline(file, line); ss.clear(); ss.str(line); value = ""; ss >> value; //std::cout << "line is " << value << std::endl; //std::cout << "ss is " << ss.str() << std::endl; if (value.compare("mtllib") == 0) { //std::cout << "mtllib not supported yet" << std::endl; } else if (value.compare("o") == 0) { //std::cout << "o not supported yet" << std::endl; } else if (value.compare("#") == 0) { //std::cout << "# not supported yet" << std::endl; } else if (value.compare("usemtl") == 0) { //std::cout << "usemtl not supported yet" << std::endl; } else if (value.compare("s") == 0) { //std::cout << "s not supported yet" << std::endl; } else if (value.compare("v") == 0) { //std::cout << "adding vertex" << std::endl; std::string tmp = ss.str().substr(2); handleVertex(m, tmp); } else if (value.compare("f") == 0) { //std::cout << "adding face" << std::endl; std::string tmp = ss.str().substr(2); handleFace(m, tmp); } else if (value.compare("vn") == 0) { //std::cout << "adding face" << std::endl; std::string tmp = ss.str().substr(2); handleNormal(m, tmp); } else if (value.compare("vt") == 0) { //std::cout << "adding face" << std::endl; std::string tmp = ss.str().substr(2); handleTexture(m, tmp); } } } #endif //m->print(); AbstractModel* a = m; return a; }
void BrepHandler::extractFace(const DirectoryEntry* de, bool orientWithSurface) { // spec says the surface can be: // parametric spline surface // ruled surface // surface of revolution // tabulated cylinder // rational b-spline surface // offset surface // plane surface // rccyl surface // rccone surface // spherical surface // toroidal surface debug("########################## E X T R A C T F A C E"); ParameterData params; _iges->getParameter(de->paramData(), params); Pointer surfaceDE = params.getPointer(1); int surf = extractSurface(_iges->getDirectoryEntry(surfaceDE)); int face = handleFace(orientWithSurface, surf); int numLoops = params.getInteger(2); bool isOuter = params.getLogical(3) || true; // outer is not set in IGES from Pro/E! for (int i = 4; (i-4) < numLoops; i++) { Pointer loopDE = params.getPointer(i); extractLoop(_iges->getDirectoryEntry(loopDE), isOuter, face); isOuter = false; } }
void AWavefrontDecoder::readObjects() { DEBUG_OUT<<"AWavefrontDecoder::readObjects()...\n"; if(!fd) return; //if(errorFlag) return; verts=new AList[nframes]; if(!verts) return; hasvns=false; hasvts=false; fseek(fd,0L,SEEK_SET); char *line=(char *)malloc(256); int a,b; //int c,d; float fa,fb,fc; bool reading=true; AVertexF3D *theVert=NULL; ATextCoord3D *theTC=NULL; AFace3D *theFace=NULL; unsigned int nvertnormals=0; while(reading) { if(feof(fd)) { reading=false; break; } fgets(line,256,fd); stringHelp.parseString(line,NULL,false,'\\'); switch(line[0]) { case '#': case ' ': case '\n': // Comment or white space break; case 's': // ???, not handled break; case 'o': // Object name(?), not handled break; case 'g': // Group name, not handled // May have name or not, faces that follow go into that group, may be repeated, out of order, etc. break; case 'u': // Probably usemtl, not handled // material to use for following faces break; case 'm': // Probably mtllib, not handled // name of material library break; case 'v': fa=0.0; fb=0.0; fc=0.0; switch(line[1]) { case ' ': case '\t': fa=0.0; fb=0.0; fc=0.0; sscanf(line+1,"%f %f %f",&fa,&fb,&fc); DEBUG_OUT<<"v: "<<fa<<","<<fb<<","<<fc<<"\n"; theVert=new AVertexF3D; theVert->x=fa; theVert->y=fb; theVert->z=fc; verts[0].append(theVert); nverts++; break; case 't': fa=0.0; fb=0.0; fc=0.0; sscanf(line+1,"%f %f",&fa,&fb); DEBUG_OUT<<"vt: "<<fa<<","<<fb<<"\n"; theTC=new ATextCoord3D; theTC->u=fa; theTC->v=fb; textCoords.append(theTC); ntextcoords++; hasvts=true; break; case 'n': fa=0.0; fb=0.0; fc=0.0; sscanf(line+1,"%f %f %f",&fa,&fb,&fc); DEBUG_OUT<<"vn: "<<fa<<","<<fb<<","<<fc<<"\n"; theVert=new AVertexF3D; theVert->x=fa; theVert->y=fb; theVert->z=fc; vertNormals.append(theVert); nvertnormals++; hasvns=true; break; default: break; } break; case 'l': // A line outside of a face, convert to a flat triangle a=0; b=0; sscanf(line+1,"%d %d\n",&a,&b); DEBUG_OUT<<"l: "<<a<<","<<b<<"\n"; theFace=new AFace3D; theFace->a=a-1; theFace->b=b-1; theFace->c=b-1; theFace->surf=0; faces.append(theFace); nfaces++; break; case 'f': nfaces+=handleFace(&faces,1,-1,0); break; default: DEBUG_OUT<<"Got "<<line[0]<<" unknown token...\n"; break; } } // TODO: Check nvertnormals is either 0 or equal to nverts }