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 TrayTracer::generate(TrayTracer::Policy policy) { for (int y = 0; y < m_bufferHeight; y++) { fprintf(stderr,"\rRendering: %5.2f%% .",100.0f*y/(m_bufferHeight)); auto sy = 1- 1.0*y / m_bufferHeight; for (int x = 0; x < m_bufferWidth; x++) { auto sx = 1.0*x / m_bufferWidth; auto ray = camera()->generateRay(sx, sy); Tcolor color(0,0,0); switch(policy) { case Policy::CUSTOM: break; case Policy::DEPTH: color = handleDepth (ray); break; case Policy::DIRECT_LIGHT: break; case Policy::NORMAL: color = handleNormal(ray); break; case Policy::RAY_TRACING_EXPLICIT_LIGHT: color = radianceWithExplicitLight(ray,3); break; case Policy::PATH_TRACING: { int sampleNums = 200; for(int sampeIndex = 0; sampeIndex < sampleNums; sampeIndex ++) { color += radiancePathTracer(ray,3) / (1.0f *sampleNums); } } break; } setPixelAt (x,y,color); } } printf("\nGenearted.\n"); }